/* ============================================================
   Asistia — mobile-first dashboard CSS (plain, no frameworks)
   ============================================================ */

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #4f46e5;
  --primary-2: #6366f1;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --radius: 12px;
  --shadow: 0 4px 18px rgba(0, 0, 0, .35);
  --sidebar-w: 260px;
  --sidebar-collapsed: 68px;
  --topbar-h: 56px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
#app { min-height: 100vh; }

/* ---------- Layout shell ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-header { display: flex; align-items: center; gap: .6rem; padding: .9rem 1rem; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--primary); color: #fff;
  font-weight: 800;
}
.brand-name { font-size: 1.05rem; font-weight: 800; letter-spacing: .3px; }

.sidebar .nav-group { padding: .25rem .5rem .5rem; }
.nav-group-title {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: .35rem .75rem;
}
.nav-item {
  display: flex; align-items: center; gap: .8rem; width: 100%;
  padding: .62rem .85rem; border-radius: 9px; border: 0;
  background: transparent; color: var(--text); cursor: pointer;
  font-size: .92rem; text-align: left;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .nav-icon { width: 1.25rem; text-align: center; flex: 0 0 auto; font-size: 1rem; }
.nav-label { flex: 1; }

.sidebar-footer {
  padding: .75rem 1rem; border-top: 1px solid var(--border); font-size: .75rem;
  color: var(--muted);
}

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .9rem; padding: 0 1.1rem;
}
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 0;
  background: transparent; color: var(--text); cursor: pointer;
  font-size: 1.15rem; display: grid; place-items: center; position: relative;
}
.icon-btn:hover { background: var(--surface-2); }
.topbar-title { font-size: 1.05rem; font-weight: 700; flex: 0 0 auto; }
.topbar-spacer { flex: 1; }
.badge-dot {
  position: absolute; top: 5px; right: 6px; min-width: 15px; height: 15px;
  border-radius: 8px; background: var(--danger); color: #fff;
  font-size: .62rem; display: grid; place-items: center;
}
.avatar-btn {
  display: inline-flex; align-items: center; gap: .45rem;
  border-radius: 10px; border: 0; background: var(--primary); color: #fff;
  padding: .38rem .8rem; cursor: pointer; font-size: .86rem; font-weight: 700;
}
.avatar-circle {
  width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .8rem;
}
.user-menu {
  position: absolute; right: .25rem; top: calc(var(--topbar-h) - 8px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 230px; padding: .75rem; z-index: 60;
  display: none;
}
.user-menu.open { display: block; }
.user-menu .um-head { font-weight: 700; font-size: .9rem; }
.user-menu .um-sub { color: var(--muted); font-size: .78rem; margin-bottom: .6rem; }
.user-menu button.menu-item {
  width: 100%; text-align: left; background: transparent; border: 0; color: var(--text);
  padding: .55rem .7rem; border-radius: 8px; cursor: pointer; font-size: .88rem;
}
.user-menu button.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); }

/* ---------- Main content ---------- */
.main { min-width: 0; min-height: 100vh; overflow-x: hidden; }
.page {
  padding: 1.2rem clamp(.9rem, 3vw, 2rem);
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* ---------- Mobile drawer + desktop collapse ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .55); z-index: 25;
  display: none;
}
body.nav-open .backdrop { display: block; }

@media (min-width: 900px) {
  body.nav-collapsed .app-shell { grid-template-columns: var(--sidebar-collapsed) 1fr; }
  body.nav-collapsed .nav-label,
  body.nav-collapsed .brand-name,
  body.nav-collapsed .nav-group-title { display: none; }
  body.nav-collapsed .sidebar-header { justify-content: center; }
  body.nav-collapsed .nav-item { justify-content: center; padding: .62rem; }
}

@media (max-width: 899px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease;
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open { overflow: hidden; }
}

/* ---------- Typography & helpers ---------- */
h1.page-title { font-size: 1.35rem; font-weight: 800; margin-bottom: .35rem; }
.page-sub { color: var(--muted); font-size: .86rem; margin-bottom: 1.1rem; }
.muted { color: var(--muted); font-size: .82rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  border-radius: 10px; border: 1px solid transparent; cursor: pointer;
  padding: .55rem 1rem; font-size: .9rem; font-weight: 700;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { filter: brightness(1.12); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #06281a; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { margin-bottom: .85rem; display: block; }
.field label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }
.input, .select, .textarea {
  width: 100%; padding: .6rem .8rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-size: .95rem; outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); }
.select { appearance: auto; }
/* Modal (used by the push-notification panel). */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(2, 6, 23, .6); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-card {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 460px;
  max-height: 88vh; overflow: auto;
}
.modal-head {
  display: flex; align-items: center; gap: .5rem; padding: 1rem 1.1rem .5rem;
  font-weight: 800;
}
.modal-head .modal-close { margin-left: auto; }
.modal-body { padding: 0 1.1rem 1.1rem; display: grid; gap: .8rem; }
.modal-foot {
  display: flex; gap: .5rem; flex-wrap: wrap; padding: .8rem 1.1rem 1.1rem;
  border-top: 1px solid var(--border);
}
.push-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.push-topic {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: .45rem .6rem; word-break: break-all;
}

