/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #ffffff;
  --bg-subtle: #f9fafb;
  --bg-hover:  #f3f4f6;
  --border:    #e5e7eb;
  --border-md: #d1d5db;
  --text:      #111827;
  --text-muted:#6b7280;
  --text-xs:   #9ca3af;
  --accent:    #0f6fec;
  --accent-h:  #0b5cc7;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --success:   #16a34a;
  --warn:      #d97706;
  --radius:    6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10);
  --font:      'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --sidebar-w: 210px;
  --topbar-h:  48px;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  height: 100vh;
  overflow: hidden;
}

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

/* ── Utilities ────────────────────────────────────────────────────────────── */
.hidden     { display: none !important; }
.w-full     { width: 100%; }
.mt-1       { margin-top: .25rem; }
.mt-2       { margin-top: .5rem; }
.mt-3       { margin-top: .75rem; }
.mt-4       { margin-top: 1rem; }
.mb-2       { margin-bottom: .5rem; }
.mb-4       { margin-bottom: 1rem; }
.gap-1      { gap: .25rem; }
.gap-2      { gap: .5rem; }
.gap-3      { gap: .75rem; }
.flex       { display: flex; }
.flex-col   { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1     { flex: 1; }
.text-sm    { font-size: .85rem; }
.text-xs    { font-size: .75rem; }
.text-muted { color: var(--text-muted); }
.text-danger{ color: var(--danger); }
.text-success{color: var(--success); }
.font-mono  { font-family: ui-monospace, monospace; }
.truncate   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nowrap     { white-space: nowrap; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-subtle);
}
.login-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 2.25rem;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow-sm);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 1.5rem;
}
.login-logo svg { color: var(--accent); }
.login-card h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
}
.form-error {
  font-size: .8rem;
  color: var(--danger);
  padding: .45rem .6rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  margin-bottom: .75rem;
}

/* ── Layout shell ─────────────────────────────────────────────────────────── */
#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .875rem .875rem .75rem;
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.sidebar-header svg { color: var(--accent); flex-shrink: 0; }
.sidebar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-list { list-style: none; padding: .375rem 0; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .4rem .875rem;
  font-size: .8125rem;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 0;
  transition: background .1s, color .1s;
  user-select: none;
  margin: 1px .375rem;
  border-radius: var(--radius);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: #eff6ff; color: var(--accent); font-weight: 500; }
.nav-item.active svg { color: var(--accent); }
.nav-item svg { flex-shrink: 0; color: var(--text-xs); }
.nav-item.active svg { color: var(--accent); }
.nav-admin { }

.sidebar-footer {
  padding: .75rem .875rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .375rem;
}
.nav-user-label {
  font-size: .75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Main area ────────────────────────────────────────────────────────────── */
.main-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  gap: 1rem;
}
.breadcrumb {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .375rem;
}
.breadcrumb .bc-sep { color: var(--text-xs); }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .375rem .75rem;
  font-size: .8125rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
  font-family: inherit;
  transition: background .1s, border-color .1s, color .1s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); border-color: var(--accent-h); }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled)  { background: var(--danger-h); border-color: var(--danger-h); }
.btn-outline  { background: var(--bg); color: var(--text); border-color: var(--border-md); }
.btn-outline:hover:not(:disabled) { background: var(--bg-hover); }
.btn-ghost    { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled)   { background: var(--bg-hover); color: var(--text); }
.btn-sm       { padding: .25rem .5rem; font-size: .75rem; }
.btn-icon     { padding: .25rem .25rem; }
.btn-icon-sm  { padding: .2rem .2rem; }

