/* =========================================================================
   AHPC BOM & Quotation System - UI v3
   Sidebar layout, soft cards, six themes (data-theme on <html>).
   Every colour below comes from the theme variables.
   ========================================================================= */

/* ---- themes ------------------------------------------------------------ */
:root, [data-theme="allway"] {            /* Allway HPC: navy + orange (the quotation's colours) */
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #f6f8fb; --surface-3: #eef1f6;
  --text: #1c2433; --heading: #14243f; --muted: #6a7488; --border: #e2e7ef;
  --primary: #e2602a; --primary-hover: #c94f1d; --on-primary: #ffffff; --primary-soft: #fdeee6;
  --accent: #1f4e8c; --accent-soft: #e6eef9;
  --sidebar-bg: #13233f; --sidebar-text: #c8d3e6; --sidebar-muted: #7f8fac; --sidebar-active: #e2602a; --sidebar-active-text: #ffffff; --sidebar-hover: rgba(255,255,255,.07);
  --success: #1f8f4e; --success-soft: #e3f5ea; --danger: #d43c3c; --danger-soft: #fde8e8;
  --warning: #b7791f; --warning-soft: #fdf3dd; --info: #1f62c9; --info-soft: #e5efff;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 4px 14px rgba(16,24,40,.06);
  --hero-1: #13233f; --hero-2: #1f4e8c; --hero-num: #ffb38c;
  color-scheme: light;
}
[data-theme="indigo"] {
  --bg: #f5f6fb; --surface: #ffffff; --surface-2: #f7f7fd; --surface-3: #eeeffa;
  --text: #1f2133; --heading: #24264a; --muted: #6c6f8c; --border: #e3e4f1;
  --primary: #5b4ce6; --primary-hover: #4a3bd1; --on-primary: #ffffff; --primary-soft: #eeebff;
  --accent: #0f9b8e; --accent-soft: #e0f5f2;
  --sidebar-bg: #ffffff; --sidebar-text: #3d4060; --sidebar-muted: #9a9cb6; --sidebar-active: #5b4ce6; --sidebar-active-text: #ffffff; --sidebar-hover: #f1f0fc;
  --success: #1f8f4e; --success-soft: #e3f5ea; --danger: #d43c3c; --danger-soft: #fde8e8;
  --warning: #b7791f; --warning-soft: #fdf3dd; --info: #2563eb; --info-soft: #e5edff;
  --shadow: 0 1px 2px rgba(30,30,70,.05), 0 6px 18px rgba(30,30,70,.07);
  --hero-1: #3b2fc9; --hero-2: #7a5cf0; --hero-num: #fff;
  color-scheme: light;
}
[data-theme="ocean"] {
  --bg: #f0f6f8; --surface: #ffffff; --surface-2: #f4f9fa; --surface-3: #e6f1f4;
  --text: #13262e; --heading: #0b3a4a; --muted: #5f7780; --border: #d9e8ec;
  --primary: #0e7c90; --primary-hover: #0a6676; --on-primary: #ffffff; --primary-soft: #dff2f5;
  --accent: #2b6cb0; --accent-soft: #e4eef9;
  --sidebar-bg: #083344; --sidebar-text: #c3e3ea; --sidebar-muted: #7fb0bd; --sidebar-active: #22b3c9; --sidebar-active-text: #04232e; --sidebar-hover: rgba(255,255,255,.07);
  --success: #1f8f4e; --success-soft: #e3f5ea; --danger: #d43c3c; --danger-soft: #fde8e8;
  --warning: #b7791f; --warning-soft: #fdf3dd; --info: #2b6cb0; --info-soft: #e4eef9;
  --shadow: 0 1px 2px rgba(8,51,68,.05), 0 6px 18px rgba(8,51,68,.07);
  --hero-1: #083344; --hero-2: #0e7c90; --hero-num: #9ff0fb;
  color-scheme: light;
}
[data-theme="forest"] {
  --bg: #f2f6f2; --surface: #ffffff; --surface-2: #f6faf5; --surface-3: #e8f1e7;
  --text: #17261a; --heading: #123b1f; --muted: #627566; --border: #dce8dc;
  --primary: #1f7a3a; --primary-hover: #17642f; --on-primary: #ffffff; --primary-soft: #e2f3e6;
  --accent: #8a6d1d; --accent-soft: #f6efd9;
  --sidebar-bg: #0f2a19; --sidebar-text: #c7e2cc; --sidebar-muted: #7fa588; --sidebar-active: #49b26a; --sidebar-active-text: #06180c; --sidebar-hover: rgba(255,255,255,.07);
  --success: #1f7a3a; --success-soft: #e2f3e6; --danger: #c93838; --danger-soft: #fbe7e7;
  --warning: #a8701a; --warning-soft: #fbf1db; --info: #2a64b8; --info-soft: #e5eefb;
  --shadow: 0 1px 2px rgba(15,42,25,.05), 0 6px 18px rgba(15,42,25,.07);
  --hero-1: #0f2a19; --hero-2: #1f7a3a; --hero-num: #b9f2c8;
  color-scheme: light;
}
[data-theme="rose"] {
  --bg: #fbf4f6; --surface: #ffffff; --surface-2: #fdf7f9; --surface-3: #f7e9ee;
  --text: #2a1820; --heading: #4a1530; --muted: #846672; --border: #f0dfe6;
  --primary: #c0265f; --primary-hover: #a31d50; --on-primary: #ffffff; --primary-soft: #fce4ed;
  --accent: #6d3fb0; --accent-soft: #efe7fa;
  --sidebar-bg: #3a0d22; --sidebar-text: #f0cdda; --sidebar-muted: #b48195; --sidebar-active: #f05d93; --sidebar-active-text: #2a0716; --sidebar-hover: rgba(255,255,255,.07);
  --success: #1f8f4e; --success-soft: #e3f5ea; --danger: #c9302c; --danger-soft: #fde6e5;
  --warning: #b7791f; --warning-soft: #fdf3dd; --info: #2f63c4; --info-soft: #e7eefc;
  --shadow: 0 1px 2px rgba(58,13,34,.05), 0 6px 18px rgba(58,13,34,.07);
  --hero-1: #3a0d22; --hero-2: #c0265f; --hero-num: #ffd0e2;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0e131c; --surface: #161d29; --surface-2: #1b2331; --surface-3: #222c3d;
  --text: #e3e8f1; --heading: #f3f6fb; --muted: #94a0b5; --border: #2a3446;
  --primary: #f0763f; --primary-hover: #ff8a55; --on-primary: #1a0c04; --primary-soft: #3a2216;
  --accent: #6aa5ff; --accent-soft: #1b2b45;
  --sidebar-bg: #0a0f17; --sidebar-text: #b9c4d6; --sidebar-muted: #6b7890; --sidebar-active: #f0763f; --sidebar-active-text: #1a0c04; --sidebar-hover: rgba(255,255,255,.05);
  --success: #3ccf7a; --success-soft: #133524; --danger: #ff6b6b; --danger-soft: #3d1a1d;
  --warning: #f2b84b; --warning-soft: #3a2c12; --info: #6aa5ff; --info-soft: #1b2b45;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
  --hero-1: #1b2a44; --hero-2: #2a3f66; --hero-num: #ffb38c;
  color-scheme: dark;
}
/* names used by older templates */
:root { --navy: var(--heading); --purple: var(--primary); --card: var(--surface); --green: var(--success); }

