/* =====================================================================
   TileFlow ERP — Design system
   Light-first, indigo accent, optional dark mode.
   No CSS framework: everything here is purpose-built and ~1 file.
   ===================================================================== */

/* ---------- 1. Tokens ---------- */
:root{
  --accent:        #4f46e5;
  --accent-hover:  #4338ca;
  --accent-soft:   #eef2ff;
  --accent-softer: #f5f6ff;
  --accent-border: #c7d2fe;
  --accent-text:   #3730a3;

  --bg:            #f4f5f9;
  --surface:       #ffffff;
  --surface-2:     #fafbfd;
  --surface-3:     #f1f3f8;
  --border:        #e6e8ef;
  --border-strong: #d6dae4;

  --text:          #101828;
  --text-2:        #475467;
  --muted:         #737c8f;
  --faint:         #98a2b3;

  --green:  #067647;  --green-bg:#e7f6ee;  --green-bd:#a9e0c4;
  --red:    #b42318;  --red-bg:  #fdecea;  --red-bd:  #f4b8b2;
  --amber:  #a35a04;  --amber-bg:#fdf3e2;  --amber-bd:#f3d6a2;
  --blue:   #175cd3;  --blue-bg: #e8f1fe;  --blue-bd: #b5d2fb;
  --violet: #6931c9;  --violet-bg:#f1ecfd; --violet-bd:#d5c5f8;
  --teal:   #0e7490;  --teal-bg: #e2f4f8;  --teal-bd: #a8dbe8;
  --cyan:   #0e7490;  --cyan-bg: #e2f4f8;  --cyan-bd: #a8dbe8;
  --orange: #b54708;  --orange-bg:#fdefe4; --orange-bd:#f6cba6;
  --indigo: #3f38b8;  --indigo-bg:#ecebfd; --indigo-bd:#c6c3f6;
  --slate:  #475467;  --slate-bg:#f0f2f6;  --slate-bd:#d9dee7;

  --r-xs: 6px;  --r-sm: 8px;  --r: 12px;  --r-lg: 16px;  --r-xl: 20px;
  --sh-xs: 0 1px 2px rgba(16,24,40,.05);
  --sh-sm: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --sh-md: 0 2px 4px rgba(16,24,40,.04), 0 8px 20px rgba(16,24,40,.07);
  --sh-lg: 0 8px 12px rgba(16,24,40,.06), 0 24px 48px rgba(16,24,40,.12);

  --sidebar-w: 252px;
  --sidebar-w-collapsed: 76px;
  --topbar-h: 62px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

html[data-theme="dark"]{
  --accent:        #7c74f5;
  --accent-hover:  #948df8;
  --accent-soft:   #24234a;
  --accent-softer: #1d1d3d;
  --accent-border: #3b3980;
  --accent-text:   #b9b4fb;

  --bg:            #0e1016;
  --surface:       #171a22;
  --surface-2:     #1c2029;
  --surface-3:     #222732;
  --border:        #272d39;
  --border-strong: #333b4a;

  --text:          #e9edf5;
  --text-2:        #b3bccd;
  --muted:         #8d97a9;
  --faint:         #6c7688;

  --green:#5ad19a; --green-bg:#123024; --green-bd:#1f5540;
  --red:#f28b82;   --red-bg:#3a1a18;   --red-bd:#6b2a26;
  --amber:#f0b95b; --amber-bg:#352713; --amber-bd:#63451c;
  --blue:#7cb0f7;  --blue-bg:#152742;  --blue-bd:#26456f;
  --violet:#b39cf7;--violet-bg:#241d3f;--violet-bd:#3f3369;
  --teal:#5cc6de;  --teal-bg:#0f2c34;  --teal-bd:#1c4c59;
  --cyan:#5cc6de;  --cyan-bg:#0f2c34;  --cyan-bd:#1c4c59;
  --orange:#f0a26b;--orange-bg:#38230f;--orange-bd:#66401d;
  --indigo:#9b95f8;--indigo-bg:#1f1e42;--indigo-bd:#39366f;
  --slate:#9aa4b5; --slate-bg:#222833; --slate-bd:#333b4a;

  --sh-xs: 0 1px 2px rgba(0,0,0,.4);
  --sh-sm: 0 1px 3px rgba(0,0,0,.45);
  --sh-md: 0 6px 18px rgba(0,0,0,.5);
  --sh-lg: 0 20px 44px rgba(0,0,0,.6);
}

/* ---------- 2. Reset ---------- */
*,*::before,*::after{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0; background:var(--bg); color:var(--text);
  font-family:var(--font); font-size:14px; line-height:1.5;
  -webkit-font-smoothing:antialiased; -moz-osx-font-smoothing:grayscale;
  -webkit-text-size-adjust:100%;
}
h1,h2,h3,h4,h5{ margin:0; font-weight:600; letter-spacing:-.01em; color:var(--text); }
h1{ font-size:22px; } h2{ font-size:18px; } h3{ font-size:15px; }
p{ margin:0 0 10px; }
a{ color:var(--accent); text-decoration:none; }
a:hover{ color:var(--accent-hover); }
img{ max-width:100%; }
hr{ border:0; border-top:1px solid var(--border); margin:18px 0; }
::-webkit-scrollbar{ width:10px; height:10px; }
::-webkit-scrollbar-thumb{ background:var(--border-strong); border-radius:8px; border:3px solid transparent; background-clip:content-box; }
::-webkit-scrollbar-track{ background:transparent; }
:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; border-radius:4px; }
.ico{ flex:none; vertical-align:middle; }

/* ---------- 3. App shell ---------- */
.app{ min-height:100vh; }

