:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #121820;
  --muted: #65717d;
  --line: #dce2e8;
  --line-soft: #e9edf1;
  --accent: #0878e8;
  --accent-2: #0aaec2;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 8px 24px rgba(20, 30, 45, .06);
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The HTML hidden attribute must always win over component display rules. */
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; font-family: Inter, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); }
button, select, input { font: inherit; }
button { cursor: pointer; }

body { min-height: 100vh; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(145deg,#eff4f8,#fafbfc); }
.login-card { width: min(440px,100%); background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 34px; box-shadow: var(--shadow); display: grid; gap: 22px; }
.login-card h1 { margin: 2px 0 8px; font-size: 30px; letter-spacing: -.6px; }
.brand-mark { width: 62px; height: 62px; border-radius: 12px; display: grid; place-items: center; background: #111820; color: #fff; font-weight: 800; letter-spacing: .8px; }
.brand-mark.small { width: 42px; height: 42px; border-radius: 8px; font-size: 14px; }
.login-actions, .dev-login { display: grid; gap: 10px; }
.dev-login { border-top: 1px solid var(--line-soft); padding-top: 18px; }
.dev-note { font-size: 12px; font-weight: 800; text-transform: uppercase; color: #8a5a00; letter-spacing: .8px; }

.topbar { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1320px; margin: auto; min-height: 74px; padding: 0 26px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand-row, .topbar-actions, .signed-in, .admin-picker { display: flex; align-items: center; }
.brand-row { gap: 12px; }
.app-title { font-weight: 800; font-size: 16px; }
.app-subtitle { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-actions { gap: 18px; }
.signed-in { align-items: flex-end; flex-direction: column; line-height: 1.2; }
.signed-in-name { font-size: 13px; font-weight: 700; }
.signed-in-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; }
.admin-picker { gap: 8px; }
.admin-picker label { font-size: 12px; color: var(--muted); }
.admin-picker select, .filter-row select { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 9px 32px 9px 11px; color: var(--text); }

.button { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 11px 15px; font-weight: 700; }
.button:hover { background: #f7f9fa; }
.button.primary { background: #111820; color: #fff; border-color: #111820; }
.button.compact { padding: 8px 12px; font-size: 12px; }

.page-shell { max-width: 1320px; margin: auto; padding: 0 26px 56px; }
.tabs { display: flex; gap: 6px; padding-top: 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: transparent; color: var(--muted); padding: 13px 16px 12px; font-weight: 750; border-bottom: 3px solid transparent; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--text); }
.pill { display: inline-block; margin-left: 6px; font-size: 10px; padding: 3px 6px; border-radius: 99px; vertical-align: 1px; }
.pill.soon { background: #eef1f4; color: #77818c; }
.tab-panel { display: none; padding-top: 30px; }
.tab-panel.active { display: block; }

.hero-row { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 24px; }
.hero-row h1 { margin: 3px 0 4px; font-size: clamp(29px,4vw,42px); letter-spacing: -1.2px; }
.eyebrow { font-size: 11px; font-weight: 850; letter-spacing: 1.15px; color: #71808c; }
.muted { color: var(--muted); }
.updated-card { min-width: 220px; border-left: 3px solid var(--accent); padding: 5px 0 5px 14px; display: flex; flex-direction: column; gap: 3px; }
.updated-card span { color: var(--muted); font-size: 12px; }
.updated-card strong { font-size: 13px; }

.kpi-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 16px; }
.kpi-grid.three { grid-template-columns: repeat(3,1fr); }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-height: 132px; box-shadow: 0 3px 14px rgba(20,30,45,.025); display: flex; flex-direction: column; }
.kpi-card span { color: var(--muted); font-size: 13px; }
.kpi-card strong { font-size: clamp(27px,3vw,38px); letter-spacing: -1px; margin: 7px 0 auto; }
.kpi-card small { color: #8a949e; font-size: 11px; }

.content-grid { display: grid; gap: 16px; margin-top: 16px; }
.content-grid.two-thirds { grid-template-columns: 2fr 1fr; }
.content-grid.equal { grid-template-columns: 1fr 1fr; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-top: 16px; box-shadow: 0 3px 14px rgba(20,30,45,.025); }
.content-grid .panel { margin-top: 0; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-heading h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.35px; }
.metric-badge, .count-badge, .read-only-badge { background: #eff5fb; color: #155895; border: 1px solid #d8e7f5; border-radius: 7px; padding: 7px 10px; font-size: 12px; font-weight: 800; }
.count-badge { min-width: 34px; text-align: center; }
.read-only-badge { background: #f2f4f6; color: #59636d; border-color: #e1e5e9; }
.target-line { display: flex; justify-content: space-between; gap: 16px; align-items: baseline; margin-bottom: 12px; }
.target-line strong { font-size: 23px; }
.target-line span { color: var(--muted); font-size: 13px; }
.progress { height: 14px; overflow: hidden; border-radius: 4px; background: #e6ebef; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg,var(--accent),var(--accent-2)); transition: width .3s ease; }
.mini-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.mini-stats div { padding: 13px 14px; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 8px; display: flex; flex-direction: column; gap: 5px; }
.mini-stats span { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.mini-stats strong { font-size: 20px; }

.bar-chart { min-height: 230px; display: flex; gap: 14px; align-items: flex-end; padding-top: 12px; }
.bar-col { flex: 1; min-width: 38px; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 205px; justify-content: flex-end; }
.bar-value { font-size: 11px; color: var(--muted); }
.bar-outer { height: 150px; width: min(42px,80%); background: #eff2f5; display: flex; align-items: flex-end; border-radius: 5px 5px 2px 2px; overflow: hidden; }
.bar-inner { width: 100%; background: linear-gradient(180deg,#0983f3,#0b65bd); min-height: 2px; }
.bar-label { font-size: 11px; color: #66727d; }

.category-bars { display: grid; gap: 13px; }
.category-row { display: grid; grid-template-columns: minmax(120px,1fr) 3fr auto; gap: 12px; align-items: center; }
.category-name { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-track { height: 10px; background: #edf1f4; border-radius: 3px; overflow: hidden; }
.category-fill { height: 100%; background: #1583eb; }
.category-money { font-size: 12px; font-weight: 750; min-width: 72px; text-align: right; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { font-size: 11px; color: #67717b; text-transform: uppercase; letter-spacing: .5px; text-align: left; padding: 10px 11px; background: #f5f7f9; border-bottom: 1px solid var(--line); }
td { padding: 11px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
tbody tr:hover { background: #fafcfd; }
th.num, td.num { text-align: right; }
.points-positive { color: var(--success); font-weight: 800; }
.points-negative { color: var(--danger); font-weight: 800; }
.order-link { color: #096cc9; text-decoration: none; font-weight: 750; }
.order-link:hover { text-decoration: underline; }
.empty-state { padding: 28px 10px; color: var(--muted); text-align: center; }

.filter-row { display: flex; gap: 8px; flex-wrap: wrap; }

.unavailable-card { max-width: 900px; margin: 40px auto; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 54px; box-shadow: var(--shadow); }
.unavailable-card h1 { margin: 8px 0 12px; font-size: 34px; letter-spacing: -.8px; }
.unavailable-card > p { max-width: 680px; margin: 0 auto 24px; color: var(--muted); line-height: 1.6; }
.lock-icon { width: 54px; height: 54px; margin: 0 auto 18px; border-radius: 12px; display: grid; place-items: center; background: #111820; color: #fff; font-size: 25px; }
.coming-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 10px; margin: 30px 0; }
.coming-grid div { text-align: left; padding: 15px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; display: flex; flex-direction: column; gap: 5px; }
.coming-grid strong { font-size: 13px; }
.coming-grid span { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.small-copy { font-size: 12px; }

.error-text { min-height: 18px; color: var(--danger); font-size: 13px; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; background: #111820; color: white; border-radius: 8px; padding: 12px 15px; max-width: 360px; box-shadow: var(--shadow); font-size: 13px; }

@media (max-width: 900px) {
  .topbar-inner { align-items: flex-start; padding-top: 12px; padding-bottom: 12px; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .signed-in { display: none; }
  .kpi-grid { grid-template-columns: repeat(2,1fr); }
  .content-grid.two-thirds, .content-grid.equal { grid-template-columns: 1fr; }
  .coming-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 620px) {
  .page-shell { padding-left: 14px; padding-right: 14px; }
  .topbar-inner { padding-left: 14px; padding-right: 14px; }
  .app-subtitle { display: none; }
  .admin-picker label { display: none; }
  .admin-picker select { max-width: 160px; }
  .hero-row { align-items: flex-start; flex-direction: column; }
  .updated-card { width: 100%; }
  .kpi-grid, .kpi-grid.three { grid-template-columns: 1fr 1fr; }
  .kpi-card { min-height: 112px; padding: 16px; }
  .kpi-card strong { font-size: 27px; }
  .panel { padding: 15px; }
  .category-row { grid-template-columns: minmax(95px,1fr) 2fr auto; }
  .coming-grid { grid-template-columns: 1fr; }
  .unavailable-card { padding: 32px 20px; margin: 20px auto; }
}

/* Phase 1.1 admin access */
.table-subtext { color: var(--muted); font-size: 12px; margin-top: 3px; }
.role-pill, .status-pill { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; font-size: 11px; font-weight: 700; text-transform: capitalize; background: var(--surface-2); }
.role-pill.admin { border-color: rgba(31,111,235,.32); background: rgba(31,111,235,.08); }
.status-pill.active { border-color: rgba(24,145,88,.32); background: rgba(24,145,88,.08); }
.status-pill.disabled { opacity: .65; }

.modal-backdrop { position: fixed; inset: 0; z-index: 200; background: rgba(0,0,0,.52); display: grid; place-items: center; padding: 18px; }
.modal-backdrop[hidden] { display: none; }
.modal-card { width: min(560px, 100%); max-height: calc(100vh - 36px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 24px 80px rgba(0,0,0,.28); padding: 22px; }
.icon-button { appearance: none; border: 0; background: transparent; color: var(--text); font-size: 28px; line-height: 1; cursor: pointer; padding: 4px 8px; }
.form-field { display: grid; gap: 7px; margin: 14px 0; font-size: 13px; font-weight: 700; }
.form-field input, .form-field select { width: 100%; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--text); padding: 10px 11px; font: inherit; font-weight: 500; }
.form-field input:focus, .form-field select:focus { outline: 2px solid rgba(31,111,235,.2); border-color: rgba(31,111,235,.65); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

@media (max-width: 620px) {
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .modal-card { padding: 18px; }
}

/* Phase 1.2.1: incomplete modules are hidden until their real feed is connected. */
.content-grid.single-panel {
  grid-template-columns: minmax(0, 1fr);
}

/* Phase 1.2.2: full-screen post-login transition so the dashboard does not appear below the login view. */
.loading-shell {
  position: fixed;
  inset: 0;
  z-index: 500;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg,#eff4f8,#fafbfc);
}
.loading-shell[hidden] { display: none; }
.loading-card {
  width: min(440px,100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 34px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 20px;
}
.loading-card h1 { margin: 3px 0 7px; font-size: 24px; letter-spacing: -.5px; }
.loading-card p { margin: 0; }
.loading-spinner {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 4px solid #dfe6ec;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: portal-spin .75s linear infinite;
}
@keyframes portal-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation-duration: 1.6s; } }

/* Phase 1.2.4: page state is authoritative. This prevents login/app views from
   ever stacking vertically, even if a proxy/browser serves stale component CSS. */
body.view-login #loginView { display: grid !important; }
body.view-login #loadingView,
body.view-login #appView { display: none !important; }

body.view-loading #loginView,
body.view-loading #appView { display: none !important; }
body.view-loading #loadingView { display: grid !important; }

body.view-app #loginView,
body.view-app #loadingView { display: none !important; }
body.view-app #appView { display: block !important; }
