@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&display=swap');

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

:root {
  --bg:        #f8f9fb;
  --bg2:       #ffffff;
  --bg3:       #f1f3f7;
  --border:    #e4e7ed;
  --border2:   #d0d5e0;
  --text:      #0f1624;
  --text2:     #4b5568;
  --text3:     #9aa3b2;
  --accent:    #2563eb;
  --accent2:   #1d4ed8;
  --accent-bg: rgba(37,99,235,0.08);
  --coral:     #f43f5e;
  --coral-bg:  rgba(244,63,94,0.08);
  --green:     #10b981;
  --green-bg:  rgba(16,185,129,0.08);
  --radius:    12px;
  --radius-lg: 18px;
  --font:      'DM Sans', system-ui, sans-serif;
  --mono:      'DM Mono', 'Consolas', monospace;
  --shadow-sm: 0 1px 3px rgba(15,22,36,0.08), 0 1px 2px rgba(15,22,36,0.06);
  --shadow:    0 4px 16px rgba(15,22,36,0.08), 0 2px 6px rgba(15,22,36,0.05);
  --shadow-lg: 0 12px 40px rgba(15,22,36,0.12), 0 4px 12px rgba(15,22,36,0.06);
  --shadow-xl: 0 24px 64px rgba(15,22,36,0.15), 0 8px 24px rgba(15,22,36,0.08);
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

/* ── SCROLLBAR ─────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ── LOGIN ──────────────────────────────── */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 1.5rem;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 50% at 80% 20%, rgba(37,99,235,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 20% 80%, rgba(244,63,94,0.05) 0%, transparent 60%);
}
.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  padding: 2.5rem 2rem;
  border-radius: 24px;
  box-shadow: var(--shadow-xl);
  width: 100%; max-width: 380px;
}
.login-logo {
  display: flex; align-items: center; gap: 12px; margin-bottom: 1.75rem;
}
.login-logo-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  box-shadow: 0 4px 12px rgba(37,99,235,0.3);
}
.login-card h1 {
  font-size: 1.25rem; font-weight: 700; color: var(--text);
  letter-spacing: -0.02em;
}
.login-card h1 span { color: var(--accent); }
.login-subtitle { color: var(--text3); font-size: 0.75rem; font-family: var(--mono); margin-top: 1px; }
.login-divider { height: 1px; background: var(--border); margin: 1.25rem 0; }

/* ── FORMS ─────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block; margin-bottom: 0.4rem;
  font-size: 0.78rem; font-weight: 600; color: var(--text2);
  letter-spacing: 0.02em;
}
.form-group input, .form-group select {
  width: 100%; padding: 0.65rem 0.9rem;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  font-size: 0.92rem; font-family: var(--font);
  color: var(--text); background: var(--bg);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.form-group input::placeholder { color: var(--text3); }
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
  background: var(--bg2);
}
.form-group select option { background: var(--bg2); }
.form-group input[type="file"] { padding: 0.4rem 0.6rem; font-size: 0.82rem; cursor: pointer; }
.error-msg { color: var(--coral); font-size: 0.8rem; margin-top: 0.4rem; min-height: 1.1em; font-family: var(--mono); }

/* ── BUTTONS ───────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 0.6rem 1.1rem; border-radius: var(--radius); border: 1.5px solid transparent;
  font-size: 0.86rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.18s; white-space: nowrap; line-height: 1;
  min-height: 38px; letter-spacing: 0.01em;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent2); border-color: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(37,99,235,0.3); }
.btn-secondary { background: var(--bg3); color: var(--text2); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-danger { background: var(--coral-bg); color: var(--coral); border-color: rgba(244,63,94,0.25); }
.btn-danger:hover { background: rgba(244,63,94,0.15); }
.btn-success { background: var(--green-bg); color: var(--green); border-color: rgba(16,185,129,0.25); }
.btn-success:hover { background: rgba(16,185,129,0.15); }
.btn-full { width: 100%; padding: 0.75rem; font-size: 0.9rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.8rem; min-height: 32px; }

/* ── NAVBAR ────────────────────────────── */
.navbar {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.5rem; height: 56px;
  position: sticky; top: 0; z-index: 50;
}
.navbar-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.01em; color: var(--text);
}
.navbar-brand-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.2);
}
.navbar-tag {
  background: var(--accent-bg); color: var(--accent);
  border: 1px solid rgba(37,99,235,0.2);
  border-radius: 6px; padding: 2px 7px;
  font-size: 0.65rem; font-family: var(--mono); font-weight: 500; letter-spacing: 0.05em;
}
.navbar-actions { display: flex; gap: 1rem; align-items: center; }
.navbar-actions a {
  color: var(--text2); text-decoration: none;
  font-size: 0.84rem; font-weight: 500; transition: color 0.15s;
}
.navbar-actions a:hover { color: var(--accent); }
.navbar-user { font-size: 0.78rem; color: var(--text3); font-family: var(--mono); }

