:root {
  --gold: #c9a227;
  --gold-hover: #b08d20;
  --gold-light: #fdfaf2;
  --beige: #f8f5f2;
  --ink: #111111;
  --muted: #71717a;
  --faint: #a1a1aa;
  --border: #e4e4e7;
  --line: #f0f0f0;
  --surface: #ffffff;
  --shadow: 0 4px 20px -2px rgba(17, 17, 17, 0.03), 0 2px 8px -1px rgba(201, 162, 39, 0.05);
  --serif: "Playfair Display", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--beige); color: var(--ink); font-family: var(--sans); font-size: 14px; -webkit-font-smoothing: antialiased; }
h1, h2 { margin: 0; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.container { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 768px) { .container { padding: 0 32px; } }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 16px; padding-bottom: 16px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.topbar h1 { font-family: var(--serif); font-size: 22px; }

.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 8px 16px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all 0.15s; border: 1px solid transparent; }
.btn-outline { background: var(--surface); border-color: var(--border); }
.btn-outline:hover { border-color: var(--ink); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover:not(:disabled) { background: var(--gold); }
.btn:disabled { opacity: 0.3; cursor: default; }
.icon { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.spin .icon { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: 0; text-decoration: underline; font-size: 12px; font-weight: 600; cursor: pointer; }

.main { padding-top: 24px; padding-bottom: 48px; }
#content > * + * { margin-top: 16px; }
.placeholder { display: grid; place-items: center; height: 240px; color: var(--muted); }
.alert { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; border: 1px solid #fecaca; background: #fef2f2; color: #991b1b; }

/* Cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.card.flush { padding: 0; }
.grid-3 { display: grid; gap: 16px; }
@media (min-width: 1024px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .span-2 { grid-column: span 2; } }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 1024px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px 20px; box-shadow: var(--shadow); }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.kpi-label .badge-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 999px; background: var(--gold-light); color: var(--gold); }
.kpi-value { margin-top: 12px; font-family: var(--serif); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-hint { margin-top: 4px; font-size: 12px; color: var(--muted); }
@media (min-width: 768px) { .kpi-value { font-size: 30px; } }

/* Daily revenue bars */
.daily-chart { display: flex; gap: 8px; }
.y-axis { position: relative; width: 40px; height: 208px; flex-shrink: 0; font-size: 10px; color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; }
.y-axis span { position: absolute; right: 0; transform: translateY(-50%); }
.plot-wrap { flex: 1; min-width: 0; }
.plot { position: relative; height: 208px; }
.gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.bars { position: absolute; inset: 0; display: flex; align-items: flex-end; gap: 2px; }
.bar-col { position: relative; flex: 1; height: 100%; display: flex; align-items: flex-end; outline: none; cursor: default; }
.bar { width: 100%; background: var(--gold); border-radius: 4px 4px 0 0; transition: background 0.15s; }
.bar-col:hover .bar, .bar-col:focus-visible .bar { background: var(--gold-hover); }
.tooltip { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); z-index: 10; white-space: nowrap; pointer-events: none; background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 8px; font-size: 11px; font-variant-numeric: tabular-nums; box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15); display: none; }
.tooltip strong { display: block; }
.bar-col:hover .tooltip, .bar-col:focus-visible .tooltip { display: block; }
.bar-col:first-child .tooltip, .bar-col:nth-child(2) .tooltip { left: 0; transform: none; }
.bar-col:last-child .tooltip, .bar-col:nth-last-child(2) .tooltip { left: auto; right: 0; transform: none; }
.x-axis { display: flex; justify-content: space-between; margin-top: 8px; font-size: 10px; color: var(--faint); }

/* Category bars */
.category-bars, .low-stock { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.cat-row-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 4px; font-size: 12px; }
.cat-row-head span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.track { height: 8px; border-radius: 999px; background: #f5f5f5; }
.fill { height: 8px; border-radius: 999px; background: var(--gold); }

/* Low stock */
.low-stock { gap: 8px; }
.low-stock li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 8px; border: 1px solid #fde68a; background: #fffbeb; color: #78350f; }
.low-stock .name { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.low-stock .count { font-size: 12px; font-weight: 600; white-space: nowrap; }
.muted { color: var(--muted); }

/* Tables */
.card-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: #f5f5f5; }
.tab { border: 0; background: none; padding: 6px 16px; border-radius: 999px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--ink); color: #fff; }
.select, .input { border: 1px solid var(--border); background: var(--surface); outline: none; }
.select { border-radius: 999px; padding: 8px 14px; font-size: 12px; font-weight: 600; }
.select:focus, .input:focus { border-color: var(--gold); }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
#orders-table { min-width: 760px; }
#inventory-table { min-width: 680px; }
.table th { text-align: left; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 12px 16px; }
.table td { padding: 12px 16px; border-top: 1px solid var(--line); vertical-align: top; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table tbody tr:hover { background: rgba(253, 250, 242, 0.6); }
.table.compact th, .table.compact td { padding: 10px 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 600; }
.sub { font-size: 12px; color: var(--muted); }
.sub .faint { color: var(--faint); }
.table select.select-sm { border-radius: 8px; padding: 6px 8px; font-size: 12px; font-weight: 400; }
.input { border-radius: 8px; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.input.price { width: 96px; }
.input.stock { width: 80px; }
.product-cell { display: flex; align-items: center; gap: 12px; }
.product-cell img { width: 40px; height: 40px; border-radius: 8px; object-fit: cover; background: #f5f5f5; }
.low-flag { display: flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 11px; font-weight: 600; color: #b45309; }
.row-error { margin-top: 4px; font-size: 11px; color: #b91c1c; }
.empty { padding: 24px 20px; color: var(--muted); }

/* Status badges — icon + label, never color alone */
.status { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; border: 1px solid; font-size: 11px; font-weight: 600; white-space: nowrap; }
.status .icon { width: 12px; height: 12px; }
.status-pending { background: #fffbeb; color: #92400e; border-color: #fde68a; }
.status-confirmed { background: #f0f9ff; color: #075985; border-color: #bae6fd; }
.status-shipped { background: #eef2ff; color: #3730a3; border-color: #c7d2fe; }
.status-delivered { background: #ecfdf5; color: #065f46; border-color: #a7f3d0; }
.status-cancelled { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

/* Toolbar actions */
.card-toolbar .btn[hidden] { display: none; }
.row-actions { display: flex; gap: 6px; align-items: center; }
.btn-danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 999px; border: 0; background: none; cursor: pointer; }
.icon-btn:hover { background: #f5f5f5; }
.icon-btn .icon { width: 18px; height: 18px; }

/* Product dialog */
.dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(17, 17, 17, 0.2); }
.dialog::backdrop { background: rgba(17, 17, 17, 0.45); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-family: var(--serif); font-size: 20px; }
.dialog-body { padding: 20px; overflow-y: auto; display: grid; gap: 16px; }
.dialog-foot { display: flex; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.field { display: grid; gap: 6px; min-width: 0; }
.field label { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.field .input { width: 100%; padding: 10px 12px; font-size: 14px; }
.field textarea.input { resize: vertical; font-family: inherit; }
.field .input:invalid:not(:placeholder-shown), .field .input.invalid { border-color: #f87171; }
.field-row { display: grid; gap: 16px; }
@media (min-width: 560px) { .field-row { grid-template-columns: 1fr 1fr; } }
.req { color: #b91c1c; }
.hint { margin: 0; font-size: 12px; color: var(--faint); }
.form-error { margin: 0; padding: 10px 12px; border-radius: 8px; border: 1px solid #fecaca; background: #fef2f2; color: #991b1b; font-size: 13px; }
.image-field { display: flex; gap: 12px; align-items: flex-start; }
.image-preview { width: 88px; height: 88px; flex-shrink: 0; border-radius: 12px; border: 1px dashed var(--border); background: #fafafa center / cover no-repeat; display: grid; place-items: center; font-size: 11px; color: var(--faint); }
.image-preview.has-image span { display: none; }
.image-inputs { flex: 1; min-width: 0; display: grid; gap: 8px; justify-items: start; }
.field .upload-btn { text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--ink); }

/* Product colors */
.color-rows { display: grid; gap: 8px; }
.color-rows:empty { display: none; }
.color-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) minmax(0, 1.4fr) auto auto; gap: 8px; align-items: center; }
.field .color-row .input { padding: 8px 10px; font-size: 13px; }
.color-row input[type="color"] { width: 40px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.color-thumb { width: 38px; height: 38px; border-radius: 8px; border: 1px dashed var(--border); background: #fafafa center / cover no-repeat; cursor: pointer; display: grid; place-items: center; }
.color-thumb.has-image { border-style: solid; }
.color-thumb .icon { width: 16px; height: 16px; color: var(--faint); }
.color-thumb.has-image .icon { display: none; }
.field .add-color { justify-self: start; text-transform: none; letter-spacing: 0; color: var(--ink); }
@media (max-width: 559px) { .color-row { grid-template-columns: 40px minmax(0, 1fr) auto auto; } .color-row .color-image { grid-column: 1 / -1; grid-row: 2; } }
.swatches { display: flex; gap: 4px; margin-top: 4px; }
.swatch { width: 12px; height: 12px; border-radius: 999px; border: 1px solid rgba(17, 17, 17, 0.15); }

/* Deleted products */
.toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.group-row td { background: #fafafa; font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 10px; padding-bottom: 10px; }
.table tbody tr.group-row:hover { background: none; }
.deleted-row img, .deleted-row .image-preview { opacity: 0.5; filter: grayscale(1); }
.deleted-row td:first-child > .product-cell > div > div:first-child { color: var(--muted); text-decoration: line-through; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 32px); padding: 10px 10px 10px 16px; border-radius: 12px; background: var(--ink); color: #fff; font-size: 13px; box-shadow: 0 12px 30px rgba(17, 17, 17, 0.25); }
.toast-action { border: 0; background: none; color: var(--gold); font-weight: 700; font-size: 13px; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.toast-action:hover { background: rgba(255, 255, 255, 0.08); }
.toast-close { display: grid; place-items: center; border: 0; background: none; color: #a1a1aa; cursor: pointer; padding: 4px; border-radius: 6px; }
.toast-close:hover { color: #fff; }

/* Hero editor */
.hero-panel { padding: 20px; }
.hero-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 16px; }
.hero-status { font-size: 12px; color: var(--muted); }
.hero-status.dirty { color: #b45309; font-weight: 600; }
.hero-error { margin-bottom: 16px; }
.hero-grid { display: grid; gap: 16px; }
@media (min-width: 1024px) { .hero-grid { grid-template-columns: 1fr 1fr; } .hero-card-wide { grid-column: 1 / -1; } }
.hero-card { margin: 0; min-width: 0; border: 1px solid var(--border); border-radius: 12px; padding: 16px; display: grid; gap: 14px; align-content: start; }
.hero-card legend { padding: 0 6px; font-size: 13px; font-weight: 600; }
.lang-flag { font-size: 10px; font-weight: 700; letter-spacing: 0.06em; color: var(--gold); background: var(--gold-light); border-radius: 999px; padding: 1px 7px; margin-left: 4px; text-transform: uppercase; }
.hero-preview { width: 150px; height: 110px; }
.toggles { display: grid; gap: 10px; }
@media (min-width: 560px) { .toggles { grid-template-columns: 1fr 1fr; } }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--gold); }
.badge-grid { display: grid; gap: 10px; }
@media (min-width: 768px) { .badge-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .badge-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.badge-item { display: grid; gap: 6px; padding: 10px; border-radius: 10px; background: #fafafa; }
.badge-item .num { font-size: 11px; font-weight: 700; color: var(--faint); }
.badge-item .input { padding: 8px 10px; font-size: 13px; width: 100%; }
.hero-panel [dir="rtl"] { text-align: right; }

/* Categories editor */
.cat-items { display: grid; gap: 10px; }
.cat-item { display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.cat-item.is-hidden { background: #fafafa; }
.cat-item.is-hidden .cat-thumb { opacity: 0.45; filter: grayscale(1); }
.cat-side { display: grid; gap: 8px; justify-items: center; align-content: start; }
.cat-thumb { width: 84px; height: 112px; border-radius: 10px; background: #f5f5f5 center / cover no-repeat; border: 1px solid var(--line); }
.cat-move { display: flex; gap: 4px; }
.cat-move .icon-btn { width: 28px; height: 28px; border: 1px solid var(--border); }
.cat-move .icon-btn:disabled { opacity: 0.3; cursor: default; }
.cat-main { display: grid; gap: 10px; min-width: 0; }
.cat-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.cat-key { font-weight: 700; font-size: 14px; }
.cat-fields { display: grid; gap: 10px; }
@media (min-width: 900px) { .cat-fields { grid-template-columns: 1fr 1.4fr 1fr; } }
.cat-fields .field label { font-size: 10px; }
.cat-fields .input { padding: 8px 10px; font-size: 13px; }
.cat-image-row { display: flex; gap: 6px; }
.cat-image-row .input { flex: 1; min-width: 0; }
.cat-image-row .upload-btn { padding: 6px 10px; white-space: nowrap; }

/* Category manager */
.cm-list { display: grid; gap: 8px; }
.cm-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 10px; background: #fafafa; }
@media (min-width: 900px) { .cm-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 150px auto; } }
.cm-row .input, .cm-add .input { padding: 8px 10px; font-size: 13px; width: 100%; min-width: 0; }
.cm-count { font-size: 12px; color: var(--muted); }
.cm-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cm-actions .btn { padding: 6px 12px; }
.cm-add { display: grid; gap: 8px; }
@media (min-width: 700px) { .cm-add { grid-template-columns: 1fr 1fr auto; } }
@media (max-width: 899px) { .cm-count { grid-column: 1 / -1; order: 3; } }

@media (min-width: 900px) { .cat-fields.cat-fields-4 { grid-template-columns: 1fr 1fr 1.4fr 1fr; } }
.cat-head .spacer { flex: 1; }
.cat-remove { padding: 5px 12px; }
