/* BeeBlown Zone — Business OS design system
   Tokens → base → layout → components → modules. Light & dark themes. */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef1f7;
  --ink: #141c2b;
  --ink-2: #3a4558;
  --muted: #6b778c;
  --faint: #98a2b3;
  --line: #e4e8f0;
  --line-2: #d5dbe6;
  --primary: #315de8;
  --primary-ink: #ffffff;
  --primary-soft: #ecf0ff;
  --primary-strong: #2348c7;
  --accent: #7259ee;
  --green: #0f8a5f; --green-soft: #e3f6ee;
  --red: #d63b3b;   --red-soft: #fdecec;
  --amber: #b26a00; --amber-soft: #fff3dc;
  --blue: #2563eb;  --blue-soft: #e7efff;
  --gray-soft: #eef0f4;
  --violet: #7259ee; --violet-soft: #efebff;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 6px 24px rgba(23, 38, 76, .06);
  --shadow-lg: 0 18px 50px rgba(23, 38, 76, .16);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 252px;
  --topbar: 64px;
  --font: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --display: 'Manrope', 'DM Sans', system-ui, sans-serif;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0d1220;
  --surface: #141b2d;
  --surface-2: #182036;
  --surface-3: #1e2741;
  --ink: #e8ecf5;
  --ink-2: #c3cad8;
  --muted: #8d97ab;
  --faint: #66708a;
  --line: #232d47;
  --line-2: #2e3a59;
  --primary: #5b7cff;
  --primary-soft: #1d2850;
  --primary-strong: #7d97ff;
  --green: #3ccf91; --green-soft: #12301f;
  --red: #ff6b6b;   --red-soft: #3a1717;
  --amber: #f5b13d; --amber-soft: #3a2a0c;
  --blue: #6c9bff;  --blue-soft: #16264a;
  --gray-soft: #222b42;
  --violet-soft: #251e4d;
  --shadow: 0 6px 24px rgba(0, 0, 0, .25);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

/* ───────── Base ───────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
h1, h2, h3, h4 { font-family: var(--display); color: var(--ink); margin: 0; letter-spacing: -.01em; }
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
p { margin: 0 0 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 8px 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
small { font-size: 12px; }
code, kbd { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
kbd { border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--muted); background: var(--surface); }
.icon { flex-shrink: 0; vertical-align: middle; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pad { padding: 14px 18px; margin: 0; }
.text-green { color: var(--green); } .text-red { color: var(--red); } .text-amber { color: var(--amber); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; } .mb { margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
[data-theme="dark"] .only-light, :root:not([data-theme="dark"]) .only-dark { display: none; }

/* ───────── App shell ───────── */
.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; transition: width .2s, transform .2s;
}
.brand-lockup { display: flex; align-items: center; gap: 11px; padding: 18px 18px 14px; color: var(--ink); }
.brand-lockup:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center; color: #fff; font: 800 18px var(--display);
  background: linear-gradient(135deg, #315de8, #7259ee); box-shadow: 0 6px 16px rgba(49, 93, 232, .28);
}
.brand-mark.lg { width: 52px; height: 52px; border-radius: 15px; font-size: 26px; }
.brand-text strong { display: block; font: 800 16px var(--display); letter-spacing: -.3px; }
.brand-text small { display: block; font-size: 9px; letter-spacing: 1.6px; color: var(--faint); margin-top: 2px; }
.nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; scrollbar-width: thin; }
.nav-group { margin-bottom: 4px; }
.nav-group-label {
  width: 100%; display: flex; align-items: center; justify-content: space-between; border: 0; background: none;
  padding: 10px 10px 5px; font-size: 10.5px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; color: var(--faint);
}
.nav-group-label .icon { transition: transform .15s; }
.nav-group.collapsed .nav-group-label .icon { transform: rotate(-90deg); }
.nav-group.collapsed .nav-items { display: none; }
.nav-items a {
  display: flex; align-items: center; gap: 11px; height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500; white-space: nowrap; overflow: hidden;
}
.nav-items a .icon { color: var(--muted); }
.nav-items a:hover { background: var(--surface-3); text-decoration: none; color: var(--ink); }
.nav-items a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-items a.active .icon { color: var(--primary); }
.sidebar-foot { border-top: 1px solid var(--line); padding: 8px 10px; }
.nav-collapse { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 8px 10px; border-radius: 8px; color: var(--muted); }
.nav-collapse:hover { background: var(--surface-3); }
.nav-collapsed { --sidebar: 68px; }
.nav-collapsed .brand-text, .nav-collapsed .nav-items a span, .nav-collapsed .nav-group-label, .nav-collapsed .nav-collapse span { display: none; }
.nav-collapsed .nav-items a { justify-content: center; padding: 0; }
.nav-collapsed .nav-collapse .icon { transform: rotate(180deg); }
.nav-collapsed .nav-group.collapsed .nav-items { display: block; }
.nav-collapsed .brand-lockup { justify-content: center; padding-inline: 0; }

