:root {
  --bg: #f9f9f7;
  --card: #fcfcfb;
  --border: #e1e0d9;
  --border-strong: #c3c2b7;
  --text: #0b0b0b;
  --muted: #52514e;
  --muted-label: #898781;
  --primary: #2a78d6;
  --primary-dark: #1c5cab;
  --success: #006300;
  --success-wash: #eaf6ea;
  --danger: #d03b3b;
  --danger-wash: #fbeceb;
  --warn: #fab219;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: #111827;
  color: #fff;
  padding: 0 20px;
  display: flex;
  align-items: center;
  height: 56px;
  justify-content: space-between;
}
.topbar .brand { font-weight: 700; font-size: 16px; }
.topbar nav a {
  color: #d1d5db;
  margin-right: 16px;
  font-size: 14px;
}
.topbar nav a.active, .topbar nav a:hover { color: #fff; }
.topbar .userbox { font-size: 13px; color: #9ca3af; }
.topbar .userbox a { color: #f87171; margin-left: 10px; }

.container { max-width: 1180px; margin: 24px auto; padding: 0 20px; }
.container.is-refreshing { opacity: .55; transition: opacity .15s ease; pointer-events: none; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(11,11,11,.04);
}
.card h2 { margin-top: 0; font-size: 16px; font-weight: 700; }
.card-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.card-header h2 { margin-bottom: 0; }

h1 { font-size: 22px; margin-bottom: 4px; }
.subtitle { color: var(--muted); margin-top: 0; margin-bottom: 20px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:hover td { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row.full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: #374151; }
input, select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 12px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
}
.badge.status-New, .badge.status-Cutting, .badge.status-Sent-to-Tailor, .badge.status-Received, .badge.status-Packed { background: #e4ecf9; color: var(--primary-dark); }
.badge.status-Dispatched { background: #fdf1d9; color: #8a5a00; }
.badge.status-Delivered { background: var(--success-wash); color: var(--success); }
.badge.status-Returned, .badge.status-Cancelled { background: var(--danger-wash); color: var(--danger); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 4px; }
.stats-grid + .stats-grid { margin-top: 12px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px;
}
.stat .label {
  font-size: 11px; color: var(--muted-label); text-transform: uppercase;
  font-weight: 700; letter-spacing: .04em;
}
.stat .value { font-size: 22px; font-weight: 700; margin-top: 6px; color: var(--text); line-height: 1.15; }
.stat.compact .value { font-size: 19px; }
.stat .value.positive { color: var(--success); }
.stat .value.negative { color: var(--danger); }
.positive { color: var(--success); }
.negative { color: var(--danger); }
.margin-good { color: var(--success); font-weight: 700; }
.margin-warning { color: #8a5a00; font-weight: 700; }
.margin-critical { color: var(--danger); font-weight: 700; }

.stat.highlight {
  padding: 18px 20px;
  border-width: 1px;
  border-left-width: 4px;
}
.stat.highlight .value { font-size: 30px; margin-top: 8px; }
.stat.highlight.positive { border-left-color: var(--success); background: var(--success-wash); }
.stat.highlight.negative { border-left-color: var(--danger); background: var(--danger-wash); }

.section-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 700;
  color: var(--muted-label); margin: 18px 0 8px;
}
.stats-grid:first-of-type + .section-label,
.card > .section-label:first-child { margin-top: 0; }

.filter-row {
  display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap;
  margin-bottom: 10px; padding: 0 2px;
}
.filter-row .form-row { gap: 2px; }
.filter-row label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted-label); font-weight: 700; }
.filter-row input { padding: 6px 9px; font-size: 13px; }

.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.alert.success { background: var(--success-wash); color: var(--success); }
.alert.error { background: var(--danger-wash); color: var(--danger); }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filters select, .filters input { padding: 6px 8px; font-size: 13px; }
.filters input[type="checkbox"] { padding: 0; width: auto; }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 90vh; }
.login-card { width: 340px; }

.amount-link { cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.amount-link:hover { color: var(--primary); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: none; align-items: center; justify-content: center; z-index: 1000; padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card); border-radius: 10px; padding: 20px 22px;
  width: 380px; max-width: 100%; box-shadow: 0 20px 60px rgba(0,0,0,.25); position: relative;
}
.modal-box h3 { margin: 0 0 14px; font-size: 16px; padding-right: 20px; }
.modal-box table { width: 100%; font-size: 14px; }
.modal-box td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.modal-total-row td { border-bottom: none; border-top: 2px solid var(--border); font-weight: 700; padding-top: 10px; }
.modal-close {
  position: absolute; top: 14px; right: 16px; cursor: pointer; color: var(--muted);
  font-size: 20px; line-height: 1; user-select: none;
}
.modal-close:hover { color: var(--text); }

.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 720px) { .chart-row { grid-template-columns: 1fr; } }
.chart-block { min-width: 0; }
.chart-title { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.trend-chart { width: 100%; height: auto; display: block; }
.trend-chart rect { transition: opacity .1s; }
.trend-chart rect:hover { opacity: .75; }
.chart-axis-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted-label); margin-top: 4px; }
.chart-legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

.insights-list { list-style: none; margin: 0; padding: 0; }
.insight { display: flex; align-items: flex-start; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px; line-height: 1.4; }
.insight:last-child { border-bottom: none; }
.insight-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.insight-good .insight-dot { background: #0ca30c; }
.insight-warning .insight-dot { background: #fab219; }
.insight-critical .insight-dot { background: #d03b3b; }
.insight-body { flex: 1; min-width: 0; }
.insight-text { color: var(--text); }
.insight-solution { color: var(--muted); font-size: 13px; margin-top: 4px; }
.insight-link { display: inline-block; font-size: 13px; font-weight: 600; margin-top: 6px; }

/* Flatpickr — match SMARTECOMM */
input.js-date,
.flatpickr-input,
.form-row .flatpickr-input,
.filter-row .flatpickr-input,
.filters .flatpickr-input {
  background: #fff;
  cursor: pointer;
  min-width: 132px;
}
.flatpickr-calendar {
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(11, 11, 11, .12);
  font-family: inherit;
  overflow: hidden;
}
.flatpickr-months .flatpickr-month,
.flatpickr-weekdays {
  background: var(--card);
}
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
  font-weight: 700;
}
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover {
  background: var(--primary);
  border-color: var(--primary);
}
.flatpickr-day.today {
  border-color: var(--primary);
}
.flatpickr-day:hover {
  background: #e4ecf9;
}
.flatpickr-day.inRange {
  background: #e4ecf9;
  box-shadow: none;
  border-color: transparent;
}

/* Tom Select — searchable dropdowns */
.ts-wrapper {
  min-width: 160px;
}
.ts-wrapper.single .ts-control {
  padding: 6px 32px 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  box-shadow: none;
  min-height: 36px;
}
.filter-row .ts-wrapper.single .ts-control,
.filters .ts-wrapper.single .ts-control {
  padding: 5px 28px 5px 8px;
  font-size: 13px;
  min-height: 32px;
}
.ts-wrapper.single.input-active .ts-control,
.ts-wrapper.focus .ts-control {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(42, 120, 214, .15);
}
.ts-dropdown {
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(11, 11, 11, .12);
  font-size: 14px;
  z-index: 1100;
}
.ts-dropdown .dropdown-input-wrap {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.ts-dropdown .dropdown-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
.ts-dropdown .dropdown-input:focus {
  outline: none;
  border-color: var(--primary);
}
.ts-dropdown .option {
  padding: 8px 12px;
}
.ts-dropdown .option.active,
.ts-dropdown .option.selected {
  background: #e4ecf9;
  color: var(--text);
}
.ts-dropdown .no-results {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
}
.form-row .ts-wrapper { width: 100%; }
.form-row .ts-wrapper.single .ts-control { width: 100%; }

.badge-warn { background: #fdf1d9; color: #8a5a00; margin-left: 8px; }
.badge-info { background: #e4ecf9; color: var(--primary-dark); margin-left: 8px; }
.user-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-details { display: inline-block; position: relative; }
.inline-details summary { list-style: none; cursor: pointer; }
.inline-details summary::-webkit-details-marker { display: none; }
.set-password-form {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; display: flex; gap: 8px; box-shadow: 0 8px 24px rgba(11,11,11,.1);
  min-width: 260px;
}
.reset-link-card { border-left: 4px solid var(--primary); }
.reset-link-row { display: flex; gap: 10px; }
.reset-link-row input { flex: 1; font-size: 13px; }
.help-list { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; line-height: 1.55; }
.help-list li { margin-bottom: 8px; }
.help-list strong { color: var(--text); }
