/* ================================================================
   Design tokens
   ================================================================ */

:root {
  --bg-top: #f8fafc;
  --bg-bottom: #edf2f7;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --surface-hover: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-faint: #94a3b8;

  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #6366f1;
  --primary-soft: #eef2ff;

  --success: #059669;
  --success-bg: #ecfdf5;
  --error: #dc2626;
  --error-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --info: #2563eb;
  --info-bg: #eff6ff;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 20px 44px rgba(15, 23, 42, 0.14), 0 2px 8px rgba(15, 23, 42, 0.06);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;

  --sidebar-w: 238px;
  --sidebar-w-collapsed: 70px;
  --header-h: 64px;
}

:root[data-theme="dark"] {
  --bg-top: #0b0f19;
  --bg-bottom: #06080e;
  --surface: #111827;
  --surface-alt: #162032;
  --surface-hover: #1f293d;
  --border: #222f46;
  --border-strong: #2e3e5c;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.16);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.14);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.14);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.14);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 1px 4px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 48px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 540px);
  background-color: var(--bg-bottom);
  color: var(--text);
  font-family: "Inter", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body.modal-open {
  overflow: hidden;
}

::selection { background: var(--primary-soft); color: var(--primary-dark); }

/* ================================================================
   Header
   ================================================================ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  height: var(--header-h);
  padding: 0 24px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 9px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-alt); color: var(--text); border-color: var(--border-strong); }

#mobile-menu-btn { display: none; }

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }

.brand-logo-img {
  height: 45px;
  width: auto;
  display: block;
  flex-shrink: 0;
  background: #fff;
  border-radius: 6px;
  padding: 4px 0px;
  box-shadow: var(--shadow-xs);
}

.brand-text { min-width: 0; }
.breadcrumb { font-size: 12px; color: var(--text-faint); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.breadcrumb .current { color: var(--text); font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

.badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

.badge-label { color: var(--text-faint); font-weight: 500; }
.badge strong { color: var(--text); font-weight: 600; }

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.status-dot.ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.status-dot.err { background: var(--error); box-shadow: 0 0 0 3px var(--error-bg); }

/* user menu */

.user-menu { position: relative; }

.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 3px 10px 3px 3px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  transition: background 0.15s, border-color 0.15s;
}

.user-menu-btn:hover { background: var(--surface-alt); border-color: var(--border-strong); }

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(150deg, var(--primary-light), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-menu-btn .chev { width: 12px; height: 12px; color: var(--text-faint); }

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 190px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 50;
  display: none;
}

.user-menu-dropdown.open { display: block; animation: pop-in 0.12s ease; }

.user-menu-meta {
  padding: 8px 10px 6px;
  font-size: 11px;
  color: var(--text-faint);
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  text-align: left;
  font-family: inherit;
}

.user-menu-item svg { width: 14px; height: 14px; color: var(--text-faint); }
.user-menu-item:hover { background: var(--surface-alt); }
.user-menu-item.danger { color: var(--error); }
.user-menu-item.danger svg { color: var(--error); }
.user-menu-item.danger:hover { background: var(--error-bg); }

@keyframes pop-in {
  from { opacity: 0; transform: translateY(-4px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ================================================================
   App shell (sidebar layout)
   ================================================================ */

.app-shell {
  display: flex;
  align-items: flex-start;
  width: 100%;
  padding: 20px 24px 60px;
  gap: 22px;
}

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.55);
  backdrop-filter: blur(4px);
  z-index: 39;
}

.sidebar-backdrop.show { display: block; animation: fade-in 0.15s ease; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: calc(var(--header-h) + 16px);
  height: calc(100vh - var(--header-h) - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.07), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  padding: 16px 12px 12px;
  transition: width 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s ease;
  z-index: 25;
}

.sidebar-scroll {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 4px;
}
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.nav-group-wrapper {
  display: flex;
  flex-direction: column;
  position: relative;
}

.nav-group-wrapper:not(:first-child) {
  padding-top: 10px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
}

.nav-group-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 4px 10px 6px;
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
  text-align: left;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.16s ease;
  position: relative;
}

