/*
  Kay Bee Motors ERP — shared design tokens.
  The login page establishes this visual language; every future module
  (masters, sales, purchase, stock, accounts, reports...) reuses these same
  variables instead of introducing new colors/spacing/radii per screen.
*/

:root {
  /* Brand — Day/Night theme system (2026-09-13 revert): #12A2A8 teal is
     back as the ERP's Day Mode primary/identity color (explicit
     request — the 2026-09-12 blue rebrand below was reverted for Day
     Mode only; Night Mode's own html.dark block keeps its separately-
     declared blue #2F80FF/gold accents completely unchanged, per the
     same request's own "Dark Mode must not break" requirement). Every
     module's own CSS file reads these same variable names (never a
     hardcoded hex), so this single block (plus its .dark counterpart
     below) is what makes "one click, whole ERP" possible without
     touching masters.css/sales.css/stock.css/dashboard.css
     individually. --blue-accent/--accent-color are kept as distinct
     secondary tokens (unrelated to the day/night swap). */
  --primary-color: #12a2a8;
  --primary-dark: #0e8388;
  --primary-light: #d6f0f0;
  --secondary-color: #6c757d;
  --accent-color: #e0503f;
  --blue-accent: #1a4fd6;
  --blue-accent-dark: #123a9e;

  /* Surfaces — a very light #12A2A8-derived teal wash for the page
     itself (explicit "plain white is too flat" request), with cards/
     forms staying pure white so PAGE -> FORM -> SECTION -> INPUT ->
     TABLE reads as a clear visual hierarchy instead of one flat white
     field (see this file's own input/label tokens below for how the
     rest of that hierarchy is expressed). */
  --background-color: #e8f6f6;
  /* A hint of the same teal tint, not pure #ffffff — explicit follow-up
     ("Credit Note still looks flat white, use the same light
     background as Debit Note"): a plain white card against the teal
     page read as "just white" at a glance, especially on a full-bleed
     workspace panel (Credit Note/Debit Note/Stock Receipt's own entry
     forms) where the teal page only shows as a thin margin around it.
     Barely different from white in isolation, but keeps every card/
     form/table visibly part of the same teal-identity surface instead
     of reverting to flat white the moment the page background isn't
     directly visible next to it. */
  --card-background: #f4fbfb;
  --footer-background: #0b1830;

  /* Text — near-black, explicit "no light grey/white labels in Day
     Mode" requirement; #111827 is the exact shade requested. */
  --text-color: #111827;
  --muted-color: #6b7688;
  --text-inverse: #ffffff;

  /* Borders — thin but clearly dark (#1F2937, explicit request) rather
     than the previous light-grey hairlines, so field/section
     boundaries read clearly against the new teal-tinted page. */
  --border-color: #1f2937;
  --border-color-strong: #111827;

  /* State — semantic only: green=success/paid, red=error/danger/return,
     orange=pending/warning, blue=informational. Never the sole signal
     for status — pair with an icon or label, not color alone. */
  --success-color: #198754;
  --danger-color: #dc3545;
  --danger-dark: #a52834;
  --warning-color: #ffc107;
  --info-color: #0dcaf0;

  /* Sidebar — deliberately fixed dark navy in BOTH Day and Night mode
     (explicit correction, with a reference screenshot): the sidebar is
     not part of the light/dark swap the way the main content area is,
     it's a permanent dark rail regardless of theme, matching the
     reference design. Same values repeated in html.dark below (not
     just left to inherit) so this stays correct even if either block
     is edited independently later. --sidebar-active-bg still tracks
     --primary-color on purpose — the highlighted nav item's own accent
     is the one sidebar color that SHOULD follow the theme (blue in Day,
     red in Night), per that same reference. */
  --sidebar-bg: #0f1729;
  --sidebar-text: #e2e8f0;
  --sidebar-active-bg: var(--primary-color);
  --sidebar-active-text: #ffffff;

  /* App shell layout — the ERP is targeted/tested primarily at 1360x768;
     these are the single source of truth for shell dimensions so no
     template/CSS file hardcodes its own copy of the sidebar width. */
  --sidebar-width: 210px;
  --header-height: 60px;
  --footer-height: 40px;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(11, 24, 48, 0.08);
  --shadow-md: 0 10px 30px rgba(11, 24, 48, 0.16);
  --shadow-lg: 0 24px 60px rgba(11, 24, 48, 0.28);

  --font-base: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

  /* Global UI visibility/contrast standard (explicit standing instruction,
     applies to every module, current and future — see the memory file
     feedback_kbm_ui_contrast_standard.md). This ERP is read by accountants
     for hours at a stretch; readability beats decoration everywhere. */
  --label-color: #111827;
  --input-text-color: #111827;
  --input-border-color: #1f2937;
  /* Input surface — explicit request: inputs need to read as clearly
     distinct boxes against both the new teal-tinted page AND the white
     card they sit on, not just "white on white". */
  --input-background: #f7ffff;
  /* Focus effect — Day Mode now uses a #12A2A8 teal border + soft glow
     (explicit request, replacing the earlier gold-everywhere focus for
     Day Mode specifically); html.dark below keeps its own separately-
     declared gold focus completely unchanged ("Dark Mode must not
     break"). --gold-accent/--gold-glow-rgb stay defined here too since
     other Day Mode UI (e.g. the Premium theme-variant icon) still
     references them directly. */
  --gold-accent: #f0b429;
  --gold-glow-rgb: 240, 180, 41;
  --input-border-focus: var(--primary-color);
  --input-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  --input-shadow-focus: 0 0 0 2px rgba(18, 162, 168, 0.18);
  /* Focus PULSE animation's own color — teal in Day Mode, gold in Night
     (see html.dark's own redefinition below); kept separate from
     --gold-glow-rgb (which stays a fixed gold value in both themes —
     it's what the Stock Receipt/Credit Note gold CONFIRM buttons etc.
     deliberately use regardless of theme, an unrelated accent, not the
     focus affordance). */
  --focus-glow-rgb: 18, 162, 168;

  /* Readonly/auto-generated field surface — one token, reused by both
     the sitewide input[readonly] rule below and any module CSS (e.g.
     masters.css's Code boxes) that needs the exact same "muted, not
     editable" shade instead of re-hardcoding its own hex (which is what
     let a Night Mode white-on-light-grey bug slip in previously). */
  --readonly-bg: #f4f6f8;
  /* A visibly stronger/darker readonly shade for fields that sit on
     their own already-muted panel background (e.g. Sales Invoice's
     ADDRESS/CITY/CODE boxes) — --readonly-bg above is too close to
     --background-color to read as "distinct" there. */
  --readonly-bg-strong: #e7e7e7;

  /* Pastel status/alert surfaces (success/warning/danger/info tinted
     cards, table headers, banners) — used across masters/sales/eway_bill/
     stock so every module's "light green/red/orange card" reads from the
     same pair instead of each file hardcoding its own hex pastel, which
     is invisible-text-prone the moment Night Mode makes the paired text
     go light (see html.dark block below for the dark equivalents). */
  --status-success-bg: #e8f5ec;
  --status-success-border: #bfe3cb;
  --status-warning-bg: #fdf1de;
  --status-warning-border: #f3d9a3;
  --status-danger-bg: #fdecea;
  --status-danger-border: #f6c4bd;
  --status-info-bg: #eaf6fb;
  --status-info-border: #bfe3ee;

  /* Legacy-VFP "active entry row" yellow highlight (Sales Invoice item/
     service entry blocks). Kept as its own token pair — not folded into
     --warning-color — because this is a fixed visual callback to the old
     VFP screen's yellow input row, not a semantic warning state. */
  --entry-highlight-bg: #fffbdc;
  --entry-highlight-border: #ecdf8a;
  --entry-highlight-text: #3a3220;

  /* ---------------------------------------------------- Z-index system
     ONE global hierarchy — every stacking layer in the app pulls from
     here, nothing hardcodes its own z-index number. If something needs
     to stack above/below an existing layer, change its home here, not
     at the call site. */
  --z-base: 1;
  --z-header: 100;
  --z-sidebar: 200;
  --z-submenu-backdrop: 490;
  --z-submenu: 500;
  --z-fullscreen-workspace: 800;
  --z-dropdown: 1000;
  --z-tooltip: 1100;
  --z-popover: 1200;
  --z-datepicker: 1300;
  --z-autocomplete: 1400;
  --z-modal-backdrop: 1990;
  --z-modal: 2000;
  --z-toast: 3000;
  --z-confirmation: 4000;
  --z-loading: 5000;
}

