/* =============================================================================
   ST Courier ERP Demo — application styles
   -----------------------------------------------------------------------------
   Sections (search for "==== " to jump):
     1. Reset & base typography
     2. Shell layout: sidebar, topbar, main, help panel
     3. Sidebar navigation
     4. Topbar pieces: pills, bell dropdown, search
     5. Login page & role switcher
     6. Buttons & links
     7. Inputs, fields, forms
     8. Page, section, card, KPI
     9. Tables
    10. Chips, badges, tags, dots
    11. Modal, drawer, toast
    12. Timeline, tabs, steps, progress, stats, kv, empty, avatar, heat
    13. Scan box
    14. Help system: eye buttons, popover, panel, glossary, banner
    15. Guided tour
    16. Global search dropdown (base rules live in section 4)
    17. Geo map
    18. Phone frame (delivery app)
    19. Print preview on screen
    20. Charts
    21. Utilities
    22. Responsive rules (1200 / 900 / 600)
    23. Public tracking page & print-hidden helpers
   All class names follow §17 of ARCHITECTURE.md exactly.
   ============================================================================= */

/* ==== 1. Reset & base ====================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
body.app-mode { overflow: hidden; height: 100vh; }
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; line-height: var(--lh-tight); color: var(--text); }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
h4 { font-size: var(--fs-base); }
p { margin: 0 0 var(--s2); }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0 0 var(--s2); padding-left: 20px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
strong, b { font-weight: 600; }
small { font-size: var(--fs-sm); }
code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.93em; }
kbd {
  display: inline-block; padding: 0 5px; border: 1px solid var(--border-strong); border-bottom-width: 2px;
  border-radius: 4px; background: var(--surface-2); font-size: var(--fs-xs); line-height: 16px; color: var(--text-muted);
}
pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s3); overflow: auto; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s4) 0; }
img, svg { max-width: 100%; }
svg { display: inline-block; vertical-align: middle; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; margin: 0; }
button:disabled { cursor: not-allowed; }
:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
::selection { background: var(--accent-soft); color: var(--text); }
::placeholder { color: var(--text-faint); opacity: 1; }
table { border-collapse: collapse; border-spacing: 0; }
[hidden] { display: none !important; }
noscript { display: block; padding: var(--s6); text-align: center; }

/* Thin, unobtrusive scrollbars that still work everywhere. */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* Brand mark: the ST Courier globe logo. */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: #fff; overflow: hidden;
  box-shadow: 0 1px 3px rgba(12, 36, 84, 0.18);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-text strong { font-size: var(--fs-md); font-weight: 700; white-space: nowrap; }
.brand-text small { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.brand-lg .brand-mark { width: 56px; height: 56px; }
.brand-lg .brand-text strong { font-size: var(--fs-xl); }
.brand-lg .brand-text small { font-size: var(--fs-sm); }

/* ==== 2. Shell layout ======================================================= */
#app { min-height: 100vh; }
body.app-mode #app { height: 100vh; }
.app-layout { display: flex; height: 100vh; width: 100%; position: relative; }

/* Sidebar: fixed left column, own scroll. */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: var(--z-sidebar);
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: width var(--transition-slow), transform var(--transition-slow);
  overflow: hidden;
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  height: var(--topbar-h); padding: 0 var(--s3) 0 var(--s4); flex: none;
  border-bottom: 1px solid var(--border);
}
.sidebar-nav { flex: 1; overflow-y: auto; overflow-x: hidden; padding: var(--s2) var(--s2) var(--s4); }
.sidebar-foot { flex: none; padding: var(--s2); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--s1); background: var(--surface); }

/* Body column beside the sidebar; topbar fixed height, main scrolls. */
.app-body {
  flex: 1; min-width: 0; height: 100vh;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  transition: margin-left var(--transition-slow);
}
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar); flex: none;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.main {
  flex: 1; min-height: 0; overflow: auto;
  padding: var(--main-pad);
  background: var(--bg);
  scroll-behavior: smooth;
}

/* Help panel: docked right, pushes content on wide screens. */
.help-panel {
  flex: none; width: 0; overflow: hidden; height: 100vh;
  background: var(--surface); border-left: 1px solid var(--border);
  transition: width var(--transition-slow);
  display: flex; flex-direction: column;
  z-index: var(--z-help);
}
body.help-open .help-panel { width: var(--help-w); overflow-y: auto; }
.help-panel > * { min-width: calc(var(--help-w) - 1px); }
.help-panel-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: var(--s2);
  height: var(--topbar-h); padding: 0 var(--s3) 0 var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.help-panel-head strong { flex: 1; font-size: var(--fs-md); }
.help-panel .help-body { padding: var(--s4); }
.help-panel .help-roleguide { margin: 0 var(--s4) var(--s4); padding: var(--s3) var(--s4); background: var(--accent-soft); border-radius: var(--radius); }
.help-panel .help-roleguide .help-label { color: var(--accent-text); }

/* Collapsed sidebar: icons only, tooltips via title attribute. */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .app-body { margin-left: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar-brand { padding: 0; justify-content: center; flex-direction: column; height: auto; padding: var(--s2) 0; gap: var(--s1); }
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-caret,
body.sidebar-collapsed .nav-sub,
body.sidebar-collapsed .nav-group-label,
body.sidebar-collapsed .user-chip-text { display: none; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 0; height: 40px; }
body.sidebar-collapsed .nav-module.active .nav-item::before { left: 0; }
body.sidebar-collapsed .sidebar-nav { padding: var(--s2) var(--s1); }
body.sidebar-collapsed .sidebar-foot .btn-block { padding: 0; }
body.sidebar-collapsed .sidebar-foot .btn-block span + * { display: none; }
body.sidebar-collapsed .user-chip { justify-content: center; padding: var(--s1); }
body.sidebar-collapsed .user-chip .nav-caret { display: none; }
.sidebar-toggle { color: var(--text-muted); }

/* ==== 3. Sidebar navigation ================================================ */
.nav-group-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); padding: var(--s3) var(--s3) var(--s1); margin-top: var(--s1);
  white-space: nowrap; overflow: hidden;
}
.nav-group-label:first-child { margin-top: 0; }
.nav-module { position: relative; margin-bottom: 1px; }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 34px; padding: 0 var(--s3) 0 14px;
  border-radius: var(--radius-sm);
  color: var(--text-muted); font-weight: 500; font-size: var(--fs-base);
  text-decoration: none; white-space: nowrap; overflow: hidden;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item::before {
  content: ''; position: absolute; left: 2px; top: 7px; bottom: 7px; width: 3px; border-radius: 3px;
  background: var(--primary); opacity: 0; transform: scaleY(0.4); transition: opacity var(--transition), transform var(--transition);
}
.nav-module.active > .nav-item { background: var(--primary-soft); color: var(--text); font-weight: 700; }
.nav-module.active > .nav-item::before { opacity: 1; transform: scaleY(1); }
.nav-module.active > .nav-item .nav-icon { color: var(--primary); }
.nav-icon { display: inline-flex; width: 18px; height: 18px; align-items: center; justify-content: center; flex: none; color: var(--text-faint); }
.nav-icon svg { width: 18px; height: 18px; }
.nav-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-caret { display: inline-flex; color: var(--text-faint); transition: transform var(--transition-slow); }
.nav-caret svg { width: 14px; height: 14px; }
.nav-module.active > .nav-item .nav-caret { transform: rotate(180deg); }
.nav-sub { display: none; flex-direction: column; padding: 2px 0 4px 0; }
.nav-module.active > .nav-sub { display: flex; }
.nav-subitem {
  display: block; padding: 5px 10px 5px 42px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: var(--fs-sm); text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: relative;
  transition: background var(--transition), color var(--transition);
}
.nav-subitem::before { content: ''; position: absolute; left: 24px; top: 50%; width: 4px; height: 4px; border-radius: 50%; background: var(--border-strong); transform: translateY(-50%); }
.nav-subitem:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-subitem.active { color: var(--primary-text); font-weight: 600; background: transparent; }
.nav-subitem.active::before { background: var(--primary); width: 6px; height: 6px; left: 23px; }

/* Sidebar footer user chip (opens role switcher). */
.user-chip {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: var(--s2); border-radius: var(--radius); text-align: left;
  transition: background var(--transition);
}
.user-chip:hover { background: var(--surface-3); }
.user-chip-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.2; }
.user-chip-text strong { font-size: var(--fs-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-text small { color: var(--text-muted); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ==== 4. Topbar pieces ===================================================== */
.topbar-left { display: flex; align-items: center; gap: var(--s2); min-width: 0; flex: 0 1 auto; }
.topbar-menu { display: none; }
.topbar-title { font-size: var(--fs-lg); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-center { flex: 1; display: flex; justify-content: center; min-width: 0; }
.topbar-center .search { width: 100%; max-width: 560px; }
.topbar-right { display: flex; align-items: center; gap: var(--s1); flex: none; }
.topbar-right .icon-btn { color: var(--text-muted); }

.scope-pill, .clock-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px 0 8px;
  border-radius: var(--radius-pill); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
  border: 1px solid var(--border); color: var(--text-muted); background: var(--surface-2);
}
.scope-pill { color: var(--accent-text); background: var(--accent-soft); border-color: transparent; font-weight: 600; }
.scope-pill svg, .clock-pill svg { width: 14px; height: 14px; }
.clock-pill { font-family: var(--mono); font-size: var(--fs-xs); }

/* Notification bell with count and dropdown. */
.topbar-bell { position: relative; display: inline-flex; }
.bell-count {
  position: absolute; top: 1px; right: 1px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-pill); background: var(--primary); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; pointer-events: none;
  box-shadow: 0 0 0 2px var(--surface);
}
.bell-count:empty { display: none; }
.bell-dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: var(--z-dropdown);
  width: 360px; max-width: calc(100vw - 24px); padding: 0;
  box-shadow: var(--shadow-lg); animation: dropIn var(--transition-slow) both;
}
.bell-head { display: flex; align-items: center; gap: var(--s2); padding: 10px var(--s3); border-bottom: 1px solid var(--border); }
.bell-head strong { flex: 1; }
.bell-item {
  display: flex; align-items: center; gap: 10px; padding: 9px var(--s3);
  color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.bell-item:last-child { border-bottom: 0; }
.bell-item:hover { background: var(--surface-2); text-decoration: none; }
.bell-text { flex: 1; min-width: 0; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bell-item small { flex: none; }
@keyframes dropIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Global search with suggestion dropdown. */
.search { position: relative; }
.search-input {
  width: 100%; height: var(--control-h); padding: 0 var(--s3) 0 34px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text); font-size: var(--fs-base);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.search-input:focus { background: var(--surface); border-color: var(--accent); box-shadow: var(--focus); border-radius: var(--radius-pill); }
.search > svg, .search > .search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); pointer-events: none; }
.search-suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: var(--z-dropdown);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 380px; overflow: auto; padding: var(--s1);
  animation: dropIn var(--transition-slow) both;
}
.search-suggest:empty { display: none; }
.search-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
  border-radius: var(--radius-sm); color: var(--text); text-align: left; font-size: var(--fs-base);
  text-decoration: none; cursor: pointer; transition: background var(--transition);
}
.search-item:hover, .search-item.active, .search-item:focus-visible { background: var(--surface-3); text-decoration: none; box-shadow: none; }
.search-item-icon { display: inline-flex; width: 26px; height: 26px; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-muted); flex: none; }
.search-item-icon svg { width: 14px; height: 14px; }

