:root {
  /* Az Online Store brand: rose-gold logo (deep wine sidebar + gold accent) */
  --bg: #faf7f5;
  --surface: #ffffff;
  --border: #ecdfdd;
  --text: #2b1c1f;
  --text-muted: #7d6b6a;
  --primary: #b8860b;
  --primary-dark: #96700a;
  --success: #16a34a;
  --success-bg: #e8f8ee;
  --warning-bg: #fdf3d8;
  --danger: #dc2626;
  --danger-bg: #fce8e8;
  --sidebar-bg: #3a1e29;
  --sidebar-text: #e6cfd2;
  --sidebar-active: #55293a;
  --radius: 10px;

  /* Categorical series palette for reports/*.ejs -- fixed hue order (never
     cycled/reassigned), validated for CVD-safe adjacency. Values are the
     dataviz skill's documented reference palette, used unmodified. */
  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */
  --series-5: #e87ba4; /* magenta */
  --series-6: #008300; /* green */
  --series-7: #4a3aa7; /* violet */
  --series-8: #e34948; /* red */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14.5px;
  line-height: 1.5;
}

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

h1 { font-size: 1.5rem; margin: 0 0 20px; font-weight: 700; }
h2, h3 { font-weight: 600; }

/* Layout */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

/* Desktop: the <details> wrapper is neutralized so the sidebar lays out
   exactly as if it were plain divs — a real collapsible menu only matters
   once the mobile breakpoint below turns it back on. */
.sidebar-toggle { display: contents; }
.sidebar-toggle > summary.brand { cursor: default; list-style: none; }
.sidebar-toggle > summary.brand::-webkit-details-marker { display: none; }
.nav-caret { display: none; }

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 24px; }
.brand-logo { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #e8c56b);
  color: white; font-weight: 700; font-size: 0.8rem;
  align-items: center; justify-content: center;
}
.brand-name { font-weight: 700; color: white; font-size: 0.95rem; flex: 1; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500; font-size: 0.92rem;
}
.nav-link:hover { background: var(--sidebar-active); text-decoration: none; color: white; }
.nav-link.active { background: var(--primary); color: white; }
.nav-icon { font-size: 1rem; width: 18px; text-align: center; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px; margin-top: 14px;
  display: flex; align-items: center; justify-content: space-between;
}
.whoami-name { color: white; font-weight: 600; font-size: 0.88rem; }
.whoami-role { color: var(--sidebar-text); font-size: 0.75rem; opacity: 0.7; }
.sidebar-footer .link-button { color: var(--sidebar-text); font-size: 0.82rem; }
.sidebar-footer .link-button:hover { color: white; }

.content { flex: 1; padding: 32px 40px; min-width: 0; }

/* Page header */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-header h1 { margin: 0; }

/* Cards */
.cards { display: flex; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; flex: 1; min-width: 180px; text-decoration: none; color: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03); transition: box-shadow 0.15s, transform 0.15s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,0.08); transform: translateY(-1px); text-decoration: none; }
.card-icon { font-size: 1.3rem; line-height: 1; margin-bottom: 8px; }
.card-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.card-label { color: var(--text-muted); font-size: 0.88rem; margin-top: 2px; }

/* Stats row (products list): the stat cards plus the stock-status donut
   chart side by side, wrapping to a stacked layout on narrow screens. */
.stats-row { display: flex; gap: 16px; align-items: stretch; margin-bottom: 28px; flex-wrap: wrap; }
.stats-row .cards { flex: 3 1 480px; margin-bottom: 0; }

.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 22px; flex: 2 1 300px; max-width: 380px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  display: flex; flex-direction: column; gap: 14px;
}
.chart-card-title { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); }
.donut-chart-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }

/* Pure-CSS donut: a circle with a conic-gradient background (percentages
   computed server-side in the view from real stats — no chart library, no
   client-side JS, matching this project's existing convention) with a
   plain surface-colored circle punched out on top to leave a ring. The
   --primary border on the hole echoes .card-number's accent color above,
   tying the chart visually back to the stat cards. */
