/* ============================================================
   DS Xenia — Stylesheet
   DS family palette (shared with Rheia/Themis/Hercules):
   maroon #911132 primary, deep wine #240a13 structure, gold
   #ffb000 accent (DS logo colours). Original token NAMES kept (--navy/--gold/…)
   so component rules are untouched; values re-mapped.
   Light + dark themes via [data-theme] on <html>.
   ============================================================ */

:root {
  --navy:       #240a13;   /* deep wine — sidebar/structure (DS logo maroon family) */
  --navy-light: #3a1421;
  --gold:       #ffb000;   /* DS logo gold */
  --gold-light: #ffc233;
  --blue:       #911132;   /* DS logo maroon — primary actions (token name kept) */
  --blue-deep:  #6d0c25;
  --blue-bg:    #f7e3e9;
  --bg:         #f4f6f9;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --text-muted: #64748b;
  --red:        #dc2626;
  --red-bg:     #fef2f2;
  --green:      #059669;
  --green-bg:   #ecfdf5;
  --amber:      #f59e0b;
  --amber-bg:   #fffbeb;
  --sidebar-w:  240px;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md:  0 4px 6px rgba(15,23,42,.07), 0 2px 4px rgba(15,23,42,.05);
}

[data-theme="dark"] {
  --navy:       #190509;
  --navy-light: #331019;
  --gold:       #ffbe33;
  --gold-light: #ffcd5c;
  --blue:       #d94f74;
  --blue-deep:  #e87b97;
  --blue-bg:    #3d1422;
  --bg:         #120810;
  --surface:    #221220;
  --border:     #41263a;
  --text:       #e2e8f0;
  --text-muted: #bf9fae;
  --red:        #f05252;
  --red-bg:     #3a1620;
  --green:      #10b981;
  --green-bg:   #0c2f25;
  --amber:      #fbbf24;
  --amber-bg:   #34280f;
  --shadow:     0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-md:  0 6px 14px rgba(0,0,0,.55);
}

html { background: var(--bg); color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* Slate scrollbars (family treatment) */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Smooth theme transitions */
body, #sidebar, #main-content, .card, .auth-card, #modal-box, input, select, textarea, table, tbody td {
  transition: background-color .25s ease, border-color .25s ease, color .15s ease;
}

/* Theme toggle (fixed — visible on auth + dashboard screens) */
#theme-toggle {
  position: fixed; right: 16px; bottom: 16px; z-index: 900;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-md);
  font-size: 17px; cursor: pointer; line-height: 1;
}
#theme-toggle:hover { border-color: var(--blue); }

