/* Buzones SOL. Light theme by default; dark when <html data-theme="dark"> (toggle in the top bar).
   Shape rule: controls (buttons, inputs, selects) 8px; containers (cards, tables, dialogs) 12px; badges and pills fully round. */
@font-face { font-family: "Geist"; src: url("/fonts/Geist-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "Geist Mono"; src: url("/fonts/GeistMono-Variable.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #f5f6f8; --surface: #fcfcfd; --surface-2: #f0f2f5; --border: #e2e5ea; --border-strong: #cfd4dc;
  --text: #14181e; --muted: #5a6371; --accent: #0f766e; --accent-hover: #0d6961; --accent-ink: #f7fffd; --accent-soft: #e3f3f1;
  --danger: #b42318; --danger-soft: #fdeceb; --warn: #9a5800; --warn-soft: #fff3df; --ok: #17803d; --ok-soft: #e6f4ea;
  --shadow: 0 1px 2px rgb(20 30 45 / .05), 0 2px 6px rgb(20 30 45 / .04);
  --r-control: 8px; --r-box: 12px;
  --skeleton: #e9ecf0;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0e1115; --surface: #151a20; --surface-2: #1c222a; --border: #283039; --border-strong: #36404b;
  --text: #e7eaee; --muted: #98a2af; --accent: #2bc4b0; --accent-hover: #3fd3bf; --accent-ink: #052b26; --accent-soft: #11302c;
  --danger: #f2766b; --danger-soft: #3a1b19; --warn: #f0ad4e; --warn-soft: #382910; --ok: #4cc97a; --ok-soft: #12301e;
  --shadow: 0 1px 2px rgb(0 0 0 / .35);
  --skeleton: #222932;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 "Geist", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1; }
[hidden] { display: none !important; }
h1 { font-size: 24px; line-height: 1.2; font-weight: 650; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
.muted { color: var(--muted); }
small { display: block; color: var(--muted); font-size: 12px; }
.mono { font-family: "Geist Mono", ui-monospace, monospace; font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.i { width: 18px; height: 18px; fill: currentColor; flex: none; }

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand strong { font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.logo { width: 32px; height: 32px; border-radius: var(--r-control); background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; flex: none; }
.logo .i { width: 19px; height: 19px; }
.brand-lg .logo { width: 42px; height: 42px; }
.brand-lg .logo .i { width: 24px; height: 24px; }
.brand-lg strong { font-size: 20px; }

/* Buttons */
.btn { appearance: none; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); border-radius: var(--r-control); padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap; transition: background-color .15s, border-color .15s, transform .1s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .65; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--muted); width: 36px; height: 36px; border-radius: var(--r-control); cursor: pointer; display: inline-grid; place-items: center; transition: background-color .15s, color .15s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn:disabled { opacity: .5; cursor: progress; }
.spinning .i { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Forms */
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-control); padding: 9px 11px; min-width: 0; width: 100%; }
input::placeholder { color: var(--muted); opacity: 1; }
:is(input, select, .btn, .icon-btn, .tab, .seg button, .link, .kpi):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field { display: grid; gap: 6px; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
.field input { font-weight: 400; font-size: 15px; }
.field .hint { margin: 0; font-weight: 400; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 0 0 12px; font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: -4px 0 12px; display: flex; gap: 6px; align-items: flex-start; }
.hint .i { width: 15px; height: 15px; margin-top: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; position: relative; }
.login-theme { position: absolute; top: 16px; right: 16px; }
.login-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-box); padding: 32px 28px 28px; box-shadow: var(--shadow); }
.login-lead { margin: 16px 0 24px; }

/* Layout */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; height: 64px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-right { display: flex; align-items: center; gap: 2px; }
.topbar-right .me { margin-right: 10px; font-size: 13px; }
.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 24px 40px; }
.hero { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.hero p { margin: 0; }
.hero-actions { display: flex; gap: 8px; }
.progress { height: 3px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: -8px 0 18px; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s ease; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 26px; }
.kpi { display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-box); padding: 14px 16px; box-shadow: var(--shadow); }
button.kpi { cursor: pointer; transition: border-color .15s, transform .1s; }
button.kpi:hover { border-color: var(--accent); }
button.kpi:active { transform: translateY(1px); }
.kpi .v { font-size: 28px; font-weight: 650; letter-spacing: -.03em; line-height: 1.15; }
.kpi .k { color: var(--muted); font-size: 12.5px; font-weight: 550; line-height: 1.3; }
.kpi.alert { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); background: var(--danger-soft); }
.kpi.alert .v { color: var(--danger); }
.kpi.warn .v { color: var(--warn); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 7px; }
.tab .i { width: 17px; height: 17px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.count { background: var(--surface-2); border-radius: 999px; padding: 0 8px; font-size: 12px; line-height: 20px; }

/* Filters */
.filters { display: grid; grid-template-columns: auto minmax(160px, 1fr) minmax(160px, 1fr) minmax(200px, 1.4fr); gap: 8px; margin-bottom: 12px; align-items: center; }
.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-control); padding: 3px; }
.seg button { appearance: none; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); padding: 6px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.search { position: relative; display: block; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; pointer-events: none; }
.search input { padding-left: 34px; }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-box); overflow: hidden; box-shadow: var(--shadow); }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.grid td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.num { text-align: right; }
.nowrap { white-space: nowrap; }
.c-dot { width: 18px; padding-right: 0 !important; }
.unread td { font-weight: 600; }
.unread-mark { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--accent); margin-top: 7px; }
.client-cell strong { font-weight: 600; }
.client-cell small { font-weight: 400; }
.link { appearance: none; border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.link:hover strong { color: var(--accent); }
.subject { display: block; }
.badges { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-left: 6px; vertical-align: 1px; }
.attach { display: inline-flex; align-items: center; gap: 3px; color: var(--muted); }
.attach .i { width: 15px; height: 15px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty .i { width: 28px; height: 28px; display: block; margin: 0 auto 10px; color: var(--accent); }
.note { color: var(--muted); font-size: 12.5px; margin: 12px 2px 0; max-width: 80ch; }

/* Badges and statuses */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; line-height: 18px; }
.b-new { background: var(--accent-soft); color: var(--accent); }
.b-urg { background: var(--danger-soft); color: var(--danger); }
.b-folder { background: var(--warn-soft); color: var(--warn); }
.b-noti { background: var(--accent-soft); color: var(--accent); }
.b-msg { background: var(--surface-2); color: var(--muted); }
.status { font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; display: inline-flex; align-items: center; gap: 5px; }
.status .i { width: 14px; height: 14px; }
.st-ok { background: var(--ok-soft); color: var(--ok); }
.st-nuevo { background: var(--surface-2); color: var(--muted); }
.st-error { background: var(--warn-soft); color: var(--warn); }
.st-credenciales { background: var(--danger-soft); color: var(--danger); }
.st-running { background: var(--accent-soft); color: var(--accent); }
.err-text { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; max-width: 280px; font-weight: 400; }
.zero { color: var(--muted); font-weight: 400; }
.hot { color: var(--danger); font-weight: 650; }
.actions { white-space: nowrap; text-align: right; padding-top: 7px !important; padding-bottom: 7px !important; }

/* Skeleton rows while loading */
.sk { display: block; height: 12px; border-radius: 999px; background: var(--skeleton); }
.sk.w1 { width: 70%; } .sk.w2 { width: 40%; margin-top: 8px; } .sk.w3 { width: 90%; }
@media (prefers-reduced-motion: no-preference) {
  .sk { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: .45; } }
}

