/* Trefato Admin (v200). Tokens no :root, tema escuro em [data-theme="dark"]. */

:root {
  color-scheme: light;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;

  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --surface-3: #eef0f5;
  --ink: #111827;
  --text: #374151;
  --muted: #6b7280;
  --line: #dfe2ea;
  --line-strong: #c7cbd8;
  --brand: #5b4bff;
  --brand-hover: #4535e8;
  --brand-ink: #ffffff;
  --brand-soft: #eeebff;
  --accent: #5b4bff;
  --focus: #5b4bff;
  --link: #4535e8;
  --shadow: 0 1px 2px rgb(17 24 39 / 6%), 0 8px 24px rgb(17 24 39 / 5%);
  --shadow-pop: 0 18px 48px rgb(7 10 18 / 22%);

  --sidebar-bg: #0b0f19;
  --sidebar-ink: #e6e8f0;
  --sidebar-muted: #aeb5c8;
  --sidebar-hover: rgb(255 255 255 / 6%);
  --sidebar-active: #1e1b4b;
  --sidebar-line: rgb(255 255 255 / 9%);

  --success-bg: #e2f5e9; --success-ink: #13663a; --success-line: #2f9e5f;
  --warning-bg: #fdf0d3; --warning-ink: #855600; --warning-line: #d99a16;
  --danger-bg: #fde5e2; --danger-ink: #a3241a; --danger-line: #d64534;
  --info-bg: #e3edf9; --info-ink: #1b5292; --info-line: #3b7dd0;
  --neutral-bg: #edf0f0; --neutral-ink: #475654; --neutral-line: #9aa6a4;

  --mix-paying: #5b4bff;
  --mix-free: #79c2b3;
  --mix-trial: #3b7dd0;
  --mix-pending: #a2adab;
  --mix-problem: #d99a16;
  --mix-suspended: #d64534;

  --radius-lg: 12px;
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1517;
  --surface: #152023;
  --surface-2: #1a272b;
  --surface-3: #213135;
  --ink: #eef5f3;
  --text: #c8d5d2;
  --muted: #94a7a3;
  --line: #29393d;
  --line-strong: #3b4e53;
  --brand: #8b7bff;
  --brand-hover: #43c9b9;
  --brand-ink: #052320;
  --brand-soft: rgb(43 181 166 / 14%);
  --accent: #8b7bff;
  --focus: #c4b5fd;
  --link: #6fdccd;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  --shadow-pop: 0 18px 48px rgb(0 0 0 / 50%);

  --sidebar-bg: #0a1214;
  --sidebar-ink: #d6e5e2;
  --sidebar-muted: #84a29d;
  --sidebar-active: #15363b;

  --success-bg: #12341f; --success-ink: #8fe0b0; --success-line: #3fbf78;
  --warning-bg: #3b2c0b; --warning-ink: #f4cc72; --warning-line: #e0a728;
  --danger-bg: #421a17; --danger-ink: #ffaaa1; --danger-line: #ee6a5a;
  --info-bg: #132b46; --info-ink: #9ec6f6; --info-line: #5b98e2;
  --neutral-bg: #223236; --neutral-ink: #b6c4c1; --neutral-line: #708581;

  --mix-paying: #8b7bff;
  --mix-free: #1f6f66;
  --mix-trial: #5b98e2;
  --mix-pending: #6f8480;
  --mix-problem: #e0a728;
  --mix-suspended: #ee6a5a;
}

