/* ============================================================================
   ENVISION DMS — Modern UI Refresh (2026)
   Additive, cascade-layered enhancement loaded AFTER styles.css and BEFORE
   garage-view.css. It only restyles existing components (no markup, IDs,
   handlers, or layout structure change) so wiring and permissions are untouched.
   Color overrides that could affect dark mode are scoped to body:not(.dark-mode);
   geometry (radius, shadow, spacing, motion, focus) is shared by both themes.
   ============================================================================ */

/* ── Refined design tokens (light). Dark mode keeps its own via higher specificity. ── */
:root {
  --ink:   #0b1524;
  --muted: #667085;
  --line:  #e6ebf2;
  --paper: #eef2f7;
  --panel: rgba(255, 255, 255, 0.98);

  /* Modern radius scale */
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 22px;

  /* Softer, neutral layered elevation (less blue tint, more depth) */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shadow:    0 4px 12px rgba(16, 24, 40, 0.06), 0 12px 28px rgba(16, 24, 40, 0.09);
  --shadow-lg: 0 24px 60px rgba(16, 24, 40, 0.20);

  /* Focus rings (accessibility) */
  --ring-accent: 0 0 0 3px rgba(0, 180, 166, 0.35);
  --ring-focus:  0 0 0 3px rgba(37, 99, 235, 0.35);
}

/* ── Calmer, modern app canvas ─────────────────────────────────────────────── */
body:not(.dark-mode) {
  background:
    radial-gradient(1100px 520px at 100% -12%, rgba(0, 180, 166, 0.07), transparent 60%),
    radial-gradient(900px 480px at -8% -6%, rgba(37, 99, 235, 0.06), transparent 55%),
    linear-gradient(180deg, #f5f8fc 0%, #eef2f7 100%);
}

html { scroll-behavior: smooth; }

/* Slightly wider, softer scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c7d0dc; border: 2px solid transparent; background-clip: padding-box; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #9aa7b6; border: 2px solid transparent; background-clip: padding-box; }

/* ── Global accessible focus ring ──────────────────────────────────────────── */
a:focus-visible,
button:focus-visible,
.primary:focus-visible,
.secondary:focus-visible,
.danger:focus-visible,
.icon-button:focus-visible,
.nav-button:focus-visible,
[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--ring-focus);
}
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--ring-accent);
  border-color: var(--porter-teal);
}

/* ── Sidebar: deep modern slate + roomier nav ──────────────────────────────── */
.sidebar {
  /* Lightened from a near-black navy so module names read clearly against the
     72%+ white nav text while keeping the dark sidebar look. */
  background: linear-gradient(180deg, #1f3050 0%, #263a5c 100%);
  border-right: 1px solid rgba(255, 255, 255, 0.09);
}
.mark {
  border-radius: 10px;
  background: linear-gradient(150deg, var(--porter-teal-2), var(--porter-teal));
  box-shadow: 0 4px 12px rgba(0, 180, 166, 0.35);
}
.nav-button {
  border-radius: 9px;
  padding: 8px 11px;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
@media (hover: hover) and (pointer: fine) {
  .nav-button:hover { background: rgba(255, 255, 255, 0.08); }
}
.nav-button.active {
  background: linear-gradient(90deg, rgba(0, 180, 166, 0.22), rgba(0, 180, 166, 0.10));
}
.nav-button.active::before { top: 6px; bottom: 6px; width: 3px; border-radius: 0 3px 3px 0; }

/* ── Buttons: modern radius, hover lift, gradient primary ──────────────────── */
.primary,
.secondary,
.danger,
.icon-button {
  border-radius: 10px;
  transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease),
              background var(--fast) var(--ease), border-color var(--fast) var(--ease);
}
.primary {
  background: linear-gradient(180deg, var(--porter-teal-2), var(--porter-teal));
  box-shadow: 0 1px 2px rgba(0, 180, 166, 0.25);
}
.primary:hover {
  background: linear-gradient(180deg, var(--porter-teal-2), var(--porter-teal-2));
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(0, 180, 166, 0.28);
}
.primary:active { transform: translateY(0); box-shadow: 0 2px 6px rgba(0, 180, 166, 0.28); }
.secondary:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.danger:hover { transform: translateY(-1px); }
.icon-button { border-radius: 10px; }

/* ── Inputs: modern radius + calm borders ──────────────────────────────────── */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea { border-radius: 10px; }
body:not(.dark-mode) input:not([type="checkbox"]):not([type="radio"]),
body:not(.dark-mode) select,
body:not(.dark-mode) textarea {
  border-color: var(--line);
  background: #ffffff;
}
/* The sidebar search sits on the DARK sidebar, so it must stay dark — the global
   white input background above would otherwise make its white text and the
   keyboard-shortcut pill invisible (white-on-white). The `.sidebar` ancestor is
   included so this rule out-specifies the global input override above. */
body:not(.dark-mode) .sidebar .search-sidebar input {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.16);
  color: #fff;
  -webkit-text-fill-color: #fff;
}
body:not(.dark-mode) .sidebar .search-sidebar input::placeholder { color: rgba(255, 255, 255, 0.55); }