.main { margin-left: var(--sidebar); min-height: 100vh; display: flex; flex-direction: column; transition: margin .2s; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.menu-toggle { display: none; }
.global-search { flex: 1; min-width: 160px; max-width: 520px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.global-search:focus-within { border-color: var(--primary); background: var(--surface); }
.global-search input[type=search], .search-input input[type=search] { flex: 1; width: auto; min-width: 0; min-height: 0; padding: 0; border: 0 !important; background: none; outline: 0; box-shadow: none !important; color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.brand-switch { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--surface); }
.brand-switch select { width: auto; min-height: 0; padding: 0 2px; border: 0 !important; box-shadow: none !important; background: none; outline: 0; max-width: 150px; font-size: 13px; color: var(--ink); cursor: pointer; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 9px; background: none; color: var(--muted); }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.badge-dot { position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--surface); }
.user-btn { display: flex; align-items: center; gap: 9px; border: 0; background: none; padding: 4px 6px; border-radius: 10px; color: var(--ink); text-align: left; }
.user-btn:hover { background: var(--surface-3); }
.user-meta strong, .user-meta small { display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta strong { font-size: 13px; } .user-meta small { font-size: 11px; color: var(--muted); }
.page { flex: 1; padding: 24px 28px 40px; max-width: 1480px; width: 100%; }
.app-footer { display: flex; justify-content: space-between; gap: 10px; padding: 16px 28px; color: var(--faint); font-size: 12px; border-top: 1px solid var(--line); }
.sidebar-scrim { display: none; }

/* ───────── Dropdowns, toasts ───────── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; z-index: 50; display: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu a, .dropdown-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: none; border-radius: 7px; color: var(--ink-2); text-align: left; font-size: 13.5px; }
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--surface-3); text-decoration: none; color: var(--ink); }
.dropdown-menu form { margin: 0; }
.dropdown-wide { width: 360px; padding: 0; }
.dropdown-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.notif-list { max-height: 400px; overflow-y: auto; }
.notif-item { display: block; padding: 11px 14px; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item strong { display: block; color: var(--ink); font-size: 13px; }
.notif-item small { color: var(--muted); }
.notif-item.unread { background: var(--primary-soft); }
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; animation: toast-in .2s ease; }
.toast.error { background: var(--red); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ───────── Page head, alerts ───────── */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .subtitle { color: var(--muted); margin: 4px 0 0; max-width: 720px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.page-actions form { margin: 0; }
.crumbs { display: flex; align-items: center; gap: 4px; font-size: 12.5px; margin-bottom: 4px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; border: 1px solid transparent; font-size: 13.5px; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--green-soft); color: var(--green); border-color: color-mix(in srgb, var(--green) 25%, transparent); }
.alert-error { background: var(--red-soft); color: var(--red); border-color: color-mix(in srgb, var(--red) 25%, transparent); }
.alert-info { background: var(--blue-soft); color: var(--blue); border-color: color-mix(in srgb, var(--blue) 25%, transparent); }
.alert-warn { background: var(--amber-soft); color: var(--amber); border-color: color-mix(in srgb, var(--amber) 25%, transparent); }

/* ───────── Buttons ───────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px;
  border-radius: 9px; border: 1px solid transparent; font-weight: 600; font-size: 13.5px; white-space: nowrap; line-height: 1;
  transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 28%, transparent); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-2); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--faint); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { color: var(--red) !important; }
.btn-danger-solid { background: var(--red); color: #fff; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; border-radius: 7px; gap: 4px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg a, .seg button { display: inline-flex; align-items: center; gap: 6px; padding: 0 12px; height: 36px; color: var(--muted); font-weight: 600; font-size: 13px; border: 0; background: none; }
.seg a + a, .seg button + button { border-left: 1px solid var(--line-2); }
.seg a.active, .seg button.active { background: var(--primary-soft); color: var(--primary); }
.seg a:hover { text-decoration: none; color: var(--ink); }
.wa-link { color: #1fa855; display: inline-flex; vertical-align: middle; }

/* ───────── Panels & cards ───────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); margin-bottom: 18px; min-width: 0; }
.panel-flat { box-shadow: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.panel-head h2 { display: flex; align-items: center; gap: 8px; }
.panel-head p { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }
.panel-body { padding: 16px 18px; }
.count { display: inline-grid; place-items: center; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--surface-3); color: var(--muted); font: 600 11.5px var(--font); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.grid-2-1 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; }
.grid-2 > .panel, .grid-3 > .panel, .grid-2-1 > .panel { margin-bottom: 0; }
.stack > * + * { margin-top: 18px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm); overflow: hidden; color: var(--ink); }
a.kpi:hover { text-decoration: none; border-color: var(--line-2); box-shadow: var(--shadow); }
.kpi-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.kpi-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi-icon.green { background: var(--green-soft); color: var(--green); }
.kpi-icon.red { background: var(--red-soft); color: var(--red); }
.kpi-icon.amber { background: var(--amber-soft); color: var(--amber); }
.kpi-icon.violet { background: var(--violet-soft); color: var(--violet); }
.kpi strong { display: block; font: 800 26px/1.15 var(--display); margin-top: 10px; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi small { color: var(--muted); display: block; margin-top: 3px; }
.delta-up { color: var(--green); font-weight: 600; } .delta-down { color: var(--red); font-weight: 600; }
.stat-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 11px; padding: 12px 15px; border-left: 3px solid var(--primary); }
.stat span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.stat strong { display: block; font: 800 20px var(--display); margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat small { color: var(--faint); }
.stat.tone-green { border-left-color: var(--green); } .stat.tone-red { border-left-color: var(--red); }
.stat.tone-amber { border-left-color: var(--amber); } .stat.tone-violet { border-left-color: var(--violet); } .stat.tone-gray { border-left-color: var(--faint); }

/* ───────── Tables ───────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.toolbar select, .toolbar input[type=date] { height: 34px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 8px; background: var(--surface); font-size: 13px; max-width: 200px; }
.search-input { display: flex; align-items: center; gap: 6px; height: 34px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 10px; color: var(--muted); background: var(--surface); min-width: 220px; flex: 1; max-width: 340px; }
.filter-date { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.chip-toggle { display: inline-flex; align-items: center; cursor: pointer; }
.chip-toggle input { display: none; }
.chip-toggle span { height: 34px; display: inline-flex; align-items: center; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2); font-size: 13px; font-weight: 600; color: var(--muted); }
.chip-toggle input:checked + span { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 700; padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th a { color: inherit; }
.table th a.sort.is-asc::after { content: ' ↑'; } .table th a.sort.is-desc::after { content: ' ↓'; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.row-link { cursor: pointer; }
.row-title { font-weight: 600; color: var(--ink); }
.table-compact td, .table-compact th { padding: 8px 12px; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
.subline { display: block; color: var(--muted); font-size: 12px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.pager { display: flex; gap: 4px; }
.pager a { min-width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--line); color: var(--ink-2); font-weight: 600; font-size: 13px; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager a:hover { text-decoration: none; }

/* ───────── Pills, avatars, badges ───────── */
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 9px; border-radius: 11px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-red { background: var(--red-soft); color: var(--red); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-blue { background: var(--blue-soft); color: var(--blue); }
.pill-gray { background: var(--gray-soft); color: var(--muted); }
.pill-violet { background: var(--violet-soft); color: var(--violet); }
.avatar { --h: 220; display: inline-grid; place-items: center; border-radius: 50%; font-weight: 700; flex-shrink: 0; background: hsl(var(--h) 70% 92%); color: hsl(var(--h) 55% 35%); }
[data-theme="dark"] .avatar { background: hsl(var(--h) 35% 24%); color: hsl(var(--h) 80% 82%); }
.avatar-xs { width: 22px; height: 22px; font-size: 9.5px; }
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 40px; height: 40px; font-size: 14px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatars { display: flex; } .avatars .avatar { border: 2px solid var(--surface); margin-left: -6px; } .avatars .avatar:first-child { margin-left: 0; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; border: 1px solid var(--line-2); }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--ink-2); font-size: 12px; font-weight: 600; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.dot-green { background: var(--green); } .dot-red { background: var(--red); } .dot-amber { background: var(--amber); } .dot-blue { background: var(--blue); }

/* ───────── Forms ───────── */
.form-panel { padding: 6px 22px 20px; }
.form-section { margin: 18px 0 2px; padding-bottom: 8px; border-bottom: 1px dashed var(--line); color: var(--ink-2); font-size: 13px; text-transform: uppercase; letter-spacing: .6px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; padding-top: 14px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.span-2 { grid-column: span 2; } .field.span-3 { grid-column: 1 / -1; }
.field label, .label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.req { color: var(--red); font-weight: 700; }
input[type=text], input[type=email], input[type=tel], input[type=url], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=time], input[type=search], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); color: var(--ink); outline: 0; transition: border-color .12s, box-shadow .12s;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
input[disabled], select[disabled], textarea[disabled] { background: var(--surface-2); color: var(--muted); }
.has-error { border-color: var(--red) !important; }
.field .help { color: var(--muted); }
.field .error { color: var(--red); font-weight: 600; }
.input-prefix, .input-suffix { display: flex; align-items: stretch; }
.input-prefix span, .input-suffix span { display: grid; place-items: center; padding: 0 11px; background: var(--surface-3); border: 1px solid var(--line-2); color: var(--muted); font-weight: 600; }
.input-prefix span { border-radius: 9px 0 0 9px; border-right: 0; } .input-prefix input { border-radius: 0 9px 9px 0; }
.input-suffix span { border-radius: 0 9px 9px 0; border-left: 0; } .input-suffix input { border-radius: 9px 0 0 9px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--line-2); border-radius: 12px; transition: .15s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: var(--shadow-sm); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 140px; }

