:root {
  --sidebar-w: 220px;
  --bg:        #0F1117;
  --bg-2:      #181B24;
  --surface:   #1E2130;
  --surface-2: #252A3A;
  --border:    rgba(255,255,255,.07);
  --divider:   rgba(255,255,255,.05);
  --ink:       #EEF0F8;
  --ink-2:     #B8BCCE;
  --muted:     #6B7194;
  --accent:    #6C8FFF;
  --accent-dark: #5070E8;
  --accent-bg: rgba(108,143,255,.12);
  --green:   #34C759;
  --green-bg: rgba(52,199,89,.12);
  --red:     #FF453A;
  --red-bg:  rgba(255,69,58,.12);
  --amber:   #FF9F0A;
  --amber-bg: rgba(255,159,10,.12);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --shadow: 0 8px 32px rgba(0,0,0,.4), 0 2px 8px rgba(0,0,0,.2);
  --ff: "Inter", system-ui, -apple-system, sans-serif;
  --ease: cubic-bezier(.25,.46,.45,.94);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ff);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }

/* ===== Shell ===== */
.shell {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}
.sidebar-logo {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--divider);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-logo-mark {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--ink);
}
.sidebar-logo-badge {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  background: rgba(108,143,255,.15);
  color: var(--accent);
  padding: 2px 5px;
  border-radius: 4px;
  margin-left: auto;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--r-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
  user-select: none;
}
.nav-item:hover { background: var(--surface); color: var(--ink-2); }
.nav-item.active { background: rgba(108,143,255,.12); color: var(--accent); }
.nav-item svg { flex-shrink: 0; opacity: .75; }
.nav-item.active svg { opacity: 1; }
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--divider);
  font-size: 12px;
  color: var(--muted);
}
.sidebar-footer strong { color: var(--ink-2); display: block; margin-bottom: 2px; font-size: 13px; }
.logout-btn {
  margin-top: 8px;
  width: 100%;
  padding: 7px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-family: var(--ff);
}
.logout-btn:hover { background: var(--surface); color: var(--ink-2); }

/* ===== Main ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}
.main-header {
  padding: 28px 32px 0;
}
.main-header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.4px;
  color: var(--ink);
}
.main-header p {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 3px;
}
.main-content {
  padding: 24px 32px 40px;
}

/* ===== Pane ===== */
.pane { display: none; }
.pane.active { display: block; }

/* ===== Nav badge ===== */
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 6px;
  min-width: 18px;
  text-align: center;
  display: none;
}
.nav-badge:not(:empty) { display: inline-block; }

/* ===== Stats row ===== */
.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.stats-row--6 {
  grid-template-columns: repeat(3, 1fr);
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 22px;
}
.stat-card-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 8px;
}
.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--ink);
}
.stat-card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}
.stat-card--green  { border-color: rgba(52,199,89,.2); }
.stat-card--green .stat-card-value { color: var(--green); }
.stat-card--amber  { border-color: rgba(255,159,10,.2); }
.stat-card--amber .stat-card-value { color: var(--amber); }
.stat-card--red    { border-color: rgba(255,69,58,.2); }
.stat-card--red .stat-card-value { color: var(--red); }
.stat-card--accent { border-color: rgba(108,143,255,.2); }
.stat-card--accent .stat-card-value { color: var(--accent); }
.stat-card-value--sm { font-size: 22px; }

/* ===== Section header ===== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-head h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  font-family: var(--ff);
  transition: background .15s var(--ease), opacity .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-2);
}
.btn-ghost:hover { background: var(--surface-2); opacity: 1; }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-sm { padding: 5px 11px; font-size: 12px; }

/* ===== Tenant table ===== */
.tenant-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.tenant-table-head {
  display: grid;
  grid-template-columns: 2fr 2fr 1.2fr 1fr 1fr 120px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--divider);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
}
.tenant-row {
  display: grid;
  grid-template-columns: 2fr 2fr 1.2fr 1fr 1fr 120px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--divider);
  align-items: center;
  transition: background .12s;
}
.tenant-row:last-child { border-bottom: none; }
.tenant-row:hover { background: var(--surface-2); }
.tenant-name {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
}
.tenant-slug {
  font-size: 12px;
  color: var(--muted);
  font-family: "SF Mono", "Fira Code", monospace;
  margin-top: 2px;
}
.tenant-email {
  font-size: 13px;
  color: var(--ink-2);
}
.tenant-plan {
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--accent);
}
.tenant-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ===== Status badges ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}
.badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.badge-trial  { background: var(--amber-bg); color: var(--amber); }
.badge-trial .badge-dot  { background: var(--amber); }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-active .badge-dot { background: var(--green); }
.badge-inactive { background: var(--surface-2); color: var(--muted); }
.badge-inactive .badge-dot { background: var(--muted); }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state-icon {
  font-size: 32px;
  margin-bottom: 12px;
  opacity: .4;
}
.empty-state p { font-size: 14px; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  width: 520px;
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  transform: translateY(12px) scale(.98);
  transition: transform .25s var(--ease);
}
.modal-backdrop.open .modal {
  transform: translateY(0) scale(1);
}
.modal-header {
  padding: 22px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.modal-close {
  width: 28px; height: 28px;
  background: var(--surface-2);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 16px;
  transition: background .15s;
  font-family: var(--ff);
}
.modal-close:hover { background: var(--border); color: var(--ink-2); }
.modal-body {
  padding: 20px 24px 24px;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--divider);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ===== Form ===== */
.form-section {
  margin-bottom: 20px;
}
.form-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--divider);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid.full { grid-template-columns: 1fr; }
.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
}
.form-field input,
.form-field select {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  color: var(--ink);
  font-family: var(--ff);
  font-size: 13.5px;
  outline: none;
  transition: border-color .15s;
}
.form-field input:focus,
.form-field select:focus {
  border-color: var(--accent);
}
.form-field input::placeholder { color: var(--muted); }
.form-field select option { background: var(--surface); }

