/* Admin SPA styles. Self-contained; shares the public site's design tokens and
   flat, editorial aesthetic (Inter + Playfair Display, square corners, calm
   neutrals with a gold accent). The public catalog has its own app.css. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #F9F6F1;
  --surface:   #FFFFFF;
  --ink:       #1A1A1A;
  --ink2:      #555550;
  --ink3:      #999490;
  --border:    #E2DDD6;
  --border2:   #CEC8BF;
  --available: #2A5C2A;
  --avail-bg:  #E8F5E8;
  --sold-bg:   #F0EDE8;
  --sold-text: #999490;
  --gold:      #B8832A;
  --gold-bg:   #FDF6EA;
  --red:       #C0392B;
  --red-bg:    #FBEAE8;
}

html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
}
h1, h2, h3, h4 { font-family: 'Playfair Display', serif; }
a { color: var(--ink2); }

/* ─── App shell ─────────────────────────────────────────────── */
.admin-app { display: none; min-height: 100vh; flex-direction: column; }
.admin-app.ready { display: flex; }

.topbar {
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; height: 60px; position: sticky; top: 0; z-index: 100;
}
.topbar-title { font-family: 'Playfair Display', serif; font-size: 1.15rem; font-weight: 700; }
.topbar-title span { font-style: italic; font-weight: 400; opacity: 0.7; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions a { color: rgba(255,255,255,0.7); text-decoration: none; font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; }
.topbar-actions a:hover { color: #fff; }
.topbar-email { font-size: 0.78rem; color: rgba(255,255,255,0.6); }
.btn-logout {
  background: none; border: 1px solid rgba(255,255,255,0.4); color: #fff;
  font-family: 'Inter', sans-serif; font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; padding: 7px 14px; cursor: pointer;
}
.btn-logout:hover { border-color: #fff; }

.admin-layout { display: flex; flex: 1; align-items: stretch; }

/* ─── Sidebar nav ───────────────────────────────────────────── */
.sidebar {
  width: 220px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); padding: 18px 0;
}
.nav-group-label {
  font-size: 0.66rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink3); padding: 12px 22px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; text-align: left; background: none; border: none;
  border-left: 3px solid transparent; font-family: 'Inter', sans-serif;
  font-size: 0.9rem; color: var(--ink2); padding: 9px 22px; cursor: pointer;
  text-decoration: none; transition: color 0.12s, background 0.12s;
}
.nav-item:hover { color: var(--ink); background: var(--bg); }
.nav-item.active { color: var(--ink); border-left-color: var(--gold); background: var(--bg); font-weight: 600; }
.nav-badge {
  background: var(--gold); color: #fff; border-radius: 999px;
  min-width: 20px; height: 20px; padding: 0 6px; font-size: 0.7rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-badge:empty { display: none; }

/* ─── Screen area ───────────────────────────────────────────── */
.screen { flex: 1; min-width: 0; padding: 32px 36px; overflow-x: hidden; }
.screen-head { margin-bottom: 24px; }
.screen-head h2 { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.screen-tag {
  font-size: 0.68rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink3); margin-bottom: 6px; font-weight: 600;
}
.screen-desc { font-size: 0.9rem; color: var(--ink2); margin-top: 6px; max-width: 760px; }
.screen-toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 18px 0; }
.placeholder {
  border: 1px dashed var(--border2); background: var(--surface);
  padding: 48px 32px; text-align: center; color: var(--ink3); font-size: 0.95rem;
}
.muted { color: var(--ink3); }
.danger-text { color: var(--red); }
.loading { color: var(--ink3); font-style: italic; padding: 24px 0; }

/* ─── Buttons ───────────────────────────────────────────────── */
.btn {
  font-family: 'Inter', sans-serif; font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.04em; padding: 10px 18px; cursor: pointer; border: none;
  background: var(--ink); color: #fff; transition: background 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--gold); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border2);
}
.btn-secondary:hover { background: var(--surface); border-color: var(--ink); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #9b2d22; }
.btn-sm { padding: 6px 12px; font-size: 0.74rem; }

/* ─── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--ink2); margin-bottom: 6px; font-weight: 600;
}
.form-optional { text-transform: none; letter-spacing: 0; color: var(--ink3); font-weight: 400; }
.form-input {
  width: 100%; font-family: 'Inter', sans-serif; font-size: 16px;
  padding: 10px 12px; border: 1px solid var(--border2); background: var(--surface);
  color: var(--ink);
}
.form-input:focus { border-color: var(--ink); outline: none; }
textarea.form-input { resize: vertical; min-height: 64px; }
.form-error { font-size: 0.82rem; color: var(--red); margin-top: 8px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ─── Badges / chips ────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: 0.66rem; letter-spacing: 0.08em;
  text-transform: uppercase; font-weight: 600; padding: 3px 8px;
}
.badge-avail { background: var(--avail-bg); color: var(--available); }
.badge-sold  { background: var(--sold-bg); color: var(--sold-text); }
.badge-best  { background: var(--gold-bg); color: var(--gold); }

/* ─── Generic data table ────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; background: var(--surface); }
.data-table th {
  font-size: 0.68rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink3);
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border2); font-weight: 600;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 0.86rem; vertical-align: middle; }
.data-table tr:hover td { background: var(--bg); }
.thumb { width: 44px; height: 44px; object-fit: contain; background: #f5f3ef; flex-shrink: 0; }

/* ─── Designs screen ────────────────────────────────────────── */
.design-row-id { font-size: 0.7rem; color: var(--ink3); margin-top: 2px; }
.cell-num-input { width: 84px; }
.cell-cost-input { width: 92px; }
.sold-to-input { min-width: 160px; }
.sold-to-input:disabled { opacity: 0.4; cursor: not-allowed; }

/* toggle switch */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .thumb {
  position: absolute; inset: 0; background: var(--border2); transition: background 0.15s; border-radius: 999px;
}
.toggle .thumb::after {
  content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: transform 0.15s;
}
.toggle input:checked + .thumb { background: var(--gold); }
.toggle input:checked + .thumb::after { transform: translateX(16px); }

/* ─── Best Sellers grid ─────────────────────────────────────── */
.bs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px; }
.bs-card {
  background: var(--surface); border: 2px solid var(--border); padding: 8px; cursor: pointer;
  position: relative; transition: border-color 0.12s;
}
.bs-card.selected { border-color: var(--gold); }
.bs-card img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #f5f3ef; pointer-events: none; }
.bs-card-label { font-size: 0.72rem; margin-top: 6px; color: var(--ink2); line-height: 1.2; }
.bs-card-sold { font-size: 0.66rem; margin-top: 3px; color: var(--gold); font-weight: 600; }
.bs-card-star { position: absolute; top: 8px; right: 10px; color: var(--gold); font-size: 1.1rem; display: none; }
.bs-card.selected .bs-card-star { display: block; }

/* ─── Upload ────────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed var(--border2); background: var(--surface); padding: 36px;
  text-align: center; cursor: pointer; margin-bottom: 20px;
}
.upload-zone:hover { border-color: var(--ink); }
.upload-zone input[type=file] { display: none; }
.upload-zone-icon { font-size: 2rem; margin-bottom: 10px; }
.upload-zone p { font-size: 0.9rem; color: var(--ink2); }
.upload-zone span { font-size: 0.76rem; color: var(--ink3); display: block; margin-top: 4px; }
.upload-preview { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 20px; }
.upload-item { width: 150px; }
.upload-item-imgwrap { position: relative; width: 150px; }
.upload-item img { width: 150px; height: 120px; object-fit: contain; background: #f5f3ef; }
.upload-item-remove {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border: none;
  background: rgba(0,0,0,0.6); color: #fff; cursor: pointer; line-height: 1;
}
.upload-item .form-group { margin: 8px 0 0; }

/* ─── Displays ──────────────────────────────────────────────── */
.disp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; margin-bottom: 28px; }
.disp-card { background: var(--surface); border: 1px solid var(--border); position: relative; }
.disp-card img { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; }
.disp-card-body { padding: 12px 14px; border-top: 1px solid var(--border); }
.disp-card-store { font-size: 0.88rem; font-weight: 600; }
.disp-card-date { font-size: 0.72rem; color: var(--ink3); margin-top: 2px; }
.disp-card-delete {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: none;
  background: rgba(0,0,0,0.55); color: #fff; cursor: pointer; opacity: 0; transition: opacity 0.12s; line-height: 1;
}
.disp-card:hover .disp-card-delete { opacity: 1; }
.disp-add-form { background: var(--surface); border: 1px solid var(--border); padding: 22px; max-width: 560px; }
.disp-add-form h4 { font-size: 1.05rem; margin-bottom: 16px; }
.disp-upload-preview { display: none; max-width: 220px; margin: 14px 0; border: 1px solid var(--border); }
.disp-upload-preview.visible { display: block; }