/* Night Mode — same variable names as :root above, redefined. The
   `dark` class lives on <html> (see static/js/theme.js's toggleTheme()/
   initTheme() and base.html), toggled by the sun/moon control in the
   sidebar and matching Tailwind's own darkMode:'class' strategy (see
   the tailwind.config in base.html) — one class flip drives both this
   CSS-variable cascade (which every existing module's CSS already
   consumes, so this file is the ONLY place that needed to change for
   the whole ERP to re-theme) and any Tailwind utility classes at once.
   SUPERSEDES the earlier red-primary Night Mode (#EF4444) from a prior
   pass — explicit follow-up request: "remove the red theme completely,
   Night Mode = dark navy + blue + gold, red only for genuine danger/
   error semantics" (--danger-color/--danger-dark below stay red on
   purpose — that distinction is exactly what this rebrand asked to
   preserve). Every module's own CSS still only ever reads
   var(--primary-color) etc., never a hardcoded hex, so this single
   block is still the one place a full re-theme requires. */
html.dark {
  --primary-color: #2f80ff;
  --primary-dark: #1c66e0;
  --primary-light: #142c4f;
  --secondary-color: #94a3b8;

  /* Visibly blue-navy, not near-black — explicit follow-up ("halka blue
     effect background, not black"): #0b1220's blue channel is technically
     highest but reads as almost-black at a glance, especially across a
     full-page wash. Lightened/more saturated toward blue while staying a
     comfortable dark background --card-background (#1e293b, unchanged)
     still reads clearly lighter than. */
  --background-color: #0f1c33;
  --card-background: #1e293b;
  --footer-background: #0f1c33;

  --text-color: #ffffff;
  --muted-color: #94a3b8;
  --text-inverse: #0b1220;

  --border-color: #334155;
  --border-color-strong: #475569;

  --success-color: #22c55e;
  --danger-color: #f87171;
  --danger-dark: #dc2626;
  --warning-color: #f59e0b;
  --info-color: #38bdf8;

  --readonly-bg: #334155;
  /* Lighter than --card-background (#1e293b), same "distinct, still
     readable" role --readonly-bg-strong plays in Day Mode above. */
  --readonly-bg-strong: #3a4a5e;

  --status-success-bg: #163a24;
  --status-success-border: #245c3a;
  --status-warning-bg: #3f2f10;
  --status-warning-border: #6b4f1a;
  --status-danger-bg: #3f1d1d;
  --status-danger-border: #6b2c2c;
  --status-info-bg: #0f2f3d;
  --status-info-border: #1c4f61;

  /* Same fixed dark navy as :root above (not a lighter Night variant —
     see that block's own comment: the sidebar doesn't change with the
     toggle in either direction). --sidebar-active-text stays white too,
     readable against either theme's --primary-color highlight. */
  --sidebar-bg: #0f1729;
  --sidebar-text: #e2e8f0;
  --sidebar-active-text: #ffffff;

  --label-color: #e2e8f0;
  --input-text-color: #e2e8f0;
  --input-border-color: #475569;
  /* Same --card-background — Night Mode inputs were never asked to
     look different from its existing panels, unlike Day Mode's new
     dedicated --input-background. */
  --input-background: var(--card-background);
  /* Same gold focus token as :root — deliberately NOT re-pointed at this
     block's own (now blue) --primary-color, so the focus affordance
     stays gold regardless of theme, matching the explicit "golden glow"
     request for Night Mode (Day Mode's own focus is teal now instead —
     see :root's own --input-border-focus/--focus-glow-rgb). */
  --gold-accent: #f0b429;
  --gold-glow-rgb: 240, 180, 41;
  --focus-glow-rgb: 240, 180, 41;
  --input-border-focus: var(--gold-accent);
  --input-shadow-focus: 0 0 0 2px rgba(var(--gold-glow-rgb), 0.45);

  /* Same legacy-yellow highlight row, darkened so it stays readable
     against light label/input text instead of the Day Mode pale-yellow
     (which was invisible against white/light text — the exact
     white-text-on-white/light-bg bug class this file exists to close). */
  --entry-highlight-bg: #3a3319;
  --entry-highlight-border: #6b5f2e;
  --entry-highlight-text: #f3ecd0;
}