/* ── SECTION TABS ──────────────────────── */
.section-tabs {
  display: flex; gap: 6px;
  padding: 1rem 1.5rem 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.section-tab {
  padding: 0.55rem 1.25rem; border: none; background: none;
  font-size: 0.84rem; font-weight: 600; cursor: pointer;
  color: var(--text3); border-bottom: 2.5px solid transparent;
  margin-bottom: -1px; transition: all 0.2s; font-family: var(--font);
  touch-action: manipulation;
}
.section-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.section-tab:hover:not(.active) { color: var(--text2); background: var(--bg3); border-radius: 8px 8px 0 0; }

/* ── BOXES SECTION ─────────────────────── */
.boxes-section { display: none; }
.boxes-section.active { display: block; }
.boxes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 1rem;
  padding: 1.25rem 1.5rem 3rem;
}

/* ── BOX CARD — the star of the show ──── */
.box-card {
  position: relative; cursor: pointer; user-select: none;
  border-radius: 16px; overflow: hidden;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.22s ease, border-color 0.2s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  display: flex; flex-direction: column;
}
.box-card:hover {
  transform: translateY(-6px) scale(1.01);
  box-shadow: var(--shadow-xl);
  border-color: var(--accent);
}
.box-card:active { transform: translateY(-2px) scale(0.99); }

.box-img {
  display: block; width: 100%; height: 100px;
  object-fit: contain; padding: 10px 14px 0;
}
.box-overlay {
  position: absolute; left: 0; right: 0;
  top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.box-number {
  font-size: 2.6rem; font-weight: 900; line-height: 1;
  color: white; font-family: var(--mono);
  letter-spacing: -0.04em;
  text-shadow: 0 2px 8px rgba(15,22,36,0.35), 0 1px 3px rgba(15,22,36,0.25);
}
.box-footer {
  padding: 6px 8px 8px;
  display: flex; flex-wrap: wrap; gap: 4px;
  border-top: 1px solid var(--border);
  background: var(--bg3);
  min-height: 30px; align-items: center;
}
.cat-tag {
  background: var(--accent-bg); color: var(--accent);
  border-radius: 6px; padding: 2px 7px;
  font-size: 0.6rem; font-weight: 600; font-family: var(--mono);
  white-space: nowrap; border: 1px solid rgba(37,99,235,0.15);
  letter-spacing: 0.03em;
}
.cat-tag-empty { color: var(--text3); font-size: 0.62rem; font-family: var(--mono); }
.box-stock-badge {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg2); color: var(--text2);
  border: 1px solid var(--border);
  border-radius: 8px; padding: 2px 7px;
  font-size: 0.62rem; font-weight: 700; font-family: var(--mono);
  box-shadow: var(--shadow-sm);
}