.nav-link svg {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  color: var(--text-faint);
  transition: color 0.16s ease, transform 0.16s ease;
}

.nav-link span {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  transform: translateX(2px);
}

.nav-link:hover svg {
  color: var(--primary);
  transform: scale(1.08);
}

.nav-link.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #ffffff;
  font-weight: 600;
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.32);
  transform: translateX(0);
}

.nav-link.active svg {
  color: #ffffff !important;
  transform: scale(1.05);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.sidebar-footer-info {
  font-size: 11px;
  color: var(--text-faint);
  padding-left: 6px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
  padding: 16px 8px 12px;
}
.sidebar.collapsed .nav-group-label,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .sidebar-footer-info {
  display: none;
}
.sidebar.collapsed .nav-group-wrapper:not(:first-child) {
  padding-top: 6px;
  margin-top: 4px;
}
.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 10px;
  border-radius: 10px;
}
.sidebar.collapsed #sidebar-collapse-btn svg {
  transform: rotate(180deg);
}

.app-content { flex: 1; min-width: 0; }

@media (max-width: 960px) {
  #mobile-menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -300px;
    height: 100vh;
    width: 270px;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    padding: 20px 16px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    transition: left 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .sidebar.mobile-open { left: 0; }
  .sidebar.collapsed { width: 270px; padding: 20px 16px; }
  .sidebar.collapsed .nav-group-label,
  .sidebar.collapsed .nav-link span,
  .sidebar.collapsed .sidebar-footer-info { display: block; }
  .sidebar.collapsed .nav-link { justify-content: flex-start; padding: 9px 12px; }

  #sidebar-collapse-btn { display: none; }
}

/* ================================================================
   Layout / typography
   ================================================================ */

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade-in 0.18s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-head h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -0.02em; font-weight: 700; }
.subtitle { margin: 0; color: var(--text-muted); font-size: 13.5px; line-height: 1.5; max-width: 65ch; }

.section-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  margin: 24px 0 10px;
}

h3 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; font-size: 12.5px; }
.muted { color: var(--text-faint); font-size: 12.5px; }
.hint { font-weight: 400; text-transform: none; color: var(--text-faint); font-size: 11.5px; }

/* ================================================================
   Buttons & Actions
   ================================================================ */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  white-space: nowrap;
  user-select: none;
}

button:hover, .btn:hover {
  background: var(--surface-alt);
  border-color: var(--border-strong);
}

button.primary, .btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
  box-shadow: var(--shadow-sm);
}

button.primary:hover, .btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

button.btn-sm, .btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

button.btn-secondary, .btn-secondary {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text-muted);
}

button.btn-secondary:hover, .btn-secondary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

button.btn-danger, .btn-danger {
  background: var(--error-bg);
  border-color: rgba(220, 38, 38, 0.2);
  color: var(--error);
}

button.btn-danger:hover, .btn-danger:hover {
  background: var(--error);
  color: #fff;
}

button:disabled, .btn:disabled {
  opacity: 0.6;
  cursor: not-allowed !important;
}

button.is-loading, .btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

button.is-loading::after, .btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: btn-spin 0.6s linear infinite;
  color: var(--text);
}

button.primary.is-loading::after, .btn-primary.is-loading::after {
  color: #fff;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

/* ================================================================
   Forms & Inputs
   ================================================================ */

form {
  margin: 0;
  padding: 0;
}

.row {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: flex-end;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 200px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
}

label.grow { flex: 2 1 280px; }

input, textarea, select {
  font-size: 13.5px;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea { resize: vertical; }

input::placeholder, textarea::placeholder { color: var(--text-faint); }

input:hover, textarea:hover, select:hover { border-color: var(--border-strong); }

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2394a3b8'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
  cursor: pointer;
}

input[type="checkbox"], input[type="radio"] {
  width: auto;
  padding: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ================================================================
   Segmented control
   ================================================================ */

.segmented {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 10px;
}

.segmented-option { position: relative; cursor: pointer; margin: 0; }

.segmented-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  margin: 0;
}

.segmented-option span {
  display: block;
  padding: 6px 16px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s ease;
}

.segmented-option input:checked + span {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-xs);
}

