/* ── CSS Variables (overridden per-tenant in base.html) ── */
:root {
  --primary:      #1a56db;
  --primary-dark: #1e40af;
  --primary-light:#eff6ff;
  --secondary:    #eff6ff;
  --accent:       #0ea5e9;

  --bg:           #f8fafc;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;

  --sidebar-bg:   #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active:#ffffff;
  --sidebar-w:    240px;

  --radius:       8px;
  --radius-sm:    4px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
textarea { resize: vertical; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.sidebar-brand .brand-name {
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-brand .brand-sub {
  color: var(--sidebar-text);
  font-size: 11px;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section {
  padding: 8px 16px 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #475569;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  transition: background .15s, color .15s;
  cursor: pointer;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--primary); color: var(--sidebar-active); }
.nav-item svg { flex-shrink: 0; opacity: .7; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: var(--sidebar-text);
  font-size: 12px;
}

.sidebar-footer .user-name { color: #fff; font-weight: 500; }
.sidebar-footer .user-role { color: #64748b; font-size: 11px; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content {
  padding: 28px 24px;
  flex: 1;
  max-width: 1200px;
}

/* ── Auth pages ── */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo .logo-circle {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.auth-logo .logo-circle svg { color: #fff; }
.auth-logo h1 { font-size: 20px; font-weight: 700; }
.auth-logo p  { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Form elements ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}
.form-control-sm { padding: 5px 9px; font-size: 13px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }
textarea.form-control { min-height: 100px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error { font-size: 12px; color: #dc2626; margin-top: 4px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, box-shadow .15s, opacity .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger    { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm        { padding: 5px 11px; font-size: 12.5px; }
.btn-full      { width: 100%; justify-content: center; }
.btn-icon      { padding: 7px; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  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: 14px; font-weight: 600; }
.card-body  { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--bg); border-radius: 0 0 var(--radius) var(--radius); }

/* ── Stats row ── */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; line-height: 1; }
.stat-card.stat-open       .stat-value { color: #0ea5e9; }
.stat-card.stat-inprogress .stat-value { color: #8b5cf6; }
.stat-card.stat-pending    .stat-value { color: #f59e0b; }
.stat-card.stat-resolved   .stat-value { color: #10b981; }
.stat-card.stat-closed     .stat-value { color: var(--text-light); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg); text-transform: uppercase; letter-spacing: .04em; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 13.5px; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.table-link { color: var(--text); font-weight: 500; }
.table-link:hover { color: var(--primary); text-decoration: none; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-open        { background: #e0f2fe; color: #0369a1; }
.badge-inprogress  { background: #ede9fe; color: #6d28d9; }
.badge-pending     { background: #fef3c7; color: #92400e; }
.badge-resolved    { background: #d1fae5; color: #065f46; }
.badge-closed      { background: #f1f5f9; color: #475569; }

.badge-low    { background: #f0fdf4; color: #166534; }
.badge-medium { background: #fffbeb; color: #92400e; }
.badge-high   { background: #fff7ed; color: #9a3412; }
.badge-urgent { background: #fef2f2; color: #991b1b; }

.badge-customer   { background: #f0f9ff; color: #0c4a6e; }
.badge-agent      { background: #faf5ff; color: #581c87; }
.badge-admin      { background: #fff7ed; color: #9a3412; }
.badge-superadmin { background: #0f172a; color: #e2e8f0; }

/* ── Alerts / Flash messages ── */
.flash-list { list-style: none; margin-bottom: 20px; }
.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.flash-success { background: #d1fae5; color: #065f46; border-left: 3px solid #10b981; }
.flash-error   { background: #fee2e2; color: #991b1b; border-left: 3px solid #dc2626; }
.flash-info    { background: #dbeafe; color: #1e40af; border-left: 3px solid #3b82f6; }
.flash-warning { background: #fef3c7; color: #92400e; border-left: 3px solid #f59e0b; }

/* ── Ticket thread ── */
.thread { display: flex; flex-direction: column; gap: 16px; }
.thread-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.thread-item.internal {
  border-color: #fbbf24;
  background: #fffbeb;
}
.thread-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.thread-item.internal .thread-header { border-color: #fde68a; }
.thread-author { font-weight: 600; font-size: 13.5px; }
.thread-meta   { font-size: 12px; color: var(--text-muted); }
.thread-body   { padding: 16px; white-space: pre-wrap; font-size: 13.5px; line-height: 1.7; }
.internal-label {
  font-size: 11px;
  font-weight: 600;
  color: #92400e;
  background: #fef3c7;
  padding: 2px 7px;
  border-radius: 100px;
}

/* ── Ticket detail header ── */
.ticket-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
}
.ticket-number { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.ticket-title  { font-size: 20px; font-weight: 700; line-height: 1.3; margin-bottom: 12px; }
.ticket-meta   { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-muted); align-items: center; }
.ticket-meta strong { color: var(--text); }

/* ── Sidebar ticket controls ── */
.ticket-controls { display: flex; flex-direction: column; gap: 12px; }
.control-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }

/* ── Tabs ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Filters bar ── */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.filter-label { font-size: 12px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty h3   { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty p    { font-size: 13.5px; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%; max-width: 500px;
  margin: 16px;
  transform: translateY(8px);
  transition: transform .2s;
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-weight: 600; }
.modal-body  { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Pill filters ── */
.pill {
  padding: 5px 12px;
  border-radius: 100px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  transition: background .15s, color .15s, border-color .15s;
}
.pill:hover, .pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ── Two-column layout ── */
.two-col { display: grid; grid-template-columns: 1fr 280px; gap: 20px; align-items: start; }
.two-col-main { min-width: 0; }
.two-col-side { position: sticky; top: 76px; }

/* ── User avatar circle ── */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Utilities ── */
.flex       { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }
.mt-2   { margin-top: 8px; }
.mt-4   { margin-top: 16px; }
.mt-6   { margin-top: 24px; }
.mb-4   { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-sm    { font-size: 12.5px; }
.text-xs    { font-size: 11.5px; }
.fw-600     { font-weight: 600; }
.w-full     { width: 100%; }

/* ── Superadmin hub ── */
.tenant-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.tenant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.tenant-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

/* ── Search box ── */
.search-wrap { position: relative; flex: 1; max-width: 320px; }
.search-wrap input { padding-left: 32px; }
.search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-light); pointer-events: none; }

/* ── Divider ── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Reply box ── */
.reply-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 20px;
}
.reply-box-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.reply-box-body { padding: 16px; }
.reply-box-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* ── Auth pages (login, register, magic link) ── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px 16px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}
.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.auth-logo-mark {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: .5px;
  flex-shrink: 0;
}
.auth-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.auth-heading {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text);
}
.auth-sub {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.5;
}
.auth-links {
  margin-top: 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Billing / invoice extras ── */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 14px;
}
.btn-active {
  background: var(--primary-light);
  color: var(--primary);
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .two-col { grid-template-columns: 1fr; }
  .two-col-side { position: static; }
  .form-row { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}
