/* ============================================================
   TEKLEASE DASHBOARD — DESIGN TOKENS & BASE SYSTEM
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* ── Brand ── */
  --brand:        #F26A1F;
  --brand-600:    #DB5C12;
  --brand-700:    #B84B0E;
  --brand-50:     #FFF1E8;
  --brand-100:    #FFE0CC;

  /* ── Neutrals — warm ── */
  --bg:           #FAF8F5;
  --bg-elevated:  #FFFFFF;
  --bg-subtle:    #F4F1EC;
  --bg-hover:     #F0EBE3;
  --border:       #ECE6DC;
  --border-strong:#DDD5C7;

  --ink:          #1A1714;
  --ink-soft:     #4A443C;
  --ink-muted:    #847C70;
  --ink-faint:    #B8AE9E;

  /* ── Semantic ── */
  --pos:          #1F8F4D;
  --pos-bg:       #E8F5EC;
  --neg:          #C8341A;
  --neg-bg:       #FBE9E5;
  --warn:         #B57A0F;
  --warn-bg:      #FBF1DD;
  --info:         #2469B5;
  --info-bg:      #E5F0FB;

  /* ── Radius ── */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* ── Shadows ── */
  --shadow-xs: 0 1px 2px rgba(26,23,20,0.04);
  --shadow-sm: 0 1px 2px rgba(26,23,20,0.04), 0 1px 3px rgba(26,23,20,0.03);
  --shadow-md: 0 2px 4px rgba(26,23,20,0.05), 0 4px 12px rgba(26,23,20,0.04);

  /* ── Typography ── */
  --font-ui: 'Inter', 'Urbanist', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

/* ============ Reset ============ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01';
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ============ Typography ============ */
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.page-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--ink);
}
.page-sub {
  font-size: 13px;
  color: var(--ink-muted);
}

/* ============ App Shell ============ */
.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ============ Topbar ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--ink);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: -0.02em;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand-sub {
  font-size: 9.5px;
  color: var(--ink-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 3px;
}

/* ── Nav segmented ── */
.nav {
  display: flex;
  gap: 2px;
  background: var(--bg-subtle);
  padding: 3px;
  border-radius: 10px;
}
.nav-item {
  position: relative;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
  background: transparent;
  border: 0;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 120ms;
  white-space: nowrap;
}
.nav-item:hover { color: var(--ink); }
.nav-item.active {
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: var(--shadow-xs);
}
.nav-item .alert-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--neg);
  display: inline-block;
}

.spacer { flex: 1; }

/* ── Status ── */
.status {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-muted);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--pos-bg);
  color: var(--pos);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
}
.status-pill .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 0 3px rgba(31,143,77,0.2);
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  transition: all 120ms;
}
.icon-btn:hover { background: var(--bg-subtle); color: var(--ink); }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  border: 0;
  padding: 0;
  cursor: pointer;
}

/* ============ Page Layout ============ */
.page {
  flex: 1;
  padding: 28px 28px 60px;
  max-width: 1480px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 24px;
}

/* ============ Cards ============ */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 20px; }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
  margin: 0;
}

/* ============ KPI Tiles ============ */
.kpi {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
}
.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.1;
}
.kpi-value .unit { font-size: 16px; color: var(--ink-muted); margin-left: 4px; }
.kpi-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 5px;
  font-family: var(--font-mono);
}
.kpi-delta.pos { background: var(--pos-bg); color: var(--pos); }
.kpi-delta.neg { background: var(--neg-bg); color: var(--neg); }
.kpi-delta.neutral { background: var(--bg-subtle); color: var(--ink-muted); }
.kpi-hint { font-size: 11.5px; color: var(--ink-muted); }