/* ---- base -------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; font-size: .85em; }
mark { background: #ffe58f; color: #1c2433; padding: 0 2px; border-radius: 3px; }
h1, h2, h3, h4 { color: var(--heading); }

/* ---- app shell: sidebar + main ------------------------------------------ */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid var(--border); z-index: 40;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 18px; }
.brand .mark { width: 38px; height: 38px; border-radius: 10px; background: var(--sidebar-active); color: var(--sidebar-active-text);
  display: grid; place-items: center; font-weight: 800; font-size: .95rem; letter-spacing: .5px; }
.brand .name { font-weight: 800; font-size: 1.05rem; color: var(--sidebar-text); line-height: 1.1; }
[data-theme="indigo"] .brand .name { color: var(--heading); }
.brand .name small { display: block; font-weight: 500; font-size: .7rem; color: var(--sidebar-muted); letter-spacing: .6px; text-transform: uppercase; margin-top: 3px; }
.nav { padding: 6px 12px; display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: .68rem; text-transform: uppercase; letter-spacing: .9px; color: var(--sidebar-muted); padding: 14px 10px 6px; font-weight: 700; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: var(--sidebar-text); font-weight: 600; font-size: .92rem; }
.nav a svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .85; }
.nav a:hover { background: var(--sidebar-hover); text-decoration: none; }
.nav a.active { background: var(--sidebar-active); color: var(--sidebar-active-text); }
.nav a.active svg { opacity: 1; }
.nav a .count { margin-left: auto; font-size: .72rem; background: var(--sidebar-hover); padding: 1px 8px; border-radius: 10px; }
.nav a.active .count { background: rgba(255,255,255,.25); }
.side-foot { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid var(--sidebar-hover); }
.me { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--sidebar-hover); color: var(--sidebar-text); display: grid; place-items: center; font-weight: 800; font-size: .85rem; flex: 0 0 34px; }
.me b { display: block; color: var(--sidebar-text); font-size: .9rem; }
.me span { font-size: .75rem; color: var(--sidebar-muted); }
.side-links { display: flex; gap: 12px; font-size: .8rem; margin-bottom: 10px; }
.side-links a { color: var(--sidebar-muted); } .side-links a:hover { color: var(--sidebar-text); }
.theme-pick label { color: var(--sidebar-muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .7px; margin-bottom: 6px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatches button { width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); }
.swatches button.on { border-color: var(--sidebar-active); transform: scale(1.08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mobile-bar { display: none; }
.container { width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px 32px 60px; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent), var(--bg); }

/* ---- page header ---------------------------------------------------------- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 12px; }
.page-header h1 { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: -.3px; }
.page-header > div, .page-header > form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.subtitle { color: var(--muted); margin: -14px 0 20px; font-size: .92rem; }

/* ---- buttons ---------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--primary); color: var(--on-primary);
  border: 1px solid transparent; padding: 9px 16px; border-radius: 9px; font-weight: 650; font-size: .9rem; cursor: pointer;
  font-family: inherit; line-height: 1.2; transition: background .15s, box-shadow .15s; white-space: nowrap; }
.btn:hover { background: var(--primary-hover); text-decoration: none; color: var(--on-primary); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.btn.secondary { background: var(--surface); color: var(--heading); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-3); color: var(--heading); box-shadow: none; }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.92); background: var(--danger); }
.btn.small { padding: 5px 11px; font-size: .8rem; border-radius: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- cards ------------------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow); }
.soft-panel { background: var(--primary-soft); border: 1px dashed var(--primary); box-shadow: none; }
.note { margin-top: 12px; padding: 10px 14px; border-radius: 10px; font-size: .88rem; }
.note.warn { background: var(--warning-soft); color: var(--text); border-left: 3px solid var(--warning); }
.note.info { background: var(--info-soft); color: var(--text); border-left: 3px solid var(--info); }
.section-title { font-size: 1rem; font-weight: 750; color: var(--heading); margin: 28px 0 12px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card > .section-title:first-child { margin-top: 0; }

/* ---- stats ------------------------------------------------------------------ */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 22px; }
.stat-card { background: linear-gradient(135deg, var(--hero-1), var(--hero-2)); color: #fff; border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card::after { content: ""; position: absolute; right: -24px; top: -24px; width: 90px; height: 90px; border-radius: 50%; background: rgba(255,255,255,.08); }
.stat-card .num { font-size: 1.9rem; font-weight: 800; color: var(--hero-num); letter-spacing: -.5px; }
.stat-card .label { font-size: .8rem; color: rgba(255,255,255,.78); margin-top: 2px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(175px, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); border-top: 3px solid var(--primary); }
.kpi .v { font-size: 1.5rem; font-weight: 800; color: var(--heading); }
.kpi .l { font-size: .78rem; color: var(--muted); margin-top: 2px; }

/* ---- tables ------------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; font-weight: 700; background: var(--surface-2); }
tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; margin: 0 -22px; padding: 0 22px; }
.num-cell { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- badges / chips ---------------------------------------------------------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: .7rem; font-weight: 750; text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.badge.gray { background: var(--surface-3); color: var(--muted); }
.badge.purple { background: var(--primary-soft); color: var(--primary); }
.badge.green { background: var(--success-soft); color: var(--success); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.orange { background: var(--warning-soft); color: var(--warning); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.people-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 20px; background: var(--surface-3); color: var(--text); font-size: .86rem; border: 1px solid transparent; }
.chip:hover { text-decoration: none; border-color: var(--border); }
.chip small { color: var(--muted); font-size: .72rem; }
.chip b { background: var(--primary); color: var(--on-primary); border-radius: 10px; padding: 0 8px; font-size: .78rem; }
.chip.zero b { background: var(--border); color: var(--muted); }
.chip i { font-style: normal; color: var(--danger); font-size: .74rem; font-weight: 700; }
.chip.active { border-color: var(--primary); background: var(--surface); }

/* ---- forms ------------------------------------------------------------------------- */
form .field { margin-bottom: 14px; }
label { display: block; font-size: .8rem; font-weight: 650; margin-bottom: 5px; color: var(--heading); }
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px; font-size: .92rem; font-family: inherit;
  background: var(--surface); color: var(--text); transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--primary); }