.donut-chart {
  position: relative; width: 104px; height: 104px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 0 1px var(--border);
}
.donut-chart-hole {
  position: absolute; inset: 15px; background: var(--surface); border-radius: 50%;
  border: 2px solid var(--primary);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.donut-chart-hole-number { font-size: 1.1rem; font-weight: 700; color: var(--primary); line-height: 1.1; }
.donut-chart-hole-label { font-size: 0.6rem; color: var(--text-muted); text-align: center; }

.donut-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; flex: 1; min-width: 150px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; color: var(--text); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; }
.legend-value { color: var(--text-muted); font-weight: 600; white-space: nowrap; }

/* Table */
.table-wrap {
  width: 100%; overflow-x: auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
}
.table-wrap table { border: none; border-radius: 0; }
table {
  width: 100%; border-collapse: collapse; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #fafafa; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: #fbfaff; }
tbody tr:last-child td { border-bottom: none; }

/* Row actions (Засах / Устгах / Хурдан засах, etc.) — a tidy button group
   instead of bare underlined text links wrapping into each other. */
.row-actions { display: flex; align-items: flex-start; gap: 6px; flex-wrap: wrap; }
.row-action-btn {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.82rem; font-weight: 500;
  cursor: pointer; text-decoration: none; line-height: 1.3; font-family: inherit;
}
.row-action-btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; background: #fdfaf3; }
.row-action-btn.danger { color: var(--danger); }
.row-action-btn.danger:hover { border-color: var(--danger); background: var(--danger-bg); }
details[open] > summary.row-action-btn { border-color: var(--primary); color: var(--primary); background: #fdfaf3; }

/* The panel a <details class="row-actions-details"> reveals — a small
   bordered card of its own, so it never reads as bleeding into neighboring
   buttons or table cells the way an unstyled expanded block would. */
.row-actions-details { position: relative; }
.quick-edit-panel {
  margin-top: 8px; padding: 14px; width: max-content; min-width: 220px; max-width: min(320px, 80vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.1);
}

.pos-add-form { display: flex; gap: 6px; align-items: center; }
.pos-add-form input[type="number"] { width: 60px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }

.pos-row-nostock { color: var(--text-muted); }
.pos-row-nostock .badge { margin-left: 8px; }

/* Search bar */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input, .search-bar select {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 0.88rem; font-family: inherit;
}
.search-bar input { flex: 1; min-width: 180px; }
.search-bar select { flex: 1 1 130px; }

@media (max-width: 480px) {
  /* On a narrow phone even 180px-min inputs/buttons force horizontal
     scrolling on the filter bar — let every control take the full row
     instead of fighting for space. */
  .search-bar input, .search-bar select, .search-bar button { flex-basis: 100%; min-width: 0; }
}

/* Thumbnails */
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); display: block; }
.thumb-placeholder {
  display: flex; align-items: center; justify-content: center; background: #f2f0fb; font-size: 1.1rem;
}

/* Pagination */
.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a {
  padding: 6px 12px; border-radius: 6px; border: 1px solid var(--border); color: var(--text-muted); font-size: 0.85rem;
}
.pagination a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.pagination a.active { background: var(--primary); border-color: var(--primary); color: white; }

