:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --line: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-2: #22d3ee;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --violet: #a855f7;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(160deg, #0b1220 0%, #0f172a 100%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--accent-2); }

/* ─── Auth screen ─────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.auth-card .logo {
  width: 52px; height: 52px; border-radius: 13px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; font-size: 20px; color: #0b1220;
}
.auth-card h2 { text-align: center; margin: 0 0 4px; font-size: 20px; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; background: #0e1726; border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 9px; font-size: 14px; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.auth-toggle { text-align: center; font-size: 13px; color: var(--muted); margin-top: 16px; }
.auth-toggle button { background: none; border: none; color: var(--accent-2); cursor: pointer; font-size: 13px; }
.auth-msg { font-size: 13px; border-radius: 9px; padding: 10px 12px; margin-bottom: 14px; }
.auth-msg.err { background: rgba(239,68,68,.12); color: #fca5a5; border: 1px solid rgba(239,68,68,.3); }
.auth-msg.ok  { background: rgba(34,197,94,.12); color: #86efac; border: 1px solid rgba(34,197,94,.3); }
.setup-banner {
  background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.35); color: #fcd34d;
  border-radius: 10px; padding: 12px 14px; font-size: 13px; margin-bottom: 18px; line-height: 1.5;
}

/* ─── Top bar ──────────────────────────────────────────────────── */
header.topbar {
  padding: 18px 28px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand .logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #0b1220;
}
.brand h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.user-box { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.user-box .who { text-align: right; }
.user-box .who .email { font-weight: 600; }
.user-box .who .period { color: var(--muted); font-size: 11px; }
.role-badge { padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.role-admin  { background: rgba(168,85,247,.18); color: #d8b4fe; }
.role-agent  { background: rgba(59,130,246,.18); color: #93c5fd; }
.role-viewer { background: rgba(148,163,184,.18); color: #cbd5e1; }

main { padding: 24px 28px 48px; max-width: 1600px; margin: 0 auto; }

/* ─── KPIs ─────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::after { content: ""; position: absolute; right: -20px; top: -20px; width: 70px; height: 70px; border-radius: 50%; background: radial-gradient(circle, var(--accent) 0%, transparent 70%); opacity: .25; }
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 27px; font-weight: 800; margin-top: 6px; }
.kpi .sub { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi .sub.up { color: var(--green); } .kpi .sub.down { color: var(--red); }

/* ─── Toolbar + buttons ────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"], .toolbar select {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 9px 12px; border-radius: 9px; font-size: 13px; outline: none;
}
.toolbar input[type="search"] { min-width: 240px; flex: 1; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); }
.toolbar .spacer { flex: 1; }
.btn { background: var(--accent); color: #fff; border: none; padding: 9px 15px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

/* ─── Table ────────────────────────────────────────────────────── */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; overflow: auto; max-height: 66vh; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th { position: sticky; top: 0; background: var(--panel-2); text-align: left; padding: 12px 14px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
thead th:hover { color: var(--text); }
thead th .arrow { font-size: 10px; opacity: .6; margin-left: 4px; }
tbody td { padding: 11px 14px; border-bottom: 1px solid rgba(51,65,85,.5); white-space: nowrap; }
tbody tr:hover { background: rgba(99,102,241,.07); }
tbody tr:last-child td { border-bottom: none; }
.empty-row td { text-align: center; color: var(--muted); padding: 40px; }
.cust { display: flex; align-items: center; gap: 9px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #0b1220; flex: none; }
.cust .name { font-weight: 600; } .cust .email { font-size: 11px; color: var(--muted); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.b-open{background:rgba(59,130,246,.15);color:#93c5fd} .b-progress{background:rgba(245,158,11,.15);color:#fcd34d}
.b-pending{background:rgba(168,85,247,.15);color:#d8b4fe} .b-resolved{background:rgba(34,197,94,.15);color:#86efac}
.b-closed{background:rgba(148,163,184,.15);color:#cbd5e1} .b-escalated{background:rgba(239,68,68,.15);color:#fca5a5}
.p-low{color:#86efac} .p-medium{color:#fcd34d} .p-high{color:#fdba74} .p-critical{color:#fca5a5;font-weight:700}
.pri-dot { display:inline-block; width:8px; height:8px; border-radius:50%; margin-right:6px; }
.csat { font-weight: 700; } .csat-good{color:var(--green)} .csat-ok{color:var(--amber)} .csat-bad{color:var(--red)}
.stars { letter-spacing: 1px; }
.channel { font-size: 12px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; }
.icon-btn { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 4px 8px; font-size: 12px; cursor: pointer; }
.icon-btn:hover { border-color: var(--accent); }
.clip { color: var(--accent-2); font-size: 12px; }

.footer-note { margin-top: 14px; font-size: 12px; color: var(--muted); display:flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }
.pill-count { color: var(--text); font-weight: 600; }

/* ─── Modal ────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(2,6,23,.72); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; width: 100%; max-width: 620px; max-height: 88vh; overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.5); }
.modal.wide { max-width: 840px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-head .x { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; line-height: 1; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--panel); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .grid2 { grid-template-columns: 1fr; } }

/* attachments inside modal */
.attach-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.attach-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #0e1726; border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; font-size: 13px; }
.attach-item .meta { color: var(--muted); font-size: 11px; }
.dropzone { border: 1px dashed var(--line); border-radius: 10px; padding: 16px; text-align: center; color: var(--muted); font-size: 13px; cursor: pointer; }
.dropzone:hover { border-color: var(--accent); color: var(--text); }

/* user management table */
.users-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.users-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.users-table td { padding: 8px 10px; border-bottom: 1px solid rgba(51,65,85,.5); }
.users-table select { background: #0e1726; border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 5px 8px; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; line-height: 1.5; }

/* ─── Toast ────────────────────────────────────────────────────── */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 11px 16px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.4); animation: slideup .2s ease; }
.toast.ok { border-color: rgba(34,197,94,.5); } .toast.err { border-color: rgba(239,68,68,.5); }
@keyframes slideup { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* loading spinner */
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { min-height: 60vh; display: grid; place-items: center; color: var(--muted); }