/* ================================================================
   Reusable Data Table & Pagination
   ================================================================ */

.dt-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dt-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.dt-search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 240px;
  max-width: 360px;
}

.dt-search-icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

.dt-search-input {
  width: 100%;
  padding: 8px 30px 8px 32px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}

.dt-search-input:focus {
  background: var(--surface);
  border-color: var(--primary);
}

.dt-search-clear {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 14px;
  padding: 4px;
  cursor: pointer;
  line-height: 1;
}

.dt-search-clear:hover { color: var(--text); }

.dt-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.dt-page-size-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.dt-page-size-select {
  padding: 5px 24px 5px 8px;
  font-size: 12.5px;
  border-radius: 6px;
  background-position: right 8px center;
}

.dt-count-badge {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--surface-alt);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.dt-table-container {
  overflow-y: auto;
  overflow-x: auto;
  background: var(--surface);
  min-height: 120px;
}

.dt-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.dt-table thead th {
  background: var(--surface-alt);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  white-space: nowrap;
  user-select: none;
}

.dt-th-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dt-sortable {
  cursor: pointer;
}

.dt-sortable:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.dt-sort-icon {
  display: inline-block;
  width: 12px;
  height: 12px;
  opacity: 0.3;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path d='m7 15 5 5 5-5M7 9l5-5 5 5'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.sort-asc .dt-sort-icon {
  opacity: 1;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path d='m18 15-6-6-6 6'/></svg>");
}

.sort-desc .dt-sort-icon {
  opacity: 1;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%234f46e5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
}

.dt-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
  color: var(--text);
}

.dt-table tbody tr:last-child td { border-bottom: none; }
.dt-table tbody tr:hover { background: var(--surface-hover); }

.dt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12.5px;
}

.dt-info {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.dt-scroll-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
  font-weight: 500;
}

.dt-scroll-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  opacity: 0.8;
  animation: pulse 1.6s infinite ease-in-out;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.15); }
}

/* ================================================================
   Modal Popup Dialog System
   ================================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 26, 0.6);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-backdrop.show {
  display: flex;
  animation: modal-fade-in 0.18s ease forwards;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  position: relative;
  animation: modal-pop-in 0.22s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.modal-card.modal-lg { max-width: 820px; }
.modal-card.modal-xl { max-width: 1040px; }

@keyframes modal-pop-in {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  gap: 16px;
}

.modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}

.modal-subtitle {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: all 0.15s;
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ================================================================
   Voucher Detail Viewer Modal
   ================================================================ */

.vch-detail-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  padding: 2px 6px;
  margin: -2px -6px;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.vch-detail-link:hover {
  background: var(--primary-soft);
  color: var(--primary-dark);
  text-decoration: underline;
}

.vch-icon-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.vd-header-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.vd-info-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.vd-card-span {
  grid-column: 1 / -1;
}

.vd-info-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  text-transform: uppercase;
}

.vd-info-val {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.vd-narration-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 18px;
}

.vd-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
}

.vd-section-head h4 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ================================================================
   Total Summary Banner & Settle Bar
   ================================================================ */

.total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  margin: 18px 0;
}

.total-label { font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.total-value { font-size: 20px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }

.settle-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  margin-top: 16px;
}

/* ================================================================
   Item & Tax Tables (inside form vouchers)
   ================================================================ */

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 12px;
  background: var(--surface);
}

.table-wrap table {
  width: 100%;
  border-collapse: collapse;
}

.table-wrap thead th {
  background: var(--surface-alt);
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

.table-wrap tbody td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: middle;
}

.table-wrap tbody tr:last-child td { border-bottom: none; }

