/* ============================================================
   ROYALTY BUILD GROUP — Leadership Command Center
   Standalone dashboard · Dark premium · Gold accent
   ============================================================ */

:root {
  --bg: #0A0A0A;
  --surface: #111111;
  --surface-2: #161616;
  --surface-3: #1C1C1C;
  --green: #1A3A2A;
  --gold: #C9A84C;
  --gold-hover: #E8C96A;
  --gold-dim: rgba(201, 168, 76, 0.12);
  --text: #F5F0E8;
  --text-muted: #A39E93;
  --text-dim: #6E6A62;
  --border: rgba(201, 168, 76, 0.16);
  --border-soft: rgba(255, 255, 255, 0.06);

  --pos: #4FB477;
  --pos-dim: rgba(79, 180, 119, 0.14);
  --neg: #D9694E;
  --neg-dim: rgba(217, 105, 78, 0.14);
  --warn: #E0A93C;
  --warn-dim: rgba(224, 169, 60, 0.14);
  --info: #5B8DB8;
  --info-dim: rgba(91, 141, 184, 0.14);

  --font-head: 'Playfair Display', Georgia, serif;
  --font-body: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --radius: 8px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar-w: 244px;
}

* , *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }
::selection { background: var(--gold); color: #000; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #262421; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #35322c; }

h1,h2,h3,h4 { font-family: var(--font-head); font-weight: 700; line-height: 1.15; letter-spacing: .2px; }

/* ===================== LOGIN ===================== */
.login-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: calc(40px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
  background:
    radial-gradient(1000px 600px at 50% -10%, rgba(201,168,76,.10), transparent 60%),
    linear-gradient(160deg, #0A0A0A 0%, #0d0f0d 100%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 38px 34px 30px;
  box-shadow: 0 30px 70px rgba(0,0,0,.6), 0 0 0 1px rgba(201,168,76,.06);
}
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand-name { display: block; font-family: var(--font-head); font-size: 1.32rem; font-weight: 700; }
.login-brand-name em { color: var(--gold); font-style: italic; }
.login-brand-sub { display: block; font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; color: var(--text-muted); margin-top: 2px; }
.login-tag { color: var(--gold); font-size: .78rem; letter-spacing: .12em; text-transform: uppercase; margin: 20px 0 24px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: .78rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.field input, .drawer-body input, .drawer-body select, .drawer-body textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  color: var(--text);
  padding: 11px 14px;
  font-size: 16px; /* iOS Safari zooms the viewport on focus for inputs under 16px */
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.field input:focus, .drawer-body input:focus, .drawer-body select:focus, .drawer-body textarea:focus {
  outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-dim);
}
.login-error { color: var(--neg); font-size: .82rem; margin: -4px 0 12px; }

.btn-gold-solid {
  background: var(--gold); color: #0A0A0A; border: none; font-weight: 600;
  padding: 12px 22px; border-radius: var(--radius); font-size: .92rem; letter-spacing: .02em;
  transition: background .2s var(--ease), transform .1s var(--ease);
}
.btn-gold-solid:hover { background: var(--gold-hover); }
.btn-gold-solid:active { transform: translateY(1px); }
.btn-block { width: 100%; }

.login-demo {
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border-soft);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: .78rem; color: var(--text-dim);
}
.login-demo span { text-transform: uppercase; letter-spacing: .12em; font-size: .68rem; }
.login-demo code { background: var(--bg); border: 1px solid var(--border-soft); border-radius: 4px; padding: 3px 8px; color: var(--text-muted); font-size: .78rem; }
.login-foot { color: var(--text-dim); font-size: .82rem; letter-spacing: .08em; }
.link-btn { background: none; border: none; color: var(--gold); font-size: .82rem; font-weight: 500; padding: 0; }
.link-btn:hover { color: var(--gold-hover); text-decoration: underline; }
.link-btn.small { font-size: .78rem; }

/* ===================== APP LAYOUT ===================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, #0c0c0c, #0a0a0a);
  border-right: 1px solid var(--border-soft);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 22px 20px 18px; border-bottom: 1px solid var(--border-soft); }
.sidebar-brand span { font-family: var(--font-head); font-size: 1.02rem; font-weight: 700; line-height: 1.1; }
.sidebar-brand em { color: var(--gold); font-style: italic; }

.side-nav { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: .64rem; text-transform: uppercase; letter-spacing: .16em; color: var(--text-dim); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text-muted); text-decoration: none; font-size: .88rem; font-weight: 500;
  transition: background .18s var(--ease), color .18s var(--ease);
}
.nav-item .ni-icon { width: 16px; text-align: center; color: var(--text-dim); font-size: .8rem; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--gold-dim); color: var(--gold); }
.nav-item.active .ni-icon { color: var(--gold); }
.sidebar-foot { padding: 14px 20px; border-top: 1px solid var(--border-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: calc(16px + env(safe-area-inset-top)) calc(26px + env(safe-area-inset-right)) 16px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: #0c0c0c;
  position: sticky; top: 0; z-index: 30;
}
.menu-toggle { display: none; background: none; border: none; color: var(--text); font-size: 1.5rem; }
.topbar-title h1 { font-size: 1.3rem; }
.topbar-title p { color: var(--text-muted); font-size: .8rem; }
.topbar-tools { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.search-box input {
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: 20px;
  color: var(--text); padding: 8px 16px; width: 230px; font-size: .84rem; transition: border-color .2s, width .2s;
}
.search-box input:focus { outline: none; border-color: var(--gold); width: 260px; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), #9c8038); color: #0A0A0A;
  display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-meta #user-name { font-weight: 600; font-size: .86rem; }
.user-role { color: var(--text-dim); font-size: .72rem; }

.view-wrap { padding: 26px; max-width: 1500px; width: 100%; }

/* ===================== KPI CARDS ===================== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 18px 18px 16px; position: relative; overflow: hidden;
  transition: border-color .2s var(--ease), transform .2s var(--ease);
}
.kpi-card:hover { border-color: var(--border); transform: translateY(-2px); }
.kpi-card::before { content:""; position:absolute; left:0; top:0; bottom:0; width:3px; background: var(--gold); opacity:.7; }
.kpi-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .1em; color: var(--text-muted); }
.kpi-value { font-family: var(--font-head); font-size: 1.85rem; font-weight: 700; margin: 8px 0 4px; }
.kpi-value .unit { font-size: 1rem; color: var(--text-muted); }
.kpi-delta { font-size: .78rem; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.kpi-delta.up { color: var(--pos); }
.kpi-delta.down { color: var(--neg); }
.kpi-delta.flat { color: var(--text-muted); }
.kpi-sub { color: var(--text-dim); font-size: .74rem; margin-top: 2px; }

/* accent variants */
.kpi-card.warn::before { background: var(--warn); }
.kpi-card.neg::before { background: var(--neg); }
.kpi-card.pos::before { background: var(--pos); }
.kpi-card.info::before { background: var(--info); }

/* ===================== PANELS ===================== */
.panel {
  background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.panel-head h3 { font-size: 1.05rem; }
.panel-head .eyebrow { color: var(--gold); font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; display:block; margin-bottom: 3px; }
.panel-sub { color: var(--text-muted); font-size: .8rem; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 20px; }
@media (max-width: 1080px){ .grid-2, .grid-3, .grid-2-1 { grid-template-columns: 1fr; } }

/* ===================== TABLES ===================== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border-soft); }
table.data { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 640px; }
table.data thead th {
  text-align: left; padding: 12px 14px; background: var(--surface-2);
  color: var(--text-muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em;
  border-bottom: 1px solid var(--border-soft); white-space: nowrap; position: sticky; top: 0;
}
table.data tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr { transition: background .15s var(--ease); cursor: pointer; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.t-strong { font-weight: 600; color: var(--text); }
.t-mono { font-variant-numeric: tabular-nums; }
.t-right { text-align: right; }
.t-dim { color: var(--text-dim); }
.t-neg { color: var(--neg); }
.t-pos { color: var(--pos); }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 20px;
  font-size: .72rem; font-weight: 600; white-space: nowrap; letter-spacing: .01em;
}
.pill::before { content:""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.green { color: var(--pos); background: var(--pos-dim); }
.pill.gold  { color: var(--gold); background: var(--gold-dim); }
.pill.blue  { color: var(--info); background: var(--info-dim); }
.pill.amber { color: var(--warn); background: var(--warn-dim); }
.pill.red   { color: var(--neg); background: var(--neg-dim); }
.pill.grey  { color: var(--text-muted); background: rgba(255,255,255,.06); }

/* Progress bar */
.bar { height: 7px; background: var(--surface-3); border-radius: 6px; overflow: hidden; min-width: 90px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-hover)); border-radius: 6px; }
.bar.green > span { background: linear-gradient(90deg, #3c9a63, var(--pos)); }

/* ===================== TOOLBAR ===================== */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-muted);
  padding: 6px 13px; border-radius: 18px; font-size: .8rem; transition: all .18s var(--ease);
}
.chip:hover { color: var(--text); border-color: var(--border); }
.chip.active { background: var(--gold-dim); color: var(--gold); border-color: var(--border); }
.toolbar .spacer { margin-left: auto; }
.btn-ghost-sm {
  background: transparent; border: 1px solid var(--border); color: var(--gold);
  padding: 7px 15px; border-radius: var(--radius); font-size: .82rem; font-weight: 500; transition: all .18s var(--ease);
}
.btn-ghost-sm:hover { background: var(--gold-dim); }
.btn-gold-sm {
  background: var(--gold); border: none; color: #0A0A0A; font-weight: 600;
  padding: 8px 16px; border-radius: var(--radius); font-size: .82rem;
}
.btn-gold-sm:hover { background: var(--gold-hover); }