.form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem;
}
.form-card h3 { font-size: .95rem; font-weight: 800; margin-bottom: .8rem; }

/* ---------- Cards & lists ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.grid-cards { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.stat-card { display: grid; grid-auto-flow: column; align-items: center; gap: .7rem; }
.stat-card .stat-num { font-size: 1.5rem; font-weight: 800; }
.stat-card .stat-label { color: var(--muted); font-size: .78rem; }
.stat-card .stat-icon { font-size: 1.3rem; }

.table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border-radius: var(--radius); overflow: hidden; font-size: .86rem;
}
.table th, .table td { padding: .6rem .75rem; text-align: left; }
.table th { background: var(--surface-2); color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:nth-child(even) { background: rgba(51, 65, 85, .25); }
.table td .row { gap: .45rem; }

.badge {
  display: inline-block; padding: .12rem .6rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700;
}
.badge-active { background: rgba(34, 197, 94, .16); color: var(--success); }
.badge-disabled { background: rgba(239, 68, 68, .16); color: var(--danger); }
.badge-configuring { background: rgba(245, 158, 11, .16); color: var(--warn); }
.badge-role { background: var(--surface-2); color: var(--muted); }

.empty {
  padding: 2.2rem 1rem; text-align: center; color: var(--muted);
  font-size: .92rem;
}

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px; padding: 1.6rem;
  box-shadow: var(--shadow);
}
.auth-brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1rem; }
.auth-title { text-align: center; font-size: 1.2rem; font-weight: 800; margin-bottom: .15rem; }
.auth-sub { text-align: center; color: var(--muted); font-size: .84rem; margin-bottom: 1.3rem; }
.lang-switch { display: flex; justify-content: center; gap: .4rem; margin-bottom: 1.4rem; }
.lang-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: .2rem .55rem; border-radius: 7px; font-size: .78rem; font-weight: 700;
}
.lang-btn.active { background: var(--primary); color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow); max-width: min(92vw, 460px);
  padding: .7rem 1.1rem; border-radius: 12px; z-index: 100;
  font-size: .88rem; animation: fadeIn .2s ease;
}
.toast.error { border-color: var(--danger); color: #fff; background: var(--danger); }
.toast.success { border-color: var(--success); color: #fff; background: var(--success); }

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9; --surface: #ffffff; --surface-2: #eef2f7;
    --border: #d7dce4; --text: #0f172a; --muted: #64748b;
  }
}

/* ---------- Inbox (unified, per-channel tabs) ---------- */
.inbox { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 2.4rem); min-height: 440px; }
.inbox-tabs { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .6rem; }
.inbox-tab {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: .35rem .9rem; font-size: .8rem; cursor: pointer;
  white-space: nowrap;
}
.inbox-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.inbox-body { display: grid; grid-template-columns: 320px 1fr; gap: 1rem; flex: 1; min-height: 0; }
.conv-list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-y: auto; }
.conv-item {
  display: flex; flex-direction: column; gap: .15rem;
  padding: .7rem .8rem; border-bottom: 1px solid var(--border); cursor: pointer;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--surface-2); border-left: 3px solid var(--primary); }
.conv-top { display: flex; gap: .5rem; align-items: center; }
.conv-name { font-weight: 700; font-size: .9rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview { color: var(--muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.thread-head { display: flex; gap: .6rem; align-items: center; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.thread-msgs { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .55rem; }
.msg {
  max-width: 78%; padding: .55rem .8rem; border-radius: 14px;
  font-size: .9rem; line-height: 1.35; word-wrap: break-word;
}
.msg .msg-meta { font-size: .66rem; opacity: .75; margin-top: .2rem; }
.msg-contact { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.msg-agent { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-bot { align-self: flex-end; background: var(--surface-2); border: 1px dashed var(--border); border-bottom-right-radius: 4px; }
/* Internal staff comment: team-only, never shown to the visitor. */
.msg-comment {
  align-self: flex-end; max-width: 78%; padding: .45rem .7rem; border-radius: 12px;
  background: #fffbeb; border: 1px dashed #f59e0b; color: #78350f;
  font-size: .85rem; line-height: 1.35; word-wrap: break-word;
}
.thread-composer { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--border); }
.thread-composer .input { flex: 1; }
.empty-thread { flex: 1; display: grid; place-items: center; color: var(--muted); }
@media (max-width: 899px) {
  .inbox-body { grid-template-columns: 1fr; }
  .thread { display: none; }
  .inbox.show-thread .conv-list { display: none; }
  .inbox.show-thread .thread { display: flex; }
}

/* ---------- Code snippet ---------- */
.textarea { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; }

/* ---------- Token quota progress bars (Phase 4) ---------- */
.quota-bar {
  width: 110px; height: 8px; border-radius: 4px;
  background: var(--surface-2, #e5e7eb); overflow: hidden; display: inline-block;
  vertical-align: middle; margin-right: .4rem;
}
.quota-fill { height: 100%; background: var(--accent, #4f46e5); border-radius: 4px; }
.quota-fill.hot { background: var(--danger, #dc2626); }
.quota-input { width: 130px; }