/* ─── Orders ────────────────────────────────────────────────── */
.orders-empty { color: var(--ink3); font-style: italic; font-size: 0.9rem; }
.order-card { background: var(--surface); border: 1px solid var(--border); padding: 18px 20px; margin-bottom: 14px; }
.order-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.order-card-store { font-family: 'Playfair Display', serif; font-size: 1.1rem; font-weight: 700; line-height: 1.2; }
.order-card-contact { font-size: 0.82rem; color: var(--ink2); margin-top: 3px; }
.order-card-contact a { color: var(--ink2); }
.order-card-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.order-card-date { font-size: 0.72rem; color: var(--ink3); letter-spacing: 0.06em; text-transform: uppercase; }
.order-status-select { font-family: 'Inter', sans-serif; font-size: 0.8rem; padding: 5px 8px; border: 1px solid var(--border2); background: var(--surface); }
.order-card-items { list-style: none; margin: 14px 0 0; padding: 0; }
.order-card-items li { font-size: 0.85rem; color: var(--ink); padding: 4px 0; border-bottom: 1px solid var(--border); }
.order-card-items li:last-child { border-bottom: none; }
.order-qty { color: var(--ink3); }
.order-custom { font-style: italic; }
.order-card-notes { font-size: 0.82rem; color: var(--ink2); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ─── Login gate ────────────────────────────────────────────── */
.login-gate {
  display: none; position: fixed; inset: 0; background: rgba(26,26,26,0.55);
  align-items: center; justify-content: center; z-index: 600; padding: 20px; /* above modal (300) + toast (400) so re-login is always reachable */
}
.login-gate.open { display: flex; }
.login-box { background: var(--surface); padding: 32px; width: 100%; max-width: 360px; border: 1px solid var(--border); }
.login-box h2 { font-size: 1.4rem; margin-bottom: 18px; }
.login-box .form-input { margin-bottom: 10px; }
.login-error { font-size: 0.8rem; color: var(--red); margin: 4px 0 12px; display: none; }
.login-error.show { display: block; }

/* ─── Modal (store edit, order fulfillment — used by later phases) ──────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(26,26,26,0.55);
  align-items: flex-start; justify-content: center; z-index: 300; padding: 40px 20px; overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); width: 100%; max-width: 540px; border: 1px solid var(--border); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 1.25rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--ink2); line-height: 1; }
.modal-body { padding: 22px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 12px; padding: 16px 24px; border-top: 1px solid var(--border); }

/* ─── Toast ─────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 12px 22px; font-size: 0.85rem;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 400; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-warn { background: var(--gold); }
.toast.toast-error { background: var(--red); }

/* ─── Inventory read screens (dashboard/stores/detail/warehouse/reports) ── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 8px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); padding: 18px 20px; text-decoration: none; color: inherit; display: block; }
a.stat-card:hover { border-color: var(--ink); }
.stat-card-alert { border-color: var(--gold); background: var(--gold-bg); }
.stat-num { font-family: 'Playfair Display', serif; font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink3); margin-top: 6px; }

.section { margin-top: 28px; }
.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.cols-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }

.attn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.attn-card { display: block; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--gold); padding: 14px 16px; text-decoration: none; color: inherit; }
.attn-card:hover { border-left-color: var(--ink); }
.attn-card-name { font-weight: 600; }
.attn-card-meta { font-size: 0.78rem; color: var(--ink3); margin-top: 4px; }
.attn-card-cta { font-size: 0.78rem; color: var(--gold); margin-top: 8px; font-weight: 600; }

.rank-list { list-style: none; counter-reset: r; }
.rank-list li { padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.rank-list li:last-child { border-bottom: none; }
.rank-num { display: inline-block; min-width: 42px; font-weight: 700; color: var(--ink2); }

.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.neg { color: var(--red); font-weight: 600; }
.row-link { cursor: pointer; }
.row-inactive { opacity: 0.55; }
.store-name { font-weight: 600; }
.small { font-size: 0.74rem; }
.star { color: var(--gold); }
.back-link { font-size: 0.8rem; color: var(--ink3); text-decoration: none; display: inline-block; margin-bottom: 6px; }
.back-link:hover { color: var(--ink); }

.badge-ok   { background: var(--avail-bg); color: var(--available); }
.badge-warn { background: #FBF3D9; color: #8a6d1a; }
.badge-late { background: #FBE9D9; color: #9a5a1a; }
.badge-bad  { background: var(--red-bg); color: var(--red); }

.st-bar { display: inline-block; width: 90px; height: 8px; background: var(--border); vertical-align: middle; margin-right: 8px; }
.st-fill { height: 100%; }
.st-fill.st-good { background: var(--available); }
.st-fill.st-mid { background: var(--gold); }
.st-fill.st-low { background: var(--border2); }
.st-pct { font-size: 0.78rem; font-variant-numeric: tabular-nums; }

/* ─── Phase 5 write UIs (visit logging, modals) ─────────────── */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-head .section-title { margin-bottom: 0; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; text-transform: none; letter-spacing: 0; color: var(--ink); }
.link-btn { background: none; border: none; color: var(--ink3); cursor: pointer; font-size: 0.9rem; font-family: 'Inter', sans-serif; }
.link-btn:hover { color: var(--red); }
.link-btn.danger { color: var(--red); }

/* Visit logging — mobile-first */
.visit-meta { background: var(--surface); border: 1px solid var(--border); padding: 12px 16px; margin-bottom: 14px; }
.visit-meta summary { cursor: pointer; font-size: 0.85rem; font-weight: 600; color: var(--ink2); }
.visit-add { position: relative; margin-bottom: 16px; }
.visit-results { position: absolute; z-index: 20; left: 0; right: 0; background: var(--surface); border: 1px solid var(--border2); max-height: 280px; overflow-y: auto; }
.visit-results:empty { display: none; }
.visit-result { display: block; width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--border); padding: 10px 12px; cursor: pointer; font-family: 'Inter', sans-serif; font-size: 0.9rem; }
.visit-result:hover { background: var(--bg); }
.visit-custom-btn { margin-top: 10px; }
.visit-custom-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.visit-custom-form .form-input { flex: 1; }
.visit-custom-tag { display: inline-block; font-size: 0.62rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 700; color: var(--gold); border: 1px solid var(--gold); border-radius: 3px; padding: 1px 5px; margin-right: 4px; vertical-align: middle; }