/* Subtle blue ambient background — explicit follow-up: a flat solid
   --background-color (#0f1c33) still read as "black" across large empty
   areas even after lightening it once already; a soft radial glow plus
   a gentle linear gradient gives the same premium-dashboard depth the
   reference screenshot has, without a page-wide neon wash (~10-15%
   glow opacity, per the explicit "subtle, not neon" limit). Card/panel
   surfaces (--card-background) stay flat/opaque as before — this only
   affects the page's own empty background, visible around/behind them.
   background-attachment:fixed keeps the gradient anchored to the
   viewport rather than repeating oddly as .app-main scrolls. */
html.dark body {
  color-scheme: dark;
  background:
    radial-gradient(circle at 28% 12%, rgba(47, 128, 255, 0.14), transparent 42%),
    radial-gradient(circle at 85% 85%, rgba(47, 128, 255, 0.08), transparent 40%),
    linear-gradient(160deg, #0c1a30 0%, #0f1c33 45%, #081526 100%);
  background-attachment: fixed;
}

/* PREMIUM — a second Night Mode accent variant (explicit request: "add
   this [gold-bordered] theme too, name it Premium" — user picks BLUE or
   PREMIUM from the sidebar's own second toggle, see theme-variant-toggle
   in base.html/theme.js, only ever layered on top of .dark, never
   instead of it). Same dark-navy background/card/text as the BLUE
   variant above — only the accent (--primary-color, which every module's
   CSS already reads instead of a hardcoded hex, same leverage the
   original re-theme used) swaps from blue to a deep gold. Not the same
   bright lemon-gold as --gold-accent (kept unchanged, still used for the
   focus glow both variants share) — --gold-accent is only ever a border/
   glow color, never a background text sits on, so it can stay vivid;
   --primary-color backs real button/header surfaces that ALSO carry a
   sitewide (Day-Mode-safe) hardcoded white text color in a number of
   places (buttons, section header bars) that weren't part of this pass
   — a bright lemon-gold there would fail contrast against that white
   text. Dark goldenrod keeps that same white text readable while still
   reading clearly as gold, not blue. */
html.dark.premium {
  --primary-color: #b8860b;
  --primary-dark: #96690a;
  --primary-light: #3a2f10;
  /* Background/card/text intentionally NOT overridden here — the
     reference screenshot's Premium theme still sits on the same dark
     NAVY (not brown/black), only the accent color changes; inherits
     html.dark body's own navy+blue-glow gradient above unchanged. */
}

* {
  box-sizing: border-box;
}

/* Smooth day/night transition (explicit 300ms request) — scoped to the
   properties that actually change between themes, not `all` (animating
   `all` is what makes unrelated layout changes elsewhere on the page
   visibly janky/slow, not just color changes). */
body,
.app-sidebar,
.app-footer,
input,
select,
textarea,
button,
.btn,
[class*="card"],
[class*="panel"],
[class*="table"] {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-base);
  color: var(--text-color);
  background: var(--background-color);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary-color);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
}

