/* SiWAVE Admin. Tokens follow siwave_app/lib/theme.dart (design-system
   tokens v0.1): dark by default like the app, light scheme on request. */

:root {
  --teal: #00B7B3;
  --navy: #002E3F;
  --purple: #8058A3;
  --cream: #F7F1E2;
  --pink: #E63368;
  --indigo: #5A4FA5;

  --bg: #061821;
  --surface: #0B2431;
  --surface-2: #123243;
  --border: #1B3D50;
  --text: #F8F8F8;
  --text-2: #8FAABB;
  --link: #3FD6D2;
  --danger: #FF6B93;
  --warn: #F2C94C;
  --ok: #3FD6A0;

  --radius: 14px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F7F1E2;
    --surface: #FFFFFF;
    --surface-2: #EFE7D2;
    --border: #E2D8BE;
    --text: #002E3F;
    --text-2: #4A6373;
    --link: #007F7C;
    --danger: #C2185B;
    --warn: #9A6B00;
    --ok: #13795B;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1rem; margin: 0 0 .75rem; letter-spacing: .01em; }
h3 { font-size: .8rem; margin: 1rem 0 .5rem; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
p { margin: 0 0 .5rem; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .9em; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
.text-danger { color: var(--danger); font-weight: 600; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ── layout ─────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  padding: .35rem 1.5rem; background: var(--navy); color: #F8F8F8;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #F8F8F8; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand span { padding-left: .6rem; border-left: 1px solid rgb(255 255 255 / .25); color: #8FAABB; font-weight: 500; }
.logo { height: 44px; display: block; }
.nav { display: flex; gap: .25rem; }
.nav a { color: #C9D8E1; padding: .4rem .8rem; border-radius: var(--radius-sm); font-weight: 500; }
.nav a:hover { background: rgb(255 255 255 / .06); text-decoration: none; }
.nav a.active { color: var(--navy); background: var(--teal); }
.who { margin-left: auto; display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.who .btn-ghost { color: #F8F8F8; border-color: rgb(255 255 255 / .25); }

.view { max-width: 1320px; margin: 0 auto; padding: 1.5rem; outline: none; }
.page-head { margin-bottom: 1.25rem; }
.page-head p { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.back { display: inline-block; margin-bottom: .75rem; font-size: .9rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 1.25rem; align-items: start; }
.stack { display: grid; gap: 1.25rem; min-width: 0; }
.stack-sm { display: grid; gap: .75rem; }
.row { display: flex; gap: .75rem; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.row > label { flex: 1; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { width: min(420px, 100%); }
.narrow-form { max-width: 520px; }
.empty { text-align: center; color: var(--text-2); padding: 2.5rem 1rem; }
.loading { color: var(--text-2); padding: 2rem 0; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login { display: grid; gap: .9rem; }
.login picture { justify-self: start; }
.login-logo { height: 80px; display: block; margin-bottom: .25rem; }

/* ── forms ──────────────────────────────────────────────────────────────── */
label { display: grid; gap: .3rem; font-size: .85rem; color: var(--text-2); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .55rem .7rem; width: 100%; min-width: 0;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgb(0 183 179 / .25); }
label.check { display: flex; align-items: center; gap: .5rem; color: var(--text); font-weight: 400; }
label.check input { width: auto; flex: none; padding: 0; }
label.check.small { align-items: flex-start; }
label.check.small input { margin-top: .15rem; }
/* Layout classes (.stack, .row) must not override the hidden attribute. */
[hidden] { display: none !important; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: .25rem; font-weight: 600; color: var(--text); }

.filters { display: grid; grid-template-columns: minmax(220px, 2fr) repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: 1rem; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 12px;
  padding: .6rem 1.1rem; border: 1px solid transparent; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn-primary { background: var(--teal); color: var(--navy); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-link { background: none; border: none; color: var(--link); padding: .25rem; font-weight: 500; }
.btn-sm { padding: .3rem .7rem; font-size: .85rem; }

/* ── tables ─────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-weight: 600; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-2); padding: .7rem .9rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: .65rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table.compact th, .table.compact td { padding: .45rem .6rem; }
.table.clickable tbody tr { cursor: pointer; }
.table.clickable tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.num { text-align: right; }
.row-danger td { background: rgb(230 51 104 / .10); }

/* ── badges ─────────────────────────────────────────────────────────────── */
.badge, .pill {
  display: inline-block; padding: .12rem .55rem; border-radius: 999px;
  font-size: .78rem; font-weight: 600; white-space: nowrap; border: 1px solid transparent;
}
.pill { background: rgb(255 255 255 / .1); color: #F8F8F8; }
.pill-warn { background: var(--warn); color: var(--navy); }

.urg-high { background: rgb(230 51 104 / .18); color: var(--danger); border-color: rgb(230 51 104 / .4); }
.urg-medium { background: rgb(242 201 76 / .15); color: var(--warn); border-color: rgb(242 201 76 / .35); }
.urg-normal { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

.st-open { background: rgb(0 183 179 / .16); color: var(--link); border-color: rgb(0 183 179 / .4); }
.st-inProgress { background: rgb(90 79 165 / .25); color: #B5ACF2; border-color: rgb(90 79 165 / .55); }
.st-waitingUser { background: rgb(242 201 76 / .12); color: var(--warn); border-color: rgb(242 201 76 / .3); }
.st-resolved { background: rgb(63 214 160 / .12); color: var(--ok); border-color: rgb(63 214 160 / .3); }
.st-closed { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

/* Maintenance, as in the app: vencida pink, próxima cream, em dia teal. */
.mt-due { background: rgb(230 51 104 / .18); color: var(--danger); border-color: rgb(230 51 104 / .4); }
.mt-soon { background: rgb(247 241 226 / .14); color: var(--warn); border-color: rgb(242 201 76 / .35); }
.mt-ok { background: rgb(0 183 179 / .14); color: var(--link); border-color: rgb(0 183 179 / .35); }
.mt-none { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .st-inProgress { color: var(--indigo); }
}

.outcome { font-weight: 500; }
.oc-connectionLost { color: var(--danger); font-weight: 700; }
.oc-stoppedEarly { color: var(--warn); }
.oc-completed { color: var(--text-2); }

/* ── key/value, stats ───────────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--text-2); font-size: .88rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.diag-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.5rem; }
.diag-grid h3:first-child { margin-top: 0; }

#session-history .day { margin-top: 1rem; }
#session-history .day h3 { text-transform: none; letter-spacing: 0; font-size: .9rem; color: var(--text); }
.seg { display: flex; gap: .35rem; }

.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 1.5rem; }
.usage-grid h3:first-child { margin-top: 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; display: grid; gap: .2rem; }
.stat-label { color: var(--text-2); font-size: .8rem; }
.stat-value { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; }

ul.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }

/* ── thread, timeline ───────────────────────────────────────────────────── */
.thread { display: grid; gap: .6rem; margin-bottom: 1rem; }
.read-receipt { justify-self: end; margin: 0; }
.msg { max-width: 80%; padding: .6rem .85rem; border-radius: 14px; border: 1px solid var(--border); }
.msg-customer { background: var(--surface-2); justify-self: start; border-bottom-left-radius: 4px; }
.msg-support { background: rgb(0 183 179 / .13); border-color: rgb(0 183 179 / .35); justify-self: end; border-bottom-right-radius: 4px; }
.msg-meta { font-size: .75rem; color: var(--text-2); margin-bottom: .2rem; }

.timeline { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .75rem; }
.timeline li { padding-left: .9rem; border-left: 2px solid var(--border); font-size: .9rem; }
.timeline li.tl-note { border-left-color: var(--teal); }
.tl-meta { font-size: .75rem; color: var(--text-2); }

/* ── attachments, raw ───────────────────────────────────────────────────── */
.attachments { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; }
.attachment { display: grid; gap: .3rem; background: var(--surface-2); border-radius: var(--radius-sm); padding: .5rem; min-height: 80px; align-content: start; }
.attachment img, .attachment video { width: 100%; max-height: 260px; object-fit: contain; border-radius: 6px; background: #000; }
details.raw { margin-top: 1rem; }
details.raw summary { cursor: pointer; color: var(--text-2); font-size: .85rem; }
details.raw pre { background: var(--surface-2); padding: .75rem; border-radius: var(--radius-sm); overflow: auto; max-height: 360px; font-size: .8rem; }

/* ── toast ──────────────────────────────────────────────────────────────── */
.toasts {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); z-index: 100;
  display: grid; gap: .5rem; justify-items: center; width: max-content; max-width: calc(100vw - 2rem);
}
.toast {
  background: var(--navy); color: #F8F8F8; border: 1px solid var(--teal);
  padding: .65rem 1.1rem; border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / .35);
}
.toast-error { border-color: var(--pink); }

/* ── small screens ──────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: .5rem 1rem; padding: .6rem 1rem; }
  .who { margin-left: 0; width: 100%; }
  .who-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45vw; }
  .view { padding: 1rem; }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { grid-column: 1 / -1; }
  .msg { max-width: 95%; }
  .row { flex-wrap: wrap; }
}