/* ===================== CHARTS ===================== */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--text-muted); }
.chart-legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.axis-label { fill: var(--text-dim); font-size: 10px; font-family: var(--font-body); }
.grid-line { stroke: var(--border-soft); stroke-width: 1; }
.bar-val { fill: var(--text-muted); font-size: 10px; font-family: var(--font-body); }

/* ===================== PIPELINE (KANBAN) ===================== */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.kcol { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius); display: flex; flex-direction: column; }
.kcol-head { padding: 13px 15px; border-bottom: 1px solid var(--border-soft); display: flex; align-items: center; justify-content: space-between; }
.kcol-head .kc-name { font-weight: 600; font-size: .86rem; display: flex; align-items: center; gap: 8px; }
.kcol-head .kc-dot { width: 8px; height: 8px; border-radius: 50%; }
.kcol-head .kc-sum { font-size: .74rem; color: var(--text-muted); }
.kcol-body { padding: 12px; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.kcard {
  background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--radius);
  padding: 13px 14px; transition: border-color .18s var(--ease), transform .18s var(--ease); cursor: pointer;
}
.kcard:hover { border-color: var(--border); transform: translateY(-2px); }
.kcard .kc-title { font-weight: 600; font-size: .86rem; margin-bottom: 6px; }
.kcard .kc-meta { display: flex; justify-content: space-between; align-items: center; font-size: .76rem; color: var(--text-muted); }
.kcard .kc-val { color: var(--gold); font-weight: 600; font-variant-numeric: tabular-nums; }
.kcard .kc-line { font-size: .74rem; color: var(--text-dim); margin-top: 4px; }