.table-wrap input, .table-wrap select {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.table-wrap input:hover, .table-wrap select:hover { border-color: var(--border); }
.table-wrap input:focus, .table-wrap select:focus { border-color: var(--primary); background: var(--surface); box-shadow: 0 0 0 3px var(--primary-soft); }

.amt { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

.del-item, .del-tax {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 4px;
}

.del-item:hover, .del-tax:hover { color: var(--error); background: var(--error-bg); }

/* ================================================================
   Hero stat cards
   ================================================================ */

.hero-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.hero-card {
  position: relative;
  border-radius: var(--radius);
  padding: 20px 22px;
  color: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 130px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.hero-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.hero-card.c-blue { background: linear-gradient(135deg, #4f46e5, #3730a3); }
.hero-card.c-amber { background: linear-gradient(135deg, #f59e0b, #d97706); }
.hero-card.c-rose { background: linear-gradient(135deg, #f43f5e, #e11d48); }
.hero-card.c-violet { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }

.hero-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.hero-card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  opacity: 0.9;
}

.hero-card-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-card-icon svg { width: 16px; height: 16px; }

.hero-card-value {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.hero-card-sub {
  font-size: 11.5px;
  opacity: 0.85;
  margin-top: 4px;
}

.hero-card-wave {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40px;
  pointer-events: none;
}

/* ================================================================
   Secondary Stat Tiles & Charts
   ================================================================ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--primary-soft);
  color: var(--primary);
}

.stat-icon svg { width: 18px; height: 18px; }

.stat-tile.accent-info .stat-icon { background: var(--info-bg); color: var(--info); }
.stat-tile.accent-success .stat-icon { background: var(--success-bg); color: var(--success); }

.stat-body { min-width: 0; }

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
  margin-bottom: 22px;
}

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.chart-card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.chart-legend-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.trend-chart { width: 100%; height: auto; display: block; }
.grid-line { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 3; }
.axis-label, .month-label { fill: var(--text-faint); font-size: 10px; font-family: inherit; }
.bar-sales { fill: var(--primary); }
.bar-purchase { fill: #d97706; }

.donut-wrap { height: 100%; display: flex; align-items: center; gap: 20px; justify-content: center; padding: 10px 0; }
.donut-wrap svg { flex-shrink: 0; }
.radial-center-value { fill: var(--text); font-size: 13px; font-weight: 700; text-anchor: middle; }
.radial-center-label { fill: var(--text-faint); font-size: 8px; text-anchor: middle; }

.donut-legend { display: flex; flex-direction: column; gap: 10px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.donut-legend-item .dot { width: 9px; height: 9px; border-radius: 3px; flex-shrink: 0; }
.donut-legend-item .lbl { color: var(--text-muted); }
.donut-legend-item .val { font-weight: 700; color: var(--text); margin-left: 4px; }

/* ================================================================
   Horizontal bar list — "Top N" style charts (best sellers, deadstock)
   ================================================================ */

.hbar-list { display: flex; flex-direction: column; gap: 12px; }

.hbar-row {
  display: grid;
  grid-template-columns: minmax(90px, 220px) 1fr auto;
  align-items: center;
  gap: 12px;
}

.hbar-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
  margin-right: 6px;
}

.hbar-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
}

.hbar-track {
  background: var(--surface-alt);
  border-radius: 6px;
  height: 10px;
  overflow: hidden;
}

.hbar-fill {
  height: 100%;
  border-radius: 6px;
  min-width: 3px;
  transition: width 0.4s ease;
}

.hbar-value {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}

@media (max-width: 640px) {
  .hbar-row { grid-template-columns: 1fr; gap: 4px; }
  .hbar-value { text-align: left; }
}

.dashboard-tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-top: 20px;
}

.dashboard-table-col {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dashboard-table-col h3 {
  margin-top: 0;
  margin-bottom: 12px;
}

@media (max-width: 1100px) {
  .dashboard-tables-grid {
    grid-template-columns: 1fr;
  }
}

/* Deadstock report: "Sold" has more columns than "Not Sold", so it gets more
   width instead of a strict 50/50 split. */
.deadstock-tables-grid {
  grid-template-columns: 2fr 3fr;
}

/* ================================================================
   Toasts
   ================================================================ */

#toast-container {
  position: fixed;
  top: 76px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--info);
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease;
  font-size: 13px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warning { border-left-color: var(--warning); }

.toast-icon { flex-shrink: 0; margin-top: 1px; }
.toast-icon svg { width: 16px; height: 16px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }

.toast-msg { flex: 1; color: var(--text); line-height: 1.45; }
.toast-close { border: none; background: transparent; padding: 0; color: var(--text-faint); cursor: pointer; flex-shrink: 0; }
.toast-close:hover { color: var(--text); background: transparent; }

.toast.leaving { animation: toast-out 0.15s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(16px); }
}

/* ================================================================
   Skeleton loaders & empty states
   ================================================================ */

.skel {
  background: linear-gradient(90deg, var(--surface-alt) 25%, var(--surface-hover) 37%, var(--surface-alt) 63%);
  background-size: 400% 100%;
  animation: skel-shimmer 1.4s ease infinite;
  border-radius: 6px;
}

@keyframes skel-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

.skel-stat-value { width: 70px; height: 21px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 36px 20px;
  color: var(--text-faint);
  text-align: center;
}

.empty-state svg { width: 32px; height: 32px; color: var(--text-faint); opacity: 0.7; }
.empty-state .empty-title { font-size: 13.5px; font-weight: 600; color: var(--text-muted); }
.empty-state .empty-hint { font-size: 12px; }

/* ================================================================
   Result panel
   ================================================================ */

.result-wrap { margin-top: 14px; }

.result-banner {
  display: none;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
}

.result-banner.show { display: flex; }
.result-banner svg { width: 16px; height: 16px; flex-shrink: 0; }

.result-banner.success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(5, 150, 105, 0.25); }
.result-banner.error { background: var(--error-bg); color: var(--error); border: 1px solid rgba(220, 38, 38, 0.25); }

.result-details {
  margin-top: 6px;
}

.result-details summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-bottom: 4px;
  user-select: none;
}

.result {
  background: #0b1020;
  color: #c7cedb;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid #1c2333;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow: auto;
}

.result:empty::before { content: "—"; color: #3a4356; }
.result.success { border-color: var(--success); box-shadow: 0 0 0 1px rgba(5, 150, 105, 0.3) inset; }
.result.error { border-color: var(--error); box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.3) inset; }

/* ================================================================
   Searchable dropdown (autocomplete combobox)
   ================================================================ */

.ss { position: relative; width: 100%; }
.ss select { display: none; }

.ss-input {
  width: 100%;
  cursor: text;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M0 0l5 6 5-6z' fill='%2394a3b8'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
}

.ss-input:disabled { cursor: not-allowed; opacity: 0.6; }

.ss-clear {
  position: absolute;
  top: 50%;
  right: 26px;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--text-faint);
  width: 20px;
  height: 20px;
  border-radius: 5px;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.ss-clear:hover { background: var(--surface-alt); color: var(--text); }

.ss-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  width: 100%;
  z-index: 500;
  max-height: 230px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  box-shadow: 0 10px 28px -4px rgba(0, 0, 0, 0.18), 0 4px 10px -2px rgba(0, 0, 0, 0.08);
  padding: 4px;
}

.table-wrap {
  position: relative;
  overflow: visible;
  margin-bottom: 14px;
}

#items-table,
#p-items-table,
#taxes-table,
#p-taxes-table {
  overflow: visible;
}

#items-table td,
#p-items-table td,
#taxes-table td,
#p-taxes-table td {
  overflow: visible;
  position: relative;
}