/* ------------------------------------------------------------------ base */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; color: var(--ink); line-height: 1.25; }
p { margin: 0; }
a { color: var(--link); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
code, .mono { font-family: var(--mono); font-size: 0.92em; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.muted { color: var(--muted); }
.optional { color: var(--muted); font-weight: 400; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.sr-only { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; padding: 10px 14px; border-radius: var(--radius); background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.skip-link:focus { top: 12px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 16px; align-content: start; }

.progress-bar {
  position: fixed; inset: 0 0 auto 0; z-index: 90; height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 40% 100%; background-repeat: no-repeat;
  animation: progress 1.1s ease-in-out infinite;
}
@keyframes progress { from { background-position: -40% 0; } to { background-position: 140% 0; } }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius);
  font-weight: 650; font-size: 14px; line-height: 1; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:disabled { cursor: not-allowed; opacity: 0.6; }
.btn[aria-busy="true"] { cursor: progress; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--danger-line); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn-danger-soft { background: var(--danger-bg); color: var(--danger-ink); border-color: transparent; }
.btn-danger-soft:hover:not(:disabled) { border-color: var(--danger-line); }
.btn-ghost-inverse { background: transparent; color: var(--sidebar-ink); border-color: var(--sidebar-line); }
.btn-ghost-inverse:hover { background: var(--sidebar-hover); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 38px; height: 38px; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn.is-spinning .icon { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link-btn { padding: 0; border: 0; background: none; color: var(--link); font-size: 13px; font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------------------------------------------------------------- fields */
.field { display: grid; gap: 6px; align-content: start; font-size: 13px; font-weight: 600; color: var(--ink); min-width: 0; }
input, select, textarea {
  width: 100%; min-height: 38px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 400;
}
textarea { resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.85; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[readonly] { background: var(--surface-3); color: var(--muted); }
input[type="checkbox"] { width: 18px; min-height: 18px; height: 18px; padding: 0; accent-color: var(--brand); }
.hint { font-size: 12px; font-weight: 400; color: var(--muted); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; font-weight: 500; color: var(--ink); min-height: 38px; }
.check-group { display: flex; flex-wrap: wrap; gap: 4px 20px; margin: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.check-group legend { padding: 0 6px; font-size: 13px; font-weight: 650; color: var(--ink); }
.input-affix { display: flex; align-items: stretch; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.input-affix:focus-within { outline: 2px solid var(--focus); border-color: transparent; }
.input-affix input { border: 0; outline: 0; min-width: 0; }
.affix-btn { flex: 0 0 auto; padding: 0 12px; border: 0; border-left: 1px solid var(--line); background: transparent; color: var(--link); font-size: 13px; font-weight: 650; cursor: pointer; }
.affix-btn:hover { background: var(--surface-3); }
.affix-btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.form-message { min-height: 20px; font-size: 13px; color: var(--muted); margin-right: auto; }
.form-message[data-type="error"] { color: var(--danger-ink); font-weight: 600; }
.form-message[data-type="success"] { color: var(--success-ink); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.span-full { grid-column: 1 / -1; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; }
.note { padding: 10px 12px; border-left: 3px solid var(--accent); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; background: var(--brand-soft); color: var(--text); font-size: 13px; }

/* ----------------------------------------------------------------- brand */
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; min-width: 0; }
/* A marca e o logo da Trefato (mesmo arquivo do site). A versao clara tem o texto em
   #111827 e a escura em branco: em fundo escuro (menu e login) vai sempre a escura. */
.brand-logo { display: block; height: auto; max-width: 100%; }
.brand-compact .logo-escuro { display: none; }
[data-theme="dark"] .brand-compact .logo-claro { display: none; }
[data-theme="dark"] .brand-compact .logo-escuro { display: block; }
.brand-text { display: grid; line-height: 1.15; min-width: 0; }
.brand-text small { color: var(--sidebar-muted); font-size: 12px; white-space: nowrap; }

/* ----------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr); }
.login-brand {
  display: flex; flex-direction: column; justify-content: center; gap: 28px; padding: 56px clamp(32px, 6vw, 96px);
  background: radial-gradient(120% 90% at 0% 0%, #1e1b4b 0%, #0b0f19 55%, #070a12 100%); color: #e6e8f0;
}
.login-claim { max-width: 30ch; font-size: clamp(24px, 2.6vw, 34px); line-height: 1.2; font-weight: 650; color: #f8f8ff; letter-spacing: -0.5px; }
.login-points { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; color: #aeb5c8; font-size: 15px; }
.login-points li { display: flex; align-items: center; gap: 10px; }
.login-points li::before { content: ""; width: 18px; height: 2px; border-radius: 2px; background: #c4b5fd; }
.login-card { align-self: center; justify-self: center; width: min(420px, calc(100% - 32px)); display: grid; gap: 8px; padding: 36px 0; }
.login-card h1 { font-size: 26px; letter-spacing: -0.4px; margin-top: 18px; }
.login-card form { margin-top: 18px; }
.brand-compact { display: none; }

/* ----------------------------------------------------------------- shell */
.shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); transition: grid-template-columns 180ms ease; }
.shell.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 18px;
  padding: 16px 12px; background: var(--sidebar-bg); color: var(--sidebar-ink); scrollbar-width: thin;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; }
.sidebar-toggle { width: 34px; height: 34px; background: transparent; border-color: var(--sidebar-line); color: var(--sidebar-ink); }
.sidebar-toggle:hover { background: var(--sidebar-hover); }
.nav { display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: var(--radius);
  color: var(--sidebar-ink); text-decoration: none; font-weight: 550; font-size: 14px;
}
.nav-item .icon { color: var(--sidebar-muted); }
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.is-active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #c4b5fd; }
.nav-item.is-active .icon { color: #c4b5fd; }
.nav-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: rgb(255 255 255 / 12%); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding-top: 12px; border-top: 1px solid var(--sidebar-line); }
.sidebar-user { font-size: 12px; color: var(--sidebar-muted); overflow-wrap: anywhere; }
.shell.is-collapsed .brand-text,
.shell.is-collapsed .nav-label,
.shell.is-collapsed .nav-count,
.shell.is-collapsed .sidebar-user { display: none; }
.shell.is-collapsed .sidebar-head { flex-direction: column; }
.shell.is-collapsed .nav-item { justify-content: center; padding: 0; }
.shell.is-collapsed .sidebar-foot .btn { padding: 0; }
.sidebar-scrim { position: fixed; inset: 0; z-index: 40; background: rgb(5 15 16 / 55%); }

.workspace { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar-title { min-width: 0; flex: 1 1 auto; }
.topbar-title h1 { font-size: 22px; letter-spacing: -0.3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title p { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.last-updated { font-size: 12px; white-space: nowrap; }
.menu-btn { display: none; }
.main { flex: 1 1 auto; padding: 24px 28px 48px; display: grid; gap: 16px; align-content: start; outline: none; max-width: 1480px; width: 100%; }
.view { display: grid; gap: 16px; align-content: start; min-width: 0; }
.global-alert { padding: 12px 14px; border-radius: var(--radius); background: var(--warning-bg); color: var(--warning-ink); border: 1px solid var(--warning-line); font-weight: 550; }

/* --------------------------------------------------------- notifications */
.notif { position: relative; }
.notif-badge { position: absolute; top: -6px; right: -6px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: var(--danger-line); color: #fff; font-size: 11px; font-weight: 700; line-height: 19px; }
.notif-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50; width: min(400px, calc(100vw - 24px)); max-height: min(560px, 75vh); overflow: auto;
  padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-pop);
}
.notif-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 10px; }
.notif-head strong { margin-right: auto; color: var(--ink); }
.notif-list { display: grid; gap: 6px; }
.notif-item { display: grid; gap: 3px; width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-left: 3px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); color: var(--text); text-align: left; cursor: pointer; font-size: 13px; }
.notif-item strong { color: var(--ink); }
.notif-item small { color: var(--muted); }
.notif-item.is-unread { background: var(--brand-soft); border-left-color: var(--accent); }
.notif-item.is-high { border-left-color: var(--danger-line); }
.notif-item:hover { border-color: var(--line-strong); }

/* ------------------------------------------------------------ panels etc */
.panel { min-width: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 16px; }
.panel-head p { font-size: 13px; margin-top: 2px; }
.panel-body { padding: 18px; }
.panel-foot { padding: 12px 18px; border-top: 1px solid var(--line); font-size: 13px; }
.subhead { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 12px; }
.field-search { position: relative; flex: 1 1 280px; }
.field-search input { padding-left: 36px; }
.field-icon { position: absolute; left: 11px; bottom: 10px; color: var(--muted); pointer-events: none; }
.field-compact { flex: 0 1 260px; }
.field-inline { flex: 0 1 200px; }
.result-count { font-size: 13px; margin-top: -6px; }
.footnote { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.callout { padding: 10px 12px; border-radius: var(--radius); background: var(--surface-3); font-size: 13px; color: var(--text); }
.callout-warning { background: var(--warning-bg); color: var(--warning-ink); }
.callout-danger { background: var(--danger-bg); color: var(--danger-ink); }

/* ---------------------------------------------------------------- badges */
.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 22px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.tone-success { background: var(--success-bg); color: var(--success-ink); }
.tone-warning { background: var(--warning-bg); color: var(--warning-ink); }
.tone-danger { background: var(--danger-bg); color: var(--danger-ink); }
.tone-info { background: var(--info-bg); color: var(--info-ink); }
.tone-neutral { background: var(--neutral-bg); color: var(--neutral-ink); }
.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--muted); }
.health::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.health-healthy { color: var(--success-ink); }
.health-attention { color: var(--warning-ink); }
.health-risk { color: var(--danger-ink); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { padding: 10px 14px; text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; color: var(--text); overflow-wrap: break-word; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td a { font-weight: 650; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-hover tbody tr:hover td { background: var(--surface-2); }
.cell-sub { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); font-weight: 400; }
.cell-error { color: var(--danger-ink); }
.cell-actions { width: 1%; white-space: nowrap; text-align: right; }
.cell-actions .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-link { color: var(--ink); text-decoration: none; }
.row-link:hover { color: var(--link); text-decoration: underline; }

/* --------------------------------------------------------- empty/loading */
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 36px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 15px; }
.empty-state p { max-width: 52ch; font-size: 13px; }
.empty-state .btn { margin-top: 8px; }
.empty-state.is-error strong { color: var(--danger-ink); }
.skeleton-list { display: grid; gap: 12px; padding: 18px; }
.skeleton-line, .skeleton-block { display: block; height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton-line:nth-child(3n) { width: 70%; }
.skeleton-block { height: 120px; border-radius: var(--radius-lg); border: 0; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* -------------------------------------------------------------- overview */
.overview { display: grid; gap: 16px; }
.pulse { display: grid; grid-template-columns: minmax(260px, 0.9fr) minmax(0, 1.4fr); overflow: hidden; }
.pulse-main { padding: 22px 24px; background: linear-gradient(160deg, var(--brand-soft), transparent 70%); border-right: 1px solid var(--line); }
.pulse-label { font-size: 13px; font-weight: 650; color: var(--muted); }
.pulse-value { margin: 6px 0 16px; font-size: clamp(32px, 4vw, 44px); font-weight: 750; letter-spacing: -1px; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.05; }
.pulse-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; margin: 0; }
.pulse-facts dt { font-size: 12px; color: var(--muted); }
.pulse-facts dd { margin: 1px 0 0; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; }
.pulse-mix { padding: 22px 24px; display: grid; gap: 14px; align-content: start; }
.mix-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; }
.mix-head h3 { font-size: 15px; }
.mix-head span { font-size: 12px; }
.mix-bar { display: flex; gap: 2px; height: 14px; border-radius: 4px; overflow: hidden; background: var(--surface-3); }
.mix-seg { display: block; min-width: 6px; flex-basis: 0; }
.mix-paying { background: var(--mix-paying); }
.mix-free { background: var(--mix-free); }
.mix-trial { background: var(--mix-trial); }
.mix-pending { background: var(--mix-pending); }
.mix-problem { background: var(--mix-problem); }
.mix-suspended { background: var(--mix-suspended); }
.mix-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px 12px; margin: 0; padding: 0; list-style: none; }
.mix-legend a { display: flex; align-items: center; gap: 8px; padding: 6px 8px; margin: 0 -8px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-size: 13px; }
.mix-legend a:hover { background: var(--surface-3); }
.mix-legend a.is-zero { color: var(--muted); }
.mix-legend strong { margin-left: auto; color: var(--ink); font-variant-numeric: tabular-nums; }
.mix-legend .is-zero strong { color: var(--muted); font-weight: 500; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }
.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi {
  display: grid; gap: 2px; align-content: start; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); text-decoration: none; box-shadow: var(--shadow); border-top: 3px solid var(--line-strong);
}
.kpi:hover { border-color: var(--line-strong); }
.kpi-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.kpi-value { font-size: 28px; font-weight: 750; color: var(--ink); font-variant-numeric: tabular-nums; letter-spacing: -0.5px; }
.kpi-detail { font-size: 12px; color: var(--muted); }
.kpi-info { border-top-color: var(--info-line); }
.kpi-warning { border-top-color: var(--warning-line); }
.kpi-danger { border-top-color: var(--danger-line); }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.attention-list { margin: 0; padding: 6px 0; list-style: none; }
.attention-item { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; align-items: baseline; padding: 10px 18px; border-left: 3px solid transparent; }
.attention-item + .attention-item { border-top: 1px solid var(--line); }
.tone-line-danger { border-left-color: var(--danger-line); }
.tone-line-warning { border-left-color: var(--warning-line); }
.tone-line-info { border-left-color: var(--info-line); }
.attention-kind { font-size: 12px; font-weight: 650; color: var(--muted); }
.attention-text { display: grid; gap: 1px; min-width: 0; }
.attention-text a, .attention-text strong { font-weight: 650; color: var(--ink); text-decoration: none; overflow-wrap: anywhere; }
.attention-text a:hover { color: var(--link); text-decoration: underline; }
.attention-text span { font-size: 13px; }
.bar-table td { vertical-align: middle; }
.bar { display: inline-block; vertical-align: middle; width: min(160px, 40vw); height: 8px; margin-right: 10px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.bar-fill { display: block; height: 100%; min-width: 2px; border-radius: 0 4px 4px 0; background: var(--mix-paying); }
.bar-value { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------------------------------------------------------------- detail */
.detail { display: grid; gap: 16px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; width: fit-content; font-weight: 600; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
.detail-hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px 24px; padding: 20px 22px; }
.detail-name { font-size: 24px; letter-spacing: -0.4px; overflow-wrap: anywhere; }
.detail-id { display: grid; gap: 8px; min-width: 0; }
.detail-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.detail-actions { align-self: start; justify-content: flex-end; }
.detail-contact { grid-column: 1 / -1; padding: 14px 0 0; border-top: 1px solid var(--line); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.span-detail { grid-column: 1 / -1; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px 18px; margin: 0; padding: 16px 18px; }
.info-grid-tight { padding: 0; }
.info dt { font-size: 12px; color: var(--muted); }
.info dd { margin: 2px 0 0; color: var(--ink); font-weight: 600; overflow-wrap: anywhere; }
.info-wide { grid-column: 1 / -1; }
.info-wide dd { font-weight: 400; }
.meter { display: grid; gap: 6px; }
.meter-head { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.meter-head strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.meter-track { display: block; height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.meter-fill { display: block; height: 100%; border-radius: 4px; }
.meter-ok { background: var(--mix-paying); }
.meter-warning { background: var(--warning-line); }
.meter-danger { background: var(--danger-line); }
.checklist { display: flex; flex-wrap: wrap; gap: 8px; margin: 0; padding: 0; list-style: none; }
.checklist li { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: 13px; }
.checklist li .icon { width: 15px; height: 15px; }
.checklist li.is-done { background: var(--success-bg); color: var(--success-ink); font-weight: 600; }
.simple-list { margin: 0; padding: 0; list-style: none; }
.simple-list li { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.simple-list li:last-child { border-bottom: 0; }
.timeline { margin: 0; padding: 8px 18px 16px; list-style: none; display: grid; gap: 12px; }
.timeline li { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px; font-size: 13px; }
.timeline strong { color: var(--ink); }
.timeline-date { color: var(--muted); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- support */
.ticket-list { display: grid; gap: 12px; }
.ticket { padding: 16px 18px; display: grid; gap: 12px; }
.ticket-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.ticket-title { font-size: 16px; }
.ticket-head p { font-size: 13px; margin-top: 3px; }
.ticket-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.ticket-message { padding: 12px 14px; border-radius: var(--radius); background: var(--surface-2); color: var(--text); }
.ticket-form { display: grid; grid-template-columns: 170px 150px minmax(0, 1fr); gap: 12px; align-items: start; }
.ticket-response textarea { min-height: 76px; }
.ticket-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; font-size: 12px; }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
#emailTemplatesPanel, #emailOutboxPanel { display: grid; gap: 14px; align-content: start; min-width: 0; }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 650; text-decoration: none; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }
.tab-count { padding: 0 7px; border-radius: 999px; background: var(--danger-bg); color: var(--danger-ink); font-size: 12px; font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--accent); }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chip-count { padding: 0 7px; border-radius: 999px; background: var(--surface-3); color: var(--ink); font-size: 12px; font-variant-numeric: tabular-nums; }
.chip[aria-checked="true"] .chip-count { background: color-mix(in srgb, var(--bg) 20%, transparent); color: var(--bg); }
.chip-filter { background: var(--brand-soft); border-color: transparent; }
.chip-filter .icon { width: 14px; height: 14px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); font-size: 13px; }
.pager:empty { display: none; }
.pager-page { font-size: 13px; color: var(--muted); padding: 0 6px; }
.log-details summary { margin-top: 6px; color: var(--link); font-size: 12px; font-weight: 600; cursor: pointer; }
.log-json { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 8px; }
.json { max-height: 280px; overflow: auto; margin: 0; padding: 10px; border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--mono); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Erros dos clientes */
.errors-summary { padding: 14px 18px; border-left: 4px solid var(--success-line); }
.errors-summary.has-errors { border-left-color: var(--warning-line); }
.errors-summary-title { font-size: 16px; }
.errors-summary-title strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.errors-summary .muted { font-size: 13px; margin-top: 2px; }
.errors-table .error-message { min-width: 240px; max-width: 520px; }
.error-detail { display: grid; gap: 4px; margin: 8px 0; font-size: 12px; }
.error-detail div { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 8px; }
.error-detail dt { color: var(--muted); font-weight: 600; }
.error-detail dd { margin: 0; }
.error-text { color: var(--danger-ink); font-size: 13px; }

/* Pedidos LGPD */
.request-note { font-size: 13px; color: var(--muted); }
.request-actions { display: inline-flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
@media (min-width: 1101px) { .ticket-form[data-request] { grid-template-columns: 170px minmax(0, 1fr); } }
@media (max-width: 720px) { .error-detail div { grid-template-columns: minmax(0, 1fr); gap: 0; } .errors-table .error-message { min-width: 0; } }

/* --------------------------------------------------------------- dialogs */
.dialog {
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop);
}
.dialog[open] { display: flex; flex-direction: column; }
.dialog > form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.dialog::backdrop { background: rgb(5 15 16 / 58%); }
.dialog-sm { width: min(500px, calc(100vw - 32px)); }
.dialog-lg { width: min(960px, calc(100vw - 32px)); }
.dialog-xl { width: min(1360px, calc(100vw - 24px)); height: calc(100vh - 32px); max-height: calc(100vh - 32px); }
.dialog-head { display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.dialog-head > div:first-child { flex: 1 1 auto; min-width: 0; }
.dialog-head p { font-size: 13px; margin-top: 3px; }
.dialog-title { font-size: 18px; }
.dialog-body { padding: 18px 20px; overflow-y: auto; min-height: 0; flex: 1 1 auto; }
.dialog-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
#confirmDialog .dialog-body { display: grid; gap: 10px; }
.confirm-details ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; }
.dialog-inline-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

/* -------------------------------------------------------- template editor */
.template-editor { height: 100%; }
.template-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 0; flex: 1 1 auto; }
.template-edit { display: grid; gap: 14px; align-content: start; padding: 18px 20px; overflow-y: auto; border-right: 1px solid var(--line); min-height: 0; }
.template-preview { display: flex; flex-direction: column; gap: 10px; padding: 18px 20px; overflow-y: auto; min-height: 0; background: var(--surface-2); }
.dialog-head .editor-switch { display: none; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.code-input { font-family: var(--mono); font-size: 13px; line-height: 1.6; min-height: 280px; tab-size: 2; }
.lint-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.lint-list li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--warning-ink); }
.lint-list .icon { width: 16px; height: 16px; margin-top: 2px; }
.help { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.help summary { cursor: pointer; font-weight: 650; color: var(--ink); }
.help ul { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 6px; }
.variables { display: grid; gap: 8px; }
.var-group { font-size: 13px; color: var(--muted); font-weight: 650; margin-top: 4px; }
.var-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.var-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 2px 12px; align-items: center; padding: 6px 8px; border-radius: var(--radius-sm); }
.var-item:hover { background: var(--surface-2); }
.var-chip { padding: 3px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); cursor: pointer; }
.var-chip:hover { border-color: var(--accent); background: var(--brand-soft); }
.var-desc { font-size: 13px; }
.var-sample { grid-column: 2 / 3; font-size: 12px; overflow-wrap: anywhere; }
.var-used { grid-column: 3; grid-row: 1; display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--success-ink); font-weight: 600; }
.var-used .icon { width: 14px; height: 14px; }
.segmented { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.seg { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg .icon { width: 16px; height: 16px; }
.seg[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.preview-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.preview { display: grid; gap: 10px; align-content: start; }
.preview-meta { display: grid; gap: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-size: 13px; }
.preview-meta > div { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 10px; }
.preview-k { color: var(--muted); }
.preview-subject { color: var(--ink); overflow-wrap: anywhere; }
.preview-status { font-size: 12px; }
.preview-status[data-type="error"] { color: var(--danger-ink); font-weight: 600; }
.preview-stage { display: flex; justify-content: center; }
.preview-frame { display: block; width: 100%; height: min(720px, 70vh); border: 1px solid var(--line); border-radius: var(--radius); background: #f3f6f8; }
.preview[data-mode="mobile"] .preview-frame { width: 390px; max-width: 100%; height: min(760px, 72vh); border: 10px solid #1d2629; border-radius: 28px; }
.preview-text { display: none; width: 100%; max-height: 70vh; overflow: auto; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-family: var(--mono); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink); }
.preview[data-mode="text"] .preview-frame { display: none; }
.preview[data-mode="text"] .preview-text { display: block; }
#previewDialog .dialog-body { display: grid; gap: 12px; }

/* ----------------------------------------------------------------- toast */
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 120; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius); background: var(--ink); color: var(--bg); box-shadow: var(--shadow-pop); font-size: 14px; border-left: 4px solid var(--success-line); animation: toast-in 160ms ease-out; }
.toast span { flex: 1 1 auto; }
.toast-error { border-left-color: var(--danger-line); }
.toast-info { border-left-color: var(--info-line); }
.toast-close { border: 0; background: transparent; color: inherit; font-size: 18px; line-height: 1; cursor: pointer; opacity: 0.75; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1240px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .mix-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1100px) {
  .overview-grid, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .pulse { grid-template-columns: minmax(0, 1fr); }
  .pulse-main { border-right: 0; border-bottom: 1px solid var(--line); }
  .template-grid { grid-template-columns: minmax(0, 1fr); }
  .template-grid[data-pane="edit"] .template-preview { display: none; }
  .template-grid[data-pane="preview"] .template-edit { display: none; }
  .template-edit { border-right: 0; }
  .dialog-head .editor-switch { display: inline-flex; }
  .ticket-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ticket-response { grid-column: 1 / -1; }
}

@media (max-width: 960px) {
  .shell, .shell.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(290px, 86vw); transform: translateX(-102%);
    transition: transform 180ms ease; box-shadow: var(--shadow-pop);
  }
  .shell.menu-open .sidebar { transform: none; }
  .shell.is-collapsed .brand-text, .shell.is-collapsed .nav-label, .shell.is-collapsed .nav-count, .shell.is-collapsed .sidebar-user { display: initial; }
  .shell.is-collapsed .nav-item { justify-content: flex-start; padding: 0 12px; }
  .shell.is-collapsed .sidebar-head { flex-direction: row; }
  .sidebar-toggle { display: none; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 16px; gap: 10px; }
  .main { padding: 16px 16px 40px; }
  .last-updated { display: none; }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login-brand { display: none; }
  .brand-compact { display: flex; }
}

@media (max-width: 720px) {
  body { font-size: 15px; }
  .topbar-title h1 { font-size: 18px; }
  .topbar-title p { display: none; }
  .btn-label { display: none; }
  #newOrgBtn { width: 38px; padding: 0; }
  .toolbar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .field-search { grid-column: 1 / -1; }
  .field-search, .field-inline, .field-compact { flex: 1 1 auto; }
  .panel-head .field-compact { width: 100%; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .kpi-row { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: 24px; }
  .mix-legend { grid-template-columns: minmax(0, 1fr); }
  .pulse-main, .pulse-mix { padding: 18px; }
  .detail-hero { grid-template-columns: minmax(0, 1fr); padding: 16px; }
  .detail-actions { justify-content: flex-start; }
  .timeline li { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .attention-item { grid-template-columns: minmax(0, 1fr); gap: 2px; padding: 10px 14px; }
  .ticket-form { grid-template-columns: minmax(0, 1fr); }
  .log-json { grid-template-columns: minmax(0, 1fr); }
  .preview-meta > div { grid-template-columns: minmax(0, 1fr); gap: 0; }

  /* Tabela vira lista de cartoes: cada celula mostra o rotulo da coluna. */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { position: relative; min-height: 30px; padding: 5px 0 5px calc(36% + 12px); border: 0; text-align: left; }
  .table td::before { content: attr(data-label); position: absolute; left: 0; top: 6px; width: 36%; font-size: 12px; font-weight: 600; color: var(--muted); overflow-wrap: break-word; }
  .table td:not([data-label]) { padding-left: 0; min-height: 0; }
  .table td:not([data-label])::before { content: none; }
  .table .num { text-align: left; white-space: normal; }
  .table-hover tbody tr:hover td { background: transparent; }
  .cell-actions { width: 100%; text-align: left; padding-top: 8px !important; }
  .cell-actions .btn-row { justify-content: flex-start; flex-wrap: wrap; }
  .bar { width: 90px; }

  .dialog, .dialog-sm, .dialog-lg, .dialog-xl { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; }
  .dialog-sm { height: auto; max-height: 100dvh; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .dialog-foot { border-radius: 0; }
  .dialog-head { padding: 14px 16px; }
  .dialog-body, .template-edit, .template-preview { padding: 14px 16px; }
  .preview[data-mode="mobile"] .preview-frame { border-width: 6px; border-radius: 20px; }
  .var-item { grid-template-columns: minmax(0, 1fr); }
  .var-sample, .var-used { grid-column: auto; grid-row: auto; }
  .login-card { padding: 28px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .badge, .chip, .seg[aria-pressed="true"], .nav-item.is-active { border: 1px solid CanvasText; }
  .mix-seg, .swatch, .bar-fill, .meter-fill { forced-color-adjust: none; }
}
