/*
  Dashboard design-system — WS-DASHBOARD-REDESIGN Phase A · Bundle 1.

  Ported from the vendor prototype (`~/dash_package/styles.css`) per the
  coordinator + 3-reviewer panel decision: adopt the visual SYSTEM, layout
  primitives and interaction — NOT the prototype's placeholder content,
  NOT React, NOT a new toolchain. This file is the shared chrome (sidebar,
  topbar, panels, pills, dots, buttons) for the server-rendered Jinja shell;
  page bodies keep their Tailwind utilities and sit inside `.main`.

  Loaded ONLY by `base.html`, so the standalone public landing page
  (`index.html`, which does not extend base.html) is untouched.

  System font stack only — no remote fonts (project hard rule).
*/

:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e2e8f0;
  --line-dark: rgba(148, 163, 184, .20);
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --cyan: #06b6d4;
  --green: #10b981;
  --green-soft: #ecfdf5;
  --amber: #f59e0b;
  --amber-soft: #fffbeb;
  --red: #ef4444;
  --red-soft: #fff1f2;
  --shadow: 0 20px 50px rgba(15, 23, 42, .08);
  --shadow-soft: 0 10px 24px rgba(15, 23, 42, .06);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --sidebar: 272px;
  color-scheme: light;
}

/* Collapsed sidebar (persisted in localStorage; class lives on <html> so the
   pre-paint inline script can restore it without a flash). */
.sidebar-collapsed { --sidebar: 86px; }

.dash-body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% -8%, rgba(37, 99, 235, .18), transparent 30%),
    radial-gradient(circle at 95% 4%, rgba(6, 182, 212, .14), transparent 28%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 42%, #f6f8fb 100%);
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

/* ---- Sidebar --------------------------------------------------------- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background:
    radial-gradient(circle at 16% 10%, rgba(37, 99, 235, .32), transparent 34%),
    linear-gradient(180deg, #101827 0%, #0b1220 60%, #08111f 100%);
  border-right: 1px solid rgba(255, 255, 255, .08);
  color: #dbeafe;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 18px;
  border-bottom: 1px solid rgba(148, 163, 184, .22);
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 15px;
  overflow: hidden;
  background: linear-gradient(135deg, #38bdf8 0%, #2563eb 58%, #1e3a8a 100%);
  box-shadow: 0 14px 28px rgba(37, 99, 235, .36);
  color: #fff;
  font-weight: 900;
  letter-spacing: -.04em;
}

.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-text strong { display: block; color: #fff; font-size: 16px; line-height: 1.1; }
.brand-text span { display: block; color: #93a4bd; font-size: 12px; margin-top: 2px; }

.nav-section { margin-top: 16px; }

.nav-label {
  margin: 0 10px 8px;
  color: #718198;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.nav { display: grid; gap: 5px; }

.nav-button {
  width: 100%;
  border: 0;
  min-height: 44px;
  border-radius: 14px;
  background: transparent;
  color: #a7b4c8;
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 11px;
  text-align: left;
  font-weight: 720;
  text-decoration: none;
  position: relative;
  overflow: visible;
  transition: background .16s ease, color .16s ease, transform .16s ease;
}

.nav-button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .07);
  transform: translateX(2px);
}

.nav-button.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(37, 99, 235, .26), rgba(14, 165, 233, .14));
  box-shadow: inset 0 0 0 1px rgba(96, 165, 250, .28), 0 12px 28px rgba(0, 0, 0, .18);
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: rgba(148, 163, 184, .12);
  color: inherit;
}

.nav-button.active .nav-icon { background: rgba(96, 165, 250, .22); }

/* Inline-SVG nav glyphs (WS-DASHBOARD-REDESIGN polish): stroke icons inherit
   currentColor, so the active-state colour shift needs no per-icon override. */
.nav-svg { width: 20px; height: 20px; display: block; }

/* Tooltip (desktop: hover/focus; mobile: .tooltip-open added on tap). */
.nav-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%) translateX(-6px);
  min-width: max-content;
  max-width: 220px;
  padding: 9px 11px;
  border-radius: 12px;
  background: rgba(15, 23, 42, .96);
  color: #fff;
  font-size: 12px;
  font-weight: 760;
  line-height: 1.25;
  box-shadow: 0 18px 34px rgba(2, 6, 23, .34);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  z-index: 50;
  white-space: nowrap;
}