/* ── Form elements ────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .875rem; }
.field:last-child { margin-bottom: 0; }
label { font-size: .8rem; font-weight: 500; color: var(--text); }
label .req { color: var(--danger); margin-left: 2px; }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: .375rem .625rem;
  font-size: .8125rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
  line-height: 1.4;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(15,111,236,.12);
}
input[type="search"] { padding-left: .625rem; }
textarea { resize: vertical; min-height: 72px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .625rem center; padding-right: 1.75rem; }
.field-hint { font-size: .75rem; color: var(--text-muted); }
.field-error { font-size: .75rem; color: var(--danger); }
.input-group { display: flex; gap: .5rem; }
.input-group > input { flex: 1; min-width: 0; }

/* Multi-select checkboxes */
.checkbox-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .375rem .75rem;
  padding: .5rem;
  border: 1px solid var(--border-md);
  border-radius: var(--radius);
  max-height: 140px;
  overflow-y: auto;
}
.checkbox-item { display: flex; align-items: center; gap: .3rem; font-size: .8rem; cursor: pointer; }
.checkbox-item input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.empty-options { font-size: .8rem; color: var(--text-muted); padding: .25rem; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: .8125rem; }
thead tr { background: var(--bg-subtle); border-bottom: 1px solid var(--border); }
th { padding: .5rem .75rem; text-align: left; font-weight: 500; color: var(--text-muted); font-size: .75rem; white-space: nowrap; }
td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-subtle); }
.td-actions { display: flex; gap: .25rem; justify-content: flex-end; }

