/* ── Variables — Dark (default) ─────────────────────────────────────────────── */
:root {
  --bg:        #0d0f14;
  --bg-panel:  #131720;
  --bg-card:   #1a1f2e;
  --bg-hover:  #1f2535;
  --border:    #252d3d;
  --border-light: #2d3748;
  --text:      #e2e8f0;
  --text-muted:#7c8ca0;
  --text-dim:  #4a5568;
  --accent:    #6366f1;
  --accent-light: #818cf8;
  --accent-dim: rgba(99,102,241,0.12);
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --sky:       #0ea5e9;
  --sidebar-w: 240px;
  --radius:    8px;
  --radius-lg: 12px;
  --font:      'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --shadow:    0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  /* surface aliases used by inline styles */
  --surface:   var(--bg-card);
  --surface-2: var(--bg-hover);
  /* theme-specific overrides */
  --btn-secondary-hover: #263048;
  --reply-form-bg: rgba(0,0,0,.15);
}

/* ── Variables — Light ───────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg:        #f8fafc;
  --bg-panel:  #ffffff;
  --bg-card:   #ffffff;
  --bg-hover:  #f1f5f9;
  --border:    #e2e8f0;
  --border-light: #cbd5e1;
  --text:      #0f172a;
  --text-muted:#64748b;
  --text-dim:  #94a3b8;
  --accent-light: #4f46e5;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,.08);
  --btn-secondary-hover: #e2e8f0;
  --reply-form-bg: rgba(0,0,0,.03);
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--text); }

input, select, textarea, button {
  font-family: var(--font);
  font-size: 0.9rem;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  padding: 0;
}

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  overflow-x: hidden;
}

.page-wrapper {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 32px;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  max-height: 42px;
  max-width: 160px;
  width: auto;
  object-fit: contain;
}
.brand-icon { font-size: 1.4rem; }
.brand-name {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.sidebar-section {
  padding: 16px 10px 4px;
  flex: 0;
}
.sidebar-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  padding: 0 8px;
  margin-bottom: 4px;
}

.sidebar-footer {
  margin-top: auto;
  padding: 10px 10px 16px;
  border-top: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  width: 100%;
  border: none;
  background: none;
  text-align: left;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent-light); }
.nav-logout { color: var(--text-muted); }
.nav-logout:hover { color: var(--red); background: rgba(239,68,68,.1); }

/* ── Theme toggle ──────────────────────────────────────────────────────────── */
.theme-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
}

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 20px; }

/* ── Stats Grid ────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.stat-card.blue::before { background: var(--accent); }
.stat-card.green::before { background: var(--green); }
.stat-card.amber::before { background: var(--amber); }
.stat-card.red::before { background: var(--red); }
.stat-card.sky::before { background: var(--sky); }
.stat-card.gray::before { background: var(--text-dim); }
a.stat-card-link {
  display: block;
  text-decoration: none;
  color: var(--text);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
a.stat-card-link:hover {
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.tr-link:hover { background: var(--bg-hover); }

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  margin-bottom: 6px;
}
.stat-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Page Header ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}
.page-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: #5254d3; border-color: #5254d3; color: #fff; }

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-light);
}
.btn-secondary:hover { background: var(--btn-secondary-hover); color: var(--text); }

.btn-danger {
  background: transparent;
  color: var(--red);
  border-color: rgba(239,68,68,.3);
}
.btn-danger:hover { background: rgba(239,68,68,.1); color: var(--red); }

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }
.btn-xs { padding: 3px 9px; font-size: 0.75rem; border-radius: 5px; }

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
/* Status */
.badge-open     { background: rgba(99,102,241,.15); color: var(--accent-light); }
.badge-inprogress { background: rgba(14,165,233,.15); color: var(--sky); }
.badge-pending  { background: rgba(245,158,11,.15); color: var(--amber); }
.badge-resolved { background: rgba(16,185,129,.15); color: var(--green); }
.badge-closed   { background: rgba(100,116,139,.15); color: #94a3b8; }
/* Priority */
.badge-low      { background: rgba(100,116,139,.12); color: #94a3b8; }
.badge-medium   { background: rgba(14,165,233,.12); color: var(--sky); }
.badge-high     { background: rgba(245,158,11,.12); color: var(--amber); }
.badge-critical { background: rgba(239,68,68,.12); color: var(--red); }

/* ── Table ─────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.data-table a { color: var(--text); font-weight: 500; }
.data-table a:hover { color: var(--accent-light); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  gap: 20px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
input[type=text],
input[type=email],
input[type=password],
input[type=number],
input[type=date],
input[type=datetime-local],
select,
textarea {
  background: var(--bg);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.9rem;
  color: var(--text);
  width: 100%;
  transition: border-color .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { resize: vertical; min-height: 120px; }
select option { background: var(--bg-card); color: var(--text); }

.form-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }

/* ── Alerts ────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.alert-success { background: rgba(16,185,129,.1); border: 1px solid rgba(16,185,129,.25); color: var(--green); }
.alert-error   { background: rgba(239,68,68,.1);  border: 1px solid rgba(239,68,68,.25);  color: var(--red); }

/* ── Auth Page ─────────────────────────────────────────────────────────────── */
.auth-layout {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(99,102,241,0.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(14,165,233,0.04) 0%, transparent 60%),
    var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  box-shadow: var(--shadow-md);
}
.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}
.auth-logo .logo-icon { font-size: 2.5rem; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 1.3rem; font-weight: 700; }
.auth-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }
.btn-microsoft {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 11px 20px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 600;
  text-decoration: none;
  transition: box-shadow .15s, background .15s;
}
.btn-microsoft:hover {
  box-shadow: 0 1px 6px rgba(0,0,0,.15);
  background: #f8f9fa;
  color: #1a1a1a;
}
.auth-footer {
  margin-top: 20px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Ticket Detail ─────────────────────────────────────────────────────────── */
.ticket-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}
.ticket-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.ticket-body {
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text);
  white-space: normal;
  overflow-x: auto;
}
.ticket-body *,
.comment-body * {
  background-color: transparent !important;
  color: inherit !important;
  max-width: 100%;
}
.ticket-body img,
.comment-body img {
  max-width: 100% !important;
  height: auto !important;
  display: block;
  margin: 8px 0;
  border-radius: 4px;
}
.comment-thread { display: flex; flex-direction: column; gap: 0; }
.comment {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.comment:last-child { border-bottom: none; }
.comment-internal { background: rgba(245,158,11,.04); }
.comment-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.8rem;
}
.comment-author { font-weight: 600; color: var(--text); }
.comment-time { color: var(--text-dim); }
.comment-body { font-size: 0.875rem; color: var(--text); line-height: 1.6; white-space: normal; overflow-x: auto; }
.internal-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--amber);
  background: rgba(245,158,11,.12);
  padding: 2px 7px;
  border-radius: 4px;
}
.requester-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sky);
  background: rgba(14,165,233,.12);
  padding: 2px 7px;
  border-radius: 4px;
}