.sidebar{
  position:fixed; inset:0 auto 0 0; width:var(--sidebar-w); z-index:60;
  background:var(--surface); border-right:1px solid var(--border);
  display:flex; flex-direction:column; transition:width .18s ease, transform .22s ease;
}
.sidebar__brand{
  height:var(--topbar-h); flex:none; display:flex; align-items:center; gap:10px;
  padding:0 16px; border-bottom:1px solid var(--border);
}
.brand__mark{
  width:32px; height:32px; border-radius:9px; flex:none;
  background:linear-gradient(140deg,var(--accent),#7b74f0);
  display:grid; place-items:center; color:#fff; font-weight:700; font-size:14px;
  box-shadow:0 2px 6px rgba(79,70,229,.35);
}
.brand__name{ font-weight:650; font-size:15px; letter-spacing:-.02em; white-space:nowrap; overflow:hidden; }
.brand__name small{ display:block; font-weight:450; font-size:11px; color:var(--muted); letter-spacing:0; }

.sidebar__nav{ flex:1; overflow-y:auto; overflow-x:hidden; padding:12px 10px 20px; }
.nav__label{
  font-size:10.5px; font-weight:600; letter-spacing:.08em; text-transform:uppercase;
  color:var(--faint); padding:14px 10px 6px; white-space:nowrap;
}
.nav__item{
  display:flex; align-items:center; gap:11px; padding:9px 11px; border-radius:var(--r-sm);
  color:var(--text-2); font-weight:500; font-size:13.5px; margin-bottom:2px;
  white-space:nowrap; position:relative; transition:background .12s,color .12s;
}
.nav__item:hover{ background:var(--surface-3); color:var(--text); }
.nav__item.is-active{ background:var(--accent-soft); color:var(--accent-text); font-weight:600; }
html[data-theme="dark"] .nav__item.is-active{ color:var(--accent-text); }
.nav__item.is-active .ico{ color:var(--accent); }
.nav__text{ overflow:hidden; text-overflow:ellipsis; }
.nav__pill{
  margin-left:auto; background:var(--red); color:#fff; font-size:10.5px; font-weight:700;
  min-width:19px; height:19px; padding:0 5px; border-radius:10px; display:grid; place-items:center;
}
.nav__group > .nav__item .nav__caret{ margin-left:auto; transition:transform .18s; }
.nav__group.is-open > .nav__item .nav__caret{ transform:rotate(90deg); }
.nav__sub{ overflow:hidden; max-height:0; transition:max-height .2s ease; }
.nav__group.is-open .nav__sub{ max-height:260px; }
.nav__sub .nav__item{ padding-left:40px; font-size:13px; }
.sidebar__foot{ flex:none; padding:10px; border-top:1px solid var(--border); }

/* collapsed (desktop) */
.app.is-collapsed .sidebar{ width:var(--sidebar-w-collapsed); }
.app.is-collapsed .brand__name,
.app.is-collapsed .nav__text,
.app.is-collapsed .nav__label,
.app.is-collapsed .nav__caret,
.app.is-collapsed .sidebar__foot .btn span{ display:none; }
.app.is-collapsed .nav__item{ justify-content:center; padding:10px; }
.app.is-collapsed .nav__pill{ position:absolute; top:3px; right:6px; margin:0; }
.app.is-collapsed .nav__sub{ display:none; }
.app.is-collapsed .main{ margin-left:var(--sidebar-w-collapsed); }
.app.is-collapsed .sidebar__brand{ justify-content:center; padding:0; }

.main{ margin-left:var(--sidebar-w); min-height:100vh; transition:margin .18s ease; }

/* ---------- 4. Topbar ---------- */
.topbar{
  position:sticky; top:0; z-index:40; height:var(--topbar-h);
  background:color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter:saturate(180%) blur(10px);
  border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:12px; padding:0 18px;
}
.topbar__title{ font-size:16px; font-weight:650; letter-spacing:-.01em; white-space:nowrap;
  overflow:hidden; text-overflow:ellipsis; }
.topbar__crumb{ font-size:11.5px; color:var(--muted); font-weight:500; }
.topbar__spacer{ flex:1; }

.iconbtn{
  width:36px; height:36px; border-radius:var(--r-sm); border:1px solid transparent;
  background:transparent; color:var(--text-2); display:grid; place-items:center;
  cursor:pointer; position:relative; transition:background .12s,color .12s;
}
.iconbtn:hover{ background:var(--surface-3); color:var(--text); }
.iconbtn__dot{
  position:absolute; top:3px; right:2px; min-width:17px; height:17px; padding:0 4px;
  background:var(--red); color:#fff; font-size:10px; font-weight:700;
  border-radius:9px; display:grid; place-items:center; border:2px solid var(--surface);
}
html[data-theme="dark"] .iconbtn__dot{ background:#e5534b; }

.search{ position:relative; width:min(330px, 34vw); }
.search__input{
  width:100%; height:38px; padding:0 12px 0 36px; font-size:13.5px; font-family:inherit;
  color:var(--text); background:var(--surface-3); border:1px solid transparent;
  border-radius:var(--r-sm); transition:border .12s, background .12s;
}
.search__input::placeholder{ color:var(--faint); }
.search__input:focus{ outline:none; background:var(--surface); border-color:var(--accent-border);
  box-shadow:0 0 0 3px var(--accent-soft); }
.search__ico{ position:absolute; left:11px; top:50%; transform:translateY(-50%); color:var(--faint); pointer-events:none; }
.search__kbd{ position:absolute; right:9px; top:50%; transform:translateY(-50%);
  font-size:10.5px; color:var(--faint); border:1px solid var(--border); border-radius:5px;
  padding:1px 5px; background:var(--surface); }
.search__results{
  position:absolute; top:calc(100% + 8px); left:0; right:0; background:var(--surface);
  border:1px solid var(--border); border-radius:var(--r); box-shadow:var(--sh-lg);
  max-height:70vh; overflow-y:auto; padding:6px; display:none; z-index:70;
}
.search__results.is-open{ display:block; }
.sr__group{ font-size:10.5px; font-weight:700; letter-spacing:.07em; text-transform:uppercase;
  color:var(--faint); padding:10px 10px 5px; }
.sr__item{ display:flex; align-items:center; gap:10px; padding:8px 10px; border-radius:var(--r-sm); color:var(--text); }
.sr__item:hover,.sr__item.is-active{ background:var(--accent-soft); color:var(--text); }
.sr__item strong{ font-weight:600; font-size:13.5px; }
.sr__item span{ font-size:12px; color:var(--muted); }
.sr__empty{ padding:18px; text-align:center; color:var(--muted); font-size:13px; }

.avatar{
  width:34px; height:34px; border-radius:50%; background:var(--accent-soft); color:var(--accent-text);
  display:grid; place-items:center; font-weight:650; font-size:12.5px; flex:none;
  border:1px solid var(--accent-border);
}

/* ---------- 5. Dropdown / popover ---------- */
.pop{ position:relative; }
.pop__panel{
  position:absolute; right:0; top:calc(100% + 8px); min-width:230px;
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  box-shadow:var(--sh-lg); padding:6px; display:none; z-index:80;
}
.pop__panel.is-open{ display:block; animation:popIn .13s ease; }
@keyframes popIn{ from{ opacity:0; transform:translateY(-4px);} to{ opacity:1; transform:none;} }
.pop__head{ padding:10px 12px 8px; border-bottom:1px solid var(--border); margin:-6px -6px 6px;
  display:flex; align-items:center; justify-content:space-between; gap:10px; }
.pop__title{ font-weight:650; font-size:13.5px; }
.pop__item{ display:flex; align-items:center; gap:10px; padding:9px 11px; border-radius:var(--r-sm);
  color:var(--text-2); font-size:13.5px; width:100%; background:none; border:0; cursor:pointer;
  font-family:inherit; text-align:left; }
.pop__item:hover{ background:var(--surface-3); color:var(--text); }
.pop__item--danger{ color:var(--red); }
.pop__sep{ height:1px; background:var(--border); margin:5px 0; }
.pop__panel--wide{ min-width:380px; max-width:min(420px,92vw); }
.pop__scroll{ max-height:60vh; overflow-y:auto; }

/* ---------- 6. Page container ---------- */
.page{ padding:22px 22px 40px; max-width:1600px; }
.page__head{ display:flex; align-items:flex-start; gap:14px; flex-wrap:wrap; margin-bottom:18px; }
.page__head h1{ font-size:21px; }
.page__sub{ color:var(--muted); font-size:13px; margin-top:3px; }
.page__actions{ margin-left:auto; display:flex; gap:8px; flex-wrap:wrap; }

/* ---------- 7. Buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  height:38px; padding:0 15px; border-radius:var(--r-sm); border:1px solid var(--border-strong);
  background:var(--surface); color:var(--text); font-size:13.5px; font-weight:550; font-family:inherit;
  cursor:pointer; white-space:nowrap; transition:background .12s,border .12s,box-shadow .12s,transform .06s;
  box-shadow:var(--sh-xs);
}
.btn:hover{ background:var(--surface-3); color:var(--text); }
.btn:active{ transform:translateY(1px); }
.btn--primary{ background:var(--accent); border-color:var(--accent); color:#fff;
  box-shadow:0 1px 2px rgba(16,24,40,.06), 0 2px 8px rgba(79,70,229,.25); }
.btn--primary:hover{ background:var(--accent-hover); border-color:var(--accent-hover); color:#fff; }
.btn--danger{ background:var(--red); border-color:var(--red); color:#fff; }
.btn--danger:hover{ filter:brightness(.94); color:#fff; }
.btn--ghost{ border-color:transparent; box-shadow:none; background:transparent; color:var(--text-2); }
.btn--ghost:hover{ background:var(--surface-3); }
.btn--sm{ height:32px; padding:0 11px; font-size:12.5px; border-radius:var(--r-xs); }
.btn--lg{ height:44px; padding:0 20px; font-size:14.5px; }
.btn--block{ width:100%; }
.btn[disabled]{ opacity:.55; pointer-events:none; }

/* ---------- 8. Cards ---------- */
.card{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  box-shadow:var(--sh-sm); overflow:hidden;
}
.card__head{
  padding:14px 16px; border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:10px; flex-wrap:wrap;
}
.card__head h2,.card__head h3{ font-size:14.5px; font-weight:650; }
.card__head .card__actions{ margin-left:auto; display:flex; gap:8px; align-items:center; }
.card__body{ padding:16px; }
.card__body--flush{ padding:0; }
.card__foot{ padding:12px 16px; border-top:1px solid var(--border); background:var(--surface-2); }

.grid{ display:grid; gap:14px; }
.grid--kpi{ grid-template-columns:repeat(auto-fill,minmax(215px,1fr)); }
.grid--2{ grid-template-columns:repeat(2,minmax(0,1fr)); }
.grid--3{ grid-template-columns:repeat(3,minmax(0,1fr)); }
.grid--4{ grid-template-columns:repeat(4,minmax(0,1fr)); }
.grid--sidebarwide{ grid-template-columns:minmax(0,2fr) minmax(0,1fr); }
/* stop cards stretching to the tallest sibling */
.grid--top{ align-items:start; }

/* KPI card */
.kpi{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  padding:15px 16px; box-shadow:var(--sh-sm); position:relative; overflow:hidden;
  display:flex; flex-direction:column; gap:9px; transition:box-shadow .15s, transform .15s;
}
a.kpi:hover{ box-shadow:var(--sh-md); transform:translateY(-1px); color:inherit; }
.kpi__top{ display:flex; align-items:center; gap:9px; }
.kpi__ico{ width:32px; height:32px; border-radius:9px; display:grid; place-items:center; flex:none; }
.kpi__label{ font-size:12.5px; color:var(--muted); font-weight:520; }
.kpi__value{ font-size:26px; font-weight:680; letter-spacing:-.025em; line-height:1.1; color:var(--text);
  font-variant-numeric:tabular-nums; }
.kpi__meta{ font-size:11.5px; color:var(--muted); display:flex; align-items:center; gap:6px; flex-wrap:wrap; }
.kpi__unit{ font-size:12px; font-weight:500; color:var(--muted); margin-left:3px; }

/* tone helpers used by KPI icons, chips, etc. */
.t-green{ background:var(--green-bg); color:var(--green); }
.t-red{ background:var(--red-bg); color:var(--red); }
.t-amber{ background:var(--amber-bg); color:var(--amber); }
.t-blue{ background:var(--blue-bg); color:var(--blue); }
.t-violet{ background:var(--violet-bg); color:var(--violet); }
.t-teal{ background:var(--teal-bg); color:var(--teal); }
.t-cyan{ background:var(--cyan-bg); color:var(--cyan); }
.t-orange{ background:var(--orange-bg); color:var(--orange); }
.t-indigo{ background:var(--indigo-bg); color:var(--indigo); }
.t-slate{ background:var(--slate-bg); color:var(--slate); }

/* ---------- 9. Badges & chips ---------- */
.badge{
  display:inline-flex; align-items:center; gap:5px; padding:2px 9px; border-radius:20px;
  font-size:11.5px; font-weight:600; line-height:19px; white-space:nowrap; border:1px solid transparent;
}
.badge--green{ background:var(--green-bg); color:var(--green); border-color:var(--green-bd); }
.badge--red{ background:var(--red-bg); color:var(--red); border-color:var(--red-bd); }
.badge--amber{ background:var(--amber-bg); color:var(--amber); border-color:var(--amber-bd); }
.badge--blue{ background:var(--blue-bg); color:var(--blue); border-color:var(--blue-bd); }
.badge--violet{ background:var(--violet-bg); color:var(--violet); border-color:var(--violet-bd); }
.badge--teal,.badge--cyan{ background:var(--teal-bg); color:var(--teal); border-color:var(--teal-bd); }
.badge--orange{ background:var(--orange-bg); color:var(--orange); border-color:var(--orange-bd); }
.badge--indigo{ background:var(--indigo-bg); color:var(--indigo); border-color:var(--indigo-bd); }
.badge--slate{ background:var(--slate-bg); color:var(--slate); border-color:var(--slate-bd); }
.badge--dot::before{ content:""; width:6px; height:6px; border-radius:50%; background:currentColor; }

.chip{
  display:inline-flex; align-items:center; gap:6px; height:28px; padding:0 10px;
  border-radius:20px; background:var(--surface-3); color:var(--text-2);
  font-size:12px; font-weight:550; border:1px solid var(--border);
}
.chip a,.chip button{ color:var(--muted); background:none; border:0; cursor:pointer; display:grid; place-items:center; padding:0; }
.chip a:hover,.chip button:hover{ color:var(--red); }

/* ---------- 10. Tables ---------- */
.table-wrap{ width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
.table{ width:100%; border-collapse:separate; border-spacing:0; font-size:13.3px; min-width:640px; }
.table th{
  text-align:left; font-weight:600; font-size:11.5px; letter-spacing:.03em; text-transform:uppercase;
  color:var(--muted); background:var(--surface-2); padding:10px 14px; white-space:nowrap;
  border-bottom:1px solid var(--border); position:sticky; top:0; z-index:2;
}
.table td{ padding:11px 14px; border-bottom:1px solid var(--border); vertical-align:middle; color:var(--text-2); }
.table tbody tr:hover td{ background:var(--surface-2); }
.table tbody tr:last-child td{ border-bottom:0; }
.table .num{ text-align:right; font-variant-numeric:tabular-nums; }
.table .nowrap{ white-space:nowrap; }
.table__primary{ color:var(--text); font-weight:600; }
.table__sub{ display:block; font-size:11.5px; color:var(--muted); font-weight:400; margin-top:1px; }
.table--compact td{ padding:8px 12px; }
.th-sort{ color:inherit; display:inline-flex; gap:3px; align-items:center; }
.th-sort:hover{ color:var(--accent); }
.th-sort__ind{ font-size:8px; color:var(--accent); }
.table-actions{ display:flex; gap:4px; justify-content:flex-end; }

.empty{ padding:52px 20px; text-align:center; color:var(--muted); }
.empty__ico{ width:52px; height:52px; border-radius:14px; background:var(--surface-3); color:var(--faint);
  display:grid; place-items:center; margin:0 auto 14px; }
.empty h3{ font-size:15px; margin-bottom:5px; }
.empty p{ font-size:13px; max-width:380px; margin:0 auto 16px; }

/* mobile card list (tables convert to these) */
.mcards{ display:none; }
.mcard{
  background:var(--surface); border:1px solid var(--border); border-radius:var(--r);
  padding:13px 14px; margin-bottom:10px; box-shadow:var(--sh-xs);
}
.mcard__top{ display:flex; align-items:flex-start; gap:10px; margin-bottom:9px; }
.mcard__title{ font-weight:650; font-size:14px; color:var(--text); }
.mcard__sub{ font-size:12px; color:var(--muted); margin-top:2px; }
.mcard__grid{ display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:9px 12px; }
.mcard__k{ font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; color:var(--faint); font-weight:600; }
.mcard__v{ font-size:13px; color:var(--text); font-weight:550; }
.mcard__foot{ margin-top:11px; padding-top:10px; border-top:1px solid var(--border);
  display:flex; gap:8px; justify-content:flex-end; }

/* ---------- 11. Pagination ---------- */
.pager{ display:flex; align-items:center; gap:12px; padding:12px 16px; border-top:1px solid var(--border);
  flex-wrap:wrap; background:var(--surface); }
.pager__info{ font-size:12.5px; color:var(--muted); }
.pager__btns{ margin-left:auto; display:flex; gap:4px; align-items:center; }
.pager__btn{ min-width:32px; height:32px; padding:0 9px; border-radius:var(--r-xs); display:grid; place-items:center;
  font-size:12.5px; font-weight:550; color:var(--text-2); border:1px solid var(--border); background:var(--surface); }
.pager__btn:hover{ background:var(--surface-3); color:var(--text); }
.pager__btn.is-active{ background:var(--accent); border-color:var(--accent); color:#fff; }
.pager__btn.is-disabled{ opacity:.45; pointer-events:none; }
.pager__dots{ color:var(--faint); padding:0 2px; }

/* ---------- 12. Forms ---------- */
.form-grid{ display:grid; grid-template-columns:repeat(auto-fill,minmax(240px,1fr)); gap:15px; }
.form-grid--2{ grid-template-columns:repeat(2,minmax(0,1fr)); }
.field{ display:flex; flex-direction:column; gap:6px; min-width:0; }
.field--wide{ grid-column:1 / -1; }
.field--span2{ grid-column:span 2; }
.label{ font-size:12.5px; font-weight:600; color:var(--text-2); display:flex; align-items:center; gap:5px; }
.label .req{ color:var(--red); }
.hint{ font-size:11.5px; color:var(--muted); }
.input,.select,.textarea{
  width:100%; min-height:40px; padding:9px 12px; font-size:13.5px; font-family:inherit; color:var(--text);
  background:var(--surface); border:1px solid var(--border-strong); border-radius:var(--r-sm);
  transition:border .12s, box-shadow .12s;
}
.input::placeholder,.textarea::placeholder{ color:var(--faint); }
.input:focus,.select:focus,.textarea:focus{ outline:none; border-color:var(--accent);
  box-shadow:0 0 0 3px var(--accent-soft); }
.input[readonly],.input[disabled],.select[disabled]{ background:var(--surface-3); color:var(--muted); }
.textarea{ min-height:88px; resize:vertical; }
.select{ appearance:none; padding-right:34px;
  background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23737c8f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9.5 12 15.5 18 9.5'/%3E%3C/svg%3E");
  background-repeat:no-repeat; background-position:right 11px center; }
.input--err,.select--err{ border-color:var(--red); }
.err-text{ font-size:11.5px; color:var(--red); }
.input-group{ display:flex; }
.input-group .input{ border-radius:var(--r-sm) 0 0 var(--r-sm); }
.input-group .btn{ border-radius:0 var(--r-sm) var(--r-sm) 0; border-left:0; height:auto; }

.check{ display:flex; align-items:center; gap:9px; cursor:pointer; font-size:13.5px; color:var(--text-2); }
.check input{ width:17px; height:17px; accent-color:var(--accent); cursor:pointer; }
.switchbox{ display:flex; align-items:center; gap:10px; padding:10px 12px; border:1px solid var(--border);
  border-radius:var(--r-sm); background:var(--surface-2); }

.form-section{ margin-bottom:6px; }
.form-section__title{ font-size:12px; font-weight:700; letter-spacing:.06em; text-transform:uppercase;
  color:var(--faint); padding-bottom:9px; margin-bottom:14px; border-bottom:1px solid var(--border); }
.form-actions{
  display:flex; gap:9px; justify-content:flex-end; padding:14px 16px; border-top:1px solid var(--border);
  background:var(--surface-2); position:sticky; bottom:0; z-index:5;
}

/* file dropzone */
.dropzone{
  border:1.5px dashed var(--border-strong); border-radius:var(--r); padding:22px; text-align:center;
  background:var(--surface-2); cursor:pointer; transition:border .15s, background .15s;
}
.dropzone:hover,.dropzone.is-over{ border-color:var(--accent); background:var(--accent-softer); }
.dropzone__ico{ width:40px; height:40px; border-radius:11px; background:var(--accent-soft); color:var(--accent);
  display:grid; place-items:center; margin:0 auto 10px; }
.dropzone p{ font-size:13px; color:var(--text-2); margin:0; }
.dropzone small{ font-size:11.5px; color:var(--muted); }

/* filter bar */
.filters{ display:flex; gap:9px; flex-wrap:wrap; align-items:flex-end; }
.filters .field{ min-width:145px; flex:1 1 145px; }
.filters .field--sm{ flex:0 0 130px; }
.filters__actions{ display:flex; gap:8px; }

/* ---------- 13. Flash / callouts ---------- */
.flash-stack{ position:fixed; top:14px; right:14px; z-index:200; display:flex; flex-direction:column; gap:9px;
  max-width:min(420px,92vw); }
.flash{
  display:flex; align-items:flex-start; gap:10px; padding:12px 14px; border-radius:var(--r);
  background:var(--surface); border:1px solid var(--border); box-shadow:var(--sh-lg);
  font-size:13.3px; animation:flashIn .2s ease;
}
@keyframes flashIn{ from{ opacity:0; transform:translateX(14px);} to{ opacity:1; transform:none;} }
.flash--success{ border-left:3px solid var(--green); }
.flash--danger{ border-left:3px solid var(--red); }
.flash--warning{ border-left:3px solid var(--amber); }
.flash--info{ border-left:3px solid var(--blue); }
.flash__x{ margin-left:auto; background:none; border:0; color:var(--faint); cursor:pointer; padding:0; }

.callout{ display:flex; gap:10px; padding:12px 14px; border-radius:var(--r-sm); font-size:13px;
  border:1px solid; align-items:flex-start; }
.callout--warning{ background:var(--amber-bg); border-color:var(--amber-bd); color:var(--amber); }
.callout--danger{ background:var(--red-bg); border-color:var(--red-bd); color:var(--red); }
.callout--info{ background:var(--blue-bg); border-color:var(--blue-bd); color:var(--blue); }
.callout--success{ background:var(--green-bg); border-color:var(--green-bd); color:var(--green); }
.callout strong{ display:block; margin-bottom:2px; }
.callout ul{ margin:4px 0 0; padding-left:18px; }

/* ---------- 14. Modal ---------- */
.modal-backdrop{
  position:fixed; inset:0; background:rgba(16,24,40,.45); backdrop-filter:blur(2px);
  z-index:150; display:none; align-items:center; justify-content:center; padding:16px;
}
.modal-backdrop.is-open{ display:flex; animation:fadeIn .14s ease; }
@keyframes fadeIn{ from{opacity:0} to{opacity:1} }
.modal{
  width:min(560px,100%); max-height:90vh; display:flex; flex-direction:column;
  background:var(--surface); border-radius:var(--r-lg); box-shadow:var(--sh-lg);
  animation:modalIn .18s cubic-bezier(.2,.8,.3,1);
}
.modal--lg{ width:min(820px,100%); }
@keyframes modalIn{ from{ opacity:0; transform:translateY(12px) scale(.985);} to{ opacity:1; transform:none;} }
.modal__head{ padding:16px 18px; border-bottom:1px solid var(--border); display:flex; align-items:center; gap:10px; }
.modal__head h3{ font-size:16px; }
.modal__body{ padding:18px; overflow-y:auto; }
.modal__foot{ padding:14px 18px; border-top:1px solid var(--border); display:flex; gap:9px; justify-content:flex-end;
  background:var(--surface-2); border-radius:0 0 var(--r-lg) var(--r-lg); }

/* ---------- 15. Progress & timeline ---------- */
.progress{ height:7px; border-radius:6px; background:var(--surface-3); overflow:hidden; min-width:70px; }
.progress__fill{ height:100%; border-radius:6px; transition:width .5s cubic-bezier(.3,.9,.3,1); }
.progress__fill--blue{ background:var(--blue); }
.progress__fill--indigo{ background:var(--indigo); }
.progress__fill--violet{ background:var(--violet); }
.progress__fill--green{ background:var(--green); }
.progress__fill--amber{ background:var(--amber); }
.progress__fill--red{ background:var(--red); }

.stagegrid{ display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:0; }
.stage{ padding:16px; border-right:1px solid var(--border); position:relative; }
.stage:last-child{ border-right:0; }
.stage__top{ display:flex; align-items:center; gap:9px; margin-bottom:10px; }
.stage__ico{ width:30px; height:30px; border-radius:9px; display:grid; place-items:center; flex:none; }
.stage__label{ font-size:12px; color:var(--muted); font-weight:600; text-transform:uppercase; letter-spacing:.04em; }
.stage__qty{ font-size:23px; font-weight:680; letter-spacing:-.025em; font-variant-numeric:tabular-nums; color:var(--text); }
.stage__unit{ font-size:12px; color:var(--muted); font-weight:500; margin-left:4px; }
.stage__pct{ display:flex; justify-content:space-between; font-size:11.5px; color:var(--muted); margin:9px 0 5px; }
.stage__arrow{ position:absolute; right:-9px; top:22px; width:18px; height:18px; border-radius:50%;
  background:var(--surface); border:1px solid var(--border); display:grid; place-items:center;
  color:var(--faint); z-index:2; }

.timeline{ position:relative; padding-left:26px; }
.timeline::before{ content:""; position:absolute; left:8px; top:6px; bottom:6px; width:2px; background:var(--border); }
.tl-item{ position:relative; padding-bottom:18px; }
.tl-item:last-child{ padding-bottom:0; }
.tl-item__dot{ position:absolute; left:-24px; top:3px; width:18px; height:18px; border-radius:50%;
  display:grid; place-items:center; border:2px solid var(--surface); }
.tl-item__title{ font-size:13.5px; font-weight:620; color:var(--text); }
.tl-item__meta{ font-size:12px; color:var(--muted); margin-top:2px; }

/* pending action rows */
.pending-row{
  display:flex; align-items:center; gap:12px; padding:12px 14px; border-radius:var(--r-sm);
  border:1px solid var(--border); background:var(--surface); margin-bottom:9px; transition:border .12s, box-shadow .12s;
}
.pending-row:hover{ border-color:var(--accent-border); box-shadow:var(--sh-sm); }
.pending-row__dot{ width:9px; height:9px; border-radius:50%; flex:none; }
.pending-row__label{ font-size:13.5px; color:var(--text); font-weight:520; }
.pending-row__count{ margin-left:auto; font-size:17px; font-weight:680; font-variant-numeric:tabular-nums; }

/* alerts list */
.alert-item{ display:flex; gap:12px; padding:13px 15px; border-bottom:1px solid var(--border); }
.alert-item:last-child{ border-bottom:0; }
.alert-item.is-unread{ background:var(--accent-softer); }
.alert-item__ico{ width:32px; height:32px; border-radius:9px; display:grid; place-items:center; flex:none; }
.alert-item__title{ font-size:13.5px; font-weight:620; color:var(--text); }
.alert-item__msg{ font-size:12.8px; color:var(--text-2); margin-top:2px; }
.alert-item__meta{ font-size:11.5px; color:var(--faint); margin-top:5px; display:flex; gap:10px; flex-wrap:wrap; }
.alert-item__side{ margin-left:auto; display:flex; flex-direction:column; align-items:flex-end; gap:7px; flex:none; }

/* ---------- 16. Misc ---------- */
.chart-box{ position:relative; height:280px; }
.chart-box--sm{ height:230px; }
.stat-line{ display:flex; align-items:center; justify-content:space-between; padding:9px 0;
  border-bottom:1px dashed var(--border); font-size:13px; }
.stat-line:last-child{ border-bottom:0; }
.stat-line__k{ color:var(--muted); }
.stat-line__v{ font-weight:620; color:var(--text); font-variant-numeric:tabular-nums; }

.deffs{ display:grid; grid-template-columns:repeat(auto-fill,minmax(190px,1fr)); gap:14px 18px; }
.deff__k{ font-size:11px; text-transform:uppercase; letter-spacing:.05em; color:var(--faint); font-weight:650; }
.deff__v{ font-size:13.6px; color:var(--text); margin-top:3px; word-break:break-word; }

.doc-item{ display:flex; align-items:center; gap:11px; padding:10px 12px; border:1px solid var(--border);
  border-radius:var(--r-sm); margin-bottom:8px; background:var(--surface); }
.doc-item__ext{ width:38px; height:38px; border-radius:9px; display:grid; place-items:center;
  font-size:10.5px; font-weight:700; text-transform:uppercase; flex:none; }
.doc-item__name{ font-size:13.2px; font-weight:550; color:var(--text); word-break:break-all; }
.doc-item__meta{ font-size:11.5px; color:var(--muted); }
.doc-item__act{ margin-left:auto; display:flex; gap:5px; }

.tabs{ display:flex; gap:3px; border-bottom:1px solid var(--border); overflow-x:auto; }
.tab{ padding:10px 14px; font-size:13.3px; font-weight:550; color:var(--muted); border-bottom:2px solid transparent;
  white-space:nowrap; }
.tab:hover{ color:var(--text); }
.tab.is-active{ color:var(--accent); border-bottom-color:var(--accent); }

.quick-actions{ display:grid; grid-template-columns:repeat(auto-fill,minmax(118px,1fr)); gap:10px; }
.qa{ display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px;
  padding:15px 8px; border-radius:var(--r); border:1px solid var(--border); background:var(--surface);
  color:var(--text-2); font-size:12.3px; font-weight:550; text-align:center; transition:all .14s; }
.qa:hover{ border-color:var(--accent-border); background:var(--accent-softer); color:var(--accent-text);
  transform:translateY(-1px); box-shadow:var(--sh-sm); }
.qa__ico{ width:36px; height:36px; border-radius:10px; display:grid; place-items:center; }

.mono{ font-family:var(--mono); font-size:12.5px; }
.muted{ color:var(--muted); }
.small{ font-size:12px; }
.strong{ font-weight:650; color:var(--text); }
.right{ text-align:right; } .center{ text-align:center; }
.nowrap{ white-space:nowrap; }
.flex{ display:flex; } .items-center{ align-items:center; } .gap-6{ gap:6px; } .gap-10{ gap:10px; }
.mt-0{margin-top:0}.mt-8{margin-top:8px}.mt-14{margin-top:14px}.mt-20{margin-top:20px}
.mb-0{margin-bottom:0}.mb-8{margin-bottom:8px}.mb-14{margin-bottom:14px}.mb-20{margin-bottom:20px}
.hide{ display:none !important; }
.spin{ animation:spin 1s linear infinite; }
@keyframes spin{ to{ transform:rotate(360deg);} }

.link-row{ color:var(--text); }
.link-row:hover{ color:var(--accent); }

/* mobile bottom nav + drawer scrim */
.scrim{ position:fixed; inset:0; background:rgba(16,24,40,.45); z-index:55; display:none; }
.scrim.is-open{ display:block; }
.bottomnav{ display:none; }

/* ---------- 17. Responsive ---------- */
@media (max-width:1200px){
  .grid--sidebarwide{ grid-template-columns:1fr; }
  .grid--4{ grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:1024px){
  .sidebar{ transform:translateX(-100%); box-shadow:var(--sh-lg); width:270px; }
  .app.is-drawer .sidebar{ transform:none; }
  .main{ margin-left:0 !important; }
  .app.is-collapsed .sidebar{ width:270px; }
  .app.is-collapsed .brand__name,.app.is-collapsed .nav__text,
  .app.is-collapsed .nav__label,.app.is-collapsed .nav__caret{ display:block; }
  .app.is-collapsed .nav__item{ justify-content:flex-start; padding:9px 11px; }
  .app.is-collapsed .nav__sub{ display:block; }
  .app.is-collapsed .sidebar__brand{ justify-content:flex-start; padding:0 16px; }
  .grid--3{ grid-template-columns:repeat(2,minmax(0,1fr)); }
  .stagegrid{ grid-template-columns:repeat(2,minmax(0,1fr)); }
  .stage:nth-child(2){ border-right:0; }
  .stage:nth-child(1),.stage:nth-child(2){ border-bottom:1px solid var(--border); }
  .stage__arrow{ display:none; }
}
@media (max-width:768px){
  .page{ padding:15px 14px 90px; }
  .topbar{ padding:0 12px; gap:8px; }
  .topbar__title{ font-size:15px; }
  .search{ display:none; }
  .search.is-mobile-open{
    display:block; position:absolute; left:10px; right:10px; top:11px; width:auto; z-index:45;
  }
  .grid--kpi{ grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
  .grid--2,.grid--3,.grid--4{ grid-template-columns:1fr; }
  .kpi{ padding:13px; }
  .kpi__value{ font-size:22px; }
  .form-grid,.form-grid--2{ grid-template-columns:1fr; }
  .field--span2{ grid-column:auto; }
  .page__actions{ width:100%; margin-left:0; }
  .page__actions .btn{ flex:1; }
  .btn{ height:40px; }
  .btn--sm{ height:34px; }
  .modal__foot{ flex-direction:column-reverse; }
  .modal__foot .btn{ width:100%; }
  .form-actions{ flex-direction:column-reverse; }
  .form-actions .btn{ width:100%; }
  .pop__panel--wide{ position:fixed; left:8px; right:8px; top:64px; min-width:0; max-width:none; }
  .filters .field{ flex:1 1 100%; }
  .filters__actions{ width:100%; }
  .filters__actions .btn{ flex:1; }
  .quick-actions{ grid-template-columns:repeat(3,minmax(0,1fr)); }
  .deffs{ grid-template-columns:repeat(2,minmax(0,1fr)); }

  /* tables -> cards where the page provides them */
  .table-wrap.mobile-cards{ display:none; }
  .mcards{ display:block; }

  .bottomnav{
    display:flex; position:fixed; left:0; right:0; bottom:0; z-index:50; height:60px;
    background:color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter:saturate(180%) blur(12px);
    border-top:1px solid var(--border);
    padding-bottom:env(safe-area-inset-bottom);
  }
  .bottomnav a{
    flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:3px;
    font-size:10.5px; font-weight:550; color:var(--muted); position:relative;
  }
  .bottomnav a.is-active{ color:var(--accent); }
  .bottomnav a .bn-dot{ position:absolute; top:8px; right:calc(50% - 17px); min-width:15px; height:15px;
    padding:0 4px; background:var(--red); color:#fff; font-size:9.5px; font-weight:700; border-radius:8px;
    display:grid; place-items:center; }
  .stagegrid{ grid-template-columns:1fr; }
  .stage{ border-right:0; border-bottom:1px solid var(--border); }
  .stage:last-child{ border-bottom:0; }
}
@media (max-width:420px){
  .grid--kpi{ grid-template-columns:repeat(2,minmax(0,1fr)); }
  .quick-actions{ grid-template-columns:repeat(2,minmax(0,1fr)); }
  .deffs{ grid-template-columns:1fr; }
}

/* ---------- 18. Print ---------- */
@media print{
  .sidebar,.topbar,.bottomnav,.page__actions,.form-actions,.pager,.filters,.flash-stack{ display:none !important; }
  .main{ margin:0 !important; }
  .page{ padding:0; }
  .card{ box-shadow:none; border-color:#ddd; break-inside:avoid; }
  body{ background:#fff; }
}

/* ---------- 19. Login ---------- */
.auth{ min-height:100vh; display:grid; grid-template-columns:1fr 1fr; }
.auth__side{
  background:linear-gradient(150deg,#312e81 0%,#4f46e5 55%,#6d67ec 100%);
  color:#fff; padding:48px; display:flex; flex-direction:column; justify-content:space-between; position:relative; overflow:hidden;
}
.auth__side::after{
  content:""; position:absolute; right:-120px; bottom:-120px; width:420px; height:420px;
  border-radius:50%; background:rgba(255,255,255,.07);
}
.auth__side::before{
  content:""; position:absolute; left:-90px; top:-60px; width:280px; height:280px;
  border-radius:50%; background:rgba(255,255,255,.06);
}
.auth__brand{ display:flex; align-items:center; gap:11px; font-size:17px; font-weight:650; position:relative; z-index:1; }
.auth__brand .brand__mark{ background:rgba(255,255,255,.18); box-shadow:none; }
.auth__pitch{ position:relative; z-index:1; max-width:420px; }
.auth__pitch h2{ color:#fff; font-size:29px; line-height:1.25; letter-spacing:-.02em; margin-bottom:12px; }
.auth__pitch p{ color:rgba(255,255,255,.82); font-size:14.5px; }
.auth__steps{ display:flex; flex-wrap:wrap; gap:8px; margin-top:22px; }
.auth__step{ font-size:12px; padding:5px 11px; border-radius:20px; background:rgba(255,255,255,.14);
  border:1px solid rgba(255,255,255,.18); }
.auth__foot{ position:relative; z-index:1; font-size:12.5px; color:rgba(255,255,255,.7); }
.auth__main{ display:grid; place-items:center; padding:32px; background:var(--surface); }
.auth__card{ width:min(400px,100%); }
.auth__card h1{ font-size:24px; margin-bottom:6px; }
.auth__card > p{ color:var(--muted); font-size:13.5px; margin-bottom:24px; }
@media (max-width:900px){
  .auth{ grid-template-columns:1fr; }
  .auth__side{ display:none; }
  .auth__main{ background:var(--bg); align-items:flex-start; padding-top:8vh; }
  .auth__card{ background:var(--surface); border:1px solid var(--border); border-radius:var(--r-lg);
    padding:26px 22px; box-shadow:var(--sh-md); }
}

/* ---------- 20. Install wizard ---------- */
.installer{ max-width:760px; margin:5vh auto; padding:0 16px 60px; }
.step-dots{ display:flex; gap:8px; margin-bottom:22px; }
.step-dot{ flex:1; height:4px; border-radius:3px; background:var(--border); }
.step-dot.is-done{ background:var(--accent); }
.checklist{ list-style:none; padding:0; margin:0; }
.checklist li{ display:flex; align-items:center; gap:10px; padding:10px 0; border-bottom:1px solid var(--border); font-size:13.5px; }
.checklist li:last-child{ border-bottom:0; }