/* ==== 5. Login page & role switcher ======================================== */
body.login-mode { overflow: auto; }
.login-page { display: grid; grid-template-columns: minmax(380px, 460px) 1fr; min-height: 100vh; background: var(--bg); }

/* ---- left column: brand, sign-in, links ---- */
.login-hero {
  position: sticky; top: 0; height: 100vh; overflow: auto;
  display: flex; flex-direction: column; gap: var(--s4);
  padding: var(--s6) var(--s6) var(--s5);
  background:
    radial-gradient(120% 60% at 0% 0%, color-mix(in srgb, var(--primary) 7%, transparent), transparent 60%),
    radial-gradient(90% 50% at 100% 100%, color-mix(in srgb, var(--accent) 6%, transparent), transparent 55%),
    var(--surface);
  border-right: 1px solid var(--border);
}
.login-hero::-webkit-scrollbar { width: 0; }
.login-brand { display: flex; align-items: center; gap: var(--s4); }
.brand-mark-xl { width: 76px !important; height: 76px !important; box-shadow: 0 4px 16px rgba(12, 36, 84, 0.16) !important; }
.login-brand-text h1 {
  font-size: 30px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.05; margin: 0;
  color: var(--primary);
}
.login-brand-text p {
  margin: 3px 0 0; font-size: var(--fs-sm); font-weight: 600; letter-spacing: 0.16em;
  text-transform: uppercase; color: var(--accent);
}

/* ---- the sign-in panel ---- */
.login-panel {
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--s5); border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.login-panel-title { margin: 0; font-size: var(--fs-xl); font-weight: 700; }
.login-panel-sub { margin: 0 0 var(--s3); font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.5; }
.login-label { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin-top: var(--s2); }
.login-submit { margin-top: var(--s4); width: 100%; }
.login-error { min-height: 18px; font-size: var(--fs-sm); color: var(--danger); }
.login-hint {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  font-size: var(--fs-xs); color: var(--text-muted);
  padding-top: var(--s3); border-top: 1px dashed var(--border);
}
.login-hint code {
  font-family: var(--mono); background: var(--accent-soft); color: var(--accent-text);
  padding: 1px 7px; border-radius: 5px; font-weight: 700;
}

.login-links { display: flex; flex-direction: column; gap: var(--s2); align-items: flex-start; }
.login-links .link, .login-links .link-btn { display: inline-flex; align-items: center; gap: 7px; font-size: var(--fs-base); }
.login-links svg { width: 16px; height: 16px; }
.login-highlights { display: flex; flex-direction: column; gap: var(--s2); }
.login-hl { display: flex; align-items: flex-start; gap: var(--s3); }
.login-hl-icon {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--primary-soft); color: var(--primary);
}
.login-hl-icon svg { width: 17px; height: 17px; }
.login-hl > div { display: flex; flex-direction: column; line-height: 1.35; }
.login-hl strong { font-size: var(--fs-base); font-weight: 650; }
.login-hl span { font-size: var(--fs-sm); color: var(--text-muted); }

.login-meta {
  margin-top: auto; font-size: var(--fs-xs); line-height: 1.7; color: var(--text-faint);
  padding-top: var(--s4); border-top: 1px dashed var(--border);
}

/* ---- right column: the role cards ---- */
.login-roles { padding: var(--s6); display: flex; flex-direction: column; gap: var(--s5); background: var(--bg); }
.login-roles-head h2 { margin: 0; font-size: var(--fs-xl); font-weight: 700; }
.login-roles-head p { margin: 4px 0 0; color: var(--text-muted); font-size: var(--fs-md); line-height: 1.55; max-width: 62ch; }
.login-group-title {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint);
  margin-bottom: var(--s3); display: flex; align-items: center; gap: var(--s3);
}
.login-group-title::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.login-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: var(--s3); }
.login-card {
  display: flex; flex-direction: column; gap: 10px; text-align: left;
  padding: var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); cursor: pointer; color: var(--text);
  transition: transform var(--transition-slow), box-shadow var(--transition-slow), border-color var(--transition);
}
.login-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--primary); }
.login-card:hover .login-card-cta { color: var(--accent); transform: translateX(2px); }
.login-card:focus-visible { border-radius: var(--radius-lg); }
.login-card-top { display: flex; align-items: center; gap: 10px; }
.login-card-name { font-weight: 700; font-size: var(--fs-md); }
.login-card-role { font-size: var(--fs-sm); color: var(--text-muted); }
.login-card-intro { font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.5; min-height: 36px; }
.login-card-foot { display: flex; justify-content: space-between; align-items: center; font-size: var(--fs-xs); padding-top: 6px; border-top: 1px dashed var(--border); }
.login-card-foot .muted { font-family: var(--mono); }
.login-card-cta { font-weight: 700; color: var(--primary); transition: color var(--transition), transform var(--transition); }

.role-switch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--s2); }
.role-switch-card {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.role-switch-card > span:last-child { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.role-switch-card strong { font-size: var(--fs-base); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-switch-card small { color: var(--text-muted); font-size: var(--fs-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.role-switch-card:hover { background: var(--surface-2); border-color: var(--border-strong); }
.role-switch-card.active { border-color: var(--primary); background: var(--primary-soft); box-shadow: inset 0 0 0 1px var(--primary); }

/* ==== 6. Buttons & links =================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--radius);
  font-size: var(--fs-base); font-weight: 600; line-height: 1; white-space: nowrap;
  color: var(--text); background: var(--surface); cursor: pointer; user-select: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
  text-decoration: none; vertical-align: middle;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--focus); border-radius: var(--radius); }
.btn svg { width: 16px; height: 16px; }
.btn > span { display: inline-flex; align-items: center; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; pointer-events: none; }

.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); box-shadow: var(--shadow-xs); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:active { background: var(--primary-active); }
.btn-primary:focus-visible { box-shadow: var(--focus-danger); }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-faint); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-danger:focus-visible { box-shadow: var(--focus-danger); }

.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.92); }

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); }

.btn-link { background: none; border-color: transparent; color: var(--accent); padding: 0 4px; height: auto; font-weight: 500; }
.btn-link:hover { text-decoration: underline; }

.btn-sm { height: var(--control-h-sm); padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--radius-sm); gap: 5px; }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: var(--control-h-lg); padding: 0 20px; font-size: var(--fs-md); border-radius: 10px; }
.btn-lg svg { width: 18px; height: 18px; }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: var(--control-h-sm); }
.btn-icon.btn-lg { width: var(--control-h-lg); }

/* Small square subtle icon button (close, menu, row actions). */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 30px; height: 30px; border-radius: var(--radius-sm);
  color: var(--text-muted); background: transparent; border: 1px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { background: var(--border); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn.danger:hover, .icon-btn.icon-danger:hover { background: var(--danger-soft); color: var(--danger-text); }
.icon-btn.primary:hover, .icon-btn.icon-primary:hover { background: var(--primary-soft); color: var(--primary-text); }
.icon-btn.sm { width: 24px; height: 24px; }
.icon-btn.sm svg { width: 14px; height: 14px; }

.link { color: var(--accent); cursor: pointer; text-decoration: none; }
.link:hover { text-decoration: underline; }
.link-btn { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); font-weight: 500; cursor: pointer; padding: 0; border-radius: 3px; }
.link-btn:hover { text-decoration: underline; }
.link-btn svg { width: 14px; height: 14px; }

/* Button groups */
.btn-group { display: inline-flex; }
.btn-group .btn:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.btn-group .btn:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ==== 7. Inputs, fields, forms ============================================= */
.input, .select, .textarea {
  width: 100%; height: var(--control-h); padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font-size: var(--fs-base);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  -webkit-appearance: none; appearance: none;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: var(--focus); border-radius: var(--radius); }
.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.input[readonly]:not(:disabled) { cursor: default; }
.input.invalid, .input-error, .field.has-error .input, .field.has-error .select, .field.has-error .textarea,
.input:user-invalid { border-color: var(--danger); }
.field.has-error .input:focus, .input.invalid:focus { box-shadow: var(--focus-danger); }
.textarea { height: auto; min-height: 84px; padding: 8px 10px; line-height: 1.45; resize: vertical; }
.select {
  padding-right: 30px; cursor: pointer;
  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='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 16px;
}
.select[multiple] { height: auto; min-height: 96px; padding: 4px; background-image: none; }
.select[multiple] option { padding: 4px 6px; border-radius: 4px; }
.input-lg, .select.input-lg { height: var(--control-h-lg); font-size: var(--fs-md); padding: 0 14px; border-radius: 10px; }
.input-sm, .select.input-sm { height: var(--control-h-sm); font-size: var(--fs-sm); padding: 0 8px; border-radius: var(--radius-sm); }
input[type="date"].input, input[type="time"].input, input[type="datetime-local"].input { padding-right: 6px; }
input[type="number"].input { font-variant-numeric: tabular-nums; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 15px; height: 15px; margin: 0; cursor: pointer; }
input[type="file"].input { padding: 5px 10px; line-height: 22px; }
input[type="range"] { accent-color: var(--primary); width: 100%; }

/* Field layout: label / control / hint / error */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { display: flex; align-items: center; gap: 4px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
.field-label .eye-btn { margin-left: 2px; }
.field-req { color: var(--danger); font-weight: 700; }
.field-hint { font-size: var(--fs-xs); color: var(--text-faint); line-height: 1.4; }
.field-error { font-size: var(--fs-xs); color: var(--danger-text); font-weight: 500; line-height: 1.4; }
.field-error:empty { display: none; }
.field-readonly, .readonly-value { min-height: var(--control-h); display: flex; align-items: center; padding: 0 2px; font-weight: 500; }

/* Prefix / suffix addons, e.g. ₹ or kg */
.input-group { display: flex; align-items: stretch; width: 100%; }
.input-group .input, .input-group .select { flex: 1; min-width: 0; }
.input-group .input:not(:first-child), .input-group .select:not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.input-group .input:not(:last-child), .input-group .select:not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }
.field-prefix, .field-suffix {
  display: inline-flex; align-items: center; padding: 0 10px; flex: none;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
}
.field-prefix { border-right: 0; border-radius: var(--radius) 0 0 var(--radius); }
.field-suffix { border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; }

/* Form containers */
.form { display: flex; flex-direction: column; gap: var(--s4); }
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--s3) var(--s4); align-items: start; }
.form-inline, .form.layout-inline .form-grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); }
.form-inline .field { flex: 1 1 160px; }
.col-1 { grid-column: span 1; } .col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; } .col-5 { grid-column: span 5; } .col-6 { grid-column: span 6; }
.col-7 { grid-column: span 7; } .col-8 { grid-column: span 8; } .col-9 { grid-column: span 9; }
.col-10 { grid-column: span 10; } .col-11 { grid-column: span 11; } .col-12 { grid-column: span 12; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--border); }
.form-actions .form-error { margin-right: auto; }
.form-error { color: var(--danger-text); font-size: var(--fs-sm); font-weight: 500; }
.form-error:empty { display: none; }
.form-divider { grid-column: span 12; display: flex; align-items: center; gap: var(--s3); margin: var(--s1) 0; font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-faint); }
.form-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.form-html { grid-column: span 12; font-size: var(--fs-sm); color: var(--text-muted); }