#items-table td:first-child,
#p-items-table td:first-child {
  min-width: 280px;
}

#items-table td:first-child .ss-menu,
#p-items-table td:first-child .ss-menu {
  min-width: 280px;
}

.ss-item {
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ss-item:hover, .ss-item.hl { background: var(--primary-soft); color: var(--primary); }
.ss-item.selected { font-weight: 600; color: var(--primary); }

.ss-empty {
  padding: 10px;
  font-size: 12.5px;
  color: var(--text-faint);
  text-align: center;
}

/* ================================================================
   Responsive Breakpoints
   ================================================================ */

@media (max-width: 860px) {
  .chart-grid { grid-template-columns: 1fr; }
  .app-shell { padding: 16px; }
}

@media (max-width: 640px) {
  .row { flex-direction: column; align-items: stretch; }
  label.grow { min-width: 0; }
  .header-right .badge.status-badge { display: none; }
  .section-head { flex-direction: column; align-items: flex-start; }
  .modal-card { max-height: 95vh; }
}

/* ================================================================
   Login — split screen
   ================================================================ */

.login-split {
  display: flex;
  min-height: 100vh;
}

.login-illustration {
  flex: 1 1 46%;
  background: linear-gradient(160deg, var(--surface-alt), var(--primary-soft));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
}

.login-illustration svg { width: 100%; max-width: 380px; height: auto; }

.login-form-side {
  flex: 1 1 54%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  background: var(--surface);
}

.login-theme-btn { position: absolute; top: 24px; right: 28px; }

.login-form-inner { width: 100%; max-width: 380px; }

.login-form-inner .flow-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px;     justify-content: center; }
.login-form-inner .flow-brand .brand-logo-img { height: 70px; }

