/* Verellen ERP — selectable themes.
   Loaded after base.css. "Verellen" (the original warm-clay identity) is the
   absence of a data-erp-theme attribute, so nothing here can change it. Each
   theme only re-points the tokens base.css already reads, plus the shared
   hooks below (display face, panel rule) so the chrome can differ in more
   than colour. Choice is stored per browser (static/js/erp-theme.js) — same
   mechanism and the same five names as the CRM's picker
   (static/css/crm-themes.css), ported into this shell's own --color-*
   token namespace rather than the CRM's --crm-* one. */

/* ---------- Shared hooks (no effect on the default theme) ---------- */
html[data-erp-theme] h1,
html[data-erp-theme] h2 {
  font-family: var(--font-display, var(--font-ui));
  letter-spacing: var(--display-track, -0.01em);
}
html[data-erp-theme] .sidebar { box-shadow: inset -1px 0 0 var(--color-nav-rule); }
html[data-erp-theme] .card,
html[data-erp-theme] .table-wrap { border-color: var(--color-panel-rule, var(--color-border)); }
html[data-erp-theme] .topbar { border-bottom-color: var(--color-panel-rule, var(--color-border)); }

/* ---------- Porcelain: cool white, generous radii, soft light ---------- */
html[data-erp-theme="porcelain"] {
  --color-bg: #f4f6f9;  --color-surface: #ffffff;  --color-surface-sunken: #eef2f7;
  --color-border: #dfe5ee;  --color-border-strong: #c8d1de;
  --color-text: #1b2430;  --color-text-muted: #56637a;  --color-text-faint: #8793a8;
  --color-nav-bg: #ffffff;  --color-nav-text: #1b2430;  --color-nav-text-strong: #0f1722;
  --color-nav-dim: #56637a;  --color-nav-faint: #8793a8;
  --color-nav-hover: rgba(27, 36, 48, 0.05);  --color-nav-hover-strong: rgba(27, 36, 48, 0.08);
  --color-nav-rule: rgba(27, 36, 48, 0.1);  --color-nav-rule-strong: rgba(27, 36, 48, 0.2);
  --color-nav-disabled: #aab3c2;  --color-nav-logo-filter: none;
  --color-panel-rule: transparent;  --color-focus-ring: rgba(15, 23, 34, 0.1);
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  --display-track: -0.015em;
  --radius-sm: 8px;  --radius-md: 12px;  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 34, 0.04), 0 4px 14px rgba(15, 23, 34, 0.05);
  --shadow-md: 0 10px 32px rgba(15, 23, 34, 0.12);
}
html[data-erp-theme="porcelain"] .topbar { background: transparent; }
html[data-erp-theme="porcelain"] thead th { background: transparent; }

/* ---------- Midnight: deep navy rail, cool grey paper ---------- */
html[data-erp-theme="midnight"] {
  --color-bg: #eef1f6;  --color-surface: #ffffff;  --color-surface-sunken: #e7ecf2;
  --color-border: #d7deea;  --color-border-strong: #bcc6d6;
  --color-text: #15233a;  --color-text-muted: #44546e;  --color-text-faint: #7484a0;
  --color-nav-bg: #0e1a2c;  --color-nav-text: #eef2f8;  --color-nav-text-strong: #ffffff;
  --color-nav-dim: rgba(238, 242, 248, 0.66);  --color-nav-faint: rgba(238, 242, 248, 0.46);
  --color-nav-hover: rgba(255, 255, 255, 0.07);  --color-nav-hover-strong: rgba(255, 255, 255, 0.1);
  --color-nav-rule: rgba(238, 242, 248, 0.14);  --color-nav-rule-strong: rgba(238, 242, 248, 0.3);
  --color-nav-disabled: rgba(238, 242, 248, 0.32);  --color-nav-logo-filter: invert(1) brightness(1.4);
  --color-focus-ring: rgba(46, 82, 140, 0.18);
  --font-display: "Avenir Next", Avenir, "Helvetica Neue", "Segoe UI", sans-serif;
  --display-track: -0.015em;
  --radius-sm: 5px;  --radius-md: 8px;  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(13, 27, 46, 0.06), 0 2px 8px rgba(13, 27, 46, 0.04);
  --shadow-md: 0 10px 34px rgba(13, 27, 46, 0.2);
}

/* ======================================================================
   Editions — two further themes, matching the CRM's set of five. These
   differ in structure too, not just colour: type voice, corner language,
   and (Nocturne) a dark content area, which the CRM's edition of the same
   name deliberately avoids only because its BI charts are drawn for a
   light ground — this shell has no such canvas, so it goes fully dark.
   ====================================================================== */