/* Toggle switch */
.toggle {
  position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none;
  min-height: var(--control-h); font-size: var(--fs-base);
}
.toggle::before {
  content: ''; width: 36px; height: 20px; border-radius: var(--radius-pill); flex: none;
  background: var(--border-strong); transition: background var(--transition);
}
.toggle::after {
  content: ''; position: absolute; left: 2px; top: 50%; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); transform: translateY(-50%);
  transition: transform var(--transition-slow), left var(--transition-slow);
}
.toggle.toggle-on::before { background: var(--success); }
.toggle.toggle-on::after { left: 18px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle:focus-visible, .toggle:has(input:focus-visible) { box-shadow: none; }
.toggle:focus-visible::before, .toggle:has(input:focus-visible)::before { box-shadow: var(--focus); }
.toggle.disabled, .toggle[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* Radio group & checkbox */
.radio-group { display: flex; flex-wrap: wrap; gap: 6px 14px; min-height: var(--control-h); align-items: center; }
.radio-group label, .check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font-size: var(--fs-base); user-select: none; }
.radio-group.stacked { flex-direction: column; align-items: flex-start; }
.radio-group.segmented { gap: 0; border: 1px solid var(--border-strong); border-radius: var(--radius); overflow: hidden; }
.radio-group.segmented label { padding: 0 12px; height: 32px; border-right: 1px solid var(--border); }
.radio-group.segmented label:last-child { border-right: 0; }
.radio-group.segmented label.active, .radio-group.segmented label:has(input:checked) { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.check { min-height: var(--control-h); }

/* Tags input */
.tags-input {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: var(--control-h);
  padding: 3px 6px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); cursor: text;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.tags-input:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.tags-input input { flex: 1; min-width: 80px; border: 0; background: transparent; height: 24px; padding: 0 4px; outline: none; box-shadow: none; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 4px 0 8px;
  border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent-text); font-size: var(--fs-sm); font-weight: 600;
}
.tag-chip button, .tag-chip .icon-btn { width: 16px; height: 16px; border-radius: 3px; color: inherit; display: inline-flex; align-items: center; justify-content: center; opacity: 0.7; }
.tag-chip button:hover, .tag-chip .icon-btn:hover { opacity: 1; background: rgba(0, 0, 0, 0.08); }
.tag-chip svg { width: 12px; height: 12px; }

/* ==== 8. Page, section, card, KPI ========================================= */
.page { display: flex; flex-direction: column; gap: var(--s4); max-width: 1600px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.page-head > div:first-child { min-width: 0; }
.page-title { display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-xl); font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { color: var(--text-muted); font-size: var(--fs-base); margin-top: 2px; max-width: 80ch; }
.page-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: var(--fs-sm); color: var(--text-faint); margin-bottom: 4px; }
.crumb { color: var(--text-muted); text-decoration: none; }
.crumb:hover { color: var(--accent); text-decoration: underline; }
.crumb + .crumb::before, .crumbs > *:not(:first-child)::before { content: '/'; margin: 0 6px 0 2px; color: var(--border-strong); }
.crumb:last-child { color: var(--text); font-weight: 500; pointer-events: none; }
.page-body { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.page-body > .tabs { margin-bottom: 0; }

.section {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); min-width: 0;
}
.section-head {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: 10px var(--s4); min-height: 46px; border-bottom: 1px solid var(--border);
}
.section-title { display: flex; align-items: center; gap: 6px; font-size: var(--fs-md); font-weight: 700; flex: 1; min-width: 0; }
.section-title .badge, .section-title .chip { margin-left: 4px; }
.section-actions { display: flex; align-items: center; gap: var(--s1); margin-left: auto; flex-wrap: wrap; }
.section-body { padding: var(--s4); }
.section-body > .table-wrap { margin: calc(-1 * var(--s4)); border: 0; border-radius: 0 0 var(--radius-lg) var(--radius-lg); box-shadow: none; }
.section-body > .table-wrap:first-child:last-child .table-toolbar { border-radius: 0; }
.section-dense .section-head { padding: 6px var(--s3); min-height: 38px; }
.section-dense .section-body { padding: var(--s3); }
.section-dense .section-body > .table-wrap { margin: calc(-1 * var(--s3)); }
.section-collapsible .section-title { cursor: pointer; }
.section-collapsed .section-body { display: none; }
.section-collapsed .section-head { border-bottom: 0; }
.section-collapse-btn { transition: transform var(--transition-slow); }
.section-collapsed .section-collapse-btn { transform: rotate(-90deg); }
.section-flush .section-body { padding: 0; }
.section-tone-primary { border-top: 3px solid var(--primary); }
.section-tone-accent { border-top: 3px solid var(--accent); }
.section-tone-success { border-top: 3px solid var(--success); }
.section-tone-warning { border-top: 3px solid var(--warning); }
.section-tone-danger { border-top: 3px solid var(--danger); }
.section-tone-info { border-top: 3px solid var(--info); }
.section-tone-neutral { border-top: 3px solid var(--neutral); }
.section-tone-primary .section-head { background: var(--primary-soft); }
.section-tone-accent .section-head { background: var(--accent-soft); }
.section-tone-success .section-head { background: var(--success-soft); }
.section-tone-warning .section-head { background: var(--warning-soft); }
.section-tone-danger .section-head { background: var(--danger-soft); }
.section-tone-info .section-head { background: var(--info-soft); }
.section-tone-neutral .section-head { background: var(--neutral-soft); }

/* Card: lighter than a section, used in grids. */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); display: flex; flex-direction: column; min-width: 0;
  transition: box-shadow var(--transition-slow), transform var(--transition-slow), border-color var(--transition);
}
.card-head { display: flex; align-items: center; gap: var(--s2); padding: 10px var(--s4); border-bottom: 1px solid var(--border); }
.card-title { flex: 1; display: flex; align-items: center; gap: 6px; font-size: var(--fs-base); font-weight: 700; min-width: 0; }
.card-body { padding: var(--s4); flex: 1; }
.card-foot { padding: 10px var(--s4); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); display: flex; align-items: center; gap: var(--s2); font-size: var(--fs-sm); color: var(--text-muted); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: var(--border-strong); }
.card-tone-primary { border-left: 4px solid var(--primary); }
.card-tone-accent { border-left: 4px solid var(--accent); }
.card-tone-success { border-left: 4px solid var(--success); }
.card-tone-warning { border-left: 4px solid var(--warning); }
.card-tone-danger { border-left: 4px solid var(--danger); }
.card-tone-info { border-left: 4px solid var(--info); }
.card-tone-neutral { border-left: 4px solid var(--neutral); }
.card-dense .card-body { padding: var(--s3); }
.card-dense .card-head { padding: 8px var(--s3); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: var(--s3); }
.kpi {
  position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 4px;
  padding: 12px 14px 12px 18px; min-height: 84px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  transition: box-shadow var(--transition-slow), transform var(--transition-slow);
}
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.kpi-tone-primary::before { background: var(--primary); }
.kpi-tone-accent::before { background: var(--accent); }
.kpi-tone-success::before { background: var(--success); }
.kpi-tone-warning::before { background: var(--warning); }
.kpi-tone-danger::before { background: var(--danger); }
.kpi-tone-info::before { background: var(--info); }
.kpi-tone-neutral::before { background: var(--neutral); }
.kpi-label { display: flex; align-items: center; gap: 4px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 30px; }
.kpi-value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text); }
.kpi-sub { font-size: var(--fs-xs); color: var(--text-faint); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi-delta { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-xs); font-weight: 700; padding: 1px 6px; border-radius: var(--radius-pill); background: var(--neutral-soft); color: var(--neutral-text); }
.kpi-delta.up::before { content: '▲'; font-size: 8px; }
.kpi-delta.down::before { content: '▼'; font-size: 8px; }
.kpi-delta.good { background: var(--success-soft); color: var(--success-text); }
.kpi-delta.bad { background: var(--danger-soft); color: var(--danger-text); }
.kpi-icon { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-faint); }
.kpi-icon svg { width: 16px; height: 16px; }
.kpi-tone-primary .kpi-icon { background: var(--primary-soft); color: var(--primary-text); }
.kpi-tone-success .kpi-icon { background: var(--success-soft); color: var(--success-text); }
.kpi-tone-warning .kpi-icon { background: var(--warning-soft); color: var(--warning-text); }
.kpi-tone-danger .kpi-icon { background: var(--danger-soft); color: var(--danger-text); }
.kpi-tone-info .kpi-icon { background: var(--info-soft); color: var(--info-text); }
.kpi-tone-accent .kpi-icon { background: var(--accent-soft); color: var(--accent-text); }
.kpi-spark { margin-top: auto; height: 28px; opacity: 0.9; }
.kpi-spark svg { width: 100%; height: 28px; display: block; }
.kpi-clickable { cursor: pointer; }
.kpi-clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-clickable:focus-visible { border-radius: var(--radius-lg); }