/* ===================== LISTS / MISC ===================== */
.alert-list { display: flex; flex-direction: column; gap: 10px; }
.alert-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border-soft); border-left-width: 3px; border-radius: var(--radius); }
.alert-item.red { border-left-color: var(--neg); }
.alert-item.amber { border-left-color: var(--warn); }
.alert-item.gold { border-left-color: var(--gold); }
.alert-item .ai-icon { font-size: 1.1rem; }
.alert-item .ai-body { flex: 1; }
.alert-item .ai-title { font-weight: 600; font-size: .86rem; }
.alert-item .ai-sub { color: var(--text-muted); font-size: .78rem; }
.alert-item .ai-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.mini-stat { display:flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border-soft); font-size: .86rem; }
.mini-stat:last-child { border-bottom: none; }
.mini-stat .ms-label { color: var(--text-muted); }
.mini-stat .ms-val { font-weight: 600; font-variant-numeric: tabular-nums; }

.leader-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.leader-row:last-child { border-bottom: none; }
.leader-row .lr-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-3); color: var(--gold); display: grid; place-items: center; font-weight: 600; font-size: .78rem; flex-shrink: 0; }
.leader-row .lr-name { font-weight: 600; font-size: .86rem; }
.leader-row .lr-role { color: var(--text-dim); font-size: .74rem; }
.leader-row .lr-val { margin-left: auto; text-align: right; }

.section-title { font-size: 1.15rem; margin: 6px 0 16px; }
.empty { text-align: center; color: var(--text-dim); padding: 40px; font-size: .88rem; }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 8px; }
.funnel-row { display: flex; align-items: center; gap: 12px; }
.funnel-bar { height: 34px; border-radius: 6px; display: flex; align-items: center; padding: 0 12px; color: #0A0A0A; font-weight: 600; font-size: .8rem; min-width: 60px; transition: width .6s var(--ease); }
.funnel-label { width: 130px; font-size: .82rem; color: var(--text-muted); flex-shrink: 0; }
.funnel-count { margin-left: auto; font-size: .82rem; color: var(--text-muted); font-variant-numeric: tabular-nums; width: 90px; text-align: right; }

/* ===================== DRAWER ===================== */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 60; animation: fade .2s var(--ease); }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(460px, 94vw);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border-left: 1px solid var(--border); z-index: 70; display: flex; flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,.5); animation: slideIn .28s var(--ease);
}
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--border-soft); }
.drawer-head h2 { font-size: 1.15rem; }
.drawer-body { padding: 22px; overflow-y: auto; }
.dr-field { margin-bottom: 16px; }
.dr-field label { display: block; font-size: .76rem; color: var(--text-muted); margin-bottom: 6px; }
.dr-row { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--border-soft); font-size: .88rem; }
.dr-row .drk { color: var(--text-muted); }
.dr-row .drv { font-weight: 600; text-align: right; }
.dr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px){
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .28s var(--ease); }
  .sidebar.open { transform: none; }
  .menu-toggle { display: block; }
  .search-box { display: none; }
  .user-meta { display: none; }
  .view-wrap { padding: 18px; }
}
@media (max-width: 560px){
  .kpi-value { font-size: 1.55rem; }
  .topbar-title p { display: none; }
}

.fade-in { animation: fadeUp .35s var(--ease); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