/* ===== Edit modal (tenant detail) ===== */
.edit-section {
  display: none;
}
.edit-section.active {
  display: block;
}

/* ===== Login screen ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 36px 40px;
  width: 380px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.login-logo-mark {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 9px;
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
}
.login-logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.4px;
}
.login-logo-sub {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}
.login-card h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-bottom: 6px;
}
.login-card p {
  color: var(--muted);
  font-size: 13.5px;
  margin-bottom: 24px;
}
.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.login-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
}
.login-field input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  color: var(--ink);
  font-family: var(--ff);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.login-field input:focus { border-color: var(--accent); }
.login-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.login-error.visible { display: block; }
.login-submit {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--ff);
  margin-top: 6px;
  transition: opacity .15s;
}
.login-submit:hover { opacity: .88; }

/* ===== Toast ===== */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 18px;
  border-radius: var(--r);
  font-size: 13.5px;
  font-weight: 500;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  animation: toastIn .25s var(--ease) forwards, toastOut .25s var(--ease) 3s forwards;
  pointer-events: none;
}
.toast.success { background: var(--green-bg); border-color: rgba(52,199,89,.25); color: var(--green); }
.toast.error   { background: var(--red-bg);   border-color: rgba(255,69,58,.2);  color: var(--red);   }
@keyframes toastIn  { to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ===== Confirm dialog ===== */
.confirm-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  width: 340px;
  box-shadow: var(--shadow);
}
.confirm-box h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.confirm-box p  { font-size: 13.5px; color: var(--muted); margin-bottom: 20px; }
.confirm-btns   { display: flex; gap: 10px; justify-content: flex-end; }

/* ===== Plans list ===== */
.plans-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.plan-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 20px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--divider);
  align-items: center;
  transition: background .12s;
}
.plan-row:last-child { border-bottom: none; }
.plan-row:hover { background: var(--surface-2); }
.plan-row-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}
.plan-row-desc {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 2px;
}
.plan-row-price {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
.plan-row-price span {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}
.plan-row-status { white-space: nowrap; }
.plan-row-actions {
  display: flex;
  gap: 6px;
}
.modal--sm { width: 420px; }

/* ===== Ticket filters ===== */
.ticket-filters {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}
.ticket-filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--ff);
  transition: background .12s, color .12s, border-color .12s;
}
.ticket-filter-btn:hover { background: var(--surface-2); color: var(--ink-2); }
.ticket-filter-btn.is-active {
  background: var(--accent-bg);
  border-color: rgba(108,143,255,.3);
  color: var(--accent);
}

/* ===== Ticket list ===== */
.ticket-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.ticket-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--divider);
  cursor: pointer;
  transition: background .12s;
}
.ticket-row:last-child { border-bottom: none; }
.ticket-row:hover { background: var(--surface-2); }
.ticket-row.ticket-resolved { opacity: .55; }
.ticket-row.ticket-resolved:hover { opacity: .8; }
.ticket-row-main { flex: 1; min-width: 0; }
.ticket-subject {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}
.ticket-subject.priority-high { color: var(--red); }
.priority-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
}
.ticket-new-badge {
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 20px;
  padding: 2px 7px;
  border: 1px solid rgba(108,143,255,.25);
}
.ticket-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

/* ===== Ticket detail panel ===== */
.ticket-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease);
}
.ticket-detail {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 480px;
  max-width: calc(100vw - var(--sidebar-w) - 20px);
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  z-index: 51;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform .25s var(--ease);
  box-shadow: -8px 0 32px rgba(0,0,0,.3);
}
.ticket-detail.open {
  transform: translateX(0);
}
.ticket-detail-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.ticket-detail-header {
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}
.ticket-detail-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.ticket-detail-header-top h3 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  color: var(--ink);
  line-height: 1.35;
}
.ticket-detail-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.ticket-thread {
  flex: 1;
  overflow-y: auto;
  padding: 16px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.ticket-msg {
  display: flex;
  gap: 11px;
  align-items: flex-start;
}
.ticket-msg--admin {
  flex-direction: row-reverse;
}
.ticket-msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
}
.ticket-msg--admin .ticket-msg-avatar {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: rgba(108,143,255,.25);
}
.ticket-msg-body { flex: 1; min-width: 0; }
.ticket-msg--admin .ticket-msg-body { align-items: flex-end; display: flex; flex-direction: column; }
.ticket-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}
.ticket-msg--admin .ticket-msg-header { flex-direction: row-reverse; }
.ticket-msg-header strong {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}
.ticket-msg-header span {
  font-size: 11px;
  color: var(--muted);
}
.ticket-msg-text {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 10px 14px;
  font-size: 13.5px;
  color: var(--ink);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 90%;
}
.ticket-msg--admin .ticket-msg-text {
  background: var(--accent-bg);
  border-color: rgba(108,143,255,.2);
  color: var(--ink);
}
.ticket-reply-area {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--divider);
  flex-shrink: 0;
}
.ticket-reply-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  color: var(--ink);
  font-family: var(--ff);
  font-size: 13.5px;
  resize: none;
  outline: none;
  transition: border-color .15s;
  margin-bottom: 10px;
}
.ticket-reply-input:focus { border-color: var(--accent); }
.ticket-reply-input::placeholder { color: var(--muted); }
.ticket-reply-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