/* Filters */
.filters { margin-bottom: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.filters a {
  padding: 5px 12px; border-radius: 999px; font-size: 0.85rem; font-weight: 500;
  color: var(--text-muted); background: var(--surface); border: 1px solid var(--border);
}
.filters a:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.filters a.active { background: var(--primary); border-color: var(--primary); color: white; }

/* Badges & tags */
.badge {
  padding: 3px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 600;
  background: #eee; color: var(--text-muted); display: inline-block;
}
.badge-PAID, .badge-DELIVERED, .badge-owner { background: var(--success-bg); color: var(--success); }
.badge-MANUAL_REVIEW, .badge-PENDING, .badge-REQUESTED { background: var(--warning-bg); color: #92660a; }
.badge-CANCELLED, .badge-REJECTED { background: var(--danger-bg); color: var(--danger); }
.badge-staff { background: #e7ecfd; color: #3b53c4; }

.tag {
  display: inline-block; padding: 2px 8px; margin: 1px; border-radius: 6px;
  background: #f0edfe; color: var(--primary-dark); font-size: 0.75rem; font-weight: 600;
}

/* Buttons */
.button, button {
  background: var(--primary); color: white; border: none; padding: 9px 16px; border-radius: 8px;
  cursor: pointer; text-decoration: none; display: inline-block; font-size: 0.9rem; font-weight: 600;
  transition: background 0.15s;
}
.button:hover, button:hover { background: var(--primary-dark); text-decoration: none; }
.link-button { background: none; color: var(--danger); border: none; padding: 0; text-decoration: underline; font-weight: 500; }
.link-button:hover { background: none; }
.inline-form { display: inline; }

.detail-grid, .review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-bottom: 24px; }
.receipt-image { max-width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.ocr-text {
  background: var(--surface); border: 1px solid var(--border); padding: 14px; border-radius: 8px;
  white-space: pre-wrap; max-height: 220px; overflow-y: auto; font-size: 0.85rem;
}

.review-actions { display: flex; gap: 12px; margin-top: 16px; }
.button-confirm { background: var(--success); }
.button-confirm:hover { background: #128a3e; }
.button-reject { background: var(--danger); }
.button-reject:hover { background: #b91c1c; }

/* Forms */
.stacked-form { display: flex; flex-direction: column; gap: 4px; max-width: 440px; }
.stacked-form label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-top: 8px; }
.stacked-form input, .stacked-form select, .stacked-form textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 4px;
  font-size: 0.9rem; font-family: inherit;
}
.stacked-form textarea { resize: vertical; }
.stacked-form input:focus, .stacked-form select:focus, .stacked-form textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(184,134,11,0.15);
}
.hint-warning { background: var(--warning-bg); color: #92660a; padding: 10px 14px; border-radius: 8px; font-size: 0.85rem; }

.storage-bar-track { background: var(--border); border-radius: 999px; height: 10px; overflow: hidden; margin: 10px 0; max-width: 440px; }
.storage-bar-fill { height: 100%; background: var(--primary); border-radius: 999px; }
.storage-bar-fill.storage-bar-fill-danger { background: var(--danger); }
.stacked-form button { margin-top: 14px; align-self: flex-start; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--text); margin-top: 4px; }
.checkbox-label input { margin: 0; }

.logo-preview {
  max-width: 220px; max-height: 220px; border-radius: var(--radius);
  border: 1px solid var(--border); display: block; margin: 12px 0; object-fit: contain;
}

/* Bot-messages page: one native <details> per template category, same
   no-JS collapsible convention as .row-actions-details elsewhere in this
   admin panel, just laid out as a full-width page section instead of a
   small row-action popover. */
.template-editor-form { max-width: 900px; }
.template-category {
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px;
  background: var(--surface);
}
.template-category-summary {
  padding: 12px 16px; cursor: pointer; font-weight: 600; list-style: none;
}
.template-category-summary::-webkit-details-marker { display: none; }
.template-category-summary::before { content: '▸ '; color: var(--text-muted); }
.template-category[open] > .template-category-summary::before { content: '▾ '; }
.template-category-body { padding: 4px 16px 4px; border-top: 1px solid var(--border); }
.template-field { padding: 14px 0; border-bottom: 1px solid var(--border); }
.template-field:last-child { border-bottom: none; }
.template-field label { display: block; font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }
.template-field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 0.9rem; font-family: inherit; line-height: 1.4; resize: vertical;
}
.template-field textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(184,134,11,0.15);
}
.template-hint {
  color: var(--text-muted); font-size: 0.8rem; margin: 6px 0 0;
  display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
}
.template-hint code { background: #f2f0fb; padding: 1px 5px; border-radius: 4px; font-size: 0.78rem; }
.template-reset-btn {
  background: none; border: none; padding: 0; color: var(--text-muted); text-decoration: underline;
  font-size: 0.8rem; font-weight: 500; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.template-reset-btn:hover { color: var(--danger); background: none; }

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(circle at 30% 20%, var(--sidebar-active), var(--sidebar-bg) 65%);
  padding: 24px;
}
.login-form {
  background: var(--surface); padding: 40px 36px; border-radius: 16px; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 4px; box-shadow: 0 24px 70px rgba(0,0,0,0.35);
}
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-brand-logo { width: 60px; height: 60px; border-radius: 14px; object-fit: cover; }
.login-brand-mark {
  width: 60px; height: 60px; border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), #e8c56b);
  color: white; font-weight: 700; font-size: 1.2rem;
  align-items: center; justify-content: center;
}
.login-form h1 { font-size: 1.15rem; margin: 0; text-align: center; color: var(--text); }
.login-form .subtitle { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin: 2px 0 18px; }
.login-form label { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.login-form input {
  padding: 11px 13px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px;
  font-size: 0.95rem; font-family: inherit;
}
.login-form input:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(184,134,11,0.15);
}
.login-form button { margin-top: 4px; padding: 11px; font-size: 0.95rem; }
.error { color: var(--danger); font-size: 0.85rem; background: var(--danger-bg); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; padding: 0; }

  /* Turn the desktop's neutralized <details> back into a real tap-to-expand
     menu: a slim always-visible brand/toggle bar, with the full nav list
     (and the footer, now re-shown since it's no longer fighting for space
     in a single row) revealed underneath only while open. Beats forcing
     every nav item into one horizontally-scrolling icon strip. */
  .sidebar-toggle { display: block; }
  .sidebar-toggle > summary.brand {
    cursor: pointer; padding: 14px 16px; margin: 0;
  }
  .nav-caret { display: inline-block; transition: transform 0.15s; }
  .sidebar-toggle[open] > summary.brand .nav-caret { transform: rotate(180deg); }

  .nav { flex-direction: column; padding: 0 10px 10px; }
  .sidebar-footer { display: flex; margin: 0 10px 14px; padding-top: 14px; }

  .content { padding: 20px; }
  .detail-grid, .review-grid { grid-template-columns: 1fr; }
}