/* ==== 9. Tables ============================================================ */
.table-wrap {
  display: flex; flex-direction: column; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.table-toolbar {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table-search { position: relative; flex: 0 1 280px; min-width: 160px; }
.table-search .input { height: 30px; padding-left: 30px; font-size: var(--fs-sm); background: var(--surface); }
.table-search svg, .table-search .search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-faint); pointer-events: none; }
.table-filters { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.table-filter { display: inline-flex; align-items: center; gap: 4px; }
.table-filter .select { height: 30px; font-size: var(--fs-sm); padding: 0 26px 0 8px; min-width: 120px; width: auto; background-color: var(--surface); }
.table-filter label, .table-filter-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; }
.table-tools { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.table-count { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.table-bulkbar {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: 6px 10px; background: var(--accent-soft); color: var(--accent-text); border-bottom: 1px solid var(--border);
  font-size: var(--fs-sm); font-weight: 600; animation: dropIn var(--transition) both;
}
.table-bulkbar:empty, .table-bulkbar[hidden] { display: none; }
.table-bulkbar .btn { height: 26px; font-size: var(--fs-sm); }
.table-scroll { overflow: auto; max-height: max(360px, calc(100vh - 300px)); position: relative; }
.table-wrap.table-auto .table-scroll, .table-scroll.auto { max-height: none; }
.table { width: 100%; font-size: var(--fs-base); }
.table th, .table td { padding: 0 10px; height: var(--row-h); border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; white-space: nowrap; }
.table th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-strong); user-select: none;
}
.table th::after { content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px; background: var(--border-strong); }
.table th.sortable { cursor: pointer; padding-right: 20px; position: sticky; }
.table th.sortable:hover { color: var(--text); background: var(--surface-3); }
.table th.sortable::before {
  content: '↕'; position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font-size: 11px; color: var(--text-faint); opacity: 0.5; font-weight: 400;
}
.table th.sortable.sort-asc::before { content: '↑'; opacity: 1; color: var(--accent); font-weight: 700; }
.table th.sortable.sort-desc::before { content: '↓'; opacity: 1; color: var(--accent); font-weight: 700; }
.table th.sort-asc, .table th.sort-desc { color: var(--text); }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:nth-child(even) { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.table tbody tr:hover { background: var(--surface-3); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.row-click, .table tr.row-click td { cursor: pointer; }
.table tr.row-selected, .table tr.row-selected:nth-child(even), .table tr.row-selected:hover { background: var(--accent-soft); }
.table tr.row-selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.table tr.row-muted td { color: var(--text-faint); }
.table tr.row-danger td { background: var(--danger-soft); }
.table tr.row-warning td { background: var(--warning-soft); }
.table td.num, .table th.num, .table .right, .table td.align-right, .table th.align-right { text-align: right; font-variant-numeric: tabular-nums; }
.table td.num { font-family: var(--font); }
.table td.center, .table th.center { text-align: center; }
.table td.wrap { white-space: normal; min-width: 200px; }
.table td.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.table td .chip { vertical-align: middle; }
.table td .avatar { vertical-align: middle; }
.table td.check-col, .table th.check-col, .table td.sel, .table th.sel { width: 36px; padding: 0 0 0 10px; }
.table td.actions, .table th.actions { text-align: right; width: 1%; padding-right: 8px; }
.table-actions { display: inline-flex; align-items: center; justify-content: flex-end; gap: 2px; }
.table td.actions .icon-btn, .table td.actions .btn, .table-actions .icon-btn { opacity: 0; transition: opacity var(--transition), background var(--transition); }
.table td.actions .icon-btn { width: 26px; height: 26px; }
.table tr:hover td.actions .icon-btn, .table tr:hover td.actions .btn, .table tr:hover .table-actions .icon-btn,
.table tr:focus-within td.actions .icon-btn, .table tr:focus-within .table-actions .icon-btn,
.table tr.row-selected td.actions .icon-btn { opacity: 1; }
.table-dense th, .table-dense td { height: 30px; padding: 0 8px; font-size: var(--fs-sm); }
.table-compact th, .table-compact td { height: 28px; }
.table-empty { padding: var(--s6) var(--s4); text-align: center; color: var(--text-muted); }
.table-empty .empty { padding: var(--s4); }
.table-foot {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  padding: 8px 10px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: var(--fs-sm); color: var(--text-muted);
}
.table-foot .table-count { margin-right: auto; }
.pager { display: inline-flex; align-items: center; gap: 2px; margin-left: auto; }
.pager-btn {
  display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 28px; padding: 0 6px;
  border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted);
  border: 1px solid transparent; transition: background var(--transition), color var(--transition);
}
.pager-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.pager-btn.active, .pager-btn[aria-current="page"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.pager-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pager-btn svg { width: 14px; height: 14px; }
.pager .select { height: 28px; font-size: var(--fs-sm); width: auto; padding: 0 24px 0 8px; }
.table-foot .footer-row, .table tfoot td { font-weight: 700; background: var(--surface-2); }
.table tfoot td { border-top: 2px solid var(--border-strong); position: sticky; bottom: 0; }

/* Plain data tables outside ST.ui.table (kv-like) */
.table-plain td, .table-plain th { border-bottom: 1px solid var(--border); padding: 6px 8px; height: auto; }
.table-plain th { position: static; }

/* ==== 10. Chips, badges, tags, dots ======================================= */
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--radius-pill); font-size: var(--fs-sm); font-weight: 600; line-height: 1; white-space: nowrap;
  background: var(--neutral-soft); color: var(--neutral-text); vertical-align: middle;
}
.chip svg { width: 12px; height: 12px; }
.chip-neutral { background: var(--neutral-soft); color: var(--neutral-text); }
.chip-info { background: var(--info-soft); color: var(--info-text); }
.chip-success { background: var(--success-soft); color: var(--success-text); }
.chip-warning { background: var(--warning-soft); color: var(--warning-text); }
.chip-danger { background: var(--danger-soft); color: var(--danger-text); }
.chip-accent { background: var(--accent-soft); color: var(--accent-text); }
.chip-primary { background: var(--primary-soft); color: var(--primary-text); }
.chip-sm { height: 18px; padding: 0 6px; font-size: var(--fs-xs); }
.chip-lg { height: 26px; padding: 0 10px; font-size: var(--fs-base); }
/* Dot variant: modifier on the chip (transparent bg + coloured dot) or an element inside the chip. */
.chip.chip-dot { background: transparent; padding-left: 2px; color: var(--text); font-weight: 500; }
.chip.chip-dot::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.chip.chip-dot.chip-neutral::before { background: var(--neutral); }
.chip.chip-dot.chip-info::before { background: var(--info); }
.chip.chip-dot.chip-success::before { background: var(--success); }
.chip.chip-dot.chip-warning::before { background: var(--warning); }
.chip.chip-dot.chip-danger::before { background: var(--danger); }
.chip.chip-dot.chip-accent::before { background: var(--accent); }
.chip.chip-dot.chip-primary::before { background: var(--primary); }
.chip > .chip-dot, .chip > .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; margin-left: -2px; }
.chip.chip-outline { background: transparent; box-shadow: inset 0 0 0 1px currentColor; }
.chip-remove { display: inline-flex; margin-right: -4px; opacity: 0.6; cursor: pointer; }
.chip-remove:hover { opacity: 1; }

.badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 6px;
  border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 700; line-height: 1;
  background: var(--neutral); color: #fff; vertical-align: middle; white-space: nowrap;
}
.badge-neutral { background: var(--neutral); }
.badge-info { background: var(--info); }
.badge-success { background: var(--success); }
.badge-warning { background: var(--warning); }
.badge-danger { background: var(--danger); }
.badge-accent { background: var(--accent); }
.badge-primary { background: var(--primary); }
.badge-soft { background: var(--neutral-soft); color: var(--neutral-text); }

.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 7px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--text-muted); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; vertical-align: middle;
}
.tag.mono { font-family: var(--mono); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--neutral); flex: none; vertical-align: middle; }
.dot-neutral { background: var(--neutral); }
.dot-info { background: var(--info); }
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-danger { background: var(--danger); }
.dot-accent { background: var(--accent); }
.dot-primary { background: var(--primary); }
.dot-pulse { animation: pulseDot 1.4s ease-in-out infinite; }
@keyframes pulseDot { 0%, 100% { box-shadow: 0 0 0 0 rgba(200, 16, 46, 0.35); } 50% { box-shadow: 0 0 0 5px rgba(200, 16, 46, 0); } }

/* ==== 11. Modal, drawer, toast ============================================ */
.modal-backdrop, .drawer-backdrop {
  position: fixed; inset: 0; z-index: var(--z-modal);
  background: rgba(17, 24, 39, 0.45); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: var(--s4);
  animation: fadeIn var(--transition-slow) both;
}
.drawer-backdrop { z-index: var(--z-drawer); justify-content: flex-end; padding: 0; }
.modal-backdrop.closing, .drawer-backdrop.closing { animation: fadeOut var(--transition-slow) both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* Modal is positioned fixed so it works whether ui.js nests it in the backdrop or appends it to body. */
.modal {
  position: fixed; left: 50%; top: 50%; z-index: var(--z-modal);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); overflow: hidden;
  transform: translate(-50%, -50%);
  animation: modalIn var(--transition-slow) both;
}
.modal-backdrop > .modal { position: relative; left: auto; top: auto; transform: none; animation: modalInFlex var(--transition-slow) both; }
@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -50%) scale(0.96) translateY(6px); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes modalInFlex { from { opacity: 0; transform: scale(0.96) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-sm { width: min(420px, calc(100vw - 32px)); }
.modal-md { width: min(560px, calc(100vw - 32px)); }
.modal-lg { width: min(820px, calc(100vw - 32px)); }
.modal-xl { width: min(1100px, calc(100vw - 32px)); }
.modal-full { width: calc(100vw - 32px); height: calc(100vh - 32px); }
.modal-head { display: flex; align-items: center; gap: var(--s2); padding: 12px var(--s4); border-bottom: 1px solid var(--border); flex: none; }
.modal-title { flex: 1; display: flex; align-items: center; gap: 6px; font-size: var(--fs-md); font-weight: 700; min-width: 0; }
.modal-body { padding: var(--s4); overflow: auto; flex: 1; min-height: 0; }
.modal-body > .form:only-child .form-actions { margin: var(--s4) calc(-1 * var(--s4)) calc(-1 * var(--s4)); padding: 12px var(--s4); background: var(--surface-2); }
.modal-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--s2); padding: 12px var(--s4); border-top: 1px solid var(--border); background: var(--surface-2); flex: none; }
.modal-foot .spacer { flex: 1; }
.modal-message { font-size: var(--fs-md); line-height: 1.55; }

/* Drawer: slides from the right. */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--z-drawer);
  width: min(480px, 100vw); max-width: 100vw;
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: drawerIn var(--transition-slow) both;
}
.drawer-backdrop > .drawer { position: relative; height: 100%; }
.drawer[data-side="left"], .drawer.drawer-left { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--border); animation-name: drawerInLeft; }
@keyframes drawerIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes drawerInLeft { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; gap: var(--s2); padding: 12px var(--s4); border-bottom: 1px solid var(--border); flex: none; min-height: var(--topbar-h); }
.drawer-head .drawer-title, .drawer-head strong, .drawer-head h3 { flex: 1; font-size: var(--fs-md); font-weight: 700; display: flex; align-items: center; gap: 6px; }
.drawer-body { padding: var(--s4); overflow: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: var(--s3); }
.drawer-foot { display: flex; align-items: center; justify-content: flex-end; gap: var(--s2); padding: 12px var(--s4); border-top: 1px solid var(--border); background: var(--surface-2); flex: none; }