.nav-button::before {
  content: "";
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%) translateX(-6px);
  width: 10px;
  height: 10px;
  background: rgba(15, 23, 42, .96);
  rotate: 45deg;
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
  z-index: 49;
}

.nav-button:hover::after,
.nav-button:hover::before,
.nav-button:focus-visible::after,
.nav-button:focus-visible::before,
.nav-button.tooltip-open::after,
.nav-button.tooltip-open::before {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

.side-status {
  margin-top: 18px;
  padding: 15px;
  border-radius: 20px;
  background: rgba(15, 23, 42, .68);
  border: 1px solid rgba(148, 163, 184, .20);
}

.status-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #fff;
  font-weight: 800;
  margin-bottom: 8px;
}

.sidebar-footer { margin-top: auto; padding-top: 16px; }
.sidebar-logout { margin: 12px 4px 0; }

.small { color: #94a3b8; font-size: 12px; line-height: 1.45; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  flex: 0 0 auto;
  display: inline-block;
}
.dot.red { color: var(--red); }
.dot.green { color: var(--green); }
.dot.amber { color: var(--amber); }
.dot.blue { color: var(--blue); }
.dot.gray { color: var(--muted-2); }

/* ---- Main column + topbar ------------------------------------------- */

.main { min-width: 0; padding: 22px 28px 42px; }

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title { display: flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 700; }
.page-title strong { color: var(--ink); }
.page-title .slash { color: #cbd5e1; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .75);
  color: var(--muted);
  font-weight: 720;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.btn {
  border: 0;
  border-radius: 13px;
  min-height: 40px;
  padding: 10px 14px;
  background: var(--blue);
  color: #fff;
  font-weight: 820;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(37, 99, 235, .22);
  transition: transform .14s ease, background .14s ease, box-shadow .14s ease;
}
.btn:hover { background: var(--blue-dark); transform: translateY(-1px); box-shadow: 0 14px 28px rgba(37, 99, 235, .24); }
.btn.secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); box-shadow: var(--shadow-soft); }
.btn.secondary:hover { background: var(--surface-soft); }
.btn:disabled, .btn[aria-disabled="true"] {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button.btn, a.btn { font: inherit; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }

/* ---- Content primitives (shared base for later bundles) ------------- */

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .88);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}
.panel-head {
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: rgba(248, 250, 252, .72);
}
.panel-head h2 { margin: 0; font-size: 17px; letter-spacing: -.03em; }
.panel-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.panel-body { padding: 18px; }
/* Horizontal scroll container for wide tables. Lives here (not as an inline
   style) for CSP hygiene — same move as taking inline JS out of stock-upload. */