@media (hover: none) and (pointer: coarse) {
  body:not(.dark-mode) .sidebar .search-sidebar input,
  body:not(.dark-mode) .sidebar .search-sidebar input[type="search"] {
    background: #ffffff;
    border-color: rgba(255, 255, 255, 0.45);
    color: var(--ink);
    -webkit-text-fill-color: var(--ink);
  }
  body:not(.dark-mode) .sidebar .search-sidebar input::placeholder {
    color: var(--muted);
    -webkit-text-fill-color: var(--muted);
  }
}

/* ── Panels & cards: crisp surfaces, softer neutral elevation ──────────────── */
.panel {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border-color: var(--line);
  backdrop-filter: blur(10px);
}
.panel > header { padding: 15px 18px; }
.card {
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: transform var(--mid) var(--ease), box-shadow var(--mid) var(--ease);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
body:not(.dark-mode) .panel-filters { background: #f8fafc; }

/* ── Tables: airier spacing, cleaner headers ───────────────────────────────── */
th, td { padding: 12px 16px; }
body:not(.dark-mode) th,
body:not(.dark-mode) .table-wrap table thead th { background: #f7f9fc; letter-spacing: 0.5px; }
body:not(.dark-mode) tbody tr:hover { background: rgba(0, 180, 166, 0.05); }

/* ── Badges / pills: a touch more presence ─────────────────────────────────── */
.badge { padding: 3px 10px; border-radius: 999px; letter-spacing: 0.1px; }

/* ── Toasts & login card: modern elevation ─────────────────────────────────── */
.toast { border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.login-card { border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); }
.login-gate > .login-card { border-radius: var(--radius-xl); }

/* ============================================================================
   v2 — deeper modernization: modals, tabs, chips, KPI tiles, form controls,
   typographic rhythm. Still additive & structure-preserving.
   ============================================================================ */

/* ── Native <dialog> modals: softer, deeper, blurred backdrop (all modals) ──── */
dialog {
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(16, 24, 40, 0.06);
}
dialog::backdrop {
  background: rgba(11, 18, 32, 0.50);
  backdrop-filter: blur(8px) saturate(1.08);
}

/* ── Tabs: modern pills + segmented controls ───────────────────────────────── */
.subtab, .filter-chip {
  border-radius: 999px;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
              border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.subtab.active {
  background: linear-gradient(180deg, var(--porter-teal-2), var(--porter-teal));
  border-color: var(--porter-teal);
  color: #fff;
  box-shadow: 0 6px 14px rgba(0, 180, 166, 0.25);
}
body:not(.dark-mode) .filter-chip.active { background: rgba(0, 180, 166, 0.12); color: var(--porter-teal); }
/* Segmented "module-tabs": active pill floats as a white card */
body:not(.dark-mode) .module-tabs { background: #eef2f7; }
body:not(.dark-mode) .module-tabs button.active {
  background: #ffffff;
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* ── Chips: unified modern pills ───────────────────────────────────────────── */
.insight-chip, .handoff-chip, .parts-kit-chip, .oem-order-type-chip,
.crm-pipeline-chip, .detail-stat-chip, .user-chip, .invoice-src-pill,
.parts-kit-total-chip {
  border-radius: 999px;
  transition: box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}

/* ── KPI / metric tiles: hover lift + depth ────────────────────────────────── */
.super-kpi-tile, .super-module-tile, .company-gate-stat, .service-role-stat {
  border-radius: var(--radius);
  transition: transform var(--mid) var(--ease), box-shadow var(--mid) var(--ease);
}
.super-kpi-tile:hover, .super-module-tile:hover, .company-gate-stat:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.dashboard-compact-metrics > * { transition: transform var(--mid) var(--ease), box-shadow var(--mid) var(--ease); }
.dashboard-compact-metrics > *:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }

/* ── Native form controls themed to brand; modern selection & numerals ─────── */
input[type="checkbox"], input[type="radio"], input[type="range"], progress {
  accent-color: var(--porter-teal);
}
::selection { background: rgba(0, 180, 166, 0.24); }
body:not(.dark-mode) table { font-variant-numeric: tabular-nums; }

/* ── Typographic rhythm & spacing ──────────────────────────────────────────── */
h1, h2, h3 { letter-spacing: -0.02em; }
.panel-body { padding: 18px 20px; }
.breadcrumb-item button:hover { text-decoration: underline; }

/* ── Command palette (⌘K) ──────────────────────────────────────────────────── */
.cmdk-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
  background: rgba(11, 18, 32, 0.5);
  backdrop-filter: blur(8px) saturate(1.08);
  animation: cmdkFade var(--mid, 200ms) var(--ease, ease);
}
.cmdk-panel {
  width: min(640px, 92vw);
  max-height: 66vh;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border: 1px solid rgba(16, 24, 40, 0.08);
  border-radius: 18px;
  box-shadow: 0 32px 80px rgba(16, 24, 40, 0.35);
  overflow: hidden;
  animation: cmdkPop var(--mid, 200ms) var(--ease, ease);
}
body.dark-mode .cmdk-panel { background: #0f1a2c; border-color: rgba(255, 255, 255, 0.08); color: #e6edf5; }
.cmdk-input-wrap { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.cmdk-input-icon {
  flex: 0 0 auto; font-size: 11px; font-weight: 800; letter-spacing: 0.4px;
  color: var(--porter-teal); background: rgba(0, 180, 166, 0.12);
  padding: 4px 8px; border-radius: 8px;
}
.cmdk-input { flex: 1 1 auto; border: 0; outline: none; background: transparent; font-size: 16px; color: inherit; }
.cmdk-input::placeholder { color: var(--muted); }
.cmdk-list { overflow-y: auto; padding: 8px; }
.cmdk-item {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 0; border-radius: 10px; background: transparent;
  text-align: left; color: inherit; cursor: pointer; font-size: 14px;
}
.cmdk-item.active { background: linear-gradient(90deg, rgba(0, 180, 166, 0.16), rgba(0, 180, 166, 0.08)); }
.cmdk-item-label { font-weight: 600; flex: 1 1 auto; }
.cmdk-item-section { font-size: 11px; font-weight: 700; letter-spacing: 0.4px; text-transform: uppercase; color: var(--muted); flex: 0 0 auto; }
.cmdk-item-recent {
  flex: 0 0 auto; font-size: 10px; font-weight: 800; letter-spacing: 0.5px; text-transform: uppercase;
  color: var(--porter-teal, #00b4a6); background: rgba(0, 180, 166, 0.12);
  border: 1px solid rgba(0, 180, 166, 0.28); border-radius: 999px; padding: 2px 8px; line-height: 1.4;
}

/* Bulk Outreach Center — multi-select recipient chips + channel toggle. */
.bulk-outreach-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bulk-channel-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.bulk-channel-toggle button {
  border: 0; background: transparent; padding: 5px 16px; font-weight: 700; font-size: 12.5px;
  color: var(--muted); cursor: pointer; transition: background 140ms var(--ease, ease), color 140ms var(--ease, ease);
}
.bulk-channel-toggle button.active { background: var(--porter-teal, #00b4a6); color: #fff; }
.bulk-recipient-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; min-height: 8px; }
.bulk-recipient-chips .chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--chip-bg, rgba(0,180,166,0.1)); border: 1px solid rgba(0,180,166,0.25);
  font-size: 12.5px; font-weight: 600; color: var(--text, #1f2937);
}
.bulk-recipient-chips .chip.chip-warn { background: rgba(230, 160, 30, 0.12); border-color: rgba(230, 160, 30, 0.4); }
.bulk-recipient-chips .chip-kind { opacity: 0.8; }
.bulk-recipient-chips .chip-x {
  border: 0; background: transparent; cursor: pointer; font-size: 15px; line-height: 1;
  color: var(--muted); padding: 0 2px; border-radius: 50%;
}
.bulk-recipient-chips .chip-x:hover { color: var(--danger, #c0392b); }

/* Parts order class badge — Stock Order (to manufacturer) vs Purchase Order (vendor/sublet). */
.parts-order-class-badge {
  display: inline-flex; flex-direction: column; line-height: 1.1; gap: 1px;
  padding: 3px 9px; border-radius: 8px; border: 1px solid transparent; font-weight: 700; white-space: nowrap;
}
.parts-order-class-badge .parts-order-class-label { font-size: 11.5px; letter-spacing: 0.02em; }
.parts-order-class-badge .parts-order-class-dest { font-size: 10px; font-weight: 600; opacity: 0.85; }
.parts-order-class-badge.stock { background: rgba(0, 180, 166, 0.12); border-color: rgba(0, 180, 166, 0.35); color: #0f766e; }
.parts-order-class-badge.purchase { background: rgba(100, 116, 139, 0.12); border-color: rgba(100, 116, 139, 0.32); color: #475569; }
.parts-open-po-legend { margin-left: 8px; font-weight: 500; }

/* Inline Estonian identifier (isikukood / registrikood) validation feedback. */
.ee-field-msg { display: block; margin-top: 4px; font-size: 11.5px; font-weight: 600; line-height: 1.3; }
.ee-field-msg-ok { color: #0f766e; }
.ee-field-msg-bad { color: #c0392b; }
input.ee-field-ok { border-color: rgba(0, 180, 166, 0.55) !important; }
input.ee-field-bad { border-color: rgba(192, 57, 43, 0.6) !important; }
.cmdk-empty { padding: 22px 14px; text-align: center; color: var(--muted); font-weight: 600; }
.cmdk-hint {
  display: flex; gap: 16px; justify-content: flex-end; padding: 10px 14px;
  border-top: 1px solid var(--line); color: var(--muted); font-size: 11.5px;
}
.cmdk-hint kbd {
  display: inline-block; min-width: 18px; text-align: center; padding: 1px 5px; margin-right: 2px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: #f7f9fc; color: var(--ink); font-size: 11px;
}
body.dark-mode .cmdk-hint kbd { background: rgba(255, 255, 255, 0.06); color: #e6edf5; }
body.cmdk-open { overflow: hidden; }
@keyframes cmdkFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes cmdkPop { from { opacity: 0; transform: translateY(-8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ── Route progress bar (top of viewport during navigation) ────────────────── */
#uxProgress {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  z-index: 2147483600;
  background: linear-gradient(90deg, var(--porter-teal), var(--porter-teal-2), var(--porter-gold-2));
  box-shadow: 0 0 10px rgba(0, 180, 166, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: width 240ms var(--ease), opacity 240ms var(--ease);
}
#uxProgress.active { opacity: 1; }

/* ── Button ripple (tactile feedback) — viewport-fixed, no button style deps ── */
.ux-ripple {
  position: fixed;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: rgba(0, 180, 166, 0.35);
  pointer-events: none;
  z-index: 2147483500;
  opacity: 0.9;
  animation: uxRipple 560ms var(--ease);
}
.ux-ripple.on-teal { background: rgba(255, 255, 255, 0.55); }
@keyframes uxRipple {
  to { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}

/* ── Skeleton loading placeholders (modern shimmer) ────────────────────────── */
.skeleton-panel { padding: 10px 6px; }
.skeleton-row {
  height: 14px;
  margin: 12px 0;
  border-radius: 8px;
  background: #e7edf5;
  position: relative;
  overflow: hidden;
}
.skeleton-row.w-40 { width: 40%; }
.skeleton-row.w-50 { width: 50%; }
.skeleton-row.w-60 { width: 60%; }
.skeleton-row.w-70 { width: 70%; }
.skeleton-row.w-80 { width: 80%; }
.skeleton-row.w-90 { width: 90%; }
.skeleton-row::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.65), transparent);
  animation: skelShimmer 1.3s infinite;
}
body.dark-mode .skeleton-row { background: rgba(255, 255, 255, 0.08); }
body.dark-mode .skeleton-row::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.12), transparent); }
@keyframes skelShimmer { 100% { transform: translateX(100%); } }

/* ── Dashboard real-data sparkline trend cards ─────────────────────────────── */
.dash-trends { display: flex; flex-wrap: wrap; gap: 12px; margin: 4px 0 10px; }
.dash-trend-card {
  flex: 1 1 200px;
  min-width: 180px;
  background: var(--panel, #fff);
  border: 1px solid var(--line, #e6ebf2);
  border-radius: var(--radius, 12px);
  box-shadow: var(--shadow-sm);
  padding: 12px 14px;
  transition: transform var(--mid, 200ms) var(--ease), box-shadow var(--mid, 200ms) var(--ease);
}
.dash-trend-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.dash-trend-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.dash-trend-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.dash-trend-total { font-size: 20px; font-weight: 800; color: var(--ink); }
.dash-trends .sparkline { display: block; width: 100%; height: 36px; margin: 6px 0 4px; }
.dash-trend-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dash-trend-delta { font-size: 12px; font-weight: 800; }
.dash-trend-delta.up { color: var(--green, #059669); }
.dash-trend-delta.down { color: var(--red, #DC2626); }
.dash-trend-delta.flat { color: var(--muted, #667085); }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .primary, .secondary, .danger, .icon-button, .card, .nav-button,
  .subtab, .filter-chip, .super-kpi-tile, .super-module-tile, .company-gate-stat,
  .dash-trend-card,
  .dashboard-compact-metrics > * { transition: none; }
  .primary:hover, .secondary:hover, .danger:hover, .card:hover,
  .super-kpi-tile:hover, .super-module-tile:hover, .company-gate-stat:hover,
  .dash-trend-card:hover,
  .dashboard-compact-metrics > *:hover { transform: none; }
  .cmdk-overlay, .cmdk-panel, .ux-ripple { animation: none; }
  .skeleton-row::after { animation: none; }
  #uxProgress { transition: opacity 240ms var(--ease); }
}

/* Always-visible build/version stamp in the sidebar footer — lets any user and
   support confirm which release the browser actually loaded (also proves the
   cache-buster reached the client). Intentionally quiet: small, muted, tabular. */
.sidebar-footer .app-build {
  margin-top: 8px;
  padding: 4px 6px 0;
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: var(--muted, #6b7280);
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  text-align: center;
  user-select: text;
  transition: opacity 160ms var(--ease, ease);
}
.sidebar-footer .app-build:hover { opacity: 1; }
