/* Suhavi themes 1.0 — Classic (each app's own look), Glass, Material; Light / Dark / Auto; area colours on the page.
   Same file in every app. Load AFTER brand.css and area.css. theme.js sets the html[data-sx-*] attributes and shows the picker.
   Works through the colour variables the apps already use (family A: --bg --card --ink --muted --line --soft --brand; family B (CRM): --panel --panel2 --text --primary --nav ...).
   The black + gold header, logo and 5-item menu are never changed by a theme. */

/* ---------- 1. area colour on the page (all themes, switch: html[data-sx-colors="off"]) ---------- */
html:not([data-sx-colors="off"]) body[data-sx-area] {
  --brand: var(--sx-area); --brand-ink: #fff; --brand-soft: var(--sx-area-soft); --brand2: var(--sx-area);
  --primary: var(--sx-area); --primary-ink: #fff; --primary-soft: var(--sx-area-soft);
}
html:not([data-sx-colors="off"])[data-sx-scheme="dark"] body[data-sx-area] {
  --brand: color-mix(in srgb, var(--sx-area) 62%, #fff); --brand-ink: #0b1120; --brand2: var(--brand);
  --primary: var(--brand); --primary-ink: #0b1120;
  --brand-soft: color-mix(in srgb, var(--sx-area) 26%, transparent); --primary-soft: var(--brand-soft);
}
/* a thin area bar on every page title, area-coloured top edge on KPI tiles without their own colour */
html:not([data-sx-colors="off"]) body[data-sx-area] main h1 { border-left: 4px solid var(--sx-area); padding-left: 10px; }
html:not([data-sx-colors="off"]) body[data-sx-area] .kpi:not(.red):not(.amber):not(.blue):not(.green):not(.gray):not(.violet) { border-top-color: var(--sx-area); }
html:not([data-sx-colors="off"]) body[data-sx-area] .tabs .on, html:not([data-sx-colors="off"]) body[data-sx-area] .tab.on { border-color: var(--sx-area); }

/* ---------- 2. palettes (only when a theme or a forced mode is chosen: html[data-sx-pal="1"]) ---------- */
html[data-sx-pal="1"][data-sx-theme="classic"][data-sx-scheme="light"] {
  --bg: #f6f7f9; --card: #fff; --panel: #fff; --panel2: #f9fafb; --ink: #0f172a; --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --line: #e5e7eb; --line2: #eef0f3; --soft: #f1f5f9; --nav: #1e1b4b; --nav-ink: #e0e7ff; color-scheme: light;
}
html[data-sx-pal="1"][data-sx-theme="classic"][data-sx-scheme="dark"] {
  --bg: #0b1120; --card: #111827; --panel: #1b1e26; --panel2: #20242d; --ink: #e5e7eb; --text: #e5e7eb; --muted: #94a3b8; --faint: #6f7786;
  --line: #2d323d; --line2: #262a33; --soft: #172033; --nav: #0d0f1a; --nav-ink: #c7d2fe; color-scheme: dark;
}
/* Glass: see-through surfaces over a soft colour mesh */
html[data-sx-theme="glass"][data-sx-scheme="light"] {
  --bg: transparent; --card: rgba(255, 255, 255, .58); --panel: rgba(255, 255, 255, .58); --panel2: rgba(255, 255, 255, .38);
  --ink: #0f172a; --text: #0f172a; --muted: #475569; --faint: #64748b; --line: rgba(15, 23, 42, .10); --line2: rgba(15, 23, 42, .07);
  --soft: rgba(255, 255, 255, .45); --shadow: 0 8px 28px rgba(31, 38, 135, .13); --shadow-lg: 0 18px 50px rgba(31, 38, 135, .22); --r: 16px;
  --sx-glass-edge: rgba(255, 255, 255, .7); color-scheme: light;
}
html[data-sx-theme="glass"][data-sx-scheme="dark"] {
  --bg: transparent; --card: rgba(24, 31, 48, .55); --panel: rgba(24, 31, 48, .55); --panel2: rgba(24, 31, 48, .38);
  --ink: #e5e7eb; --text: #e5e7eb; --muted: #a5b0c2; --faint: #7d8799; --line: rgba(255, 255, 255, .13); --line2: rgba(255, 255, 255, .08);
  --soft: rgba(255, 255, 255, .07); --shadow: 0 8px 28px rgba(0, 0, 0, .35); --shadow-lg: 0 18px 50px rgba(0, 0, 0, .5); --r: 16px;
  --sx-glass-edge: rgba(255, 255, 255, .16); color-scheme: dark;
}
/* Material: tonal surfaces tinted by the area colour, soft elevation, round shapes */
html[data-sx-theme="material"][data-sx-scheme="light"] body {
  --bg: color-mix(in srgb, var(--sx-area) 5%, #fffbff); --card: color-mix(in srgb, var(--sx-area) 2%, #fff); --panel: var(--card);
  --panel2: color-mix(in srgb, var(--sx-area) 7%, #fff); --soft: color-mix(in srgb, var(--sx-area) 9%, #fff);
  --ink: #1d1b20; --text: #1d1b20; --muted: #49454f; --faint: #79747e;
  --line: color-mix(in srgb, var(--sx-area) 14%, #d9d4dc); --line2: color-mix(in srgb, var(--sx-area) 9%, #e7e2ea);
  --shadow: 0 1px 2px rgba(0, 0, 0, .12), 0 2px 6px 2px rgba(0, 0, 0, .07); --shadow-lg: 0 4px 8px 3px rgba(0, 0, 0, .1), 0 1px 3px rgba(0, 0, 0, .2); --r: 16px;
  color-scheme: light;
}
html[data-sx-theme="material"][data-sx-scheme="dark"] body {
  --bg: color-mix(in srgb, var(--sx-area) 6%, #141218); --card: color-mix(in srgb, var(--sx-area) 8%, #1d1b20); --panel: var(--card);
  --panel2: color-mix(in srgb, var(--sx-area) 12%, #211f26); --soft: color-mix(in srgb, var(--sx-area) 14%, #26232b);
  --ink: #e6e0e9; --text: #e6e0e9; --muted: #cac4d0; --faint: #938f99;
  --line: color-mix(in srgb, var(--sx-area) 22%, #36343b); --line2: color-mix(in srgb, var(--sx-area) 14%, #2b292f);
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 2px 8px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 4px 12px 4px rgba(0, 0, 0, .45); --r: 16px;
  color-scheme: dark;
}
/* Material palettes need the area colour, which lives on <body>; the page background follows the body */
html[data-sx-theme="material"] { background: transparent; }
html[data-sx-theme="material"] body { background: var(--bg); color: var(--ink); font-family: Roboto, system-ui, -apple-system, "Segoe UI", sans-serif; }

/* ---------- 3. Glass shapes ---------- */
html[data-sx-theme="glass"] body {
  background-attachment: fixed; background-repeat: no-repeat; color: var(--ink);
  background-image:
    radial-gradient(900px 620px at 8% -5%, color-mix(in srgb, var(--sx-area) 42%, transparent), transparent 62%),
    radial-gradient(820px 620px at 100% 8%, rgba(56, 189, 248, .32), transparent 60%),
    radial-gradient(760px 700px at 55% 105%, rgba(244, 114, 182, .26), transparent 60%);
  background-color: #e7ebf7;
}
html[data-sx-theme="glass"][data-sx-scheme="dark"] body { background-color: #0a0f1d; }
html[data-sx-theme="glass"] .card, html[data-sx-theme="glass"] .kpi, html[data-sx-theme="glass"] .kcard, html[data-sx-theme="glass"] .tbl-wrap,
html[data-sx-theme="glass"] .col, html[data-sx-theme="glass"] .modal-card, html[data-sx-theme="glass"] .modal .card, html[data-sx-theme="glass"] .pop,
html[data-sx-theme="glass"] .menu, html[data-sx-theme="glass"] .toast, html[data-sx-theme="glass"] .authcard, html[data-sx-theme="glass"] .drop,
html[data-sx-theme="glass"] .panel, html[data-sx-theme="glass"] .login {
  -webkit-backdrop-filter: blur(18px) saturate(170%); backdrop-filter: blur(18px) saturate(170%);
  border: 1px solid var(--sx-glass-edge) !important; border-radius: 16px; box-shadow: var(--shadow);
}
html[data-sx-theme="glass"] .kpi, html[data-sx-theme="glass"] .kcard, html[data-sx-theme="glass"] .card { transition: transform .15s, box-shadow .15s; }
html[data-sx-theme="glass"] .kpi:hover, html[data-sx-theme="glass"] .kcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
html[data-sx-theme="glass"] .btn:not(.primary) { background: rgba(255, 255, 255, .35); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); border-color: var(--sx-glass-edge); }
html[data-sx-theme="glass"][data-sx-scheme="dark"] .btn:not(.primary) { background: rgba(255, 255, 255, .08); }
html[data-sx-theme="glass"] .btn { border-radius: 10px; }
html[data-sx-theme="glass"] input:not([type=checkbox]):not([type=radio]), html[data-sx-theme="glass"] select, html[data-sx-theme="glass"] textarea {
  background: rgba(255, 255, 255, .45); border: 1px solid var(--sx-glass-edge); border-radius: 10px; color: var(--ink);
}
html[data-sx-theme="glass"][data-sx-scheme="dark"] input:not([type=checkbox]):not([type=radio]), html[data-sx-theme="glass"][data-sx-scheme="dark"] select, html[data-sx-theme="glass"][data-sx-scheme="dark"] textarea { background: rgba(255, 255, 255, .07); }
html[data-sx-theme="glass"] th { background: rgba(255, 255, 255, .25) !important; }
html[data-sx-theme="glass"][data-sx-scheme="dark"] th { background: rgba(255, 255, 255, .06) !important; }
html[data-sx-theme="glass"] tbody tr:hover td { background: var(--sx-area-soft); }
html[data-sx-theme="glass"] body[data-sx-area] main { background-image: none; }
/* no blur available, or the person asked for less transparency: solid, still tinted */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  html[data-sx-theme="glass"][data-sx-scheme="light"] { --card: rgba(255, 255, 255, .92); --panel: rgba(255, 255, 255, .92); }
  html[data-sx-theme="glass"][data-sx-scheme="dark"] { --card: rgba(24, 31, 48, .94); --panel: rgba(24, 31, 48, .94); }
}
@media (prefers-reduced-transparency: reduce) {
  html[data-sx-theme="glass"] * { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
  html[data-sx-theme="glass"][data-sx-scheme="light"] { --card: #fff; --panel: #fff; --panel2: #f4f6fb; }
  html[data-sx-theme="glass"][data-sx-scheme="dark"] { --card: #182033; --panel: #182033; --panel2: #1d263b; }
}
html[data-sx-solid="1"][data-sx-theme="glass"] * { -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
html[data-sx-solid="1"][data-sx-theme="glass"][data-sx-scheme="light"] { --card: #fff; --panel: #fff; --panel2: #f4f6fb; }
html[data-sx-solid="1"][data-sx-theme="glass"][data-sx-scheme="dark"] { --card: #182033; --panel: #182033; --panel2: #1d263b; }

/* ---------- 4. Material shapes ---------- */
html[data-sx-theme="material"] .card, html[data-sx-theme="material"] .kpi, html[data-sx-theme="material"] .kcard, html[data-sx-theme="material"] .tbl-wrap,
html[data-sx-theme="material"] .col, html[data-sx-theme="material"] .authcard, html[data-sx-theme="material"] .panel {
  border-radius: 16px; border-color: transparent !important; box-shadow: var(--shadow);
}
html[data-sx-theme="material"] .modal-card, html[data-sx-theme="material"] .modal .card { border-radius: 28px; border-color: transparent; box-shadow: var(--shadow-lg); }
html[data-sx-theme="material"] .kpi { border-top-width: 0 !important; box-shadow: var(--shadow), inset 4px 0 0 var(--sx-area); }
html[data-sx-theme="material"] .btn { border-radius: 999px; padding-left: 16px; padding-right: 16px; border-color: var(--line); font-weight: 500; transition: box-shadow .15s, background .15s; }
html[data-sx-theme="material"] .btn.primary { box-shadow: var(--shadow); }
html[data-sx-theme="material"] .btn.primary:hover { box-shadow: var(--shadow-lg); filter: none; }
html[data-sx-theme="material"] .btn:not(.primary):hover { background: var(--sx-area-soft); border-color: var(--line); }
html[data-sx-theme="material"] input:not([type=checkbox]):not([type=radio]), html[data-sx-theme="material"] select, html[data-sx-theme="material"] textarea {
  background: var(--panel2); border: 0; border-bottom: 2px solid var(--line); border-radius: 8px 8px 0 0; color: var(--ink);
}
html[data-sx-theme="material"] main input:focus, html[data-sx-theme="material"] main select:focus, html[data-sx-theme="material"] main textarea:focus { box-shadow: none !important; border-bottom-color: var(--sx-area) !important; }
html[data-sx-theme="material"] th { background: var(--panel2) !important; font-weight: 600; letter-spacing: .2px; }
html[data-sx-theme="material"] .pill, html[data-sx-theme="material"] .chip, html[data-sx-theme="material"] .badge { border-radius: 8px; }
html[data-sx-theme="material"] .tabs .on, html[data-sx-theme="material"] .tab.on, html[data-sx-theme="material"] .seg .on { background: var(--sx-area-soft); border-radius: 999px; }
html[data-sx-theme="material"] body[data-sx-area] main { background-image: none; }

/* ---------- 5. picker (button + panel) ---------- */
#sx-th-btn { position: fixed; left: 14px; bottom: 14px; z-index: 400; width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--sx-gold-line, rgba(244, 196, 48, .35)); background: #000; color: var(--sx-gold, #f4c430); font-size: 18px; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); display: grid; place-items: center; }
#sx-th-btn:hover { background: #151515; }
#sx-th-btn:focus-visible, #sx-th-pop button:focus-visible { outline: 2px solid var(--sx-gold, #f4c430); outline-offset: 2px; }
#sx-th-pop { position: fixed; left: 14px; bottom: 60px; z-index: 401; width: 290px; max-width: calc(100vw - 28px); background: #0b0b0b; color: #e8e8e8; border: 1px solid var(--sx-gold-line, rgba(244, 196, 48, .35)); border-radius: 14px; box-shadow: 0 16px 44px rgba(0, 0, 0, .5); padding: 14px; font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#sx-th-pop h4 { margin: 0 0 8px; font-size: 13px; color: var(--sx-gold, #f4c430); display: flex; justify-content: space-between; }
#sx-th-pop .grp { margin: 0 0 12px; }
#sx-th-pop .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #9aa0a6; margin-bottom: 5px; }
#sx-th-pop .opts { display: flex; gap: 6px; flex-wrap: wrap; }
#sx-th-pop .opts button { flex: 1 1 0; min-width: 78px; padding: 7px 6px; border-radius: 9px; border: 1px solid #2b2b2b; background: #151515; color: #e8e8e8; cursor: pointer; font: inherit; display: flex; flex-direction: column; align-items: center; gap: 5px; }
#sx-th-pop .opts button[aria-pressed="true"] { border-color: var(--sx-gold, #f4c430); background: rgba(244, 196, 48, .12); color: var(--sx-gold-hi, #ffd95a); font-weight: 600; }
#sx-th-pop .sw { width: 100%; height: 22px; border-radius: 6px; border: 1px solid rgba(255, 255, 255, .18); }
#sx-th-pop .sw.classic { background: linear-gradient(90deg, #f6f7f9 60%, #4338ca 60%); }
#sx-th-pop .sw.glass { background: linear-gradient(120deg, #7aa2ff, #f0a0d0 60%, #8ae0ff); box-shadow: inset 0 0 0 5px rgba(255, 255, 255, .35); }
#sx-th-pop .sw.material { background: linear-gradient(90deg, #fffbff 55%, #6d28d9 55%); border-radius: 14px; box-shadow: 0 2px 5px rgba(0, 0, 0, .4); }
#sx-th-pop label { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; color: #d6d6d6; }
#sx-th-pop .foot { display: flex; justify-content: space-between; align-items: center; color: #8d9399; font-size: 11.5px; margin-top: 4px; }
#sx-th-pop .foot button { background: none; border: 0; color: var(--sx-gold, #f4c430); cursor: pointer; font: inherit; text-decoration: underline; }
@media print { #sx-th-btn, #sx-th-pop { display: none !important; } }