/* Toasts, bottom-right stack. */
.toast-root {
  position: fixed; right: var(--s4); bottom: var(--s4); z-index: var(--z-toast);
  display: flex; flex-direction: column-reverse; gap: var(--s2); width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--info); font-size: var(--fs-base); line-height: 1.4;
  animation: toastIn var(--transition-slow) both;
}
.toast.closing, .toast.hide { animation: toastOut var(--transition-slow) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }
.toast svg { width: 16px; height: 16px; margin-top: 1px; }
.toast > span:first-child, .toast-icon { flex: none; display: inline-flex; }
.toast-text, .toast-message { flex: 1; min-width: 0; }
.toast-info { border-left-color: var(--info); }
.toast-info .toast-icon, .toast-info > svg { color: var(--info); }
.toast-success { border-left-color: var(--success); }
.toast-success .toast-icon, .toast-success > svg { color: var(--success); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon, .toast-warning > svg { color: var(--warning); }
.toast-danger { border-left-color: var(--danger); }
.toast-danger .toast-icon, .toast-danger > svg { color: var(--danger); }
.toast-neutral { border-left-color: var(--neutral); }
.toast-accent, .toast-primary { border-left-color: var(--accent); }
.toast-action { flex: none; color: var(--accent); font-weight: 700; font-size: var(--fs-sm); padding: 2px 6px; border-radius: 4px; white-space: nowrap; }
.toast-action:hover { background: var(--accent-soft); }
.toast-close { flex: none; width: 22px; height: 22px; border-radius: 4px; color: var(--text-faint); display: inline-flex; align-items: center; justify-content: center; }
.toast-close:hover { background: var(--surface-3); color: var(--text); }
.toast-close svg { width: 12px; height: 12px; margin: 0; }

/* ==== 12. Timeline, tabs, steps, progress, stats, kv, empty, avatar, heat == */
.timeline { position: relative; display: flex; flex-direction: column; gap: 0; padding-left: 4px; }
.tl-item { position: relative; display: grid; grid-template-columns: 22px 1fr; gap: 0 10px; padding-bottom: var(--s4); }
.tl-item::before { content: ''; position: absolute; left: 10px; top: 18px; bottom: -2px; width: 2px; background: var(--border); }
.tl-item:last-child::before { display: none; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  grid-row: 1 / span 3; width: 22px; height: 22px; border-radius: 50%; margin-top: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--neutral); color: var(--neutral); z-index: 1; position: relative;
}
.tl-dot::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.tl-dot svg { width: 12px; height: 12px; }
.tl-dot svg + *, .tl-dot:has(svg)::after { display: none; }
.tl-neutral .tl-dot { border-color: var(--neutral); color: var(--neutral); }
.tl-info .tl-dot { border-color: var(--info); color: var(--info); }
.tl-success .tl-dot { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.tl-warning .tl-dot { border-color: var(--warning); color: var(--warning); background: var(--warning-soft); }
.tl-danger .tl-dot { border-color: var(--danger); color: var(--danger); background: var(--danger-soft); }
.tl-accent .tl-dot { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tl-primary .tl-dot { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.tl-time { font-size: var(--fs-xs); color: var(--text-faint); font-family: var(--mono); line-height: 22px; }
.tl-title { font-weight: 600; font-size: var(--fs-base); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tl-text { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; line-height: 1.45; }
.tl-meta { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.tl-meta svg { width: 12px; height: 12px; }
.timeline-compact .tl-item { padding-bottom: var(--s2); grid-template-columns: 16px 1fr; gap: 0 8px; }
.timeline-compact .tl-item::before { left: 7px; top: 14px; }
.timeline-compact .tl-dot { width: 16px; height: 16px; }
.timeline-compact .tl-dot::after { width: 6px; height: 6px; }
.timeline-compact .tl-time { line-height: 16px; }
.timeline-compact .tl-title { font-size: var(--fs-sm); }
.timeline-compact .tl-text { font-size: var(--fs-xs); }
.tl-item.tl-current .tl-dot { box-shadow: 0 0 0 4px var(--primary-soft); }

/* Tabs (underline style) */
.tabs { display: flex; align-items: flex-end; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; flex: none;
  height: 38px; padding: 0 14px; margin-bottom: -1px;
  color: var(--text-muted); font-weight: 600; font-size: var(--fs-base); white-space: nowrap;
  border-bottom: 2px solid transparent; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.tab svg { width: 15px; height: 15px; }
.tab:hover { color: var(--text); background: var(--surface-3); }
.tab.active { color: var(--primary-text); border-bottom-color: var(--primary); }
.tab.active svg { color: var(--primary); }
.tab:focus-visible { border-radius: var(--radius-sm); }
.tab-badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--radius-pill); background: var(--neutral-soft); color: var(--neutral-text); font-size: var(--fs-xs); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.tab.active .tab-badge { background: var(--primary-soft); color: var(--primary-text); }
.tab-panels { padding-top: var(--s4); min-width: 0; }
.tab-panel { display: none; animation: fadeIn var(--transition-slow) both; }
.tab-panel.active { display: block; }
/* Vertical variant: wrapper or the .tabs strip itself */
.tabs-vertical { display: flex; gap: var(--s4); align-items: flex-start; }
.tabs-vertical > .tabs, .tabs.tabs-vertical { flex-direction: column; align-items: stretch; border-bottom: 0; border-right: 1px solid var(--border); min-width: 180px; overflow: visible; flex: none; }
.tabs-vertical > .tabs .tab, .tabs.tabs-vertical .tab { justify-content: flex-start; height: 36px; margin: 0 -1px 0 0; border-bottom: 0; border-right: 2px solid transparent; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.tabs-vertical > .tabs .tab.active, .tabs.tabs-vertical .tab.active { border-right-color: var(--primary); background: var(--primary-soft); }
.tabs-vertical > .tab-panels { flex: 1; padding-top: 0; }
/* Pill tabs alternative */
.tabs.tabs-pills { border-bottom: 0; gap: 4px; padding: 3px; background: var(--surface-2); border-radius: var(--radius); display: inline-flex; }
.tabs.tabs-pills .tab { height: 28px; margin: 0; border: 0; border-radius: var(--radius-sm); font-size: var(--fs-sm); }
.tabs.tabs-pills .tab.active { background: var(--surface); box-shadow: var(--shadow-xs); color: var(--text); }

/* Steps / wizard */
.steps { display: flex; align-items: flex-start; gap: 0; counter-reset: step; overflow-x: auto; }
.step { position: relative; flex: 1; min-width: 110px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: var(--fs-sm); color: var(--text-muted); padding: 0 4px; counter-increment: step; }
.step::before {
  content: counter(step); width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 2px solid var(--border-strong); color: var(--text-faint); font-weight: 700; font-size: var(--fs-xs); z-index: 1;
}
.step::after { content: ''; position: absolute; top: 13px; left: 50%; width: 100%; height: 2px; background: var(--border); z-index: 0; }
.step:last-child::after { display: none; }
.step-done { color: var(--text); }
.step-done::before { content: '✓'; background: var(--success); border-color: var(--success); color: #fff; }
.step-done::after { background: var(--success); }
.step-active { color: var(--text); font-weight: 700; }
.step-active::before { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 4px var(--primary-soft); }
.step-todo { color: var(--text-faint); }
.steps.steps-compact .step { min-width: 80px; font-size: var(--fs-xs); }

/* Progress bar */
.progress { position: relative; height: 8px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; width: 100%; min-width: 60px; }
.progress-bar { height: 100%; border-radius: var(--radius-pill); background: var(--accent); transition: width var(--transition-slow); }
.progress-primary .progress-bar, .progress-bar.progress-primary { background: var(--primary); }
.progress-accent .progress-bar { background: var(--accent); }
.progress-success .progress-bar, .progress-bar.progress-success { background: var(--success); }
.progress-warning .progress-bar, .progress-bar.progress-warning { background: var(--warning); }
.progress-danger .progress-bar, .progress-bar.progress-danger { background: var(--danger); }
.progress-info .progress-bar, .progress-bar.progress-info { background: var(--info); }
.progress-neutral .progress-bar { background: var(--neutral); }
.progress-lg { height: 14px; }
.progress-sm { height: 5px; }
.progress-wrap { display: flex; align-items: center; gap: 8px; }
.progress-label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted); min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.progress-striped .progress-bar { background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 75%); background-size: 16px 16px; animation: stripes 1s linear infinite; }
@keyframes stripes { from { background-position: 0 0; } to { background-position: 16px 0; } }

/* Inline stat */
.stat { display: inline-flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.stat-value { font-size: var(--fs-lg); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-success .stat-value { color: var(--success-text); }
.stat-warning .stat-value { color: var(--warning-text); }
.stat-danger .stat-value { color: var(--danger-text); }
.stat-info .stat-value { color: var(--info-text); }
.stat-accent .stat-value { color: var(--accent-text); }
.stat-primary .stat-value { color: var(--primary-text); }
.stats-row { display: flex; flex-wrap: wrap; gap: var(--s4) var(--s6); }

/* Key / value grid */
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s5); }
.kv-1, .kv.cols-1 { grid-template-columns: 1fr; }
.kv-3, .kv.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kv-4, .kv.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kv-row { display: flex; flex-direction: column; gap: 1px; padding: 7px 0; border-bottom: 1px solid var(--border); min-width: 0; }
.kv-label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; gap: 4px; }
.kv-value { font-size: var(--fs-base); font-weight: 500; color: var(--text); overflow-wrap: anywhere; min-height: 18px; }
.kv-value:empty::before { content: '—'; color: var(--text-faint); }
.kv-inline .kv-row { flex-direction: row; align-items: baseline; gap: var(--s3); }
.kv-inline .kv-label { min-width: 120px; flex: none; }
.kv-inline .kv-value { flex: 1; text-align: right; }
.kv-plain .kv-row { border-bottom: 0; padding: 4px 0; }

/* Grid helpers */
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); min-width: 0; }
.grid-2 { display: grid; gap: var(--s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--s4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--s4); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2-1 { display: grid; gap: var(--s4); grid-template-columns: 2fr 1fr; }
.grid-1-2 { display: grid; gap: var(--s4); grid-template-columns: 1fr 2fr; }
.grid > *, .grid-2 > *, .grid-3 > *, .grid-4 > * { min-width: 0; }
.gap-0 { gap: 0; }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.span-all { grid-column: 1 / -1; }

/* Empty state */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--s2); padding: var(--s7) var(--s4); text-align: center; color: var(--text-muted); }
.empty-icon { width: 56px; height: 56px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); color: var(--text-faint); margin-bottom: var(--s1); font-size: 24px; }
.empty-icon svg { width: 26px; height: 26px; }
.empty-title { font-size: var(--fs-md); font-weight: 700; color: var(--text); }
.empty-text { font-size: var(--fs-base); max-width: 46ch; line-height: 1.5; }
.empty .btn { margin-top: var(--s2); }
.empty-sm { padding: var(--s4); }
.empty-sm .empty-icon { width: 40px; height: 40px; }

/* Avatars */
.avatar {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
  text-transform: uppercase; overflow: hidden; vertical-align: middle; user-select: none;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }
.avatar-lg { width: 56px; height: 56px; font-size: 20px; }
.avatar-xl { width: 80px; height: 80px; font-size: 28px; }
.avatar-group { display: inline-flex; }
.avatar-group .avatar { margin-left: -8px; box-shadow: 0 0 0 2px var(--surface); }
.avatar-group .avatar:first-child { margin-left: 0; }
.avatar-square { border-radius: var(--radius-sm); }

/* Copyable text */
.copyable { display: inline-flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 0.95em; cursor: pointer; border-radius: 4px; padding: 0 4px; margin: 0 -4px; transition: background var(--transition); }
.copyable:hover { background: var(--accent-soft); color: var(--accent-text); }
.copyable svg { width: 12px; height: 12px; opacity: 0.5; }
.copyable:hover svg { opacity: 1; }
.copyable.copied { background: var(--success-soft); color: var(--success-text); }

/* Calendar heatmap */
.heat { display: grid; grid-template-rows: repeat(7, 12px); grid-auto-flow: column; grid-auto-columns: 12px; gap: 3px; overflow-x: auto; padding: 2px 0; }
.heat-cell { width: 12px; height: 12px; border-radius: 2px; background: var(--surface-3); transition: transform var(--transition); }
.heat-cell:hover { transform: scale(1.3); outline: 1px solid var(--text-faint); }
.heat-cell[data-level="1"], .heat-1 { background: color-mix(in srgb, var(--accent) 25%, var(--surface)); }
.heat-cell[data-level="2"], .heat-2 { background: color-mix(in srgb, var(--accent) 50%, var(--surface)); }
.heat-cell[data-level="3"], .heat-3 { background: color-mix(in srgb, var(--accent) 75%, var(--surface)); }
.heat-cell[data-level="4"], .heat-4 { background: var(--accent); }
.heat-legend { display: flex; align-items: center; gap: 3px; font-size: var(--fs-xs); color: var(--text-faint); margin-top: 6px; }
.heat-wrap { display: flex; flex-direction: column; }
.heat-months { display: flex; gap: 0; font-size: var(--fs-xs); color: var(--text-faint); margin-bottom: 4px; }

/* ==== 13. Scan box ========================================================= */
/* Every scanning point in the network uses this: hub inbound, bagging, outbound,
   DRS handover, delivery. The .scanbox-big variant is for warehouse screens where
   the operator stands an arm's length away from the monitor with a gun in hand. */