.visit-card { background: var(--surface); border: 1px solid var(--border); padding: 14px 16px; margin-bottom: 10px; }
.visit-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.visit-card-title { font-weight: 600; line-height: 1.3; }
.visit-remove { background: none; border: none; color: var(--ink3); cursor: pointer; font-size: 1rem; padding: 2px 6px; }
.visit-remove:hover { color: var(--red); }
.visit-last { font-size: 0.78rem; color: var(--ink3); margin-top: 4px; }
.visit-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.visit-inputs label { display: block; font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink2); font-weight: 600; }
.visit-num { width: 100%; height: 56px; font-size: 22px; text-align: center; border: 1px solid var(--border2); background: var(--surface); margin-top: 4px; font-family: 'Inter', sans-serif; }
.visit-num:focus { border-color: var(--ink); outline: none; }
.visit-sold { font-size: 0.82rem; color: var(--available); margin-top: 10px; }

.save-bar { position: sticky; bottom: 0; background: rgba(249,246,241,0.95); padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); margin-top: 18px; border-top: 1px solid var(--border); }
.save-bar-btn { width: 100%; height: 52px; font-size: 1rem; }

/* ─── Order fulfillment dialog ──────────────────────────────── */
.fulfill-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
.fulfill-item:last-child { border-bottom: none; }
.fulfill-qty { width: 84px; display: inline-block; text-align: right; }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 760px) {
  .admin-layout { flex-direction: column; }
  .sidebar {
    width: 100%; border-right: none; border-bottom: 1px solid var(--border);
    display: flex; flex-wrap: wrap; gap: 2px; padding: 8px;
  }
  .nav-group-label { width: 100%; padding: 6px 12px 2px; }
  .nav-item { width: auto; border-left: none; border-bottom: 2px solid transparent; padding: 7px 12px; }
  .nav-item.active { border-left: none; border-bottom-color: var(--gold); }
  .screen { padding: 22px 18px; }
  .form-row { grid-template-columns: 1fr; }
  .cols-2 { grid-template-columns: 1fr; gap: 0; }
}