/* ── Cards / panels ───────────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.125rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .875rem;
  gap: .75rem;
}
.card-title {
  font-size: .875rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: .4rem;
}
.card-title svg { color: var(--text-muted); }

/* ── Page toolbar ─────────────────────────────────────────────────────────── */
.page-toolbar {
  display: flex;
  align-items: center;
  gap: .625rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-input { max-width: 260px; }

/* ── Badge / pill ─────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .5rem;
  font-size: .7rem;
  font-weight: 500;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-gray   { background: var(--bg-subtle); color: var(--text-muted); border: 1px solid var(--border); }

/* ── Product grid ─────────────────────────────────────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .875rem;
}
.product-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.product-card:hover { box-shadow: var(--shadow-sm); border-color: var(--border-md); }
.product-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: var(--bg-subtle);
  display: block;
}
.product-thumb-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-xs);
}
.product-info { padding: .6rem .75rem; }
.product-name { font-size: .8125rem; font-weight: 500; margin-bottom: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-sku  { font-size: .7rem; color: var(--text-muted); font-family: ui-monospace, monospace; }

/* ── Product detail ───────────────────────────────────────────────────────── */
.product-detail { max-width: 860px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: .75rem; }

/* ── Image upload / grid ──────────────────────────────────────────────────── */
.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .5rem;
  border: 1px dashed var(--border-md);
  border-radius: var(--radius);
  min-height: 72px;
}
.image-item {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid transparent;
  flex-shrink: 0;
}
.image-item.is-cover { border-color: var(--accent); }
.image-item.dragging { opacity: .4; }
.image-item.drag-over-item { outline: 2px dashed var(--accent); outline-offset: 2px; }
.image-item[draggable] { cursor: grab; }
.image-item[draggable]:active { cursor: grabbing; }
.drag-handle {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45);
  border-radius: 2px;
  color: #fff;
  opacity: 0;
  transition: opacity .15s;
  z-index: 1;
}
.image-item:hover .drag-handle { opacity: 1; }
.image-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-item-actions {
  position: absolute;
  top: 2px; right: 2px;
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
}
.image-item:hover .image-item-actions { opacity: 1; }
.image-item-actions button {
  width: 20px; height: 20px;
  border-radius: 3px;
  border: none;
  background: rgba(0,0,0,.55);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.cover-badge {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(15,111,236,.8);
  color: #fff;
  font-size: .6rem;
  text-align: center;
  padding: 1px 0;
}
.upload-drop {
  border: 2px dashed var(--border-md);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: .8rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-drop:hover, .upload-drop.drag-over { border-color: var(--accent); background: #eff6ff; }

/* ── Pricing table ────────────────────────────────────────────────────────── */
.price-rule-row { display: grid; grid-template-columns: 1fr 140px 120px 100px 100px 32px; gap: .5rem; align-items: center; padding: .375rem 0; border-bottom: 1px solid var(--border); }
.price-rule-row:last-child { border-bottom: none; }
.price-rule-header { font-size: .75rem; font-weight: 500; color: var(--text-muted); }

/* ── History list ─────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: .25rem; }
.history-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .4rem .625rem;
  border-radius: var(--radius);
  background: var(--bg-subtle);
  font-size: .8rem;
}
.history-date { color: var(--text-muted); font-size: .75rem; white-space: nowrap; }
.history-price { font-weight: 600; font-variant-numeric: tabular-nums; }
.history-supplier { color: var(--text-muted); }
.history-note { color: var(--text-xs); font-size: .72rem; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 5vh;
  z-index: 100;
  overflow-y: auto;
}
.modal-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 560px;
  margin: 0 .75rem 2rem;
}
.modal-box.modal-lg { max-width: 720px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: .9375rem; font-weight: 600; }
.modal-body  { padding: 1rem; }
.modal-footer {
  padding: .75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}
.modal-footer:empty { display: none; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  z-index: 200;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .6rem .875rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius);
  font-size: .8125rem;
  box-shadow: var(--shadow-md);
  pointer-events: all;
  animation: slideUp .2s ease;
  max-width: 340px;
}
.toast.toast-success { background: var(--success); }
.toast.toast-error   { background: var(--danger); }
.toast.toast-warn    { background: var(--warn); }
@keyframes slideUp { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}
.empty-state svg { margin: 0 auto .75rem; display: block; color: var(--text-xs); }
.empty-state p { font-size: .875rem; }
.empty-state small { font-size: .8rem; color: var(--text-xs); }

/* ── Loading spinner ──────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border-md);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
.spinner-lg { width: 28px; height: 28px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { display: flex; justify-content: center; padding: 3rem; }

/* ── Import/Export ────────────────────────────────────────────────────────── */
.export-section { max-width: 600px; }
.export-cols { display: grid; grid-template-columns: 1fr 1fr; gap: .25rem .75rem; padding: .5rem; border: 1px solid var(--border-md); border-radius: var(--radius); }
.import-result { margin-top: 1rem; }
.import-row-error { font-size: .75rem; color: var(--danger); }

/* ── Confirm dialog ───────────────────────────────────────────────────────── */
.confirm-text { font-size: .875rem; line-height: 1.6; }

/* ── Dashboard ────────────────────────────────────────────────────────────── */
.dashboard-wrap { display: flex; flex-direction: column; gap: 1.25rem; }

.dash-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .75rem;
}
.dash-stat-card {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: 1rem 1.125rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: box-shadow .15s, border-color .15s;
}
.dash-stat-card:hover { border-color: var(--border-md); box-shadow: var(--shadow-md); }
.dash-stat-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: #eff6ff;
  border-radius: var(--radius);
  color: var(--accent);
  flex-shrink: 0;
}
.dash-stat-value { font-size: 1.5rem; font-weight: 700; line-height: 1.1; color: var(--text); }
.dash-stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .125rem; }
.dash-stat-sub   { font-size: .72rem; color: var(--text-xs); margin-top: .125rem; }

.dash-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  align-items: start;
}

.dash-price-list { display: flex; flex-direction: column; }
.dash-price-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.dash-price-row:last-child { border-bottom: none; }
.dash-price-row:hover { background: var(--bg-hover); }
.dash-price-main { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.dash-price-product { font-size: .8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-price-supplier { display: block; }
.dash-price-right { display: flex; flex-direction: column; align-items: flex-end; gap: .1rem; flex-shrink: 0; }
.dash-price-amount { font-size: .8125rem; }
.dash-price-date { display: block; }

.dash-missing-list { display: flex; flex-direction: column; }
.dash-missing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.dash-missing-row:last-child { border-bottom: none; }
.dash-missing-row:hover { background: var(--bg-hover); }
.dash-missing-name { font-size: .8125rem; font-weight: 500; }

.dash-all-good {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .875rem .75rem;
  color: var(--success);
  font-size: .8125rem;
}

.badge-warn { background: #fef3c7; color: #92400e; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 48px; }
  .sidebar-title, .nav-item span, .sidebar-footer .nav-user-label { display: none; }
  .nav-item { justify-content: center; padding: .5rem; }
  .sidebar-header { justify-content: center; padding: .75rem .5rem; }
}