/* ───────── Detail pages ───────── */
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin: 0; }
.detail-grid > div { padding: 12px 18px; border-bottom: 1px solid var(--line); min-width: 0; }
.detail-grid > div.span-full { grid-column: 1 / -1; }
.detail-grid dt { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.detail-grid dd { margin: 4px 0 0; word-wrap: break-word; }
.meta-list { margin: 0; padding: 6px 18px 12px; }
.meta-list > div { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.meta-list > div:last-child { border-bottom: 0; }
.meta-list dt { color: var(--muted); } .meta-list dd { margin: 0; text-align: right; font-weight: 600; }
.activity { list-style: none; margin: 0; padding: 8px 18px 14px; }
.activity li { position: relative; padding: 7px 0 7px 16px; font-size: 13px; color: var(--ink-2); border-left: 2px solid var(--line); margin-left: 4px; }
.activity li::before { content: ''; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.activity small { display: block; color: var(--faint); }
.file-list { list-style: none; margin: 0; padding: 4px 0; }
.file-list li { display: flex; align-items: center; gap: 12px; padding: 9px 18px; border-bottom: 1px solid var(--line); }
.file-list li > div { flex: 1; min-width: 0; }
.file-list small { display: block; color: var(--muted); }
.file-list form { margin: 0; }
.file-ext { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-size: 10px; font-weight: 800; flex-shrink: 0; }
.upload-row { display: flex; gap: 10px; align-items: center; padding: 12px 18px; flex-wrap: wrap; }
.upload-row input[type=file] { flex: 1; min-width: 200px; font-size: 13px; }
.profile-head { display: flex; align-items: center; gap: 16px; padding: 18px; }
.profile-head h2 { font-size: 20px; }

/* Timeline (lead activities, ticket replies, comments) */
.timeline { list-style: none; margin: 0; padding: 6px 18px 16px; }
.timeline > li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.timeline > li:last-child { border-bottom: 0; }
.timeline .tl-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); flex-shrink: 0; }
.timeline .tl-body { flex: 1; min-width: 0; }
.timeline .tl-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 13px; }
.timeline .tl-head small { color: var(--faint); }
.timeline .tl-text { margin-top: 4px; color: var(--ink-2); white-space: pre-wrap; word-wrap: break-word; }
.timeline .internal { background: var(--amber-soft); border-radius: 8px; padding: 8px 10px; }
.composer { padding: 14px 18px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.composer textarea { min-height: 70px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs a { padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Progress */
.progress { height: 7px; border-radius: 4px; background: var(--surface-3); overflow: hidden; min-width: 60px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 4px; }
.progress.green > span { background: var(--green); } .progress.amber > span { background: var(--amber); } .progress.red > span { background: var(--red); }

/* ───────── Kanban ───────── */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(272px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 14px; align-items: start; }
.kanban-col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; max-height: calc(100vh - 250px); min-height: 160px; }
.kanban-col.drag-over { border-color: var(--primary); background: var(--primary-soft); }
.kanban-col-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; flex-wrap: wrap; }
.kanban-col-head small { margin-left: auto; font-weight: 600; }
.kanban-cards { padding: 4px 10px 12px; overflow-y: auto; display: grid; gap: 8px; align-content: start; flex: 1; }
.kanban-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; color: var(--ink); box-shadow: var(--shadow-sm); cursor: grab; }
.kanban-card:hover { text-decoration: none; border-color: var(--line-2); box-shadow: var(--shadow); }
.kanban-card.dragging { opacity: .5; }
.kanban-card strong { display: block; font-size: 13.5px; line-height: 1.35; }
.kanban-meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 7px; font-size: 12px; color: var(--muted); }