.scroll-x { overflow-x: auto; }

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, .8fr);
  gap: 18px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: rgba(255, 255, 255, .86);
  padding: 17px;
  box-shadow: var(--shadow-soft);
}
.metric-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--muted); font-weight: 790; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.metric-value { margin-top: 14px; font-size: 30px; font-weight: 900; letter-spacing: -.05em; }
.metric-note { margin-top: 5px; color: var(--muted); font-size: 12px; }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 25px;
  padding: 5px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 800;
  font-size: 12px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.tag.red { background: var(--red-soft); color: #b91c1c; border-color: #fecdd3; }
.tag.amber { background: var(--amber-soft); color: #92400e; border-color: #fde68a; }
.tag.green { background: var(--green-soft); color: #047857; border-color: #bbf7d0; }
.tag.blue { background: var(--blue-soft); color: #1d4ed8; border-color: #bfdbfe; }

.task-list { display: grid; gap: 10px; }
.task {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 11px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: #fff;
}
.task strong { display: block; font-size: 13px; }
.task span { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.cards-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mini-card { padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: #fff; }
.mini-card strong { display: block; font-size: 14px; }
.mini-card p { color: var(--muted); margin: 7px 0 0; font-size: 12px; line-height: 1.45; }

/* ---- Auth (login / OTP) centered card ------------------------------- */

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 26px;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  text-decoration: none;
  color: var(--ink);
}
.auth-brand .brand-text strong { color: var(--ink); }
.auth-brand .brand-text span { color: var(--muted); }
.auth-field { display: block; margin-bottom: 14px; }
.auth-field > span { margin-bottom: 6px; display: block; font-size: 13px; font-weight: 600; color: #374151; }
.auth-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.auth-input:focus { outline: none; border-color: rgba(37, 99, 235, .7); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); }

/* ---- Collapsed-state hiding ----------------------------------------- */

.sidebar-collapsed .brand-text,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .nav-button .label,
.sidebar-collapsed .side-status,
.sidebar-collapsed .sidebar-logout .btn-label {
  display: none;
}
.sidebar-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }
.sidebar-collapsed .nav-button { grid-template-columns: 1fr; justify-items: center; padding: 10px; }

/* ---- Responsive ----------------------------------------------------- */

@media (max-width: 1080px) {
  .app { grid-template-columns: 86px minmax(0, 1fr); }
  .brand-text, .nav-label, .nav-button .label, .side-status { display: none; }
  .brand { justify-content: center; padding-left: 0; padding-right: 0; }
  .nav-button { grid-template-columns: 1fr; justify-items: center; padding: 10px; }
}

@media (max-width: 760px) {
  .app { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 15;
    height: auto;
    padding: 12px;
    backdrop-filter: blur(10px);
    flex-direction: column;
  }
  .brand-text, .nav-label { display: block; }
  .brand { justify-content: flex-start; padding: 8px 10px 12px; }
  .nav { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nav-button { grid-template-columns: 1fr; justify-items: center; min-height: 58px; padding: 12px 8px; }
  .nav-button .label { display: none; }
  .side-status { display: none; }
  .sidebar-footer { margin-top: 12px; }
  /* Tooltip flips above the icon on the mobile top-bar. */
  .nav-button::after {
    left: 50%;
    top: auto;
    bottom: calc(100% + 10px);
    transform: translateX(-50%) translateY(6px);
    white-space: normal;
    max-width: 180px;
    text-align: center;
  }
  .nav-button::before {
    left: 50%;
    top: auto;
    bottom: calc(100% + 4px);
    transform: translateX(-50%) translateY(6px) rotate(45deg);
  }
  .nav-button:hover::after,
  .nav-button:hover::before,
  .nav-button:focus-visible::after,
  .nav-button:focus-visible::before,
  .nav-button.tooltip-open::after,
  .nav-button.tooltip-open::before {
    transform: translateX(-50%) translateY(0);
  }
  .main { padding: 18px 14px 34px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { justify-content: flex-start; }
  .content-grid, .grid-4, .cards-3 { grid-template-columns: 1fr; }
}

/* «ДЕМО» ribbon — demo-tenant-only marker (rendered by base.html only when
   settings.tenant_slug == "demo"). Thin amber bar pinned at the very top of the
   page so the demonstration context is unmissable but unobtrusive; it sits in
   normal flow (pushes the shell down a few px) so nothing overlaps the sidebar
   or auth card. */
.demo-ribbon {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 5px 14px;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  color: #3b2f00;
  font-size: 12.5px;
  letter-spacing: .01em;
  line-height: 1.2;
  box-shadow: inset 0 -1px 0 rgba(120, 80, 0, .25);
}
.demo-ribbon strong {
  font-weight: 800;
  letter-spacing: .12em;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(59, 47, 0, .16);
}
.demo-ribbon span { color: #5a4600; }