/* KPI variants */
.kpi.hero {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.kpi.hero .kpi-label { color: rgba(255,255,255,0.55); }
.kpi.hero .kpi-value { color: white; }
.kpi.hero .kpi-value .unit { color: rgba(255,255,255,0.55); }
.kpi.hero .kpi-hint { color: rgba(255,255,255,0.55); }

.kpi.brand-accent {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-600) 100%);
  color: white;
  border-color: transparent;
}
.kpi.brand-accent .kpi-label { color: rgba(255,255,255,0.85); }
.kpi.brand-accent .kpi-value { color: white; }
.kpi.brand-accent .kpi-hint { color: rgba(255,255,255,0.85); }
.kpi.brand-accent .kpi-delta.pos {
  background: rgba(255,255,255,0.2);
  color: white;
}

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }

table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.t thead th {
  text-align: left;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  font-weight: 600;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.t thead th.r { text-align: right; }
table.t tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-soft);
  vertical-align: middle;
}
table.t tbody td.r { text-align: right; }
table.t tbody tr:hover { background: var(--bg-subtle); }
table.t tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ============ Badges ============ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--ink-soft);
}
.badge.pos { background: var(--pos-bg); color: var(--pos); }
.badge.neg { background: var(--neg-bg); color: var(--neg); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.brand { background: var(--brand-50); color: var(--brand-700); }

/* ============ Rank ============ */
.rank {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--ink-muted);
  font-family: var(--font-mono);
}
.rank.top { background: var(--brand-50); color: var(--brand-700); }
.rank.bottom { background: var(--neg-bg); color: var(--neg); }

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  transition: all 120ms;
}
.btn:hover { background: var(--bg-subtle); }
.btn.primary {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}
.btn.primary:hover { background: var(--brand-600); }
.btn.dark { background: var(--ink); color: white; border-color: var(--ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--bg-subtle); color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn-block {
  width: 100%;
  justify-content: center;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  margin-top: 8px;
}

/* ============ Filters ============ */
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.filter-pill {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 120ms;
}
.filter-pill:hover { background: var(--bg-subtle); }
.filter-pill.active { background: var(--ink); color: white; border-color: var(--ink); }

.select {
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 12.5px;
  color: var(--ink);
  min-width: 120px;
}

/* ============ Progress bars ============ */
.bar-track {
  position: relative;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 999px;
  overflow: hidden;
  width: 100%;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--brand);
  border-radius: 999px;
}
.bar-fill.pos { background: var(--pos); }
.bar-fill.neg { background: var(--neg); }
.bar-fill.warn { background: var(--warn); }

/* ============ Alert banners ============ */
.alert-banner {
  display: flex;
  gap: 14px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: var(--r-md);
  align-items: center;
}
.alert-banner.danger { border-left-color: var(--neg); }
.alert-banner.warn { border-left-color: var(--warn); }
.alert-icon {
  width: 28px; height: 28px; border-radius: 7px;
  display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand-700);
  flex-shrink: 0;
}
.alert-banner.danger .alert-icon { background: var(--neg-bg); color: var(--neg); }
.alert-banner.warn .alert-icon { background: var(--warn-bg); color: var(--warn); }
.alert-text { flex: 1; font-size: 13px; color: var(--ink); }
.alert-text strong { font-weight: 600; }
.alert-text small { color: var(--ink-muted); display: block; margin-top: 2px; font-size: 12px; }

/* ============ Sections ============ */
.section-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 28px 0 14px;
}
.section-h h2 {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-muted);
  font-weight: 600;
  margin: 0;
}
.section-h h2 .count {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 6px;
  background: var(--bg-subtle);
  color: var(--ink-soft);
  border-radius: 4px;
  font-size: 10.5px;
  letter-spacing: 0;
}

/* ============ Legends ============ */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  font-size: 12px;
  color: var(--ink-soft);
}
.legend-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.legend-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: currentColor;
}

/* ============ Sparkline ============ */
.sparkline { display: block; }

/* ============ Layout helpers ============ */
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.row { display: flex; gap: 16px; }
.row-baseline { display: flex; align-items: baseline; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 16px; }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* ============ Footer ============ */
.footer {
  text-align: center;
  font-size: 11px;
  color: var(--ink-faint);
  padding: 24px 0;
}
.footer span { margin: 0 8px; }

/* ============ Scrollbar ============ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 10px 16px;
  border-radius: var(--r-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 200ms ease-out;
}
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
