/* Alevel Mail — estilos de la app (sin framework). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1c2129;
  --muted: #667085;
  --primary: #3b5bdb;
  --primary-ink: #ffffff;
  --primary-soft: #e8edff;
  --danger: #c92a2a;
  --danger-soft: #fdecec;
  --ok: #2b8a3e;
  --ok-soft: #e6f4ea;
  --unread: #101828;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 8px 24px rgb(16 24 40 / 8%);
  --radius: 10px;
  --topbar-h: 60px;
  --sidebar-w: 236px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111318;
    --surface: #181b22;
    --surface-2: #20242d;
    --border: #2b303b;
    --text: #e6e8ec;
    --muted: #9aa3b2;
    --primary: #7b93ff;
    --primary-ink: #0d1020;
    --primary-soft: #232a45;
    --danger: #ff8787;
    --danger-soft: #3a1f22;
    --ok: #69db7c;
    --ok-soft: #1c3324;
    --unread: #ffffff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spacer { flex: 1; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger-text { color: var(--danger); }
form.button_to { display: inline; }

/* Formularios */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }
.field small { font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; line-height: 1.5; }
.field-row { display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.field-row input { border: 0; padding: 4px 0; box-shadow: none !important; background: transparent; }
.field-label { width: 88px; flex: none; color: var(--muted); }
.form-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.file-input { font-size: 13px; color: var(--muted); max-width: 100%; }
.input-affix { display: flex; align-items: stretch; }
.input-affix input { border-radius: 8px 0 0 8px; }
.affix { display: flex; align-items: center; padding: 0 10px; background: var(--surface-2); border: 1px solid var(--border); border-left: 0; border-radius: 0 8px 8px 0; color: var(--muted); font-weight: 400; white-space: nowrap; }

/* Flash y badges */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash-alert { background: var(--danger-soft); color: var(--danger); }
.flash-notice { background: var(--ok-soft); color: var(--ok); }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* Avatar */
.avatar {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: inline-grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-weight: 600; font-size: 12px;
}
.avatar-sm { width: 26px; height: 26px; font-size: 11px; }

/* Login */
body.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-title { font-size: 22px; margin-top: 18px; }
.auth-card .muted { margin: 4px 0 20px; }

/* Marca */
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; font-size: 15px; }
.brand-lg { font-size: 18px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar .brand { width: calc(var(--sidebar-w) - 32px); flex: none; }
.search { flex: 1; max-width: 640px; }
.search input { background: var(--surface-2); border-color: transparent; border-radius: 99px; padding: 8px 16px; }
.user-menu { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* Selector de agente */
.agent-switcher { position: relative; flex: none; }
.agent-switcher > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px;
  padding: 5px 10px 5px 6px; border: 1px solid var(--border); border-radius: 99px; background: var(--surface);
  max-width: 320px;
}
.agent-switcher > summary::-webkit-details-marker { display: none; }
.agent-switcher > summary:hover { background: var(--surface-2); }
.agent-switcher[open] > summary { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.agent-current { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.agent-current strong, .agent-current small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-current small { color: var(--muted); font-size: 11px; }
.chevron { width: 16px; height: 16px; color: var(--muted); flex: none; }
.menu {
  position: absolute; top: calc(100% + 6px); left: 0; width: 340px; max-width: calc(100vw - 32px);
  max-height: 70vh; overflow: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-label { padding: 6px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.menu-item:hover { background: var(--surface-2); text-decoration: none; }
.menu-item.is-current { background: var(--primary-soft); }
.menu-item.is-inactive { opacity: .6; }
.menu-item-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.menu-item-text small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.menu-action { color: var(--primary); font-weight: 500; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 4px; }
.menu-empty { padding: 8px 10px; margin: 0; color: var(--muted); }

/* Layout principal */
.shell { display: flex; min-height: calc(100vh - var(--topbar-h)); }
.sidebar {
  width: var(--sidebar-w); flex: none; padding: 16px 12px;
  position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); overflow-y: auto;
}
.btn-compose { height: 44px; padding: 0 20px; border-radius: 12px; margin-bottom: 14px; box-shadow: var(--shadow); }
.btn-compose svg { width: 18px; height: 18px; }
.sidebar-note { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 7px 12px; border-radius: 99px; color: var(--text); }
.nav-item svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.is-active svg { color: var(--primary); }
.count { margin-left: auto; font-size: 12px; font-weight: 700; }
.nav-section { margin: 18px 12px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.content { flex: 1; min-width: 0; padding: 16px 16px 40px 0; }

/* Panel */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; min-height: 60vh; overflow: hidden; }
.panel-narrow { max-width: 760px; padding-bottom: 20px; }
.panel-narrow > .form, .panel-narrow > p { margin: 0 20px 16px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); min-height: 60px; }
.panel-narrow .panel-head { margin-bottom: 16px; }
.segmented { display: inline-flex; margin-left: auto; background: var(--surface-2); border-radius: 8px; padding: 3px; }
.segmented a { padding: 3px 12px; border-radius: 6px; color: var(--muted); font-size: 13px; font-weight: 500; }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / 8%); }
.empty { padding: 64px 20px; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 14px; }

/* Lista de hilos */
.thread-list { display: flex; flex-direction: column; }
.thread-row {
  display: grid; grid-template-columns: 32px minmax(120px, 200px) 1fr auto; align-items: center; gap: 14px;
  padding: 10px 20px; border-bottom: 1px solid var(--border); color: var(--text);
}
.thread-row:hover { background: var(--surface-2); text-decoration: none; box-shadow: inset 3px 0 0 var(--primary); }
.thread-people, .thread-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-count { color: var(--muted); font-size: 12px; }
.thread-snippet { color: var(--muted); }
.thread-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.thread-row.is-unread { background: color-mix(in srgb, var(--primary-soft) 35%, var(--surface)); }
.thread-row.is-unread .thread-people, .thread-row.is-unread .thread-subject, .thread-row.is-unread time { font-weight: 700; color: var(--unread); }
.icon-clip { width: 16px; height: 16px; }

/* Hilo */
.thread-title { font-size: 20px; }
.thread-info { padding: 10px 20px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.messages { display: flex; flex-direction: column; gap: 12px; padding: 16px 20px; }
.message { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
.message.is-out { background: color-mix(in srgb, var(--primary-soft) 30%, var(--surface)); }
.message-head { display: flex; gap: 12px; align-items: flex-start; }
.message-who { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.message-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.message-body { margin: 10px 0 0 44px; overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose p:last-child { margin-bottom: 0; }
.prose pre { overflow-x: auto; background: var(--surface-2); padding: 10px; border-radius: 8px; }
.quoted { margin-top: 10px; }
.quoted summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.quoted pre { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--muted); border-left: 3px solid var(--border); padding-left: 10px; }
.attachments { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 0; margin: 12px 0 0 44px; }
.attachment { display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface); }
.attachment svg { width: 16px; height: 16px; color: var(--muted); }
.attachment.is-infected { border-color: var(--danger); }
.reply-box { margin: 0 20px 20px; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }

/* Tabla */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 20px; border-bottom: 1px solid var(--border); }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }

/* Móvil */
@media (max-width: 820px) {
  :root { --topbar-h: auto; }
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; height: auto; }
  .topbar .brand { width: auto; }
  .brand-text { display: none; }
  .agent-switcher { flex: 1; min-width: 0; }
  .agent-switcher > summary { max-width: none; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .shell { flex-direction: column; }
  .sidebar { position: static; width: auto; height: auto; padding: 10px 16px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .sidebar .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-section { display: none; }
  .btn-compose { margin: 0; height: 36px; }
  .content { padding: 12px 16px 32px; }
  .thread-row { grid-template-columns: 32px 1fr auto; padding: 10px 12px; }
  .thread-main { grid-column: 2 / 4; }
  .thread-row .thread-meta { grid-row: 1; grid-column: 3; }
  .message-body, .attachments { margin-left: 0; }
  .table { display: block; overflow-x: auto; }
  .panel-head { padding: 12px; flex-wrap: wrap; }
}

/* Conexión SES */
.checklist { list-style: none; margin: 0 20px 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checklist li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; overflow-wrap: anywhere; }
.check-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.checklist .is-ok .check-icon { background: var(--ok-soft); color: var(--ok); }
.checklist .is-bad .check-icon { background: var(--danger-soft); color: var(--danger); }
.ses-actions { margin: 0 20px 8px; }
.section-title { font-size: 15px; margin: 24px 20px 6px; }
.panel-narrow > .table, .panel-narrow > .flash { margin: 0 20px 12px; width: calc(100% - 40px); }
.dns-table td { vertical-align: top; overflow-wrap: anywhere; }
.dns-table th, .dns-table td { padding: 8px 10px; }