.scanbox {
  position: relative; display: flex; flex-direction: column; gap: var(--s2);
  padding: var(--s3);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: background var(--transition-slow), border-color var(--transition-slow), box-shadow var(--transition-slow);
}
.scanbox:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.scanbox > .field-label, .scanbox-label {
  display: flex; align-items: center; gap: 4px;
  font-size: var(--fs-sm); font-weight: 700; color: var(--text-muted);
}
.scanbox-hint { font-size: var(--fs-xs); color: var(--text-faint); }
.scanbox-row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.scanbox-input {
  flex: 1 1 220px; min-width: 0; height: var(--control-h-lg); padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-family: var(--mono); font-size: var(--fs-lg); font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.scanbox-input:focus { border-color: var(--accent); box-shadow: var(--focus); border-radius: var(--radius); }
.scanbox-input::placeholder { font-family: var(--font); font-size: var(--fs-base); font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--text-faint); }
.scanbox-input:disabled { background: var(--surface-2); color: var(--text-muted); }

/* Big variant: 28px monospace input, taller controls, roomier padding. */
.scanbox-big { padding: var(--s4); }
.scanbox-big .scanbox-input { height: 56px; padding: 0 16px; font-size: 28px; letter-spacing: 0.08em; }
.scanbox-big .scanbox-btn, .scanbox-big .scanbox-sim, .scanbox-big .scanbox-sim > .btn { height: 56px; }
.scanbox-big .scanbox-btn { padding: 0 24px; font-size: var(--fs-md); }

/* Primary "Scan" action. Works with or without the .btn classes. */
.scanbox-btn {
  flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h-lg); padding: 0 18px;
  border: 1px solid var(--primary); border-radius: var(--radius);
  background: var(--primary); color: var(--primary-contrast);
  font-size: var(--fs-base); font-weight: 700; white-space: nowrap; cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.scanbox-btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.scanbox-btn:focus-visible { box-shadow: var(--focus-danger); border-radius: var(--radius); }
.scanbox-btn svg { width: 18px; height: 18px; }

/* "Simulate scan" split button: a wrapper (or the button itself) that drops a menu. */
.scanbox-sim { position: relative; display: inline-flex; align-items: center; flex: none; }
.scanbox-sim > .btn { height: var(--control-h-lg); }
button.scanbox-sim {
  height: var(--control-h-lg); padding: 0 12px; gap: 6px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text-muted); font-weight: 600; white-space: nowrap;
}
button.scanbox-sim:hover { background: var(--surface-2); color: var(--text); }
.scanbox-sim svg { width: 15px; height: 15px; }
.scanbox-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: var(--z-dropdown);
  min-width: 280px; max-width: min(420px, calc(100vw - 24px)); max-height: 300px; overflow: auto;
  padding: var(--s1); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  animation: dropIn var(--transition-slow) both;
}
.scanbox-menu:empty { display: none; }
.scanbox-menu-head { padding: 6px 10px 4px; font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-faint); }
.scanbox-menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--text); background: none; text-align: left; cursor: pointer;
  font-family: var(--mono); font-size: var(--fs-sm); letter-spacing: 0.02em;
  transition: background var(--transition), color var(--transition);
}
.scanbox-menu-item:hover, .scanbox-menu-item:focus-visible { background: var(--surface-3); box-shadow: none; }
.scanbox-menu-item small, .scanbox-menu-item .muted { margin-left: auto; font-family: var(--font); font-size: var(--fs-xs); color: var(--text-faint); }
.scanbox-menu-item svg { width: 14px; height: 14px; color: var(--text-faint); flex: none; }

/* Rolling log of what was just scanned — the operator's proof of work. */
.scanbox-log {
  display: flex; flex-direction: column; gap: 2px;
  max-height: 220px; overflow: auto;
  padding-top: var(--s2); border-top: 1px dashed var(--border);
}
.scanbox-log:empty { display: none; }
.scanbox-log-item {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px; border-radius: var(--radius-sm);
  background: var(--surface-2); border-left: 3px solid var(--neutral);
  font-family: var(--mono); font-size: var(--fs-sm); color: var(--text-muted); line-height: 1.5;
  animation: dropIn var(--transition) both;
}
.scanbox-log-item time, .scanbox-log-item small { margin-left: auto; flex: none; font-family: var(--font); font-size: var(--fs-xs); color: var(--text-faint); }
.scanbox-log-item svg { width: 13px; height: 13px; flex: none; }
.scanbox-log-item.success, .scanbox-log-item[data-tone="success"] { background: var(--success-soft); border-left-color: var(--success); color: var(--success-text); }
.scanbox-log-item.danger, .scanbox-log-item[data-tone="danger"] { background: var(--danger-soft); border-left-color: var(--danger); color: var(--danger-text); }
.scanbox-log-item.warning, .scanbox-log-item[data-tone="warning"] { background: var(--warning-soft); border-left-color: var(--warning); color: var(--warning-text); }
.scanbox-log-item.info, .scanbox-log-item[data-tone="info"] { background: var(--info-soft); border-left-color: var(--info); color: var(--info-text); }
.scanbox-log-item.accent, .scanbox-log-item[data-tone="accent"] { background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent-text); }
.scanbox-count { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; font-size: var(--fs-sm); font-weight: 700; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* 400 ms pulse fired by api.flash(tone) after every scan — the floor staff read
   the colour, not the text, when they are moving fast. */
@keyframes scanFlashSuccess {
  0% { background: var(--success-soft); border-color: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
  70% { background: var(--success-soft); border-color: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
  100% { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
}
@keyframes scanFlashDanger {
  0% { background: var(--danger-soft); border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
  70% { background: var(--danger-soft); border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
  100% { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
}
@keyframes scanFlashWarning {
  0% { background: var(--warning-soft); border-color: var(--warning); box-shadow: 0 0 0 4px var(--warning-soft); }
  70% { background: var(--warning-soft); border-color: var(--warning); box-shadow: 0 0 0 4px var(--warning-soft); }
  100% { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-xs); }
}
.scan-flash-success { animation: scanFlashSuccess 400ms ease-out 1; }
.scan-flash-danger { animation: scanFlashDanger 400ms ease-out 1; }
.scan-flash-warning { animation: scanFlashWarning 400ms ease-out 1; }

/* ==== 14. Help system: eye buttons, popover, panel, glossary, banner ======= */
/* The eye icon is the signature of this demo: it sits beside every title, KPI and
   tricky field, and never shouts louder than the content it explains. */
.eye-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
  background: transparent; color: var(--text-faint); cursor: pointer; vertical-align: middle;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.eye-btn svg { width: 14px; height: 14px; }
.eye-btn:hover, .eye-btn[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary); }
.eye-btn:focus-visible { background: var(--primary-soft); color: var(--primary); box-shadow: var(--focus); border-radius: 50%; }
.eye-btn:active { transform: scale(0.92); }
.eye-inline { vertical-align: -4px; margin: 0 2px; }
.eye-sm { width: 16px; height: 16px; }
.eye-sm svg { width: 12px; height: 12px; }
.eye-topbar { width: 30px; height: 30px; color: var(--text-muted); }
.eye-topbar svg { width: 17px; height: 17px; }
.eye-topbar:hover { background: var(--primary-soft); }
body.help-open .eye-topbar { background: var(--primary-soft); color: var(--primary); }

/* Floating explanation card. help.js appends it to <body> and sets left/top from
   viewport coordinates, so it must be fixed — and it must clear modals. */
.help-popover {
  position: fixed; z-index: var(--z-popover);
  width: 380px; max-width: calc(100vw - 24px); max-height: min(70vh, 560px); overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: dropIn var(--transition-slow) both;
}
.help-pop-head {
  position: sticky; top: 0; z-index: 1;
  display: flex; align-items: center; gap: var(--s2);
  padding: 10px var(--s3) 10px var(--s4);
  background: var(--surface); border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.help-pop-head strong { flex: 1; min-width: 0; font-size: var(--fs-md); font-weight: 700; }
.help-pop-icon {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
}
.help-pop-icon svg { width: 15px; height: 15px; }

/* Shared body typography for the popover, the docked panel and the help centre. */
.help-body { display: flex; flex-direction: column; gap: var(--s3); padding: var(--s4); font-size: var(--fs-base); line-height: 1.55; color: var(--text); }
.help-body p { margin: 0; }
.help-body > *:first-child { margin-top: 0; }
.help-what { font-size: var(--fs-md); line-height: 1.5; color: var(--text); }
.help-block { display: flex; flex-direction: column; gap: 5px; }
.help-block p { color: var(--text-muted); }
.help-label { font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.help-steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); }
.help-steps li { padding-left: 2px; }
.help-steps li::marker { color: var(--primary); font-weight: 700; }
.help-tips { margin: 0; padding-left: 18px; list-style: none; display: flex; flex-direction: column; gap: 4px; color: var(--text-muted); }
.help-tips li { position: relative; }
.help-tips li::before { content: '✓'; position: absolute; left: -18px; top: 0; color: var(--success); font-weight: 700; }
.help-roles { display: flex; flex-wrap: wrap; gap: 4px; }
.help-terms { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.help-links { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); padding-top: var(--s2); border-top: 1px dashed var(--border); }

/* Tamil one-liner. Kept visually distinct so a Tamil-first reader finds it fast. */
.help-ta {
  padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  color: var(--accent-text);
  font-family: 'Noto Sans Tamil', 'Latha', var(--font);
  font-size: var(--fs-base); line-height: 1.7;
}
.help-ta-label {
  display: inline-block; margin-right: 4px;
  font-family: 'Noto Sans Tamil', 'Latha', var(--font);
  font-size: var(--fs-xs); font-weight: 700; opacity: 0.75;
}

/* Role guide block (docked panel and the help centre). */
.help-roleguide { display: flex; flex-direction: column; gap: 6px; padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--surface-2); }
.help-roleguide p { color: var(--text-muted); }
.help-roleguide .help-steps { gap: 5px; }
.help-roleguide .help-steps a { font-weight: 600; }

/* Docked right panel: same body, roomier rhythm. */
.help-panel .help-body { gap: var(--s4); font-size: var(--fs-md); }
.help-panel .help-what { font-size: var(--fs-lg); line-height: 1.45; font-weight: 500; }
.help-panel .help-steps, .help-panel .help-tips, .help-panel .help-block p { font-size: var(--fs-base); }
.help-panel .help-ta { font-size: var(--fs-md); }
.help-panel .help-links { padding-top: var(--s3); }
.help-panel p.muted { padding: var(--s4); }

/* Full-width explanation banner used at the top of the complex screens. */
.help-banner {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--accent-soft); border: 1px solid transparent; border-left: 4px solid var(--accent);
  border-radius: var(--radius); color: var(--text); font-size: var(--fs-base); line-height: 1.55;
}
.help-banner > svg, .help-banner .help-pop-icon { flex: none; margin-top: 1px; }
.help-banner > svg { width: 18px; height: 18px; color: var(--accent); }
.help-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.help-banner strong { font-weight: 700; }
.help-banner .help-ta { background: transparent; border-left: 0; padding: 2px 0; }
.help-banner .help-body { padding: 0; gap: var(--s2); }
.help-banner .btn, .help-banner .icon-btn { margin-left: auto; flex: none; }
.help-banner-warning { background: var(--warning-soft); border-left-color: var(--warning); }
.help-banner-success { background: var(--success-soft); border-left-color: var(--success); }
.help-banner-danger { background: var(--danger-soft); border-left-color: var(--danger); }
.help-banner-primary { background: var(--primary-soft); border-left-color: var(--primary); }

/* Glossary (opened in a drawer by help.js). */
.glossary-list { display: flex; flex-direction: column; margin-top: var(--s3); }
.glossary-item { display: flex; flex-direction: column; gap: 3px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-base); line-height: 1.5; color: var(--text-muted); }
.glossary-item:last-child { border-bottom: 0; }
.glossary-item .help-ta { margin-top: 2px; font-size: var(--fs-sm); }
.glossary-term { font-size: var(--fs-md); font-weight: 700; color: var(--text); }
.glossary-term .muted { font-weight: 500; font-size: var(--fs-sm); }

/* ==== 15. Guided tour ====================================================== */
/* help.js drops a .tour-overlay on the body, positions .tour-box with fixed
   coordinates and marks the element being explained with .tour-target. */
.tour-overlay {
  position: fixed; inset: 0; z-index: var(--z-tour);
  background: rgba(17, 24, 39, 0.55); -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
  animation: fadeIn var(--transition-slow) both;
}
.tour-box {
  position: fixed; z-index: calc(var(--z-tour) + 2);
  width: 360px; max-width: calc(100vw - 24px);
  display: flex; flex-direction: column; gap: 6px;
  padding: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  animation: dropIn var(--transition-slow) both;
}
.tour-box h4 { font-size: var(--fs-md); font-weight: 700; }
.tour-box p { font-size: var(--fs-base); line-height: 1.55; color: var(--text-muted); margin: 0; }
.tour-step { font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); }
.tour-actions { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s2); padding-top: var(--s3); border-top: 1px solid var(--border); }
.tour-actions .spacer { flex: 1; }
/* The highlighted element is lifted above the dim layer and ringed in ST red. */
.tour-target {
  position: relative; z-index: calc(var(--z-tour) + 1);
  box-shadow: 0 0 0 4px var(--primary), 0 0 0 10px rgba(200, 16, 46, 0.18);
  border-radius: var(--radius-sm);
}
/* Fixed shell parts create their own stacking context, so lift them too. */
.sidebar:has(.tour-target), .topbar:has(.tour-target), .help-panel:has(.tour-target) { z-index: calc(var(--z-tour) + 1); }