/* Dark-mode corrections for hardcoded pastel badges */
[data-theme="dark"] .badge-open           { background: #16243f; color: #93c5fd; }
[data-theme="dark"] .badge-in-progress    { background: #1e1b4b; color: #a5b4fc; }
[data-theme="dark"] .badge-pending-client { background: #34280f; color: #fcd34d; }
[data-theme="dark"] .badge-pending-agent  { background: #3a1620; color: #fda4af; }
[data-theme="dark"] .badge-resolved       { background: #0c2f25; color: #6ee7b7; }
[data-theme="dark"] .badge-low            { background: #1c2940; color: #94a3b8; }
[data-theme="dark"] .badge-medium         { background: #34280f; color: #fcd34d; }
[data-theme="dark"] .badge-high           { background: #3a1620; color: #fda4af; }

/* Dark mode: --navy used as TEXT colour would vanish on dark surfaces */
[data-theme="dark"] .auth-logo .logo-xi,
[data-theme="dark"] .auth-logo .logo-title,
[data-theme="dark"] .auth-card h2,
[data-theme="dark"] .stat-value,
[data-theme="dark"] .page-title { color: var(--text); }
[data-theme="dark"] .auth-logo .logo-xi { color: var(--gold); }
[data-theme="dark"] .spinner { border-top-color: var(--blue); }
[data-theme="dark"] .btn-gold { color: #240a13; }
[data-theme="dark"] .btn-gold:hover:not(:disabled) { color: #240a13; }
[data-theme="dark"] input:focus, [data-theme="dark"] select:focus, [data-theme="dark"] textarea:focus { border-color: var(--blue); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--blue); text-decoration: none; }
a:hover { color: var(--blue-deep); }
code { font-family: monospace; background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ── Layout ──────────────────────────────────────── */
.hidden { display: none !important; }
.screen { min-height: 100vh; }

#app {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.logo-xi {
  font-size: 28px;
  color: var(--gold);
  font-family: Georgia, serif;
  line-height: 1;
  flex-shrink: 0;
}
.logo-title { color: #fff; font-weight: 700; font-size: 15px; }
.logo-sub   { color: rgba(255,255,255,.5); font-size: 11px; margin-top: 1px; }

.nav-links {
  list-style: none;
  padding: 12px 0;
  flex: 1;
}
.nav-links li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: rgba(255,255,255,.7);
  font-size: 14px;
  border-radius: 0;
  transition: background .15s, color .15s;
}
.nav-links li a:hover, .nav-links li a.active {
  background: rgba(255,255,255,.1);
  color: #fff;
}
.nav-links li a.active { border-left: 3px solid var(--gold); padding-left: 13px; }
.nav-links li a .nav-icon { width: 18px; text-align: center; opacity: .8; }
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.nav-user {
  color: rgba(255,255,255,.7);
  font-size: 13px;
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 28px 32px;
  max-width: 1400px;
}

/* ── Auth screens ─────────────────────────────────── */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2a0b15 0%, #911132 60%, #c01a45 100%);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 36px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.setup-2fa-card { max-width: 460px; }

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.auth-logo .logo-xi { font-size: 40px; color: var(--navy); }
.auth-logo .logo-title { color: var(--navy); font-size: 20px; font-weight: 700; }
.auth-logo .logo-sub { color: var(--text-muted); font-size: 12px; }

.auth-card h2 { font-size: 18px; font-weight: 600; margin-bottom: 20px; color: var(--navy); }
.auth-links { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-muted); display: flex; gap: 8px; justify-content: center; align-items: center; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-divider span { font-size: 12px; color: var(--text-muted); }

/* ── Forms ───────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text); margin-bottom: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="number"], input[type="search"],
textarea, select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(26,43,74,.1);
}
textarea { resize: vertical; min-height: 100px; }
.input-code {
  font-size: 22px;
  letter-spacing: 6px;
  text-align: center;
  font-weight: 600;
}

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 18px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--blue-deep); color: #fff; }
.btn-gold    { background: var(--gold); color: var(--navy); font-weight: 600; }
.btn-gold:hover:not(:disabled) { background: var(--gold-light); color: var(--navy); }
.btn-danger  { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-ms      { background: #fff; color: #333; border: 1px solid var(--border); font-weight: 600; }
.btn-ms:hover { background: var(--bg); color: #333; }
.btn-sm  { padding: 6px 12px; font-size: 13px; }
.btn-xs  { padding: 4px 9px; font-size: 12px; }
.btn-icon { background: none; border: none; cursor: pointer; padding: 4px; font-size: 16px; color: var(--text-muted); }
.btn-icon:hover { color: var(--text); }
.w-full { width: 100%; }

/* ── Alerts ──────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px; }
.alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #fecaca; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #bbf7d0; }
.alert-info    { background: var(--blue-bg);  color: var(--blue);  border: 1px solid #bfdbfe; }
.alert-warning { background: var(--amber-bg); color: var(--amber); border: 1px solid #fde68a; }

/* ── Cards ───────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 600; }
.card-body  { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); }

/* ── Stats grid ──────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--navy); line-height: 1; }
.stat-card.danger .stat-value  { color: var(--red); }
.stat-card.warning .stat-value { color: var(--amber); }
.stat-card.success .stat-value { color: var(--green); }

/* ── Tables ──────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .4px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr:hover { background: var(--bg); }
tbody tr:last-child td { border-bottom: none; }

/* ── Badges ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
  white-space: nowrap;
}
.badge-open        { background: #dbeafe; color: #1d4ed8; }
.badge-in-progress { background: #e0e7ff; color: #4338ca; }
.badge-pending-client { background: #fef3c7; color: #92400e; }
.badge-pending-agent  { background: #ffe4e6; color: #9f1239; }
.badge-resolved    { background: #dcfce7; color: #166534; }
.badge-closed      { background: var(--border); color: var(--text-muted); }
.badge-low         { background: #f1f5f9; color: #475569; }
.badge-medium      { background: #fef3c7; color: #92400e; }
.badge-high        { background: #fee2e2; color: #b91c1c; }
.badge-critical    { background: #7f1d1d; color: #fff; }

/* ── Ticket thread ───────────────────────────────── */
.message-thread { display: flex; flex-direction: column; gap: 16px; }
.message-bubble {
  max-width: 80%;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
  position: relative;
}
.message-bubble.from-client {
  background: var(--bg);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-top-left-radius: 2px;
}
.message-bubble.from-agent {
  background: var(--navy);
  color: #fff;
  align-self: flex-end;
  border-top-right-radius: 2px;
}
.message-bubble.internal {
  background: #fffbeb;
  border: 1px dashed var(--amber);
  align-self: flex-end;
  opacity: .9;
}
.message-meta { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.message-bubble.from-agent .message-meta { color: rgba(255,255,255,.6); }
.internal-label { font-size: 10px; font-weight: 700; color: var(--amber); text-transform: uppercase; margin-bottom: 4px; }

/* ── Page headers ────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--navy); }
.page-sub   { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── Filters bar ─────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filters-bar input, .filters-bar select { max-width: 200px; }
.filters-bar .search-input { max-width: 260px; }

/* ── Pagination ──────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
  font-size: 13px;
}
.pagination .page-info { color: var(--text-muted); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ── Toast ───────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: toastIn .2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.success { background: #166534; }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--amber); color: var(--text); }
@keyframes toastIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ── Modal ───────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
#modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
#modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
#modal-header h3 { font-size: 16px; font-weight: 600; }
#modal-body { padding: 20px; overflow-y: auto; }

/* ── QR code ─────────────────────────────────────── */
.qr-container {
  display: flex;
  justify-content: center;
  margin: 20px 0;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
}

/* ── SLA indicator ───────────────────────────────── */
.sla-indicator { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; }
.sla-ok      { color: var(--green); }
.sla-warning { color: var(--amber); }
.sla-breach  { color: var(--red); }
.sla-dot { width: 7px; height: 7px; border-radius: 50%; }
.sla-dot.ok      { background: var(--green); }
.sla-dot.warning { background: var(--amber); }
.sla-dot.breach  { background: var(--red); }

/* ── Misc ────────────────────────────────────────── */
.text-muted   { color: var(--text-muted); font-size: 13px; }
.text-center  { text-align: center; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.loading { display: flex; align-items: center; justify-content: center; padding: 60px; color: var(--text-muted); gap: 10px; font-size: 14px; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--navy); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.ticket-number { font-family: monospace; font-size: 13px; color: var(--text-muted); }
.priority-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.priority-dot.critical { background: #7f1d1d; }
.priority-dot.high     { background: var(--red); }
.priority-dot.medium   { background: var(--amber); }
.priority-dot.low      { background: var(--text-muted); }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { transform: translateX(-240px); transition: transform .25s; }
  #sidebar.open { transform: translateX(0); width: 240px; }
  #main-content { margin-left: 0; padding: 20px 16px; }
  .form-row { grid-template-columns: 1fr; }
  .auth-card { padding: 28px 24px; }
}