input[type=file] { padding: 7px; background: var(--surface-2); }
textarea { min-height: 80px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.cust-grid { grid-template-columns: 1fr 2fr; }

/* ---- flash ---------------------------------------------------------------------------- */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: .9rem; font-weight: 600; border-left: 4px solid; }
.flash.success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* ---- tabs / pager --------------------------------------------------------------------- */
.tabs { display: flex; gap: 4px; margin: 0 0 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 5px; width: fit-content; max-width: 100%; overflow-x: auto; box-shadow: var(--shadow); }
.tabs .tab { padding: 8px 16px; border-radius: 9px; color: var(--muted); font-weight: 650; white-space: nowrap; }
.tabs .tab:hover { text-decoration: none; color: var(--heading); }
.tabs .tab.active { background: var(--primary); color: var(--on-primary); }
.tabs .tab span { background: var(--surface-3); color: var(--muted); border-radius: 10px; padding: 1px 8px; font-size: .75rem; margin-left: 4px; }
.tabs .tab.active span { background: rgba(255,255,255,.25); color: var(--on-primary); }
.pager { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 20px; }
.pager a, .pager b { min-width: 34px; text-align: center; padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.pager a:hover { text-decoration: none; border-color: var(--primary); }
.pager b { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ---- BOM cards ------------------------------------------------------------------------- */
details.bom-card { padding: 0; overflow: hidden; }
details.bom-card > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 170px 1fr 200px 130px 140px; gap: 12px; align-items: center; padding: 15px 20px; }
details.bom-card > summary::-webkit-details-marker { display: none; }
details.bom-card > summary:hover { background: var(--surface-2); }
details.bom-card[open] > summary { border-bottom: 1px solid var(--border); background: var(--surface-2); }
details.bom-card > div { padding: 4px 20px 18px; }
.bom-no { font-weight: 750; color: var(--primary); } .bom-no small { color: var(--muted); font-weight: 500; }
.bom-no .qn { display: block; font-size: .72rem; color: var(--muted); font-weight: 600; margin-top: 2px; }
.bom-title { font-weight: 650; color: var(--heading); }
.bom-title small.src, .bom-title small.who { display: block; font-weight: 400; color: var(--muted); font-size: .76rem; }
.bom-cust { color: var(--muted); font-size: .88rem; }
.bom-total { text-align: right; font-weight: 800; color: var(--heading); font-variant-numeric: tabular-nums; }
.bom-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.bom-actions form { margin: 0; }
.bom-meta-strip { display: flex; flex-wrap: wrap; gap: 10px; margin: -8px 0 18px; }
.bom-meta-strip .pill { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 14px; box-shadow: var(--shadow); }
.bom-meta-strip .pill small { display: block; font-size: .68rem; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 700; }
.bom-meta-strip .pill b { color: var(--heading); font-size: .98rem; }
.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); font-size: .85rem; }
.upload-row label { flex-basis: 100%; font-weight: 500; color: var(--muted); }
.upload-row label b { color: var(--heading); }
.upload-row input[type=file] { flex: 1; min-width: 220px; }

