/* ══════════════════════════════════════════════════════════
   PriceList App — Functional CSS
   ══════════════════════════════════════════════════════════ */

:root {
  --primary: #333333;
  --primary-dark: #1a1a1a;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --sidebar-width: 220px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

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

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

/* ── Site Header ─────────────────────────────────────────── */

.site-header {
  background: var(--primary);
  color: #fff;
  padding: 12px 20px;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.header-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.header-text { flex: 1; }
.header-text h1 { font-size: 1.25rem; font-weight: 600; color: #fff; }
.header-contact { font-size: 13px; opacity: 0.8; }
.header-meta { font-size: 12px; opacity: 0.65; white-space: nowrap; }
.last-updated { font-size: 12px; }

/* ── Layout ──────────────────────────────────────────────── */

.layout {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 120px);
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}

.sidebar-section { margin-bottom: 24px; }

.sidebar-heading {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  padding: 0 16px 8px;
}

/* Category nav */
.category-nav { display: flex; flex-direction: column; }

.cat-link,
.subcat-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 16px;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  text-decoration: none;
}

.cat-name-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.cat-toggle {
  font-size: 8px;
  opacity: 0.45;
  flex-shrink: 0;
  transition: transform 0.15s;
  line-height: 1;
}

.cat-group.expanded > .cat-link .cat-toggle {
  transform: rotate(90deg);
}

.cat-link:hover,
.subcat-link:hover {
  background: #f0f0f0;
  text-decoration: none;
}

.cat-link.active,
.subcat-link.active {
  background: #f0f4ff;
  border-left-color: var(--primary);
  font-weight: 600;
  color: var(--primary);
}

.all-link { font-weight: 600; }

.subcat-link {
  padding-left: 28px;
  font-size: 12px;
  color: var(--text-muted);
}

.subcat-link.active { color: var(--primary); }

.cat-count {
  font-size: 11px;
  color: var(--text-muted);
  background: #f0f0f0;
  border-radius: 10px;
  padding: 1px 6px;
  min-width: 24px;
  text-align: center;
}

/* ── Filter Panel (right column) ─────────────────────────────── */

.filter-panel {
  width: 190px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 16px 0;
  overflow-y: auto;
}

/* Filters */
.filter-group { padding: 0 16px 12px; }

.filter-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.filter-select {
  width: 100%;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #fafafa;
  color: var(--text);
  cursor: pointer;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-clear-filters {
  display: block;
  margin: 4px 16px 0;
  padding: 6px 0;
  width: calc(100% - 32px);
  font-size: 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
}

.btn-clear-filters:hover { background: #f0f0f0; }

/* ── Main Content ────────────────────────────────────────── */

.main-content {
  flex: 1;
  padding: 16px 20px;
  overflow-x: hidden;
  min-width: 0;
}

.search-bar-wrap {
  margin-bottom: 16px;
}

.search-input {
  width: 100%;
  max-width: 480px;
  padding: 9px 14px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  transition: border-color 0.15s;
  outline: none;
}

.search-input:focus { border-color: var(--primary); }

/* ── Product Table ───────────────────────────────────────── */

.table-meta {
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.result-count { font-weight: 600; }

.table-scroll {
  overflow-x: auto;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.product-table thead {
  background: var(--primary);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 1;
}

.product-table th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  user-select: none;
}

.product-table th.sortable { cursor: pointer; }
.product-table th.sortable:hover { background: var(--primary-dark, #222); }

.sort-arrow { margin-left: 4px; font-size: 11px; }
.sort-arrow.muted { opacity: 0.4; }

.product-table td {
  padding: 9px 14px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
  white-space: nowrap;
}

.product-table tbody tr:last-child td { border-bottom: none; }

.product-table tbody tr:hover { background: #fafafa; }

.col-name {
  white-space: normal;
  min-width: 200px;
}

.col-price {
  text-align: right;
  white-space: nowrap;
}

.product-name-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.product-name { font-weight: 500; }

.product-desc {
  font-size: 12px;
  color: var(--text-muted);
  white-space: normal;
}

.thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  margin-right: 10px;
  float: left;
  border: 1px solid var(--border);
}

.thumb-link { display: inline-block; }

.price-value { font-weight: 600; }
.price-unit  { font-size: 11px; color: var(--text-muted); margin-left: 3px; }
.price-hidden { color: var(--text-muted); font-style: italic; }

/* ── Empty State ─────────────────────────────────────────── */

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state p { margin-bottom: 8px; }

/* ── Footer ──────────────────────────────────────────────── */

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-muted);
  max-width: 1400px;
  margin: 0 auto;
}

.price-note { font-weight: 500; }

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.admin-link {
  font-size: 11px;
  color: #fff;
  opacity: 0.35;
  text-decoration: none;
}
.admin-link:hover { opacity: 0.75; text-decoration: none; }

/* ── Admin ───────────────────────────────────────────────── */

.admin-page { background: var(--bg); }

.admin-header {
  background: #1e293b;
  color: #fff;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-header h1 { font-size: 1.1rem; }

.admin-header-links { display: flex; gap: 20px; font-size: 13px; }
.admin-header-links a { color: rgba(255,255,255,0.75); }
.admin-header-links a:hover { color: #fff; text-decoration: none; }

.admin-content {
  max-width: 840px;
  margin: 24px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.admin-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px 24px;
}

.admin-section h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.section-note { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

/* Emergency section */
.emergency-section { border-color: #fca5a5; }
.emergency-section h2 { color: var(--danger); }

.control-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 0;
  border-bottom: 1px solid #f0f0f0;
}

.control-row:last-child { border-bottom: none; padding-bottom: 0; }

.control-info strong { display: block; margin-bottom: 4px; }
.control-info p { font-size: 13px; color: var(--text-muted); }

.status-badge {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-active { background: #fef3c7; color: #92400e; }

/* Status grid */
.status-grid {
  display: flex;
  gap: 32px;
  flex-wrap: wrap;
}

.status-item { display: flex; flex-direction: column; gap: 2px; }
.status-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); }
.status-value { font-size: 1.1rem; font-weight: 600; }

/* Upload form */
.upload-form { display: flex; flex-direction: column; gap: 16px; }

.upload-field { display: flex; flex-direction: column; gap: 4px; }

.upload-field label { font-size: 13px; font-weight: 600; }

.upload-field input[type="file"] {
  padding: 6px;
  border: 1px dashed var(--border);
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}

.field-hint { font-size: 12px; color: var(--text-muted); }

.required-star { color: var(--danger); }

.upload-actions { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 4px; }

/* Embed snippet */
.embed-snippet {
  background: #f8f8f8;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 12px 14px;
  font-size: 12px;
  font-family: 'Courier New', monospace;
  white-space: pre;
  overflow-x: auto;
  color: #333;
}

/* Text utils */
.text-muted   { color: var(--text-muted); }
.text-warning { color: var(--warning); }

/* ── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.15s;
  white-space: nowrap;
  font-family: var(--font);
}

.btn:hover { opacity: 0.88; text-decoration: none; }

.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-warning   { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.btn-warning-active { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-danger    { background: #fee2e2; color: var(--danger); border-color: #fca5a5; }
.btn-danger-active  { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ── Flash Messages ──────────────────────────────────────── */

.flash {
  padding: 10px 14px;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 500;
  border-left: 4px solid;
}

.flash-success { background: #f0fdf4; border-color: var(--success); color: #14532d; }
.flash-error   { background: #fef2f2; border-color: var(--danger);  color: #7f1d1d; }
.flash-warning { background: #fffbeb; border-color: var(--warning); color: #78350f; }

/* ── Login Page ──────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-box h1 { font-size: 1.15rem; text-align: center; }

.login-box label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.login-box input[type="password"] {
  width: 100%;
  padding: 9px 12px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: 5px;
  outline: none;
}
.login-box input[type="password"]:focus { border-color: var(--primary); }
.login-box .btn { width: 100%; }

/* ── Embed mode ──────────────────────────────────────────── */

body.embed { background: #fff; }
body.embed .layout { max-width: 100%; }
body.embed .main-content { padding: 8px 12px; }

/* ── Responsive ──────────────────────────────────────────── */

@media (max-width: 700px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
  }
  .filter-panel {
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    padding: 12px 0;
  }
  .admin-content { margin: 12px auto; }
  .control-row { flex-direction: column; }
  .status-grid { gap: 16px; }
}