/* ───────── Calendar ───────── */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-dow { padding: 8px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; background: var(--surface-2); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.cal-day { min-height: 118px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal-day.other { background: var(--surface-2); }
.cal-day.other .cal-num { color: var(--faint); }
.cal-day.today .cal-num { background: var(--primary); color: #fff; }
.cal-num { align-self: flex-start; font-size: 12px; font-weight: 700; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; }
.cal-item { display: block; font-size: 11.5px; padding: 3px 6px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; border-left: 3px solid var(--primary); }
.cal-item:hover { text-decoration: none; filter: brightness(.97); }
.cal-item.green { background: var(--green-soft); color: var(--green); border-color: var(--green); }
.cal-item.amber { background: var(--amber-soft); color: var(--amber); border-color: var(--amber); }
.cal-item.red { background: var(--red-soft); color: var(--red); border-color: var(--red); }
.cal-item.gray { background: var(--gray-soft); color: var(--muted); border-color: var(--faint); }
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav h2 { min-width: 160px; text-align: center; }

/* ───────── Charts (server-rendered SVG / CSS) ───────── */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font: 11px var(--font); }
.chart .grid line { stroke: var(--line); }
.chart .bar { fill: var(--primary); }
.chart .bar-2 { fill: var(--accent); }
.chart .bar-neg { fill: var(--red); }
.chart .line { fill: none; stroke: var(--primary); stroke-width: 2.5; }
.chart .area { fill: color-mix(in srgb, var(--primary) 12%, transparent); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); padding: 0 18px 14px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbars { display: grid; gap: 10px; padding: 14px 18px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(60px, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; }
.hbar .track { height: 10px; border-radius: 5px; background: var(--surface-3); overflow: hidden; }
.hbar .track span { display: block; height: 100%; border-radius: 5px; background: var(--primary); }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hbar .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.funnel { display: grid; gap: 6px; padding: 14px 18px; }
.funnel-row { display: grid; grid-template-columns: 110px minmax(0, 1fr) 90px; gap: 10px; align-items: center; font-size: 13px; }
.funnel-row .track { height: 26px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.funnel-row .track span { display: flex; align-items: center; padding-left: 8px; height: 100%; color: #fff; font-weight: 700; font-size: 12px; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 6px; min-width: 26px; }

/* Lists in panels */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--line); min-width: 0; }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .grow strong, .list .grow a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list small { color: var(--muted); }
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 40px 20px; color: var(--muted); }
.empty-state .icon { color: var(--faint); margin-bottom: 6px; }
.empty-state strong { color: var(--ink); font-size: 15px; }
.empty-state p { margin: 0 0 8px; max-width: 360px; }

/* Line items editor (quotations / invoices) */
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11.5px; text-transform: uppercase; color: var(--muted); text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.lines td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines input, .lines select { min-height: 36px; padding: 6px 8px; }
.lines .w-qty { width: 80px; } .lines .w-rate { width: 120px; } .lines .w-tax { width: 90px; } .lines .w-disc { width: 80px; } .lines .w-amt { width: 120px; text-align: right; font-weight: 700; padding-top: 14px; }
.totals { margin-left: auto; width: min(360px, 100%); padding: 10px 0; }
.totals > div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13.5px; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font: 800 18px var(--display); }

/* Chat */
.chat { display: grid; grid-template-columns: 240px minmax(0, 1fr); height: calc(100vh - 170px); min-height: 460px; }
.chat-channels { border-right: 1px solid var(--line); overflow-y: auto; padding: 10px; }
.chat-channels a { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.chat-channels a.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.chat-channels a:hover { text-decoration: none; background: var(--surface-3); }
.chat-main { display: flex; flex-direction: column; min-width: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; gap: 10px; max-width: 80%; }
.msg .bubble { background: var(--surface-2); border: 1px solid var(--line); padding: 8px 12px; border-radius: 12px; border-top-left-radius: 4px; white-space: pre-wrap; word-wrap: break-word; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg.mine .bubble { background: var(--primary); color: #fff; border-color: var(--primary); border-top-left-radius: 12px; border-top-right-radius: 4px; }
.msg small { display: block; color: var(--faint); font-size: 11px; margin-bottom: 3px; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input textarea { min-height: 42px; height: 42px; resize: none; }

/* Welcome / hero */
.hero { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 22px 24px; margin-bottom: 18px; border-radius: 16px; color: #fff; background: linear-gradient(120deg, #2348c7 0%, #315de8 45%, #7259ee 100%); box-shadow: 0 14px 34px rgba(49, 93, 232, .25); flex-wrap: wrap; }
.hero h1 { color: #fff; font-size: 24px; }
.hero p { margin: 4px 0 0; opacity: .88; }
.hero .eyebrow { font-size: 11px; letter-spacing: 1.6px; font-weight: 700; opacity: .75; margin-bottom: 4px; }
.hero .btn-secondary { background: rgba(255, 255, 255, .14); color: #fff; border-color: rgba(255, 255, 255, .3); box-shadow: none; }
.hero .btn-secondary:hover { background: rgba(255, 255, 255, .22); }
.checkin-card { display: flex; align-items: center; gap: 12px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .25); padding: 10px 14px; border-radius: 12px; }
.checkin-card form { margin: 0; }
.checkin-card .btn { background: #fff; color: var(--primary); }

/* Auth pages */
.auth-body { background: var(--bg); }
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 1fr); }
.auth-art { position: relative; padding: 56px; display: flex; flex-direction: column; justify-content: center; gap: 18px; color: #fff; background: radial-gradient(circle at 20% 15%, #4b74ff 0%, transparent 55%), linear-gradient(140deg, #1a2f86 0%, #2348c7 45%, #6a4fe6 100%); overflow: hidden; }
.auth-art h1 { color: #fff; font-size: 44px; line-height: 1.08; letter-spacing: -1px; }
.auth-art p { opacity: .85; font-size: 16px; max-width: 440px; }
.auth-art .eyebrow { font-size: 11px; letter-spacing: 2px; font-weight: 700; opacity: .7; margin: 0; }
.auth-brands { display: flex; flex-wrap: wrap; gap: 8px; max-width: 480px; }
.auth-brands span { font-size: 12px; padding: 5px 10px; border-radius: 20px; background: rgba(255, 255, 255, .12); border: 1px solid rgba(255, 255, 255, .2); }
.auth-foot { position: absolute; bottom: 26px; left: 56px; font-size: 12px; opacity: .65; }
.auth-card { display: flex; flex-direction: column; justify-content: center; padding: 48px clamp(28px, 6vw, 80px); background: var(--surface); }
.auth-card h2 { font-size: 26px; margin-bottom: 4px; }
.auth-card form { display: grid; gap: 14px; margin-top: 22px; }
.auth-card label { display: grid; gap: 6px; font-weight: 600; font-size: 13px; }
.auth-card label.check { display: inline-flex; font-weight: 500; }
.auth-card .btn { height: 44px; }
.auth-note { color: var(--muted); font-size: 12.5px; margin-top: 18px; }
.otp-input { font-size: 24px !important; letter-spacing: 10px; text-align: center; font-family: ui-monospace, monospace; }

/* Errors */
.error-page { text-align: center; padding: 70px 20px; max-width: 520px; margin: 0 auto; }
.error-code { font: 800 72px var(--display); background: linear-gradient(135deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.error-page p { color: var(--muted); }
.error-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }

/* Search results */
.search-group h3 { padding: 12px 18px 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .6px; }

/* ───────── Responsive ───────── */
@media (max-width: 1180px) {
  .user-meta { display: none; }
  .brand-switch select { max-width: 110px; }
  .topbar { gap: 8px; padding: 0 16px; }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
  :root { --sidebar: 264px; }
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-scrim.open { display: block; position: fixed; inset: 0; background: rgba(10, 14, 25, .45); z-index: 35; }
  .nav-collapsed { --sidebar: 264px; }
  .nav-collapse { display: none; }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-grid; }
  .topbar { padding: 0 14px; }
  .page { padding: 18px 16px 36px; }
  .grid-2, .grid-2-1, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .chat { grid-template-columns: 1fr; }
  .chat-channels { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand-switch select { max-width: 100px; }
}
@media (max-width: 640px) {
  .hide-sm { display: none !important; }
  .global-search kbd { display: none; }
  .form-grid, .form-grid.cols-2, .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .field.span-2 { grid-column: auto; }
  .page-head { align-items: flex-start; }
  .kpi strong { font-size: 22px; }
  .hbar { grid-template-columns: 90px minmax(0, 1fr) auto; }
  .brand-switch { display: none; }
  .app-footer { flex-direction: column; padding: 14px 16px; }
  .cal-day { min-height: 70px; } .cal-item { font-size: 10px; padding: 2px 4px; }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; } .lines td:first-child { grid-column: 1 / -1; }
  .lines .w-qty, .lines .w-rate, .lines .w-tax, .lines .w-disc, .lines .w-amt { width: auto; }
}
@media print {
  .sidebar, .topbar, .app-footer, .page-actions, .toolbar, .no-print { display: none !important; }
  .main { margin: 0; } .page { padding: 0; } .panel { box-shadow: none; break-inside: avoid; }
}
