:root {
  --primary: #9f1239;
  --primary-dark: #7a0e2c;
  --primary-light: #fdf2f6;
  --accent: #c2410c;
  --accent-light: #fff7ed;
  --bg: #fbf8f4;
  --surface: #ffffff;
  --border: #ede4d8;
  --text: #1f1b16;
  --muted: #6b6258;
  --success: #15803d;
  --warning: #b45309;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(31, 27, 22, 0.04), 0 4px 12px rgba(31, 27, 22, 0.05);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Sidebar (vertical nav, fixed to the left) */
.topbar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: 230px;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 10;
  overflow-y: auto;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-family: 'Playfair Display', serif;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.brand-name { font-family: 'Playfair Display', serif; font-size: 17px; font-weight: 700; color: var(--primary); }
.brand-tag { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
}
.nav-link {
  display: block;
  padding: 9px 14px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  transition: all 0.15s;
  white-space: nowrap;
}
.nav-link:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }
.nav-link.active { background: var(--primary); color: white; }

/* Collapsible nav groups */
.nav-group { margin: 4px 0; }
.nav-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
}
.nav-group-header:hover { color: var(--primary); background: rgba(159,18,57,0.04); }
.nav-group-header .chevron { font-size: 10px; transition: transform .15s ease; }
.nav-group.collapsed .chevron { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
.nav-group-items { display: flex; flex-direction: column; gap: 1px; padding: 2px 0; }
.nav-sub {
  padding: 7px 12px 7px 22px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
}
.nav-sub.active { background: var(--primary); color: white !important; }
.nav-sub:not(.active) { color: var(--text); }

.topbar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-top: 12px;
  margin-top: 12px;
  border-top: 1px solid var(--border);
}
.topbar-actions .user-chip { width: 100%; justify-content: flex-start; }
.topbar-actions .btn {
  width: 100%;
  justify-content: flex-start;
  padding: 7px 12px;
  font-size: 13px;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--primary);
  color: white;
  font-weight: 500;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
  font-family: inherit;
}
.btn:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-icon { padding: 6px 9px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Container */
.container { padding: 24px 28px 60px; max-width: 1400px; margin: 0 auto; }
body.with-nav .container { margin: 0 0 0 230px; max-width: none; }
body.with-nav .footer { margin-left: 230px; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-title { font-size: 22px; font-weight: 700; color: var(--text); margin: 0; }
.page-subtitle { color: var(--muted); margin: 2px 0 0; font-size: 13px; }

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

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 6px; font-family: 'Playfair Display', serif; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-accent { color: var(--primary); }

/* Filter row */
.toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.toolbar .search {
  flex: 1; min-width: 220px;
}

/* Forms */
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(159, 18, 57, 0.12);
}
.textarea { resize: vertical; min-height: 70px; }
.field { margin-bottom: 14px; }
.field label, .label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--text); text-transform: uppercase; letter-spacing: 0.4px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.help-text { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #fcfaf6; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { white-space: nowrap; text-align: right; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin: 0 0 6px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: #eef2ff;
  color: #4338ca;
}
.badge-pending    { background: #fef3c7; color: #92400e; }
.badge-processing { background: #dbeafe; color: #1d4ed8; }
.badge-dispatched { background: #e0e7ff; color: #4338ca; }
.badge-delivered  { background: #dcfce7; color: #166534; }
.badge-completed  { background: #dcfce7; color: #166534; }
.badge-cancelled  { background: #fee2e2; color: #991b1b; }
.badge-low        { background: #fee2e2; color: #991b1b; }
.badge-ok         { background: #dcfce7; color: #166534; }

/* Catalog chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 6px 6px 14px;
  background: #fff5f7; border: 1px solid var(--border);
  border-radius: 999px; font-size: 14px; font-weight: 500;
  color: var(--text);
}
.chip-btn {
  border: none; background: transparent; cursor: pointer;
  width: 26px; height: 26px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 14px; line-height: 1;
}
.chip-btn:hover { background: rgba(159,18,57,0.1); color: var(--primary); }

/* Hide certain UI in the printable order view */
@media print {
  .no-print { display: none !important; }
}

/* Status filter pills (Orders page) */
.status-pill {
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: all .15s;
  font-family: inherit;
  line-height: 1.4;
}
.status-pill:hover { border-color: var(--primary); color: var(--primary); }
.status-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.status-pill-clear {
  padding: 6px 12px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  text-decoration: underline;
  font-family: inherit;
}
.status-pill-clear:hover { color: var(--primary); }

/* Auth screens (login / setup) */
.auth-shell {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px;
  max-width: 420px;
  width: 100%;
}
.auth-card h2 {
  margin: 0 0 6px;
  font-family: 'Playfair Display', serif;
  color: var(--primary);
}
.auth-sub { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.auth-error {
  color: #991b1b; font-size: 13px; min-height: 18px; margin: 4px 0;
}

/* Top-bar user chip */
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: #fff5f7;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 13px; font-weight: 500; color: var(--text);
  overflow: hidden;
}
.user-chip .user-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.user-chip .user-icon { font-size: 14px; }
.user-chip .user-role {
  background: var(--primary); color: white;
  font-size: 10px; padding: 1px 6px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 700;
}

/* Color swatch — used in resolved order lines */
.color-swatch {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.color-swatch-lg { width: 24px; height: 24px; }

/* Chart tabs — picker for switching between charts */
.chart-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

/* Dropdown picker — replaces the pill row when the list could get long */
.chart-picker {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding: 6px 10px 6px 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
}
.chart-picker-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 700;
  color: var(--muted);
}
.chart-picker-select {
  min-width: 220px;
  max-width: 360px;
  font-weight: 600;
  border: none;
  background: transparent;
  padding: 4px 28px 4px 6px;
  cursor: pointer;
}
.chart-picker-select:focus { outline: none; box-shadow: none; }
.chart-tab {
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  transition: all .15s;
}
.chart-tab:hover { border-color: var(--primary); color: var(--primary); }
.chart-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.chart-tab-count {
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.chart-tab.active .chart-tab-count { background: rgba(255, 255, 255, 0.25); }

/* Catalog-style color chart display (Charts page) */
.color-catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.color-catalog-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
  transition: transform .15s, box-shadow .15s;
}
.color-catalog-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
.color-catalog-swatch {
  position: relative;
  height: 90px;
  width: 100%;
}
.color-catalog-number {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  font-weight: 700;
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  min-width: 28px;
  text-align: center;
}
.color-catalog-name {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border-top: 1px solid var(--border);
  background: #fafafa;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.color-catalog-stock {
  padding: 5px 10px;
  font-size: 12px;
  text-align: center;
  font-weight: 500;
  color: #166534;
  background: #f0fdf4;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background .15s;
}
.color-catalog-stock:hover { background: #dcfce7; }
.color-catalog-stock.low  { color: #92400e; background: #fef3c7; }
.color-catalog-stock.low:hover  { background: #fde68a; }
.color-catalog-stock.zero { color: #991b1b; background: #fee2e2; }
.color-catalog-stock.zero:hover { background: #fecaca; }
.color-catalog-stock.over { color: #fff; background: #6c0518; font-weight: 700; }
.color-catalog-stock.over:hover { background: #4a0410; }

/* Activity log badge */
.badge.activity-action {
  background: #f3f4f6; color: #374151;
  font-family: monospace; font-size: 11px;
  text-transform: none; letter-spacing: 0;
}

/* Product card grid */
.product-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
}
.product-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(31,27,22,0.08); }
.product-img {
  aspect-ratio: 1;
  background: linear-gradient(135deg, #fef3c7 0%, #fce7f3 100%);
  display: flex; align-items: center; justify-content: center;
  color: var(--primary);
  font-family: 'Playfair Display', serif;
  font-size: 28px;
  overflow: hidden;
}
.product-img img { width: 100%; height: 100%; object-fit: cover; }
.product-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; }
.product-code { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.product-name { font-weight: 600; margin: 4px 0; }
.product-meta { font-size: 12px; color: var(--muted); }
.product-price { font-size: 16px; font-weight: 700; color: var(--primary); margin-top: 6px; }
.product-actions { display: flex; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); }
.product-actions .btn { flex: 1; justify-content: center; }

/* Modal */
.modal-layer { position: relative; z-index: 100; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(31, 27, 22, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: inherit;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-lg { max-width: 880px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-header h2 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
  background: #fcfaf6;
  position: sticky; bottom: 0;
}
.modal-close {
  background: transparent; border: none; cursor: pointer;
  font-size: 22px; color: var(--muted); padding: 0 4px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 12px 20px;
  background: var(--text);
  color: white;
  border-radius: 8px;
  font-weight: 500;
  opacity: 0;
  transition: all 0.25s;
  pointer-events: none;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Footer */
.footer {
  text-align: center;
  padding: 16px;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* Order items table inside modal */
.order-items-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.order-items-table th, .order-items-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.order-items-table th { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; text-align: left; }
.order-items-table input, .order-items-table select { padding: 6px 8px; font-size: 13px; }
.order-items-table .num { text-align: right; }

.summary {
  margin-top: 12px;
  border-top: 2px solid var(--border);
  padding-top: 10px;
}
.summary-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.summary-row.total { font-size: 17px; font-weight: 700; color: var(--primary); border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* Reports */
.chart-card { padding: 18px; }
.chart-card h3 { margin: 0 0 12px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.charts-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); margin-top: 16px; }

/* Role view restriction */
body[data-role="party"] [data-role-staff] { display: none !important; }

/* Pipeline cards (clickable) */
.pipe-card { cursor: pointer; transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s; }
.pipe-card:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 6px 16px rgba(159,18,57,0.12); }

/* Financial-year picker + chip */
.year-picker { max-width: 480px; }
.year-list { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; text-align: left; }
.year-card {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; width: 100%; padding: 14px 16px; border: 1px solid var(--border, #e6ddd2);
  border-radius: 10px; background: #fff; cursor: pointer; transition: border-color .12s, box-shadow .12s;
}
.year-card:hover { border-color: var(--primary, #9a3b2e); box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.year-card-active { border-color: var(--primary, #9a3b2e); background: #faf6f3; }
.year-card-fy { font-weight: 700; font-size: 16px; }
.year-card-sub { font-size: 12px; color: var(--muted, #8a7f72); margin-top: 2px; }
.year-card-side { text-align: right; }
.year-card-out { font-weight: 700; color: #991b1b; }
.year-card-out-lbl { font-size: 11px; color: var(--muted, #8a7f72); }
.year-card-badge {
  position: absolute; top: -8px; right: 12px; font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; background: var(--primary, #9a3b2e); color: #fff; padding: 2px 8px; border-radius: 999px;
}
.year-chip .year-chip-btn,
.firm-chip .firm-chip-btn { font-weight: 600; white-space: nowrap; }
.firm-chip .firm-chip-btn { color: var(--primary, #9a3b2e); }

/* Responsive */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .container { padding: 16px 14px 40px; }
  .stat-value { font-size: 22px; }
}