.login-welcome { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 6px; color: var(--primary); text-align: center; }
.login-form-inner .subtitle { margin: 0 0 24px; text-align: center;}

.login-form-inner form { box-shadow: none; border: none; padding: 0; background: transparent; }
.login-form-inner label { margin-bottom: 16px; }
.login-form-inner input { width: 100%; }
.login-form-inner button.primary { width: 100%; margin-top: 4px; }

.login-hint {
  margin: 20px 0 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
  line-height: 1.5;
}

.flow-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(220, 38, 38, 0.25);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.flow-error.show { display: block; }

@media (max-width: 860px) {
  .login-illustration { display: none; }
  .login-form-side { flex: 1 1 100%; }
}

/* Deadstock Advance — Stock Value filter pills */
.ds-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.ds-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.ds-pill:hover { background: var(--surface-hover); color: var(--text); }
.ds-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.ds-pill-count { font-variant-numeric: tabular-nums; font-weight: 500; opacity: 0.75; }

/* Deadstock Advance — "Last Transaction Comparison" control (lives in the table toolbar) */
.ds-n-ctrl { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ds-n-title { font-size: 12.5px; font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.ds-n-ctrl input[type="number"] { width: 72px; padding-top: 6px; padding-bottom: 6px; }
.ds-n-ctrl button { padding: 7px 16px; }

/* Deadstock Advance — graphical view. Colours validated with the dataviz
   palette checker: 3-step ordinal ramp (slow → fast) + 2 categorical slots. */
:root {
  --ds-ord-1: #86b6ef; --ds-ord-2: #2a78d6; --ds-ord-3: #104281;
  --ds-a: #2a78d6; --ds-b: #eb6834; --ds-c: #1baf7a;
}
:root[data-theme="dark"] {
  --ds-ord-1: #184f95; --ds-ord-2: #3987e5; --ds-ord-3: #9ec5f4;
  --ds-a: #3987e5; --ds-b: #d95926; --ds-c: #199e70;
}

.ds-graph-toolbar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.ds-two-col { grid-template-columns: 1fr 1fr; }

.ds-pie-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.ds-pie { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.ds-pie svg { flex-shrink: 0; overflow: visible; }
.ds-pie-slice { transition: opacity 0.15s; }
.ds-pie:hover .ds-pie-slice:not(:hover) { opacity: 0.55; }
.ds-pie-legend { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.ds-pie-legend-row { display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 8px; font-size: 12.5px; }
.ds-pie-legend-row .dot { width: 10px; height: 10px; border-radius: 3px; }
.ds-pie-legend-row .lbl { color: var(--text-muted); font-weight: 500; }
.ds-pie-legend-row .val { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.ds-pie-legend-row .val span { font-weight: 500; color: var(--text-faint); margin-left: 4px; }
.ds-pie-sub { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 16px; font-size: 12px; }
.ds-pie-sub div { display: flex; justify-content: space-between; gap: 8px; color: var(--text-muted); }
.ds-pie-sub b { color: var(--text); font-variant-numeric: tabular-nums; }
.ds-pie-center-value { pointer-events: none; font-size: 17px; font-weight: 800; fill: var(--text); text-anchor: middle; }
.ds-pie-center-label { pointer-events: none; font-size: 8px; fill: var(--text-faint); text-anchor: middle; text-transform: uppercase; letter-spacing: 0.06em; }

.ds-hbar-note { font-weight: 500; color: var(--text-faint); margin-left: 6px; font-size: 11.5px; }

.ds-compare { display: flex; align-items: stretch; gap: 10px; overflow-x: auto; padding-bottom: 26px; }
.ds-compare-axis { display: flex; flex-direction: column; justify-content: space-between; font-size: 10.5px; color: var(--text-faint); text-align: right; font-variant-numeric: tabular-nums; height: 240px; }
.ds-compare-plot {
  flex: 1; min-width: 0; display: flex; align-items: flex-end; gap: 14px; height: 240px;
  border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%);
}
.ds-compare-group { flex: 1 0 44px; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px; position: relative; }
.ds-compare-bar { width: 42%; max-width: 26px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height 0.4s ease; }
.ds-compare-label { position: absolute; top: 100%; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--text-muted); padding-top: 5px; }

.ds-tip {
  position: fixed; z-index: 1000; pointer-events: none; opacity: 0;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-md);
  padding: 8px 10px; font-size: 12px; line-height: 1.45; max-width: 260px;
  transition: opacity 0.08s;
}
.ds-tip.show { opacity: 1; }
.ds-tip strong { display: block; margin-bottom: 2px; }

@media (max-width: 1100px) {
  .ds-pie-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .ds-two-col { grid-template-columns: 1fr; }
}

/* Deadstock Advance — profit insights */
.stat-sub { font-size: 11.5px; color: var(--text-faint); margin-top: 2px; font-weight: 500; }
.ds-insights-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.ds-insights-list li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; font-size: 13.5px; line-height: 1.5; color: var(--text); }
.ds-insights-list li .ico { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 800; }
.ds-insights-list li .ico.warn { background: var(--warning-bg); color: var(--warning); }
.ds-insights-list li .ico.good { background: var(--success-bg); color: var(--success); }
.ds-insights-list li .ico.info { background: var(--info-bg); color: var(--info); }
.ds-insights-list b { font-variant-numeric: tabular-nums; }

/* Header company switcher */
.company-switch { position: relative; }
.company-switch-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  max-width: 220px;
}
.company-switch-btn:hover { color: var(--primary); }
.company-switch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-switch-chev { flex-shrink: 0; color: var(--text-faint); transition: transform 0.15s; }
.company-switch-btn.open .company-switch-chev { transform: rotate(180deg); color: var(--primary); }

