/* ==========================================================================
   Nexus CRM — Design tokens & components
   ========================================================================== */
:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --primary-text: #4338ca;

  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --neutral-soft: #f1f5f9;

  --sidebar: #0b1220;
  --sidebar-2: #151e31;
  --sidebar-text: #94a3b8;
  --sidebar-border: rgba(148, 163, 184, .12);

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 8px 24px -8px rgba(15, 23, 42, .15);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, .3);
  --ring: 0 0 0 3px rgba(79, 70, 229, .18);

  --sidebar-w: 252px;
  --topbar-h: 64px;
  --gutter: 28px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.text-right { text-align: right; }
.strong { font-weight: 600; }

/* Boot */
.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Layout
   ========================================================================== */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column; z-index: 40;
  transition: transform .25s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 18px; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; background: linear-gradient(135deg, #6366f1, #4338ca); display: grid; place-items: center; color: #fff; box-shadow: 0 6px 16px -4px rgba(99, 102, 241, .6); }
.brand-name { color: #fff; font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-tag { font-size: 12px; color: var(--sidebar-text); }

.sidebar-section { padding: 8px 12px; flex: 1; overflow-y: auto; }
.sidebar-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 12px 12px 8px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-text); font-weight: 500;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-link:hover { background: var(--sidebar-2); color: #e2e8f0; }
.nav-link.active { background: rgba(99, 102, 241, .16); color: #fff; }
.nav-link.active::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: #818cf8; }
.nav-link.active svg { color: #a5b4fc; }
.nav-badge { margin-left: auto; background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }

.sidebar-footer { padding: 16px; border-top: 1px solid var(--sidebar-border); display: grid; gap: 12px; }
.lang-switch { display: grid; grid-template-columns: 1fr 1fr; background: var(--sidebar-2); border-radius: var(--radius-sm); padding: 3px; }
.lang-switch button { border: 0; background: transparent; color: var(--sidebar-text); padding: 6px; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; }
.lang-switch button.active { background: #fff; color: var(--sidebar); }
.user-card { display: flex; align-items: center; gap: 10px; }
.user-card .avatar { background: #312e81; color: #c7d2fe; }
.user-name { color: #e2e8f0; font-weight: 600; font-size: 13px; }
.user-role { font-size: 12px; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 var(--gutter);
  background: rgba(245, 246, 250, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-crumb { color: var(--muted); font-size: 13px; }
.topbar-spacer { flex: 1; }
.btn.menu-toggle { display: none; }
.content { padding: var(--gutter); flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; }
.sidebar-backdrop { display: none; }

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: none; }
  .sidebar-backdrop.show { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
  .main { margin-left: 0; }
  .btn.menu-toggle { display: inline-flex; }
}
@media (max-width: 640px) {
  :root { --gutter: 16px; }
  .topbar-crumb { display: none; }
  .hide-sm { display: none !important; }
}

/* ==========================================================================
   Page header
   ========================================================================== */
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.page-subtitle { color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface); color: var(--text);
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--neutral-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

.icon-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center;
  border: 0; background: transparent; border-radius: var(--radius-xs);
  color: var(--muted); cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--neutral-soft); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }
.row-actions { display: inline-flex; gap: 2px; justify-content: flex-end; }

/* ==========================================================================
   Cards & KPIs
   ========================================================================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 0; }
.card-title { font-size: 15px; font-weight: 600; }
.card-subtitle { color: var(--muted); font-size: 13px; }
.card-body { padding: 16px 20px 20px; }
.card-link { font-size: 13px; font-weight: 600; }

.grid { display: grid; gap: 20px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.grid-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mb { margin-bottom: 20px; }
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .grid-2-1, .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 520px) { .kpi-grid { grid-template-columns: minmax(0, 1fr); } }

.kpi { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--muted); font-weight: 500; font-size: 13px; }
.kpi-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; }
.kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.trend { display: inline-flex; align-items: center; gap: 2px; font-weight: 600; padding: 1px 6px; border-radius: 999px; }
.trend.up { color: var(--success); background: var(--success-soft); }
.trend.down { color: var(--danger); background: var(--danger-soft); }
.trend.flat { color: var(--muted); background: var(--neutral-soft); }

.tone-primary { background: var(--primary-soft); color: var(--primary); }
.tone-success { background: var(--success-soft); color: var(--success); }
.tone-warning { background: var(--warning-soft); color: var(--warning); }
.tone-danger { background: var(--danger-soft); color: var(--danger); }
.tone-info { background: var(--info-soft); color: var(--info); }

/* ==========================================================================
   Badges, avatars
   ========================================================================== */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: #b45309; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary-text); }
.badge-neutral { background: var(--neutral-soft); color: var(--muted); }

.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.avatar-lg { width: 52px; height: 52px; font-size: 17px; }
.cell-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-user .title { font-weight: 600; color: var(--text); }
.cell-user .sub { color: var(--muted); font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-thumb { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 600px) { .form-grid { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2 { grid-column: auto; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-label .opt { color: var(--faint); font-weight: 400; margin-left: 4px; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; color: var(--danger); display: none; }
.field.invalid .field-error { display: block; }
.field.invalid .input { border-color: var(--danger); }
.field.invalid .input:focus { box-shadow: 0 0 0 3px rgba(220, 38, 38, .15); }

.input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; padding: 10px 12px; resize: vertical; min-height: 84px; }
select.input { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.input:hover { border-color: #b6bcc8; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input::placeholder { color: var(--faint); }
.input-sm { height: 34px; font-size: 13px; }
.input-group { position: relative; }
.input-group .prefix { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; display: flex; }
.input-group .input { padding-left: 38px; }

.segmented { display: inline-flex; background: var(--neutral-soft); border-radius: var(--radius-sm); padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ==========================================================================
   Data table
   ========================================================================== */
.dt { overflow: hidden; }
.dt-toolbar { display: flex; gap: 10px; padding: 16px; flex-wrap: wrap; align-items: center; border-bottom: 1px solid var(--border); }
.dt-search { flex: 1 1 240px; max-width: 360px; }
.dt-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.dt-filters .input { width: auto; min-width: 140px; }
.dt-toolbar-right { margin-left: auto; display: flex; gap: 8px; }
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort-ind { display: inline-flex; vertical-align: middle; margin-left: 4px; opacity: .35; }
.table th[aria-sort] .sort-ind { opacity: 1; color: var(--primary); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: #fafbff; }
.table tbody tr.clickable { cursor: pointer; }
.table .align-right { text-align: right; }
.table .align-center { text-align: center; }
.table-compact td, .table-compact th { padding: 9px 12px; }

.dt-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.pagination { display: flex; gap: 4px; align-items: center; }
.page-btn { min-width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-xs); cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text-2); display: inline-grid; place-items: center; padding: 0 8px; }
.page-btn:hover:not(:disabled) { background: var(--surface-2); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: .45; cursor: not-allowed; }
.page-size { display: flex; align-items: center; gap: 8px; }
.page-size .input { width: 76px; }

/* ==========================================================================
   Empty states, lists
   ========================================================================== */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--neutral-soft); display: grid; place-items: center; margin: 0 auto 14px; color: var(--faint); }
.empty-title { color: var(--text); font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.empty .btn { margin-top: 16px; }
.empty.compact { padding: 28px 12px; }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; color: var(--text); }
.list-item .sub { font-size: 12px; color: var(--muted); }
.rank { width: 24px; height: 24px; border-radius: 6px; background: var(--neutral-soft); color: var(--muted); font-size: 12px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.rank.r1 { background: #fef3c7; color: #b45309; }
.rank.r2 { background: #e2e8f0; color: #475569; }
.rank.r3 { background: #ffedd5; color: #c2410c; }

.progress { height: 6px; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: #f59e0b; }
.progress.danger > span { background: var(--danger); }
.stock-cell { display: flex; flex-direction: column; gap: 6px; min-width: 120px; }
.stock-cell .progress { width: 100%; }

/* ==========================================================================
   Alerts
   ========================================================================== */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius); border: 1px solid; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }
.alert-info { background: var(--info-soft); border-color: #bae6fd; color: #075985; }
.alert-title { font-weight: 600; }
.alert .grow { flex: 1; }
.alert-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: rgba(255, 255, 255, .7); border: 1px solid #fde68a; border-radius: 999px; font-size: 12px; font-weight: 600; color: #92400e; cursor: pointer; }
.chip:hover { background: #fff; }

/* ==========================================================================
   Charts
   ========================================================================== */
.chart { position: relative; height: 240px; display: flex; gap: 10px; }
.chart-y { display: flex; flex-direction: column; justify-content: space-between; font-size: 11px; color: var(--faint); text-align: right; padding-bottom: 22px; min-width: 48px; }
.chart-area { position: relative; flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chart-plot { position: relative; flex: 1; display: flex; align-items: flex-end; gap: 4px; border-bottom: 1px solid var(--border); }
.chart-grid { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.chart-grid span { border-top: 1px dashed var(--border); }
.chart-grid span:last-child { border-top: 0; }
.chart-bar { position: relative; flex: 1; display: flex; align-items: flex-end; height: 100%; min-width: 3px; }
.chart-bar > i { display: block; width: 100%; max-width: 36px; margin: 0 auto; border-radius: 5px 5px 2px 2px; background: linear-gradient(180deg, #818cf8, #4f46e5); transition: opacity .15s; min-height: 2px; }
.chart-bar:hover > i { opacity: .8; }
.chart-bar .tip {
  position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 6px; white-space: nowrap;
  pointer-events: none; opacity: 0; transition: opacity .12s; z-index: 2; box-shadow: var(--shadow-md);
}
.chart-bar .tip b { display: block; font-weight: 600; }
.chart-bar:hover .tip { opacity: 1; }
.chart-x { display: flex; gap: 4px; height: 22px; align-items: flex-end; }
.chart-x span { flex: 1; text-align: center; font-size: 11px; color: var(--faint); white-space: nowrap; overflow: visible; min-width: 3px; }

.hbar { display: grid; gap: 14px; }
.hbar-row { display: grid; gap: 6px; }
.hbar-top { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.hbar-top .label { font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.hbar-top .dot { width: 8px; height: 8px; border-radius: 3px; }
.hbar .progress { height: 8px; }

/* ==========================================================================
   Modal & drawer
   ========================================================================== */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15, 23, 42, .5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes slide { from { transform: translateX(100%); } }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: calc(100vh - 40px);
  display: flex; flex-direction: column; animation: pop .18s ease;
}
.modal.lg { max-width: 860px; }
.modal.sm { max-width: 420px; }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 20px 24px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-subtitle { color: var(--muted); font-size: 13px; margin-top: 2px; }
.modal-body { padding: 20px 24px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; flex-wrap: wrap; }
.modal-footer .left { margin-right: auto; display: flex; align-items: center; }

.overlay.drawer-overlay { justify-content: flex-end; padding: 0; }
.drawer {
  background: var(--surface); height: 100%; width: 100%; max-width: 620px;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slide .22s ease;
}
.drawer .modal-footer { border-radius: 0; }

.confirm-body { display: flex; gap: 16px; }
.confirm-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; }

@media (max-width: 600px) {
  .overlay { padding: 0; align-items: flex-end; }
  .modal { max-height: 94vh; border-radius: 16px 16px 0 0; }
  .modal-footer { border-radius: 0; }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
}

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 8px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab .count { background: var(--neutral-soft); color: var(--muted); border-radius: 999px; padding: 0 7px; font-size: 11px; }
.tab.active .count { background: var(--primary-soft); color: var(--primary); }

/* Dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 230px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 6px; display: none;
}
.dropdown.open .dropdown-menu { display: block; animation: pop .12s ease; }
.dropdown-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; border-radius: var(--radius-xs); cursor: pointer; text-align: left; font-weight: 500; color: var(--text-2); }
.dropdown-item:hover { background: var(--neutral-soft); color: var(--text); }
.dropdown-item .kbd { margin-left: auto; color: var(--faint); font-size: 12px; }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }
.dropdown-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 8px 10px 4px; }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-soft); }
.dropdown-item .check { margin-left: auto; color: var(--primary); }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 40px); }
.toast { display: flex; align-items: center; gap: 10px; background: var(--text); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); min-width: 260px; max-width: 420px; animation: pop .2s ease; font-weight: 500; }
.toast.success svg { color: #34d399; }
.toast.error svg { color: #f87171; }
.toast.warning svg { color: #fbbf24; }
.toast.leave { opacity: 0; transform: translateY(6px); transition: all .2s; }

/* ==========================================================================
   Detail views
   ========================================================================== */
.profile { display: flex; gap: 16px; align-items: center; margin-bottom: 20px; }
.profile-name { font-size: 18px; font-weight: 700; }
.stat-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
@media (max-width: 520px) { .stat-row { grid-template-columns: minmax(0, 1fr); } }
.dl { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 10px 16px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 10px; }
.notes-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; white-space: pre-wrap; color: var(--text-2); }

.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ''; position: absolute; left: 15px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline li { position: relative; display: flex; gap: 14px; padding-bottom: 16px; }
.timeline .t-icon { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; z-index: 1; border: 3px solid var(--surface); flex-shrink: 0; }
.timeline .t-body { flex: 1; min-width: 0; padding-top: 4px; }
.timeline .t-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.timeline .t-head b { color: var(--text); font-size: 13px; }
.timeline .t-text { margin-top: 2px; color: var(--text-2); overflow-wrap: anywhere; }

/* Sale form line items */
.line-items { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.line-items-head, .line-item { display: grid; grid-template-columns: minmax(0, 1fr) 90px 120px 110px 36px; gap: 10px; align-items: start; padding: 10px 12px; }
.line-items-head { background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--border); }
.line-item { border-bottom: 1px solid var(--border); }
.line-item:last-of-type { border-bottom: 0; }
.line-item .subtotal { padding-top: 9px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.line-item .avail { font-size: 11px; color: var(--muted); margin-top: 4px; }
.line-item .avail.bad { color: var(--danger); font-weight: 600; }
.line-items-add { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface-2); }
.line-items-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 680px) {
  .line-items-head { display: none; }
  .line-item { grid-template-columns: 1fr 1fr; }
  .line-item > :first-child { grid-column: span 2; }
  .line-item .subtotal { text-align: left; }
}
.totals { margin-left: auto; width: 100%; max-width: 320px; display: grid; gap: 8px; margin-top: 16px; }
.totals-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-variant-numeric: tabular-nums; }
.totals-row.grand { font-size: 18px; font-weight: 700; padding-top: 10px; border-top: 1px solid var(--border); }
.totals-row .input { width: 130px; text-align: right; }

.receipt-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.receipt-number { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }

.qty-in { color: var(--success); font-weight: 600; }
.qty-out { color: var(--danger); font-weight: 600; }

.preview-balance { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px dashed var(--border-strong); }
.preview-balance .arrow { color: var(--faint); }
.preview-balance b { font-size: 18px; font-variant-numeric: tabular-nums; }

@media (max-width: 640px) {
  .dt-search { max-width: none; }
  .dt-filters { width: 100%; }
  .dt-filters .input { flex: 1 1 140px; }
  .page-actions { width: 100%; }
  .page-actions .segmented { width: 100%; justify-content: space-between; }
}

/* ==========================================================================
   Login
   ========================================================================== */
.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(99, 102, 241, .18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(14, 165, 233, .14), transparent 60%),
    var(--bg);
}
.login-card { width: 100%; max-width: 420px; padding: 32px; box-shadow: var(--shadow-md); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-app { font-weight: 700; font-size: 16px; }
.login-title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.login-sub { margin: 6px 0 22px; }
.login-alert { margin-bottom: 16px; padding: 10px 12px; font-size: 13px; align-items: center; }
.alert-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.login-form { display: grid; gap: 16px; }
.input-lg { height: 44px; }
.pass-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.input-group .input[type=password], .input-group .input#login-pass { padding-right: 44px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.btn-lg { height: 44px; font-size: 15px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .7s linear infinite; }
.login-help { font-size: 12px; text-align: center; margin: 18px 0 0; }
.login-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.login-secure { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--success); font-weight: 600; }
@media (max-width: 480px) { .login-card { padding: 24px 20px; } }

.user-btn { padding: 0; width: 38px; border-radius: 50%; }
.user-btn .avatar { width: 34px; height: 34px; }
.dropdown-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