/* Global label/input/select/textarea visibility baseline — every PLAIN
   element gets this by default, everywhere in the ERP, even on pages
   that never touch the .form-* classes below (most per-module CSS files
   style their own rows with bare elements, not these shared classes).
   Element-level selectors have low specificity on purpose: a page's own
   more-specific class (.pty-input, .ritm-row input, a dense grid cell,
   ...) still wins for any property it explicitly sets — this is a safe
   fallback for anything left unstyled, not a forced override. */
label {
  font-weight: 600;
  color: var(--label-color);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="search"],
input[type="date"],
input[type="datetime-local"],
input:not([type]),
textarea,
select {
  font-family: inherit;
  font-weight: 600;
  color: var(--input-text-color);
  /* var(--input-background), not a hardcoded #ffffff — this is the
     site-wide baseline every plain input/select/textarea in the ERP
     falls back to, so it must respond to Night Mode too, not just the
     handful of module-specific classes that already used the variable. */
  background: var(--input-background, var(--card-background));
  border: 1px solid var(--input-border-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--input-shadow);
}

/* Golden focus pulse — sitewide, every plain input/select/textarea gets
   this for free (low-specificity element selectors, same reasoning as
   the base input rule above: a page's own more-specific class still
   wins for anything it explicitly sets). Soft -> bright -> soft, not a
   flash/blink — box-shadow/border only, no dimension change, so nothing
   shifts layout. Respects prefers-reduced-motion (static glow instead of
   an animated one) per explicit accessibility note in the request. */