/* ---- totals / workflow ------------------------------------------------------------------- */
.totals-box { max-width: 400px; margin-left: auto; background: var(--surface-2); border-radius: 12px; padding: 12px 16px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: .92rem; font-variant-numeric: tabular-nums; }
.totals-box .row.grand { font-size: 1.2rem; font-weight: 800; border-top: 2px solid var(--heading); margin-top: 6px; padding-top: 10px; color: var(--heading); }
.workflow-steps { display: flex; flex-wrap: wrap; gap: 0; margin: 4px 0 20px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.workflow-steps .step { flex: 1; text-align: center; padding: 11px 10px; font-size: .78rem; font-weight: 750; color: var(--muted); letter-spacing: .4px; border-right: 1px solid var(--border); }
.workflow-steps .step:last-child { border-right: 0; }
.workflow-steps .step.done { background: var(--success-soft); color: var(--success); }
.workflow-steps .step.active { background: var(--primary); color: var(--on-primary); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted); }

/* ---- editable tables ------------------------------------------------------------------------- */
table.edit-table { min-width: 1000px; }
table.edit-table input { padding: 6px 8px; border-radius: 7px; font-size: .85rem; background: var(--surface-2); }
table.edit-table input.num { text-align: right; }
table.edit-table td:nth-child(4) input, table.edit-table td:nth-child(5) input { min-width: 170px; }
.card:has(table.edit-table) { overflow-x: auto; }