/* ---------- Nocturne: warm-lit dark, champagne accent ---------- */
html[data-erp-theme="nocturne"] {
  color-scheme: dark;
  --color-bg: #12141a;  --color-surface: #1a1d25;  --color-surface-sunken: #161920;
  --color-border: #2b2f3b;  --color-border-strong: #3a3f4d;
  --color-text: #f2ede3;  --color-text-muted: #cdc7ba;  --color-text-faint: #a49e92;
  --color-nav-bg: #0b0d12;  --color-nav-text: #efeae0;  --color-nav-text-strong: #ffffff;
  --color-nav-dim: rgba(239, 234, 224, 0.66);  --color-nav-faint: rgba(239, 234, 224, 0.48);
  --color-nav-hover: rgba(255, 255, 255, 0.06);  --color-nav-hover-strong: rgba(255, 255, 255, 0.1);
  --color-nav-rule: rgba(239, 234, 224, 0.12);  --color-nav-rule-strong: rgba(239, 234, 224, 0.3);
  --color-nav-disabled: rgba(239, 234, 224, 0.3);  --color-nav-logo-filter: invert(1) brightness(1.5);
  --color-accent: #d6b878;  --color-accent-hover: #c6a662;  --color-accent-soft: #2c2415;
  --color-focus-ring: rgba(214, 184, 120, 0.3);
  --color-success: #86d1a4;  --color-success-bg: #14291d;
  --color-warning: #e6b765;  --color-warning-bg: #302312;
  --color-danger: #f19a8c;  --color-danger-bg: #35181a;
  --font-display: "Avenir Next", "SF Pro Display", "Helvetica Neue", system-ui, sans-serif;
  --display-track: -0.01em;
  --radius-sm: 6px;  --radius-md: 10px;  --radius-lg: 16px;
  --shadow-sm: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 18px 50px rgba(0, 0, 0, 0.6);
}
html[data-erp-theme="nocturne"] h1 { font-size: 1.65rem; }

/* ---------- Lagoon: deep teal, floating rounded surfaces, pill buttons ---------- */
html[data-erp-theme="lagoon"] {
  --color-bg: #e8f0f0;  --color-surface: #ffffff;  --color-surface-sunken: #e1ebeb;
  --color-border: #d2e0e1;  --color-border-strong: #b8cccd;
  --color-text: #0b2f38;  --color-text-muted: #44636b;  --color-text-faint: #7f99a1;
  --color-nav-bg: #0f3b45;  --color-nav-text: #eaf6f6;  --color-nav-text-strong: #ffffff;
  --color-nav-dim: rgba(234, 246, 246, 0.7);  --color-nav-faint: rgba(234, 246, 246, 0.52);
  --color-nav-hover: rgba(255, 255, 255, 0.08);  --color-nav-hover-strong: rgba(255, 255, 255, 0.12);
  --color-nav-rule: rgba(234, 246, 246, 0.17);  --color-nav-rule-strong: rgba(234, 246, 246, 0.32);
  --color-nav-disabled: rgba(234, 246, 246, 0.34);  --color-nav-logo-filter: invert(1) brightness(1.3);
  --color-panel-rule: transparent;  --color-focus-ring: rgba(15, 110, 125, 0.22);
  --font-display: "SF Pro Rounded", "Avenir Next", "Nunito Sans", system-ui, sans-serif;
  --display-track: -0.02em;
  --radius-sm: 10px;  --radius-md: 14px;  --radius-lg: 22px;
  --shadow-sm: 0 1px 2px rgba(11, 47, 56, 0.05), 0 12px 32px rgba(11, 47, 56, 0.07);
  --shadow-md: 0 18px 48px rgba(11, 47, 56, 0.22);
}
html[data-erp-theme="lagoon"] .sidebar { background: linear-gradient(170deg, #14505c 0%, #0b2f38 100%); }
html[data-erp-theme="lagoon"] .topbar { background: transparent; }
html[data-erp-theme="lagoon"] .btn,
html[data-erp-theme="lagoon"] [class^="btn-"],
html[data-erp-theme="lagoon"] [class*=" btn-"],
html[data-erp-theme="lagoon"] button { border-radius: 999px; }
html[data-erp-theme="lagoon"] .theme-picker button,
html[data-erp-theme="lagoon"] .rail-toggle { border-radius: 10px; }

/* ---------- The picker (all themes, including the default) ---------- */
.theme-picker { margin-bottom: 0.5rem; }
.theme-picker > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center;
  gap: var(--rail-gap, 0.6rem); width: 100%;
  padding: 0.5rem 0.6rem;
  font-size: calc(0.9rem * var(--rail-label, 1));
  font-weight: 500;
  color: var(--color-nav-dim); border-radius: var(--radius-sm);
  transition: background 0.12s ease, color 0.12s ease;
}
.theme-picker > summary::-webkit-details-marker { display: none; }
.theme-picker > summary:hover,
.theme-picker[open] > summary { background: var(--color-nav-hover); color: var(--color-nav-text-strong); }
.theme-picker > summary svg { width: var(--rail-icon, 16px); height: var(--rail-icon, 16px); flex-shrink: 0; opacity: 0.85; }
.theme-picker > summary:focus-visible,
.theme-picker button:focus-visible { outline: 2px solid var(--color-nav-text-strong); outline-offset: 2px; }
.theme-list { display: flex; flex-direction: column; gap: 2px; padding: 0.3rem 0 0.4rem; }
.theme-picker button {
  width: 100%; justify-content: flex-start; gap: 0.65rem; display: flex; align-items: center;
  background: transparent; border: 1px solid transparent; color: var(--color-nav-dim);
  padding: 0.38rem 0.6rem; font-size: 0.82rem; font-weight: 400; text-align: left;
  border-radius: var(--radius-sm); cursor: pointer;
}
.theme-picker button:hover { background: var(--color-nav-hover); color: var(--color-nav-text-strong); }
.theme-picker button[aria-pressed="true"] { background: var(--color-nav-hover-strong); color: var(--color-nav-text-strong); font-weight: 600; }
.theme-picker .sw {
  width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--sw-rail) 0 50%, var(--sw-paper) 50% 100%);
  border: 1px solid var(--color-nav-rule);
}
.theme-picker .nm { display: var(--rail-chrome, inline); }
/* Collapsed rail: swatches only, stacked. */
html.rail-collapsed .theme-picker button { justify-content: center; padding: 0.3rem 0; }
html.rail-collapsed .theme-picker > summary { justify-content: center; }

