:root {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --bg-card: #171717;
  --border: #2a2a2a;
  --gold: #c9a227;
  --gold-soft: #e0bc4a;
  --text: #f2f0ea;
  --text-muted: #9b9691;
  --danger: #c0392b;
  --warning: #b8842f;
  --success: #4c8a5e;
  --info: #3d6d8f;
  --font-display: 'Cinzel', serif;
  --font-body: 'Inter', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-soft); }
code { font-family: 'SF Mono', Menlo, monospace; font-size: 12.5px; color: var(--gold-soft); background: rgba(201,162,39,0.08); padding: 1px 6px; border-radius: 4px; }

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

.sidebar {
  width: 240px;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 24px 24px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.brand-mark { width: 34px; height: 34px; border: 1px solid var(--gold); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; color: var(--gold); }
.brand-name { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.04em; font-size: 17px; }
.tenant-brand-sub { padding: 0 24px 16px; margin-top: -8px; font-size: 11.5px; color: var(--text-muted); border-bottom: 1px solid var(--border); margin-bottom: 16px; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.nav a { display: flex; align-items: center; gap: 11px; color: var(--text-muted); padding: 10px 12px; border-radius: 8px; font-weight: 500; font-size: 13.5px; }
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.75; }
.nav a.active .nav-icon, .nav a:hover .nav-icon { opacity: 1; }
.nav a:hover { background: rgba(201,162,39,0.06); color: var(--text); }
.nav a.active { background: rgba(201,162,39,0.12); color: var(--gold-soft); }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-track { background: transparent; }
.nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.nav::-webkit-scrollbar-thumb:hover { background: var(--gold); }

.sidebar-footer { padding: 16px 24px 0; border-top: 1px solid var(--border); margin-top: 16px; }
.who-name { font-weight: 600; font-size: 13px; }
.who-role { color: var(--text-muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 8px; }
.logout-link { font-size: 12.5px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { padding: 22px 32px; border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; font-family: var(--font-display); font-size: 22px; font-weight: 600; }
.content { padding: 28px 32px; }

/* ---------- Flash messages ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash-stack-standalone { max-width: 420px; margin: 24px auto 0; }
.flash { padding: 11px 16px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.flash-success { background: rgba(76,138,94,0.12); border-color: var(--success); color: #8fd1a2; }
.flash-danger { background: rgba(192,57,43,0.12); border-color: var(--danger); color: #e39089; }
.flash-warning { background: rgba(184,132,47,0.12); border-color: var(--warning); color: #e0b871; }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-grid-compact { margin-bottom: 20px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--gold-soft); }
.stat-sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ---------- Panels ---------- */
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.panel-wide { grid-column: 1 / -1; }
.panel { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; margin-bottom: 20px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.panel-header h2 { font-family: var(--font-display); font-size: 15px; margin: 0; font-weight: 600; }
.panel-link { font-size: 12.5px; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 11px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tbody tr:hover { background: rgba(201,162,39,0.04); cursor: pointer; }
.data-table-compact td, .data-table-compact th { padding: 7px 10px; font-size: 12.5px; }
.empty-cell { text-align: center; color: var(--text-muted); padding: 24px !important; cursor: default !important; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; text-transform: capitalize; }
.badge-trial { background: rgba(61,109,143,0.15); color: #7cb3d6; }
.badge-active { background: rgba(76,138,94,0.15); color: #8fd1a2; }
.badge-suspended { background: rgba(184,132,47,0.15); color: #e0b871; }
.badge-cancelled, .badge-deleted, .badge-void { background: rgba(155,150,145,0.15); color: var(--text-muted); }
.badge-draft { background: rgba(155,150,145,0.15); color: var(--text-muted); }
.badge-sent { background: rgba(61,109,143,0.15); color: #7cb3d6; }
.badge-paid { background: rgba(76,138,94,0.15); color: #8fd1a2; }
.badge-overdue { background: rgba(192,57,43,0.15); color: #e39089; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 9px 16px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid transparent; cursor: pointer; font-family: var(--font-body); }
.btn-primary { background: var(--gold); color: #1a1305; }
.btn-primary:hover { background: var(--gold-soft); }
.btn-secondary { background: var(--bg-elevated); border-color: var(--border); color: var(--text); }
.btn-secondary:hover { border-color: var(--gold); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-warning { background: var(--warning); color: #1a1305; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--gold); cursor: pointer; font-size: 12.5px; padding: 0; }
.btn-link-danger { color: #e39089; }

/* ---------- Forms ---------- */
.form-card, .auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 26px; max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-field-wide { grid-column: 1 / -1; }
.form-field-checkbox { display: flex; align-items: center; }
.form-field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; color: var(--text); font-family: var(--font-body); font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.inline-form { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1; min-width: 120px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; }
.filter-form { display: flex; gap: 8px; }
.filter-form input, .filter-form select { width: auto; }

/* ---------- Auth page ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 380px; }
.auth-brand { text-align: center; margin-bottom: 24px; }
.auth-brand .brand-mark { margin: 0 auto 10px; width: 46px; height: 46px; font-size: 18px; }
.auth-brand h1 { font-family: var(--font-display); margin: 0; font-size: 22px; }
.auth-brand p { color: var(--text-muted); margin: 4px 0 0; font-size: 12.5px; }
.auth-card form label { display: block; font-size: 12.5px; color: var(--text-muted); margin: 14px 0 6px; }

/* ---------- Detail header ---------- */
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; }
.detail-header h2 { font-family: var(--font-display); margin: 0 0 4px; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.detail-actions { display: flex; gap: 10px; }
.muted { color: var(--text-muted); font-size: 12.5px; }

.info-list { display: grid; grid-template-columns: 100px 1fr; gap: 8px 12px; margin: 0; }
.info-list dt { color: var(--text-muted); font-size: 12px; }
.info-list dd { margin: 0; font-size: 13px; }

.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.mini-count { color: var(--gold-soft); font-weight: 600; }

/* ---------- Plans ---------- */
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.plan-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.plan-inactive { opacity: 0.5; }
.plan-card-header { display: flex; justify-content: space-between; align-items: center; }
.plan-card-header h3 { font-family: var(--font-display); margin: 0; font-size: 16px; }
.plan-price { font-family: var(--font-display); font-size: 26px; color: var(--gold-soft); margin: 10px 0 4px; }
.plan-price span { font-size: 13px; color: var(--text-muted); }
.plan-features { list-style: none; padding: 0; margin: 14px 0; font-size: 12.5px; color: var(--text-muted); }
.plan-features li { padding: 4px 0; }
.plan-tenant-count { font-size: 11.5px; color: var(--text-muted); border-top: 1px solid var(--border); padding-top: 10px; }

/* ---------- Modal ---------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); align-items: center; justify-content: center; z-index: 50; }
.modal.open { display: flex; }
.modal-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 100%; max-width: 420px; }
.modal-card h3 { font-family: var(--font-display); margin: 0 0 8px; font-size: 17px; }

.breadcrumb { margin: 0 0 16px; font-size: 12.5px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--gold); }

.stat-card-link { display: block; text-decoration: none; color: inherit; transition: border-color 0.15s; }
.stat-card-link:hover { border-color: var(--gold); }

.limit-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px 24px; }
.limit-item-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.limit-bar { height: 6px; border-radius: 3px; background: var(--bg-elevated); overflow: hidden; }
.limit-bar-fill { height: 100%; background: var(--gold); border-radius: 3px; }
.limit-bar-fill.limit-bar-warn { background: var(--danger); }

.logo-preview-row { display: flex; align-items: center; gap: 16px; }
.logo-preview { width: 64px; height: 64px; border-radius: 10px; border: 1px solid var(--border); object-fit: contain; background: var(--bg-elevated); padding: 6px; }
.logo-preview-empty { display: flex; align-items: center; justify-content: center; font-size: 10px; color: var(--text-muted); text-align: center; }

.form-grid-tight .form-field { margin-bottom: 0; }
input[type=color] { padding: 3px; height: 40px; cursor: pointer; }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }

/* ---------- Dashboard: stat icons, donut charts, activity feed ---------- */
.stat-card-icon { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.stat-icon-badge {
  width: 38px; height: 38px; border-radius: 10px; background: rgba(201,162,39,0.12);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon-badge svg { width: 19px; height: 19px; color: var(--gold); }

.donut-panel { display: flex; align-items: center; gap: 24px; }
.donut { position: relative; width: 140px; height: 140px; border-radius: 50%; flex-shrink: 0; }
.donut-hole {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 92px; height: 92px; border-radius: 50%; background: var(--bg-card);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-hole-value { font-family: var(--font-display); font-size: 22px; font-weight: 700; color: var(--text); line-height: 1.1; }
.donut-hole-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.donut-legend { list-style: none; margin: 0; padding: 0; flex: 1; }
.donut-legend li { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; font-size: 12.5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 8px; flex-shrink: 0; }
.legend-label { display: flex; align-items: center; color: var(--text-muted); }
.legend-count { font-weight: 600; color: var(--text); }

.activity-feed { list-style: none; margin: 0; padding: 0; }
.activity-item { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 30px; height: 30px; border-radius: 8px; background: var(--bg-elevated);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.activity-icon svg { width: 15px; height: 15px; color: var(--gold-soft); }
.activity-text { font-size: 13px; }
.activity-time { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; padding: 12px; }
  .nav { flex-direction: row; }
  .panel-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