/* ==== 16. Global search dropdown =========================================== */
/* The base .search / .search-input / .search-suggest / .search-item rules live in
   section 4 with the rest of the topbar; these are the pieces used by the
   suggestion list itself (grouped results, keyboard hint, entity meta). */
.search-suggest .search-group { padding: 6px 10px 3px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.search-item strong { font-weight: 600; }
.search-item .mono, .search-item-code { font-family: var(--mono); font-size: var(--fs-sm); }
.search-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.search-item-text small { color: var(--text-muted); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-item .chip, .search-item-meta { flex: none; margin-left: auto; font-size: var(--fs-xs); color: var(--text-faint); }
.search-item mark { background: var(--warning-soft); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-item.active .search-item-icon, .search-item:hover .search-item-icon { background: var(--accent-soft); color: var(--accent-text); }
.search-empty { padding: 10px 12px; font-size: var(--fs-sm); color: var(--text-muted); }
.search-hint { display: flex; align-items: center; gap: 6px; padding: 6px 10px; margin-top: var(--s1); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-faint); }

/* ==== 17. Geo map ========================================================== */
/* Abstract South-India canvas: no tiles, no network — just projected points on a
   hand-drawn outline, good enough to show a hub network, a trip or a geo-fence. */
.geomap {
  position: relative; width: 100%; min-width: 0; overflow: hidden;
  background: var(--map-water); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.geomap-svg { display: block; width: 100%; height: 100%; }
.geomap-svg .land, .geomap-svg .geomap-land { fill: var(--map-land); stroke: var(--map-land-stroke); stroke-width: 1; stroke-linejoin: round; }
.geomap-svg .border, .geomap-svg .geomap-border { fill: none; stroke: var(--map-land-stroke); stroke-width: 1; stroke-dasharray: 3 3; }
.geomap-svg .grid, .geomap-svg .geomap-grid { stroke: var(--map-grid); stroke-width: 1; fill: none; }
.geomap-svg .road, .geomap-svg .geomap-path { fill: none; stroke: var(--map-road); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.geomap-svg .geomap-path-active { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 5; animation: mapDash 1.4s linear infinite; }
@keyframes mapDash { to { stroke-dashoffset: -22; } }
.geomap-svg .geomap-fence { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 4; }
.geomap-point {
  fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; cursor: pointer;
  transform-box: fill-box; transform-origin: center;
  transition: transform var(--transition), filter var(--transition);
}
.geomap-point:hover, .geomap-point:focus-visible { transform: scale(1.45); filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35)); }
.geomap-point-neutral, .geomap-point.neutral { fill: var(--neutral); }
.geomap-point-info, .geomap-point.info { fill: var(--info); }
.geomap-point-success, .geomap-point.success { fill: var(--success); }
.geomap-point-warning, .geomap-point.warning { fill: var(--warning); }
.geomap-point-danger, .geomap-point.danger { fill: var(--danger); }
.geomap-point-accent, .geomap-point.accent { fill: var(--accent); }
.geomap-point-primary, .geomap-point.primary { fill: var(--primary); }
.geomap-point-pulse { animation: mapPulse 1.6s ease-in-out infinite; }
@keyframes mapPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.geomap-label { fill: var(--text-muted); font-size: 10px; font-weight: 600; pointer-events: none; paint-order: stroke; stroke: var(--map-land); stroke-width: 2.5; stroke-linejoin: round; }
.geomap-tip {
  position: absolute; z-index: 2; pointer-events: none;
  max-width: 240px; padding: 5px 9px; border-radius: var(--radius-sm);
  background: var(--surface-inverse); color: var(--text-inverse);
  font-size: var(--fs-xs); line-height: 1.45; white-space: nowrap;
  box-shadow: var(--shadow-md); opacity: 0; transition: opacity var(--transition);
}
.geomap-tip.show, .geomap-tip[data-show="1"] { opacity: 1; }
.geomap-legend {
  position: absolute; left: var(--s2); bottom: var(--s2); z-index: 1;
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
  max-width: calc(100% - var(--s4));
  padding: 5px 9px; border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--border); box-shadow: var(--shadow-xs);
  font-size: var(--fs-xs); color: var(--text-muted);
}
.geomap-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.geomap-toolbar { position: absolute; right: var(--s2); top: var(--s2); z-index: 1; display: flex; gap: 4px; }
.geomap-toolbar .icon-btn { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-xs); }

/* ==== 18. Phone frame (delivery executive app) ============================= */
.phone-frame {
  position: relative; width: 372px; max-width: 100%; margin: 0 auto; flex: none;
  padding: 12px 12px 16px;
  background: var(--surface-inverse); border-radius: 38px;
  box-shadow: var(--shadow-lg), inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}