.sidebar-panel > * + * { margin-top: 16px; }
.meta-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.meta-item:last-child { border-bottom: none; }
.meta-key { color: var(--text-muted); font-weight: 500; }
.meta-val { color: var(--text); font-weight: 500; }

/* ── History ───────────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.history-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-top: 6px;
  flex-shrink: 0;
}

/* ── Filter Grid ───────────────────────────────────────────────────────────── */
.filter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.filter-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
  flex: 1 1 130px;
}
.filter-col--search { flex: 2 1 220px; }
.filter-col--actions { flex: 0 0 auto; min-width: unset; }
.filter-footer {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.filter-col--sort { flex: 0 1 200px; min-width: 160px; }
.filter-label {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.filter-grid select,
.filter-grid input[type=text] {
  width: 100%;
  padding: 7px 10px;
}

/* ── Filters Bar (other views) ─────────────────────────────────────────────── */
.filters-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.filters-bar .form-group { margin: 0; }
.filters-bar select,
.filters-bar input[type=text] {
  width: auto;
  min-width: 140px;
  padding: 7px 10px;
}
.filters-bar input[type=text] { min-width: 220px; }

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.pagination-links { display: flex; gap: 6px; }
.pagination-links a, .pagination-links span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  background: var(--bg-card);
  color: var(--text-muted);
  text-decoration: none;
  transition: all .15s;
}
.pagination-links a:hover { border-color: var(--accent); color: var(--accent-light); background: var(--accent-dim); }
.pagination-links span.current { border-color: var(--accent); color: var(--accent-light); background: var(--accent-dim); }

/* ── Queue color pills ─────────────────────────────────────────────────────── */
.queue-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.queue-dot { width: 6px; height: 6px; border-radius: 50%; }

/* ── Reply Form ────────────────────────────────────────────────────────────── */
.reply-form {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--reply-form-bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.reply-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.reply-tab {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  transition: all .15s;
}
.reply-tab.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* ── Toggle switch ─────────────────────────────────────────────────────────── */
.toggle-group {
  display: flex;
  align-items: center;
  gap: 10px;
}
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--border-light);
  border-radius: 22px;
  transition: .2s;
}
.toggle-slider:before {
  position: absolute;
  content: "";
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(18px); }

/* ── Checkbox ──────────────────────────────────────────────────────────────── */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.checkbox-group input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Color input ───────────────────────────────────────────────────────────── */
input[type=color] {
  width: 48px; height: 36px;
  padding: 2px;
  cursor: pointer;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  background: var(--bg);
}

/* ── Avatar ────────────────────────────────────────────────────────────────── */
.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  color: var(--accent-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Validation ────────────────────────────────────────────────────────────── */
.validation-summary-errors ul {
  list-style: none;
  padding: 12px 16px;
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--radius);
  color: var(--red);
  font-size: 0.875rem;
  margin-bottom: 16px;
}
.field-validation-error { font-size: 0.78rem; color: var(--red); margin-top: 4px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .ticket-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
  .page-wrapper { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
}