@keyframes kb-gold-focus-pulse {
  0%, 100% { box-shadow: 0 0 0 2px rgba(var(--focus-glow-rgb), 0.35), 0 0 6px 1px rgba(var(--focus-glow-rgb), 0.2); }
  50% { box-shadow: 0 0 0 2px rgba(var(--focus-glow-rgb), 0.65), 0 0 12px 3px rgba(var(--focus-glow-rgb), 0.4); }
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="tel"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input:not([type]):focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: var(--input-shadow-focus);
  animation: kb-gold-focus-pulse 1.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  input:focus, textarea:focus, select:focus {
    animation: none;
  }
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-color);
  font-weight: 400;
}

/* <option> needs its OWN explicit background — the native dropdown
   popup is an OS-drawn surface that ignores the <select>'s background,
   so leaving option background transparent means Chrome fills the
   popup with its own default (white) behind our theme's light option
   text in Night Mode: near-invisible. Same rule works for .form-select
   below since it's the same element. */
option {
  background-color: var(--card-background);
  color: var(--input-text-color);
}

/* Read-only/disabled must stay readable — faded is not the same as
   read-only (explicit rule: "READ-ONLY DOES NOT MEAN FADED"). A slightly
   different background is enough to signal non-editable. */
input:disabled,
input[readonly],
textarea:disabled,
textarea[readonly],
select:disabled {
  color: var(--input-text-color);
  background: var(--readonly-bg);
  -webkit-text-fill-color: var(--input-text-color);
  opacity: 1;
}

button {
  font-family: inherit;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 13px 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, box-shadow 0.15s ease, transform 0.05s ease;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.75;
}

.btn-primary {
  background: var(--primary-color);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-block {
  display: flex;
  width: 100%;
}

/* Form controls */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--label-color);
  margin-bottom: var(--space-2);
}

.form-input,
.form-select {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--input-text-color);
  background: var(--card-background);
  border: 1px solid var(--input-border-color);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  box-shadow: var(--input-shadow);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input::placeholder {
  color: var(--muted-color);
  font-weight: 400;
}

.form-input:focus,
.form-select:focus {
  outline: none;
  border-color: var(--input-border-focus);
  box-shadow: var(--input-shadow-focus);
  animation: kb-gold-focus-pulse 1.8s ease-in-out infinite;
}

.form-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%236B7688' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  padding-right: 40px;
}

.form-checkbox {
  width: 16px;
  height: 16px;
  accent-color: var(--primary-color);
  cursor: pointer;
}

/* Inputs with a leading icon — shared by the login page, the dashboard
   filter bar, and anywhere else a form field needs one. */
.input-icon-wrap {
  position: relative;
}

.input-icon-wrap .field-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  color: var(--muted-color);
  pointer-events: none;
}

.input-icon-wrap .form-input,
.input-icon-wrap .form-select {
  padding-left: 44px;
}

.field-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

.field-error {
  margin: var(--space-2) 0 0;
  font-size: 13px;
  color: var(--danger-color);
}

/* Alerts / messages */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}

.alert-error {
  background: var(--status-danger-bg);
  border-color: var(--status-danger-border);
  color: var(--danger-color);
}

.alert-success {
  background: var(--status-success-bg);
  border-color: var(--status-success-border);
  color: var(--success-color);
}

.placeholder-card {
  background: var(--card-background);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.placeholder-card h1 {
  margin: 0 0 var(--space-3);
  font-size: 24px;
  color: var(--text-color);
}

/* PREMIUM/BLUE Night Mode variant toggle (sidebar, right under DAY/
   NIGHT MODE) — no dedicated .theme-toggle rule existed before this
   (the DAY/NIGHT button relies entirely on the base .nav-item styling),
   this one only adds what's specific to it: a gold star + an active-
   state indicator so it's clear which variant is currently selected. */
.theme-variant-icon {
  color: var(--gold-accent, #f0b429);
  font-size: 13px;
  line-height: 1;
}

#theme-variant-toggle.is-active .theme-variant-label {
  color: var(--gold-accent, #f0b429);
  font-weight: 800;
}
