/* Rahnivo OS — Track 4 Owner Dashboard
   Tokens: deep navy + cyan/teal, 8pt spacing scale only, one grid.
   Laws: no left-border accent bars, no box-inside-box collage,
   every control has hover/press/loading state and animates. */

:root {
  --navy-900: #04101f;
  --navy-800: #07182e;
  --navy-700: #0b2440;
  --cyan: #12c6d8;
  --teal: #0fb5a0;
  --ink: #12222f;
  --ink-soft: #4b6172;
  --bg: #f2f6f8;
  --card: #ffffff;
  --line: #dce7ec;
  --danger: #d64545;
  --danger-bg: #fdf0f0;
  --hot-bg: #fdecec;
  --hot-ink: #b42318;
  --warm-bg: #fff4e0;
  --warm-ink: #8a5a00;
  --cold-bg: #e8eef2;
  --cold-ink: #4b6172;
  --ok-bg: #e6f7f1;
  --ok-ink: #0a6b52;
  --radius: 16px;
  --radius-sm: 8px;
  --shadow: 0 8px 24px rgba(7, 24, 46, 0.12);
  --space: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: calc(var(--space) * 2);
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2);
  background: var(--navy-800); color: #fff;
}
.topbar-brand { display: flex; align-items: center; gap: calc(var(--space) * 1.5); min-width: 0; }
.brand-logo { border-radius: var(--radius-sm); background: var(--navy-700); object-fit: contain; }
.brand-logo-sm { width: 36px; height: 36px; }
.topbar-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.2px; }
.topbar-sub { margin: 0; font-size: 12px; color: #a9c6d8; }
.topbar-user { display: flex; align-items: center; gap: var(--space); flex-shrink: 0; }
.user-chip { font-size: 13px; color: #d7e8f2; white-space: nowrap; }

/* ---------- Layout: one centred grid column ---------- */
.screen {
  max-width: 880px; margin: 0 auto;
  padding: calc(var(--space) * 2) calc(var(--space) * 2) calc(var(--space) * 6);
  display: grid; gap: calc(var(--space) * 2);
}
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: calc(var(--space) * 2);
  display: grid; gap: calc(var(--space) * 1.5);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: calc(var(--space) * 2); flex-wrap: wrap; }
.panel-head h2, .drawer-head h2, .modal h2 { margin: 0; font-size: 17px; font-weight: 700; }
.subhead { margin: calc(var(--space) * 1) 0 0; font-size: 13px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.6px; }
.stack { display: grid; gap: var(--space); }

/* ---------- KPI row ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space); }
.kpi-card {
  background: var(--navy-800); color: #fff; border-radius: var(--radius);
  padding: calc(var(--space) * 1.5); text-align: center;
}
.kpi-value { margin: 0; font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-value.is-animating { animation: kpi-pop 320ms ease-out; }
@keyframes kpi-pop { 0% { transform: scale(0.82); opacity: 0.4; } 100% { transform: scale(1); opacity: 1; } }
.kpi-label { margin: 0; font-size: 12px; color: #a9c6d8; }
.kpi-sub { display: block; color: var(--cyan); font-weight: 600; }

.raahi-line {
  margin: 0; background: var(--ok-bg); color: var(--ok-ink);
  border: 1px solid #bfe6d8; border-radius: var(--radius);
  padding: calc(var(--space) * 1.5) calc(var(--space) * 2); font-size: 14px; font-weight: 600;
}

/* ---------- Buttons: state is always visible ---------- */
.btn {
  appearance: none; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; text-decoration: none;
  border-radius: var(--radius-sm); padding: 10px 16px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space);
  transition: transform 120ms ease, background-color 160ms ease, color 160ms ease, opacity 160ms ease;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(0.97); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid rgba(18, 198, 216, 0.55); outline-offset: 2px;
}
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-secondary { background: var(--navy-700); color: #fff; }
.btn-ghost { background: transparent; color: inherit; border-color: var(--line); }
.topbar .btn-ghost { border-color: #33506e; color: #d7e8f2; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn.is-loading { position: relative; color: transparent !important; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.45); border-top-color: #fff;
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- List rows (single level, hairline dividers) ---------- */
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: calc(var(--space) * 2);
  width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: calc(var(--space) * 1.5); font: inherit; color: inherit; cursor: pointer;
  transition: background-color 160ms ease, transform 120ms ease;
}
.list-row:hover { background: #f7fafb; }
.list-row:active { transform: scale(0.99); }
.row-main { min-width: 0; display: grid; gap: 2px; }
.row-title { font-weight: 700; font-size: 15px; overflow-wrap: anywhere; }
.row-sub { font-size: 13px; color: var(--ink-soft); overflow-wrap: anywhere; }
.row-side { flex-shrink: 0; display: grid; gap: var(--space); justify-items: end; }
.empty-note { margin: 0; color: var(--ink-soft); font-size: 14px; padding: var(--space) 0; }

/* Approvals: decision rows are not buttons themselves */
.approval-row {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: calc(var(--space) * 1.5); display: grid; gap: var(--space);
  transition: opacity 240ms ease, transform 240ms ease;
}
.approval-row.is-done { opacity: 0; transform: translateY(-4px); }
.approval-actions { display: flex; gap: var(--space); }
.approval-actions .btn { flex: 1; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; font-size: 11px; font-weight: 800;
  letter-spacing: 0.5px; text-transform: uppercase; border-radius: 999px; padding: 4px 10px;
}
.badge-hot { background: var(--hot-bg); color: var(--hot-ink); }
.badge-warm { background: var(--warm-bg); color: var(--warm-ink); }
.badge-cold { background: var(--cold-bg); color: var(--cold-ink); }
.badge-stage { background: var(--cold-bg); color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 12px; }

/* Pipeline strip */
.pipeline-strip { display: flex; flex-wrap: wrap; gap: var(--space); }
.pipeline-chip {
  border: 1px solid var(--line); border-radius: 999px; background: #f7fafb;
  padding: 6px 12px; font-size: 13px; color: var(--ink-soft);
}
.pipeline-chip strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.pipeline-chip.is-zero { opacity: 0.6; }

/* Search */
.search-box input {
  font: inherit; font-size: 16px; /* 16px stops iOS auto-zoom */
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; width: 220px; max-width: 60vw; background: #fff;
}

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; min-height: 44px; background: #fff; width: 100%;
}
.form-error {
  margin: 0; background: var(--danger-bg); color: var(--hot-ink);
  border: 1px solid #f3c2c2; border-radius: var(--radius-sm); padding: calc(var(--space) * 1.5); font-size: 14px;
}

/* ---------- Login ---------- */
.login-body { background: var(--navy-900); min-height: 100vh; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: calc(var(--space) * 2); }
.login-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 400px; padding: calc(var(--space) * 4);
  display: grid; gap: calc(var(--space) * 2); text-align: center;
}
.login-card .brand-logo { margin: 0 auto; width: 56px; height: 56px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-sub { margin: 0; color: var(--ink-soft); font-size: 14px; }
.login-form { display: grid; gap: calc(var(--space) * 1.5); text-align: left; }
.login-note { margin: 0; font-size: 12px; color: var(--ink-soft); }

/* ---------- Drawer (slide-over) ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(4, 16, 31, 0.55); z-index: 30;
  opacity: 0; transition: opacity 240ms ease;
}
.drawer-backdrop.is-open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(440px, 100vw); background: var(--card);
  box-shadow: var(--shadow); transform: translateX(102%);
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0.24, 1);
  display: flex; flex-direction: column;
}
.drawer.is-open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: calc(var(--space) * 2);
  padding: calc(var(--space) * 2); background: var(--navy-800); color: #fff;
}
.drawer-head .btn-ghost { border-color: #33506e; color: #d7e8f2; }
.drawer-body { overflow-y: auto; padding: calc(var(--space) * 2); display: grid; gap: calc(var(--space) * 2); align-content: start; }
.drawer-meta { margin: 0; color: var(--ink-soft); font-size: 13px; }
.drawer-pain { margin: 0; font-size: 15px; }
.drawer-actions { display: flex; gap: var(--space); }
.drawer-actions .btn { flex: 1; }
.drawer-form { display: grid; gap: calc(var(--space) * 1.5); }
.bubble { border-radius: var(--radius-sm); padding: calc(var(--space) * 1.25) calc(var(--space) * 1.5); font-size: 14px; overflow-wrap: anywhere; }
.bubble-in { background: #eef4f7; }
.bubble-out { background: var(--ok-bg); }
.bubble-meta { display: block; font-size: 11px; color: var(--ink-soft); margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(4, 16, 31, 0.6);
  display: grid; place-items: center; padding: calc(var(--space) * 2);
}
.modal-backdrop[hidden] { display: none; }
.modal { background: var(--card); border-radius: var(--radius); padding: calc(var(--space) * 3); width: 100%; max-width: 380px; display: grid; gap: calc(var(--space) * 1.5); box-shadow: var(--shadow); animation: kpi-pop 200ms ease-out; }
.modal p { margin: 0; color: var(--ink-soft); font-size: 14px; }
.modal-actions { display: flex; gap: var(--space); }
.modal-actions .btn { flex: 1; }

/* ---------- Toasts ---------- */
.toast-stack {
  position: fixed; left: calc(var(--space) * 2); right: calc(var(--space) * 2); bottom: calc(var(--space) * 2);
  z-index: 50; display: grid; gap: var(--space); max-width: 420px; margin-left: auto;
}
.toast {
  background: var(--navy-800); color: #fff; border-radius: var(--radius-sm);
  padding: calc(var(--space) * 1.5); display: grid; gap: 4px; box-shadow: var(--shadow);
  animation: toast-in 260ms cubic-bezier(0.32, 0.72, 0.24, 1); overflow: hidden; position: relative;
}
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity 200ms ease, transform 200ms ease; }
.toast-title { font-weight: 700; font-size: 14px; display: flex; gap: var(--space); align-items: center; }
.toast-line { font-size: 13px; color: #c4d9e6; }
.toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--cyan); width: 100%; transform-origin: left; animation: toast-progress 4.5s linear forwards; }
.toast:hover .toast-progress { animation-play-state: paused; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-progress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ---------- Skeletons ---------- */
.skeleton { background: linear-gradient(90deg, #e6eef2 25%, #f4f8fa 50%, #e6eef2 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); display: block; }
.skeleton-line { height: 16px; width: 100%; }
.skeleton-card { height: 64px; width: 100%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Small screens: designed as an app screen, not a shrunk table ---------- */
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .screen { padding-left: calc(var(--space) * 1.5); padding-right: calc(var(--space) * 1.5); }
  .user-chip { display: none; }
  .search-box, .search-box input { width: 100%; max-width: none; }
  .panel-head { align-items: stretch; }
  .toast-stack { margin-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