.phone-notch {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 3;
  width: 132px; height: 22px; border-radius: 0 0 14px 14px;
  background: var(--surface-inverse);
}
.phone-screen {
  position: relative; display: flex; flex-direction: column;
  height: 660px; max-height: calc(100vh - 180px); overflow-y: auto; overflow-x: hidden;
  background: var(--bg); border-radius: 28px;
  -webkit-overflow-scrolling: touch;
}
.phone-screen > * { flex: none; }
.phone-title {
  position: sticky; top: 0; z-index: 2; flex: none;
  display: flex; align-items: center; gap: var(--s2);
  height: 52px; padding: 0 var(--s3) 0 var(--s4);
  background: var(--primary); color: var(--primary-contrast);
  font-size: var(--fs-md); font-weight: 700;
  border-radius: 28px 28px 0 0;
}
.phone-title .icon-btn, .phone-title .eye-btn { color: rgba(255, 255, 255, 0.85); }
.phone-title .icon-btn:hover, .phone-title .eye-btn:hover { background: rgba(255, 255, 255, 0.18); color: #fff; }
.phone-title small { font-weight: 500; opacity: 0.85; }
.phone-body { flex: 1; padding: var(--s3); display: flex; flex-direction: column; gap: var(--s3); }
.phone-bottom-nav {
  position: sticky; bottom: 0; z-index: 2; margin-top: auto; flex: none;
  display: flex; align-items: stretch;
  background: var(--surface); border-top: 1px solid var(--border);
  border-radius: 0 0 28px 28px;
}
.phone-bottom-nav > * {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-width: 0; padding: 8px 2px 10px;
  color: var(--text-faint); font-size: 10px; font-weight: 600; text-decoration: none;
  transition: color var(--transition), background var(--transition);
}
.phone-bottom-nav > *:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.phone-bottom-nav > .active, .phone-bottom-nav > [aria-current="page"] { color: var(--primary); }
.phone-bottom-nav svg { width: 20px; height: 20px; }
.phone-bottom-nav .badge { position: absolute; }
.phone-frame .btn { height: 42px; font-size: var(--fs-md); }
.phone-frame .btn-sm { height: 30px; font-size: var(--fs-sm); }
.phone-frame .card, .phone-frame .section { border-radius: var(--radius); }

/* ==== 19. Print preview on screen ========================================== */
/* What the operator sees before pressing Print. css/print.css takes over for the
   actual paper; here we only imitate the sheet so the layout is believable. */
.printable { display: flex; flex-direction: column; gap: var(--s3); min-width: 0; }
.print-toolbar {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); font-size: var(--fs-sm); color: var(--text-muted);
}
.print-toolbar .btn { flex: none; }
.print-toolbar .spacer, .print-toolbar .ml-auto { margin-left: auto; }
.print-preview, .printable > .print-scroll { overflow: auto; padding: var(--s4); background: var(--surface-3); border-radius: var(--radius); display: flex; justify-content: center; }
/* The sheet itself stays paper-white in both themes — that is what will be printed. */
.print-area {
  flex: none; margin: 0 auto; padding: 12mm;
  background: #ffffff; color: #111827;
  border: 1px solid var(--border); border-radius: 2px;
  box-shadow: var(--shadow-md);
  font-family: var(--font); font-size: 11px; line-height: 1.45;
}
.print-area * { color: inherit; }
.print-area h1, .print-area h2, .print-area h3, .print-area strong, .print-area b { color: #111827; }
.print-area hr { border-top: 1px solid #d0d5dd; margin: 8px 0; }
.print-area table { width: 100%; font-size: 10px; }
.print-area th, .print-area td { padding: 4px 6px; border-bottom: 1px solid #d0d5dd; height: auto; text-align: left; }
.print-area th { background: #f2f4f7; color: #344054; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; font-size: 9px; position: static; }
.print-area .muted { color: #667085; }
.print-a4 { width: 210mm; min-height: 297mm; }
.print-a5 { width: 148mm; min-height: 210mm; padding: 8mm; }
.print-label { width: 4in; height: 6in; padding: 4mm; font-size: 10px; overflow: hidden; }
.print-thermal { width: 80mm; padding: 4mm; font-family: var(--mono); font-size: 10px; }
.print-label .print-title, .print-thermal .print-title { font-size: 13px; font-weight: 800; letter-spacing: 0.02em; }
/* Barcodes and QR blocks rendered by ST.ui.barcode / ST.ui.qr. */
.barcode, .qr { display: block; }
.barcode svg { display: block; width: 100%; height: 48px; }
.barcode-text, .barcode figcaption { font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em; text-align: center; margin-top: 2px; }
.qr svg { display: block; width: 96px; height: 96px; }
.print-label .barcode svg { height: 58px; }
.print-label .qr svg { width: 76px; height: 76px; }
.print-thermal .barcode svg { height: 40px; }
.print-area .barcode svg rect, .print-area .qr svg rect { fill: #111827; }

/* ==== 20. Charts =========================================================== */
/* charts.js injects a baseline stylesheet as the first node in <head> so these
   rules win on equal specificity; they only re-tone it with our design tokens. */
.chart { position: relative; width: 100%; min-width: 0; }
.chart svg { display: block; max-width: 100%; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: var(--s2); font-size: var(--fs-sm); color: var(--text-muted); }
.chart-legend-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 4px; margin: 0 -4px; border: 0; border-radius: var(--radius-sm);
  background: none; color: inherit; font: inherit; line-height: 1.3; cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
}
.chart-legend-item:hover { background: var(--surface-3); color: var(--text); }
.chart-legend-item.off, .chart-legend-item[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.chart-legend-item:focus-visible { box-shadow: var(--focus); border-radius: var(--radius-sm); }
.chart-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; }
.chart-legend-value { margin-left: 2px; font-variant-numeric: tabular-nums; opacity: 0.8; }
.chart-tip {
  position: fixed; z-index: var(--z-toast); pointer-events: none; display: none;
  max-width: 280px; padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: var(--fs-sm); line-height: 1.45;
}
.chart-tip-title { font-weight: 700; margin-bottom: 2px; }
.chart-tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-tip-row b { margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }
.chart-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 120px; padding: var(--s4); text-align: center;
  border: 1px dashed var(--border); border-radius: var(--radius);
  color: var(--text-muted); font-size: var(--fs-base);
}
.chart-empty svg { width: 22px; height: 22px; color: var(--text-faint); }
.chart-mark { transition: opacity var(--transition); }
.chart-mark:hover { opacity: 0.78; }
.chart-donut-wrap { display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap; }
.chart-donut-wrap .chart-legend { margin-top: 0; flex-direction: column; gap: 4px; min-width: 140px; }
.chart-title { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); font-weight: 700; color: var(--text-muted); margin-bottom: var(--s2); }

/* ==== 21. Utilities ======================================================== */
.muted { color: var(--text-muted); }
.small { font-size: var(--fs-sm); }
.strong { font-weight: 700; }
.right { text-align: right; }
.center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.w-100 { width: 100%; }
.ml-auto { margin-left: auto; }
.spacer { flex: 1 1 auto; min-width: 0; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hstack { display: flex; flex-direction: row; align-items: center; gap: var(--s2); flex-wrap: wrap; min-width: 0; }
.vstack { display: flex; flex-direction: column; gap: var(--s2); min-width: 0; }
.gap-1 { gap: var(--s1); }
.gap-2 { gap: var(--s2); }
.gap-3 { gap: var(--s3); }
.gap-4 { gap: var(--s4); }
.mt-1 { margin-top: var(--s1); }
.mt-2 { margin-top: var(--s2); }
.mt-3 { margin-top: var(--s3); }
.mt-4 { margin-top: var(--s4); }
.mb-1 { margin-bottom: var(--s1); }
.mb-2 { margin-bottom: var(--s2); }
.mb-3 { margin-bottom: var(--s3); }
.mb-4 { margin-bottom: var(--s4); }
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface-2); color: var(--text-muted);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; vertical-align: middle;
}
.pill svg { width: 12px; height: 12px; }
.text-neutral { color: var(--neutral-text); }
.text-info { color: var(--info-text); }
.text-success { color: var(--success-text); }
.text-warning { color: var(--warning-text); }
.text-danger { color: var(--danger-text); }
.text-accent { color: var(--accent-text); }
.text-primary { color: var(--primary-text); }

/* ==== 22. Responsive rules (1200 / 900 / 600) ============================== */
/* Nothing may ever push the body sideways — check every new component here. */
html, body { max-width: 100%; }
.main, .page, .page-body, .section, .card, .table-wrap, .kpi, .form, .modal-body, .drawer-body { min-width: 0; }

/* --- Under 1200px: the help panel floats over the content instead of pushing it. */
@media (max-width: 1200px) {
  .help-panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: 0;
    box-shadow: var(--shadow-lg); z-index: var(--z-drawer);
  }
  body.help-open .help-panel { width: min(var(--help-w), calc(100vw - 32px)); }
  .help-panel > * { min-width: min(calc(var(--help-w) - 1px), calc(100vw - 33px)); }
  .clock-pill { display: none; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
}

/* --- Under 900px: sidebar becomes an off-canvas drawer, topbar compacts. */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; width: var(--sidebar-w); }
  body.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  /* An off-canvas drawer is never "collapsed to icons" — undo that state here. */
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
  body.sidebar-collapsed .brand-text { display: flex; }
  body.sidebar-collapsed .nav-label { display: block; }
  body.sidebar-collapsed .nav-caret, body.sidebar-collapsed .user-chip .nav-caret { display: inline-flex; }
  body.sidebar-collapsed .nav-group-label { display: block; }
  body.sidebar-collapsed .user-chip-text { display: flex; }
  body.sidebar-collapsed .nav-module.active > .nav-sub { display: flex; }
  body.sidebar-collapsed .nav-item { justify-content: flex-start; padding: 0 var(--s3) 0 14px; height: 34px; }
  body.sidebar-collapsed .nav-module.active .nav-item::before { left: 2px; }
  body.sidebar-collapsed .sidebar-nav { padding: var(--s2) var(--s2) var(--s4); }
  body.sidebar-collapsed .user-chip { justify-content: flex-start; padding: 6px 8px; }
  body.sidebar-collapsed .sidebar-brand { flex-direction: row; justify-content: space-between; height: var(--topbar-h); padding: 0 var(--s3) 0 var(--s4); gap: var(--s2); }
  .app-body, body.sidebar-collapsed .app-body { margin-left: 0; }
  /* Dimmed backdrop behind the open drawer. */
  body.sidebar-open .app-body::before {
    content: ''; position: fixed; inset: 0; z-index: calc(var(--z-sidebar) - 1);
    background: rgba(17, 24, 39, 0.45); animation: fadeIn var(--transition-slow) both;
  }
  .topbar { gap: var(--s2); padding: 0 var(--s3); }
  .topbar-menu { display: inline-flex; }
  .topbar-title { font-size: var(--fs-md); }
  .topbar-center .search { max-width: none; }
  .topbar-right .btn-ghost, .scope-pill { display: none; }
  .main { padding: var(--s3); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi { min-height: 76px; }
  .grid, .grid-3, .grid-4, .grid-2-1, .grid-1-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-height: max(320px, calc(100vh - 260px)); }
  .table-toolbar { gap: 6px; }
  .table-search { flex: 1 1 100%; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid > [class*="col-"] { grid-column: span 1 / span 1; }
  .form-divider { grid-column: span 1; }
  .modal-backdrop { padding: var(--s2); }
  .modal, .modal-sm, .modal-md, .modal-lg, .modal-xl, .modal-full {
    width: calc(100vw - 16px); max-width: calc(100vw - 16px); max-height: calc(100vh - 16px);
  }
  .modal-full { height: calc(100vh - 16px); }
  .drawer { width: min(480px, 100vw); }
  .login-page { grid-template-columns: minmax(0, 1fr); }
  .login-hero { position: static; height: auto; padding: var(--s5) var(--s4); border-right: 0; border-bottom: 1px solid var(--border); }
  .login-roles { padding: var(--s4); }
  .login-brand { justify-content: flex-start; }
  .brand-mark-xl { width: 60px !important; height: 60px !important; }
  .login-brand-text h1 { font-size: 25px; }
  .help-popover { max-width: calc(100vw - 24px); }
  .tour-box { width: min(360px, calc(100vw - 24px)); }
  .print-preview, .printable > .print-scroll { padding: var(--s2); justify-content: flex-start; }
}

/* --- Under 600px: one KPI per row, smaller type, the phone app fills the screen. */
@media (max-width: 600px) {
  body { --main-pad: 12px; }
  .main { padding: 12px; }
  .page { gap: var(--s3); }
  .page-title { font-size: var(--fs-lg); }
  .page-subtitle { font-size: var(--fs-sm); }
  .topbar { padding: 0 var(--s2); }
  .topbar-center { display: none; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .kpi-value { font-size: var(--fs-xl); }
  .grid, .grid-2, .grid-3, .grid-4, .grid-2-1, .grid-1-2 { grid-template-columns: minmax(0, 1fr); }
  .kv, .kv-3, .kv-4, .kv.cols-3, .kv.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .section-head, .card-head { padding: 8px var(--s3); }
  .section-body, .card-body { padding: var(--s3); }
  .section-body > .table-wrap { margin: calc(-1 * var(--s3)); }
  .form-actions { flex-direction: column-reverse; align-items: stretch; }
  .form-actions .btn { width: 100%; }
  .page-actions { width: 100%; }
  .login-cards, .role-switch-grid { grid-template-columns: minmax(0, 1fr); }
  .login-hero { padding: var(--s4); gap: var(--s4); }
  .login-panel { padding: var(--s4); }
  .login-brand-text h1 { font-size: 23px; }
  .login-brand-text p { font-size: var(--fs-xs); letter-spacing: 0.12em; }
  .brand-mark-xl { width: 54px !important; height: 54px !important; }
  .login-roles-head h2 { font-size: var(--fs-lg); }
  .login-highlights { display: grid; grid-template-columns: 1fr; gap: var(--s2); }
  .toast-root { left: var(--s2); right: var(--s2); bottom: var(--s2); width: auto; }
  .modal, .modal-sm, .modal-md, .modal-lg, .modal-xl, .modal-full {
    width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; border: 0;
  }
  .modal-backdrop { padding: 0; }
  body.help-open .help-panel { width: 100vw; }
  .help-panel > * { min-width: 100vw; }
  .phone-frame { width: 100%; padding: 0; border-radius: var(--radius-lg); box-shadow: none; background: transparent; }
  .phone-notch { display: none; }
  .phone-screen { height: auto; min-height: 70vh; max-height: none; border-radius: var(--radius-lg); border: 1px solid var(--border); }
  .phone-title, .phone-bottom-nav { border-radius: 0; }
  .print-a4, .print-a5, .print-label, .print-thermal { width: 100%; min-height: 0; height: auto; padding: 6mm; }
  .scanbox-big .scanbox-input { height: 48px; font-size: 22px; }
  .scanbox-big .scanbox-btn, .scanbox-big .scanbox-sim, .scanbox-big .scanbox-sim > .btn { height: 48px; }
  .scanbox-row .scanbox-btn, .scanbox-row .scanbox-sim { flex: 1 1 auto; }
  .geomap-legend { position: static; max-width: none; border-radius: 0 0 var(--radius-lg) var(--radius-lg); border-width: 1px 0 0; }
}

/* ==== 23. Public tracking page & print-hidden helpers ====================== */
/* The public tracking page has no shell: no sidebar, no topbar, just the brand
   and the consignment story. Reachable at #/tracking/t/<cn> without logging in. */
body.public-mode { overflow: auto; height: auto; background: var(--bg); }
.public-page {
  max-width: 860px; margin: 0 auto; padding: var(--s6) var(--s4) var(--s7);
  display: flex; flex-direction: column; gap: var(--s4); min-width: 0;
}
.public-page .page-head { padding-bottom: var(--s3); border-bottom: 1px solid var(--border); }
.public-page .brand { margin-bottom: var(--s2); }
.public-foot { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px dashed var(--border); font-size: var(--fs-xs); color: var(--text-faint); text-align: center; line-height: 1.7; }
/* Hidden on screen, shown by css/print.css on paper. */
.print-only { display: none; }