/* Message documents */
.msg-dialog { width: min(560px, calc(100vw - 32px)); }
.md-meta { margin: -10px 0 16px; font-size: 13px; }
.callout { background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border)); border-radius: var(--r-box); padding: 14px 16px; margin-bottom: 14px; }
.callout p { margin: 0 0 12px; }
.md-loading { display: grid; gap: 10px; padding: 6px 0 12px; }
.md-loading p { margin: 0; font-size: 13px; }
.doc-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.doc-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r-box); background: var(--surface); }
.doc-list .doc-ico { width: 34px; height: 34px; border-radius: var(--r-control); background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.doc-list .doc-name { font-weight: 600; word-break: break-all; font-size: 13.5px; }
.doc-list small { margin-top: 2px; }
.md-body { background: var(--surface-2); border-radius: var(--r-box); padding: 16px 18px; margin: 0 0 12px; max-height: 50vh; overflow: auto; line-height: 1.6; overflow-wrap: anywhere; }
.md-body.plain { white-space: pre-wrap; }
.msg-dialog .doc-list:empty { display: none; }
.msg-dialog .form-error:empty { min-height: 0; margin: 0; }
.msg-dialog .doc-list { margin-top: 12px; }
.msg-dialog .md-body { margin-bottom: 0; }
.md-body strong { font-weight: 650; }
.md-body a { color: var(--accent); font-weight: 600; text-underline-offset: 2px; }
.subject-link { appearance: none; border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.subject-link:hover .subject { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* Events (admin) */
.events-bar { grid-template-columns: auto 1fr auto; }
.events-sum { margin: 0; font-size: 13px; }
.events td:nth-child(3) { max-width: 460px; word-break: break-word; }
.events .ev-ok { background: var(--ok-soft); color: var(--ok); }
.events .ev-err { background: var(--danger-soft); color: var(--danger); }
.events .ev-user { background: var(--warn-soft); color: var(--warn); }

/* Dialogs */
dialog { border: 1px solid var(--border); border-radius: var(--r-box); padding: 22px 24px 24px; width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 24px 60px rgb(10 20 35 / .22); }
dialog::backdrop { background: rgb(12 18 28 / .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.dialog-head .icon-btn { margin-right: -8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: var(--r-control); font-weight: 600; box-shadow: 0 8px 24px rgb(10 20 35 / .2); z-index: 30; width: max-content; max-width: calc(100vw - 32px); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* Tablet */
@media (max-width: 1024px) {
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .seg { grid-column: 1 / -1; }
  .filters .search { grid-column: 1 / -1; }
}

/* Phone: tables become cards, the two main actions sit in a fixed bottom bar */
@media (max-width: 767px) {
  body { font-size: 15px; }
  .topbar { height: 56px; padding: 0 12px 0 16px; }
  .topbar .brand small, .topbar-right .me { display: none; }
  .wrap { padding: 20px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 21px; }
  .hero { margin-bottom: 16px; }
  .hero-actions { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 16px rgb(10 20 35 / .06); }
  .hero-actions .btn { padding: 12px 14px; }
  .progress { margin: 0 0 16px; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 20px; }
  .kpi { padding: 10px 12px; border-radius: var(--r-box); }
  .kpi .v { font-size: 22px; }
  .kpi .k { font-size: 11.5px; }

  .tabs .tab { flex: 1; justify-content: center; }
  .filters { grid-template-columns: 1fr 1fr; }
  .seg button { padding: 8px 6px; }
  input, select { font-size: 16px; } /* avoids iOS zoom on focus */

  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .grid thead { display: none; }
  .grid tbody { display: grid; gap: 10px; }
  .grid tbody tr { display: grid; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-box); box-shadow: var(--shadow); padding: 14px; gap: 6px 10px; }
  .grid td { display: block; padding: 0; border: 0; }
  .grid tbody tr:hover td { background: none; }
  .empty { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-box); }

  /* Message card */
  .msgs tbody tr { grid-template-columns: auto auto minmax(0, 1fr); grid-template-areas: "client client client" "asunto asunto asunto" "tipo adj fecha"; align-items: center; }
  .msgs tbody tr.unread { border-left: 3px solid var(--accent); }
  .msgs td:nth-child(1) { display: none; }
  .msgs td:nth-child(2) { grid-area: client; }
  .msgs td:nth-child(3) { grid-area: tipo; }
  .msgs td:nth-child(4) { grid-area: fecha; font-size: 12.5px; color: var(--muted); font-weight: 400; text-align: right; }
  .msgs .client-cell strong { font-size: 13.5px; color: var(--muted); font-weight: 600; }
  .msgs td:nth-child(5) { grid-area: asunto; font-size: 15px; line-height: 1.4; }
  .msgs td:nth-child(6) { grid-area: adj; text-align: left; }
  .msgs .badges { display: flex; margin: 6px 0 0; }
  .msgs .client-cell small { display: none; }

  /* Client card */
  .clients tbody tr { position: relative; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-template-areas: "client client client client" "unread total op coact" "status status upd upd"; gap: 12px 8px; }
  .clients td:nth-child(1) { grid-area: client; padding-right: 116px; min-width: 0; }
  .clients td:nth-child(2) { display: none; }
  .clients td:nth-child(3) { grid-area: unread; }
  .clients td:nth-child(4) { grid-area: total; }
  .clients td:nth-child(5) { grid-area: op; }
  .clients td:nth-child(6) { grid-area: coact; }
  .clients td:nth-child(7) { grid-area: upd; text-align: right; align-self: center; font-size: 12.5px; }
  .clients td:nth-child(8) { grid-area: status; }
  .clients td:nth-child(9) { position: absolute; top: 8px; right: 8px; padding: 0 !important; }
  .clients td.num { text-align: left; background: var(--surface-2); border-radius: var(--r-control); padding: 8px 10px; font-size: 18px; font-weight: 650; min-width: 0; }
  .clients td.num::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .clients .zero { color: var(--text); font-weight: 650; }
  .err-text { max-width: none; }

  .events-bar { grid-template-columns: 1fr; }
  .events tbody tr { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "tipo fecha" "detalle detalle" "usuario usuario" "cliente ms"; }
  .events td:nth-child(1) { grid-area: fecha; font-size: 12.5px; color: var(--muted); text-align: right; }
  .events td:nth-child(2) { grid-area: tipo; }
  .events td:nth-child(3) { grid-area: detalle; max-width: none; }
  .events td:nth-child(4) { grid-area: usuario; font-size: 13px; color: var(--muted); }
  .events td:nth-child(5) { grid-area: cliente; font-size: 13px; }
  .events td:nth-child(6) { grid-area: ms; font-size: 12.5px; color: var(--muted); }

  .row2 { grid-template-columns: 1fr; gap: 0; }
  dialog { padding: 20px 18px; }
  .doc-list li { grid-template-columns: auto minmax(0, 1fr); }
  .doc-list li .btn { grid-column: 1 / -1; }
  .dialog-actions .btn { flex: 1; }
}
