:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #16191f;
  --muted: #5d6573;
  --primary: #0f7b5f;
  --primary-hover: #0c664f;
  --primary-soft: #e3f3ee;
  --primary-text: #ffffff;
  --danger: #c43d3d;
  --danger-soft: #fbeaea;
  --warn: #a76a00;
  --warn-soft: #fdf3dc;
  --info: #2c62c9;
  --info-soft: #e7eefb;
  --ok: #157a3c;
  --ok-soft: #e4f4ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --border: #2a3039; --text: #e7eaee; --muted: #9aa3af;
    --primary: #2bb38a; --primary-hover: #36c79b; --primary-soft: #133229; --primary-text: #071a14;
    --danger: #ef6b6b; --danger-soft: #3a1c1e; --warn: #e3a83a; --warn-soft: #362a12; --info: #6f9cf0; --info-soft: #18243b;
    --ok: #4cc77a; --ok-soft: #14301f; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1216; --surface: #171b21; --surface-2: #1e232b; --border: #2a3039; --text: #e7eaee; --muted: #9aa3af;
  --primary: #2bb38a; --primary-hover: #36c79b; --primary-soft: #133229; --primary-text: #071a14;
  --danger: #ef6b6b; --danger-soft: #3a1c1e; --warn: #e3a83a; --warn-soft: #362a12; --info: #6f9cf0; --info-soft: #18243b;
  --ok: #4cc77a; --ok-soft: #14301f; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
svg.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; transition: width .18s ease; flex: none; z-index: 20;
}
.shell.collapsed .sidebar { width: var(--sidebar-w-collapsed); }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; flex: none; }
.brand .logo svg { width: 16px; height: 16px; }
.nav { padding: 6px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a, .nav button {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--muted);
  font: inherit; background: none; border: 0; cursor: pointer; text-align: left; white-space: nowrap; overflow: hidden; width: 100%;
}
.nav a:hover, .nav button:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.shell.collapsed .nav .label, .shell.collapsed .brand .label { display: none; }
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 48px; max-width: 1280px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.section { margin-top: 24px; }
.kpi { display: flex; flex-direction: column; gap: 4px; }
.kpi .label { color: var(--muted); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon-only { width: 36px; padding: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 560; font-size: 13px; }
.field .hint { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { width: 38px; height: 22px; appearance: none; background: var(--border); border-radius: 22px; position: relative; cursor: pointer; padding: 0; border: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 19px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
tbody tr.clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table-wrap table tr:last-child td { border-bottom: 0; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.plain::before { display: none; }

.empty, .loading, .error-box { padding: 36px 16px; text-align: center; color: var(--muted); }
.empty svg.icon, .error-box svg.icon { width: 28px; height: 28px; margin-bottom: 8px; }
.error-box { color: var(--danger); }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 8px; background: var(--info-soft); color: var(--info); margin-bottom: 16px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert div { color: var(--text); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 150px; flex: 1; }

.progress { height: 8px; background: var(--surface-2); border-radius: 8px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); width: 0; transition: width .3s; }

.toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 380px; font-size: 13.5px; animation: fadein .15s; }
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 16, .45); display: grid; place-items: center; z-index: 90; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; border: 1px solid var(--border); width: 100%; max-width: 480px; padding: 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h2 { margin-bottom: 8px; }
.modal .btn-row { justify-content: flex-end; margin-top: 18px; }

.qr-box { display: grid; place-items: center; background: #fff; border-radius: 10px; padding: 14px; width: 260px; height: 260px; margin: 12px auto; }
.qr-box svg { width: 100%; height: 100%; }

.transcript { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 80%; padding: 9px 12px; border-radius: 12px; background: var(--surface-2); }
.bubble.assistant { align-self: flex-start; }
.bubble.user { align-self: flex-end; background: var(--primary-soft); }
.bubble .who { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }
audio { width: 100%; max-width: 360px; height: 36px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { padding: 0 0 18px; justify-content: center; font-size: 20px; }

/* ---------- responsivo ---------- */
.menu-toggle { display: none; }
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; width: var(--sidebar-w) !important; }
  .shell.mobile-open .sidebar { transform: none; }
  .shell.collapsed .nav .label, .shell.collapsed .brand .label { display: inline; }
  .menu-toggle { display: inline-flex; }
  .collapse-toggle { display: none !important; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 12px 16px; }
  .bubble { max-width: 92%; }
}
.w-full { width: 100%; }
.field-card { padding: 14px 16px; }
.field-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.field-head .spacer { flex: 1; }
.switch.small { font-size: 13px; }