/* ── MODAL ─────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,22,36,0.4); z-index: 200;
  align-items: center; justify-content: center;
  padding: 1rem; backdrop-filter: blur(4px);
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  width: 100%; max-width: 540px; max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-xl);
  animation: modal-in 0.22s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.modal-close {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 8px;
  width: 28px; height: 28px; cursor: pointer; color: var(--text3);
  font-size: 1rem; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.modal-close:hover { background: var(--coral-bg); color: var(--coral); border-color: rgba(244,63,94,0.2); }
.modal-body { padding: 1rem 1.25rem; overflow-y: auto; flex: 1; }
.modal-footer { padding: 0.75rem 1.25rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.empty-state { text-align: center; color: var(--text3); padding: 2.5rem 0; font-size: 0.88rem; }

/* ── PRODUCT LIST ──────────────────────── */
.product-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.product-item {
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 0.8rem; border: 1.5px solid var(--border);
  border-radius: 12px; background: var(--bg);
  transition: border-color 0.15s;
}
.product-item:hover { border-color: var(--accent); }
.product-header { display: flex; align-items: center; gap: 0.7rem; }
.prod-thumb {
  width: 52px; height: 52px; border-radius: 10px;
  object-fit: cover; flex-shrink: 0;
  border: 1.5px solid var(--border); cursor: zoom-in;
  transition: transform 0.15s, box-shadow 0.15s;
}
.prod-thumb:hover { transform: scale(1.05); box-shadow: var(--shadow); }
.prod-thumb-placeholder {
  width: 52px; height: 52px; border-radius: 10px;
  background: var(--bg3); display: flex; align-items: center;
  justify-content: center; font-size: 1.4rem; flex-shrink: 0;
  border: 1.5px solid var(--border);
}
.product-info { flex: 1; min-width: 0; }
.product-name { font-size: 0.9rem; font-weight: 600; display: block; color: var(--text); }
.product-qty-label { font-size: 0.75rem; color: var(--text3); display: block; margin-top: 2px; font-family: var(--mono); }
.product-qty { font-size: 0.88rem; font-weight: 700; color: var(--accent); }
.product-qty.zero { color: var(--coral); }
.product-controls { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.qty-input {
  width: 54px; padding: 0.38rem 0.3rem;
  border: 1.5px solid var(--border); border-radius: 8px;
  text-align: center; font-size: 0.88rem; font-weight: 700; font-family: var(--mono);
  color: var(--text); background: var(--bg3);
  -moz-appearance: textfield;
}
.qty-input:focus { outline: none; border-color: var(--accent); background: var(--bg2); }
.qty-input::-webkit-inner-spin-button,
.qty-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ── QTY SPINNER ───────────────────────── */
.qty-spinner {
  display: flex; align-items: center;
  border: 1.5px solid var(--border); border-radius: var(--radius);
  overflow: hidden; width: fit-content;
}
.qty-spinner input[type="number"] {
  width: 64px; border: none; border-left: 1.5px solid var(--border); border-right: 1.5px solid var(--border);
  text-align: center; font-size: 16px; font-weight: 700; font-family: var(--mono);
  color: var(--text); padding: 0.5rem 0.3rem; background: var(--bg2);
  -moz-appearance: textfield;
}
.qty-spinner input[type="number"]::-webkit-inner-spin-button,
.qty-spinner input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
.qty-spinner input[type="number"]:focus { outline: none; background: var(--accent-bg); }
.qty-spin-btn {
  background: var(--bg3); border: none; cursor: pointer;
  width: 40px; height: 40px; font-size: 1.1rem; font-weight: 600;
  color: var(--text2); transition: all 0.15s; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  user-select: none; touch-action: manipulation;
}
.qty-spin-btn:hover { background: var(--accent-bg); color: var(--accent); }
.qty-spin-btn:active { background: rgba(37,99,235,0.15); }

/* ── LIGHTBOX ──────────────────────────── */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 500;
  background: rgba(15,22,36,0.92); backdrop-filter: blur(8px);
  align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox.active { display: flex; animation: fade-in 0.2s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.lightbox img { max-width: 90vw; max-height: 85vh; border-radius: 16px; object-fit: contain; }
.lightbox-close {
  position: absolute; top: 1.2rem; right: 1.5rem;
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px; width: 40px; height: 40px; color: white; font-size: 1.3rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.22); }

/* ── ADMIN ─────────────────────────────── */
.admin-container { max-width: 980px; margin: 1.5rem auto; padding: 0 1.5rem; }
.tabs {
  display: flex; gap: 0; margin-bottom: 1.5rem;
  border-bottom: 1.5px solid var(--border); overflow-x: auto;
}
.tab-btn {
  padding: 0.65rem 1.1rem; border: none; background: none;
  font-size: 0.84rem; cursor: pointer; color: var(--text3); white-space: nowrap;
  border-bottom: 2.5px solid transparent; margin-bottom: -1.5px;
  transition: all 0.2s; font-weight: 600; font-family: var(--font);
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-btn:hover:not(.active) { color: var(--text2); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.card {
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg); padding: 1.25rem;
  margin-bottom: 1rem; box-shadow: var(--shadow-sm);
}
.card h3 {
  margin-bottom: 1rem; font-size: 0.75rem; font-weight: 700; font-family: var(--mono);
  color: var(--text3); text-transform: uppercase; letter-spacing: 0.1em;
}
.table-wrap { overflow-x: auto; }
.table-list { width: 100%; border-collapse: collapse; }
.table-list th, .table-list td {
  padding: 0.6rem 0.75rem; text-align: left;
  border-bottom: 1px solid var(--border); font-size: 0.86rem;
}
.table-list th {
  color: var(--text3); font-weight: 600; font-size: 0.72rem;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--bg);
}
.table-list tr:last-child td { border-bottom: none; }
.table-list tr:hover td { background: var(--bg3); }
.inline-form { display: flex; gap: 0.5rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 0.75rem; }
.inline-form .form-group { margin-bottom: 0; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 0.7rem; font-weight: 700; font-family: var(--mono);
}
.badge-admin  { background: var(--green-bg);   color: var(--green); border: 1px solid rgba(16,185,129,0.2); }
.badge-viewer { background: var(--accent-bg);  color: var(--accent); border: 1px solid rgba(37,99,235,0.2); }
.badge-danger { background: var(--coral-bg);   color: var(--coral); border: 1px solid rgba(244,63,94,0.2); }
.badge-ok     { background: var(--green-bg);   color: var(--green); border: 1px solid rgba(16,185,129,0.2); }
.cat-check-group { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.cat-check-label {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg3); border-radius: 8px; padding: 5px 10px;
  cursor: pointer; font-size: 0.84rem; user-select: none;
  border: 1.5px solid var(--border); transition: all 0.15s;
}
.cat-check-label:hover { background: var(--accent-bg); border-color: rgba(37,99,235,0.3); color: var(--accent); }
.cat-check-label input { cursor: pointer; width: 14px; height: 14px; accent-color: var(--accent); }
.cats-assigned { font-size: 0.8rem; color: var(--text3); font-family: var(--mono); }

/* ── BOTTOM NAV ────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  height: 60px; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav-item {
  display: flex; flex: 1; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; text-decoration: none;
  color: var(--text3); font-size: 0.65rem; font-weight: 600; font-family: var(--mono);
  transition: color 0.15s; letter-spacing: 0.03em;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.bottom-nav-item svg { width: 20px; height: 20px; }
.bottom-nav-item.active { color: var(--accent); }
.bottom-nav-item:hover { color: var(--accent); }
.modal-full-mobile { max-height: 100vh; border-radius: 20px; }

/* ── SECTION ENTER ANIMATION ───────────── */
.boxes-section.active {
  animation: section-enter 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes section-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── RESPONSIVE ────────────────────────── */
@media (max-width: 600px) {
  body { padding-bottom: 60px; }
  .bottom-nav { display: flex; }
  .navbar { padding: 0 1rem; height: 50px; }
  .section-tabs { padding: 0.5rem 0.75rem 0; }
  .section-tab { padding: 0.45rem 0.9rem; font-size: 0.8rem; }
  .boxes-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0.65rem; padding: 0.85rem 0.75rem 5rem; }
  .box-img { height: 85px; }
  .box-number { font-size: 1.8rem; }
  .box-overlay { top: 52%; }
  .cat-tag { font-size: 0.56rem; }
  .modal-full-mobile { max-height: calc(100vh - 60px); border-radius: 20px 20px 0 0; margin-top: auto; }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .admin-container { padding: 0 0.75rem; }
  .btn-sm { min-height: 34px; }
}
@media (max-width: 380px) {
  .boxes-grid { grid-template-columns: repeat(2, 1fr); }
  .box-img { height: 75px; }
  .box-number { font-size: 1.6rem; }
}