/* Bordered field group used by products/form.ejs's "Хугацааны хяналт"
   section — the only spot in the admin panel that groups a few related
   inputs visually apart from the rest of a flat .stacked-form. */
.fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  margin: 10px 0 16px;
}
.fieldset > legend {
  padding: 0 6px;
  margin-left: -6px;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.fieldset > label:first-of-type { margin-top: 0; }

/* Reports (src/admin/views/reports/*.ejs) — server-rendered, no chart lib
   (CSP blocks CDN scripts; this codebase ships no client JS framework),
   so trends/breakdowns are plain flex/CSS bars. Colors follow the dataviz
   skill's method: --series-N (fixed order, never reassigned) for identity,
   --primary/--danger/--success for single-series or good/bad state. */
.report-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.report-toolbar select { min-width: 140px; }

.trend-chart { display: flex; align-items: flex-end; gap: 3px; height: 170px; padding-top: 8px; border-bottom: 1px solid var(--border); }
.trend-bar-col { flex: 1; display: flex; flex-direction: column-reverse; height: 100%; min-width: 4px; border-radius: 3px 3px 0 0; overflow: hidden; }
.trend-bar-seg { width: 100%; }
.trend-bar-seg-online { background: var(--primary); }
.trend-bar-seg-pos { background: var(--series-1); }
.trend-axis { display: flex; gap: 3px; margin-top: 6px; }
.trend-axis-label { flex: 1; min-width: 4px; text-align: center; font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trend-legend { display: flex; gap: 16px; margin-top: 10px; font-size: 0.82rem; color: var(--text-muted); }
.trend-legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

.bar-chart-h { display: flex; flex-direction: column; gap: 9px; }
.bar-chart-h-row { display: grid; grid-template-columns: minmax(0, 170px) 1fr auto; align-items: center; gap: 10px; }
.bar-chart-h-label { font-size: 0.85rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-chart-h-track { background: var(--bg); border-radius: 6px; height: 20px; overflow: hidden; }
.bar-chart-h-fill { height: 100%; border-radius: 6px; min-width: 3px; }
.bar-chart-h-value { font-size: 0.82rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.stat-tile-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-tile-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-tile-label { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }

.profit-row-positive { color: var(--success); }
.profit-row-negative { color: var(--danger); }