/* Home embeds the CRM components (crm.css) inside the ERP shell. crm.css
   carries one fixed light palette, so under any chosen theme the page kept
   a beige slab and light panels. Re-point its tokens at the theme's own. */
html[data-erp-theme] .crm-themed {
  --crm-ink: var(--color-text);
  --crm-body: var(--color-text);
  --crm-muted: var(--color-text-muted);
  --crm-soft: var(--color-text-faint);
  --crm-surface: var(--color-surface);
  --crm-bg: transparent;
  --crm-sunken: var(--color-surface-sunken);
  --crm-rule: var(--color-border);
  --crm-rule-soft: var(--color-border);
  --crm-pos: var(--color-success);
  --crm-warn: var(--color-warning);
  --crm-neg: var(--color-danger);
  --crm-info: #2b5878;
  --crm-neutral: var(--color-text-muted);
  --crm-pos-bg: color-mix(in srgb, var(--crm-pos) 14%, var(--color-surface));
  --crm-warn-bg: color-mix(in srgb, var(--crm-warn) 14%, var(--color-surface));
  --crm-neg-bg: color-mix(in srgb, var(--crm-neg) 14%, var(--color-surface));
  --crm-info-bg: color-mix(in srgb, var(--crm-info) 12%, var(--color-surface));
  --crm-neutral-bg: var(--color-surface-sunken);
  --crm-pos-rule: color-mix(in srgb, var(--crm-pos) 35%, var(--color-surface));
  --crm-warn-rule: color-mix(in srgb, var(--crm-warn) 35%, var(--color-surface));
  --crm-neg-rule: color-mix(in srgb, var(--crm-neg) 35%, var(--color-surface));
  --crm-info-rule: color-mix(in srgb, var(--crm-info) 30%, var(--color-surface));
  --crm-neutral-rule: var(--color-border);
  --crm-shadow: var(--shadow-sm);
  --crm-radius: var(--radius-sm);
  --crm-radius-lg: var(--radius-md);
  background: transparent;
  color: var(--color-text);
}
html[data-erp-theme="nocturne"] .crm-themed { --crm-info: #8fb8e0; }
html[data-erp-theme] .crm-themed button,
html[data-erp-theme] .crm-themed .btn { background: var(--color-accent); color: var(--color-surface); border-color: var(--color-accent); }
html[data-erp-theme="nocturne"] .crm-themed button,
html[data-erp-theme="nocturne"] .crm-themed .btn { color: #1a1408; }
html[data-erp-theme] .crm-themed input,
html[data-erp-theme] .crm-themed select { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }

/* Headings read --color-ink (near-black), which only suits a light page:
   on Nocturne the page title was dark on dark. */
html[data-erp-theme="nocturne"] { --color-ink: var(--color-text); --color-ink-light: var(--color-text-muted); }
/* Porcelain's rail is white, so the default active pill (ink fill, light
   text token that is dark here) rendered as a black bar with black text. */
html[data-erp-theme="porcelain"] .nav-link.active { background: var(--color-surface-sunken); color: var(--color-nav-text-strong); }