/* ---- charts --------------------------------------------------------------------------------------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 18px; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; box-shadow: var(--shadow); }
.chart-card h3 { margin: 0 0 12px; font-size: .95rem; }
.chart-card .cbox { position: relative; height: 290px; }
.chart-card.wide { grid-column: 1 / -1; }
.chart-card.wide .cbox { height: 310px; }

/* ---- dashboard ---------------------------------------------------------------------------------------- */
.search-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.search-bar input[name=q] { flex: 1; min-width: 240px; font-size: 1rem; padding: 12px 14px 12px 40px; border-radius: 11px;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%238a94a6' stroke-width='2' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 13px center; }
.search-results h4 { margin: 18px 0 6px; }
.search-results table td { font-size: .88rem; }
table.pending td { vertical-align: top; }
tr.group-row td { background: var(--primary-soft); font-weight: 750; color: var(--heading); padding: 9px 12px; }
.last-remark { font-size: .82rem; background: var(--surface-2); border-radius: 8px; padding: 7px 9px; margin-bottom: 6px; }
.remark-form, .mini-assign { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.remark-form input { flex: 1; min-width: 0; }
.remark-form input, .remark-form select, .mini-assign select, .mini-assign input,
.assign-form select, .assign-form input, .remark-box select, .remark-box input { padding: 6px 8px; font-size: .84rem; border-radius: 7px; width: auto; }
.mini-assign select { max-width: 130px; } .mini-assign input[type=date] { max-width: 135px; }
.assign-box { border: 1px dashed var(--border); border-radius: 12px; padding: 12px 16px; margin: 6px 0 14px; background: var(--surface-2); }

/* ---- thread ------------------------------------------------------------------------------------------------ */
.thread .assign-line { margin-bottom: 10px; font-size: .92rem; }
.assign-form, .remark-box { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.thread-list { margin-top: 12px; border-top: 1px solid var(--border); }
.thread-list .msg { padding: 10px 6px; border-bottom: 1px solid var(--border); font-size: .88rem; }
.thread-list .msg .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 3px; }
.thread-list .msg .when { color: var(--muted); font-size: .75rem; margin-left: auto; }
.thread-list .msg.delay { background: var(--danger-soft); }
.thread-list .msg.assignment { background: var(--success-soft); }
.thread-list .msg.system .body { color: var(--muted); font-style: italic; }

/* ---- inline popovers ---------------------------------------------------------------------------------------- */
.inline-form { display: inline; margin: 0; }
.inline-edit { display: inline-block; vertical-align: top; position: relative; }
.inline-edit > summary { list-style: none; cursor: pointer; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] form { position: absolute; z-index: 30; right: 0; top: 34px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0,0,0,.18); border-radius: 12px; padding: 14px; display: grid; gap: 7px; width: 290px; }
.inline-edit form label { font-size: .76rem; color: var(--muted); display: grid; gap: 3px; margin: 0; }
.inline-edit form label:has(input[type=checkbox]) { display: flex; gap: 6px; align-items: center; color: var(--text); }

/* ---- work tracker ---------------------------------------------------------------------------------------------- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 10px; align-items: end; }
.filters .field { margin: 0; }
table.tracker { font-size: .84rem; min-width: 980px; }
table.tracker td { padding: 9px 10px; }
table.tracker .qn { font-weight: 750; color: var(--heading); white-space: nowrap; font-variant-numeric: tabular-nums; }
table.tracker .sno { color: var(--muted); font-variant-numeric: tabular-nums; }
table.tracker .req { max-width: 260px; }
table.tracker .rem { max-width: 240px; color: var(--muted); font-size: .8rem; }
table.tracker tr.stage-DONE td:first-child { box-shadow: inset 3px 0 0 var(--success); }
table.tracker tr.stage-OPEN td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
table.tracker tr.stage-CANCELLED td { opacity: .6; }
table.tracker tr.stage-CANCELLED td:first-child { box-shadow: inset 3px 0 0 var(--muted); }
.eng-board { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; margin-bottom: 18px; }
.eng-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 14px; box-shadow: var(--shadow); color: var(--text); }
.eng-card:hover { text-decoration: none; border-color: var(--primary); }
.eng-card b { display: block; color: var(--heading); font-size: .92rem; }
.eng-card .bar { height: 6px; border-radius: 4px; background: var(--surface-3); margin: 8px 0 5px; overflow: hidden; display: flex; }
.eng-card .bar i { display: block; background: var(--success); } .eng-card .bar i.o { background: var(--warning); }
.eng-card small { color: var(--muted); font-size: .75rem; }
.eng-card.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.legend-dots { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin: -6px 0 12px; flex-wrap: wrap; }
.legend-dots i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* ---- print ---------------------------------------------------------------------------------------------------- */
@media print {
  .sidebar, .mobile-bar, .no-print, .flash { display: none !important; }
  body, .main { background: #fff !important; }
  .container { max-width: none; padding: 0; }
}

/* ---- tablets / phones ------------------------------------------------------------------------------------------- */
@media screen and (max-width: 1100px) {
  .filters { grid-template-columns: 1fr 1fr; }
  details.bom-card > summary { grid-template-columns: 150px 1fr 120px; }
  details.bom-card > summary .bom-cust, details.bom-card > summary .badge { display: none; }
}
@media screen and (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 35; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--sidebar-bg); color: var(--sidebar-text); position: sticky; top: 0; z-index: 30; }
  .mobile-bar button { background: none; border: 0; color: inherit; padding: 4px; cursor: pointer; }
  .mobile-bar b { font-size: 1rem; }
  .container { padding: 16px 12px 40px; }
  .page-header h1 { font-size: 1.3rem; }
  .card { padding: 15px; overflow-x: auto; }
  .table-wrap { margin: 0 -15px; padding: 0 15px; }
  .grid-2, .grid-3, .grid-4, .cust-grid, .filters { grid-template-columns: 1fr; }
  .grid-2 > *, .grid-3 > * { grid-column: auto !important; }
  table { min-width: 560px; }
  input, select, textarea { font-size: 16px; }
  .assign-form > *, .remark-box > * { flex: 1 1 100%; min-width: 0 !important; }
  .assign-form button, .remark-box button { flex: 0 0 auto; }
  .thread-list .msg .when { margin-left: 0; width: 100%; }
  .field[style*="grid-template-columns:170px"] { grid-template-columns: 1fr !important; }
  details.bom-card > summary { grid-template-columns: 1fr auto; }
  details.bom-card > summary .bom-title { grid-column: 1 / -1; order: 3; }
  table.pending { min-width: 0; }
  table.pending, table.pending tbody, table.pending tr, table.pending td { display: block; width: 100%; }
  table.pending thead { display: none; }
  table.pending tr { border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; margin-bottom: 12px; background: var(--surface); }
  table.pending tr.group-row { padding: 0; border: 0; }
  table.pending td { border: 0; padding: 6px 0; }
  table.pending td::before { content: attr(data-label); display: block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 2px; }
  .qpage { zoom: .95; margin-left: 0; margin-right: 0; }
  .inline-edit[open] form { position: fixed; left: 12px; right: 12px; top: 80px; width: auto; }
}
@media screen and (max-width: 640px) { .qpage { zoom: .7; } .stat-card .num { font-size: 1.5rem; } .eng-board { grid-template-columns: 1fr 1fr; gap: 8px; } .eng-card { padding: 9px 11px; } .stats-row { grid-template-columns: 1fr 1fr; } }
@media screen and (max-width: 480px) { .qpage { zoom: .46; } }