.company-menu {
  position: absolute;
  top: calc(100% + 14px);
  right: -12px;
  z-index: 60;
  width: 290px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-md), 0 18px 40px rgba(15, 23, 42, 0.14);
  padding: 8px;
  animation: company-pop 0.14s ease;
}
.company-menu[hidden] { display: none; }
@keyframes company-pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }

.company-menu-title { padding: 6px 10px 8px; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-faint); }
.company-search { padding: 0 2px 8px; }
.company-search input { width: 100%; padding: 8px 10px; font-size: 13px; border-radius: 8px; }
.company-list { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow-y: auto; }

.company-item {
  display: grid;
  grid-template-columns: 30px 1fr 16px;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}
.company-item:hover, .company-item:focus-visible { background: var(--surface-hover); outline: none; }
.company-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.company-avatar {
  width: 30px; height: 30px; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface-alt); color: var(--text-muted);
  font-size: 11px; font-weight: 800; letter-spacing: 0.02em;
}
.company-item.active .company-avatar { background: var(--primary); color: #fff; }
.company-item-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-check { opacity: 0; color: var(--primary); }
.company-item.active .company-check { opacity: 1; }
.company-empty { padding: 14px 10px; font-size: 12.5px; color: var(--text-faint); text-align: center; }

@media (max-width: 640px) {
  .company-menu { position: fixed; top: 64px; left: 12px; right: 12px; width: auto; }
}
