* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-secondary: #f2f2f5;
  --border: #e0e0e4;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --success: #34c759;
  --danger: #ff3b30;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 10px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  --font-display: 'Sora', sans-serif;
}

[data-theme="dark"] {
  --bg: #1d1d1f;
  --surface: #2d2d2f;
  --surface-secondary: #3a3a3c;
  --border: #48484a;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  padding-bottom: 70px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s, color 0.2s;
}

/* ─── Header ─── */

.app-header {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
}

.header-actions { display: flex; gap: 6px; }

.icon-btn {
  background: none;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: var(--surface-secondary); color: var(--text); }

/* ─── Search ─── */

.search-section { padding: 0 16px 12px; }

.search-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-secondary);
  border-radius: var(--radius);
  padding: 0 12px;
  border: 1px solid transparent;
  transition: border-color 0.15s, background 0.15s;
}

.search-wrapper:focus-within {
  border-color: var(--accent);
  background: var(--surface);
}

.search-icon { color: var(--text-secondary); font-size: 1rem; }

.search-wrapper input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 15px;
  padding: 10px 0;
  color: var(--text);
  font-family: var(--font);
}

.search-wrapper input::placeholder { color: var(--text-secondary); }

.header-action-btn {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 6px;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
}

.header-action-btn:hover { background: var(--surface); color: var(--text); }

/* ─── Stats ─── */

.stats-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.stat-card-mobile {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 110px;
  box-shadow: var(--shadow-sm);
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.stat-card-mobile div:last-child {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 2px;
}

/* ─── Breadcrumb ─── */

.nav-breadcrumb {
  padding: 8px 16px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
}

.breadcrumb-item {
  background: var(--surface-secondary);
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s;
}

.breadcrumb-item.active {
  background: var(--accent);
  color: white;
  font-weight: 500;
}

/* ─── Content ─── */

.content-area { padding: 12px 16px; }

.hierarchy-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hierarchy-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: var(--shadow-sm);
}

.hierarchy-card:active { transform: scale(0.98); }

.card-title {
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
}

.card-badge {
  background: var(--surface-secondary);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.68rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* ─── Product Card ─── */

.product-detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--success);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: var(--shadow-sm);
}

.product-detail-card:active { transform: scale(0.98); }

.product-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.product-row span:first-child { font-weight: 500; font-size: 0.95rem; }

/* ─── FAB ─── */

.fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--accent);
  color: white;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  font-size: 1.5rem;
  font-weight: 300;
  z-index: 90;
  transition: transform 0.12s, box-shadow 0.12s;
}

.fab:active { transform: scale(0.93); }

/* ─── Modal ─── */

.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  justify-content: center;
  align-items: flex-end;
}

.modal.active { display: flex; }

.modal-sheet {
  background: var(--surface);
  border-radius: 14px 14px 0 0;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px 20px 28px;
  animation: sheetUp 0.25s ease-out;
}

@keyframes sheetUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-header h3 { font-size: 1.05rem; font-weight: 600; font-family: var(--font-display); }

.modal-x {
  width: 32px;
  height: 32px;
  font-size: 0.9rem;
}

.modal-location {
  background: var(--surface-secondary);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.modal-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* ─── Buttons ─── */

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  flex: 1;
  transition: opacity 0.15s, transform 0.1s;
  font-family: var(--font);
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { opacity: 0.9; }
.btn-danger { background: var(--surface-secondary); color: var(--danger); }
.btn-success { background: var(--success); color: white; }

/* ─── Form ─── */

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  margin-bottom: 5px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-secondary);
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus, .form-group select:focus { border-color: var(--accent); }

/* ─── Quantity ─── */

.qty-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.qty-btn {
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text);
  transition: background 0.12s;
}

.qty-btn:active { background: var(--border); }

.qty-value {
  font-size: 1.4rem;
  font-weight: 600;
  min-width: 50px;
  text-align: center;
  font-family: var(--font-display);
}

/* ─── Scanner ─── */

.scanner-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: black;
  z-index: 1100;
  display: none;
  flex-direction: column;
}

.scanner-overlay.active { display: flex; }

#scannerVideo { width: 100%; height: 100%; object-fit: cover; }

.scanner-x {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.3rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

/* ─── Toast ─── */

.toast {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  margin: 0 auto;
  width: fit-content;
  max-width: 90%;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  z-index: 1050;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  text-align: center;
}

.toast.visible { opacity: 1; transform: translateY(0); }

/* ─── Login ─── */

.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--surface);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-screen.hidden { display: none; }

.login-box { text-align: center; }

.login-title {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.pin-input {
  width: 180px;
  text-align: center;
  font-size: 1.6rem;
  letter-spacing: 14px;
  padding: 14px 10px;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface-secondary);
  color: var(--text);
  outline: none;
  font-family: var(--font-display);
  transition: border-color 0.15s;
}

.pin-input:focus { border-color: var(--accent); }
.pin-input::placeholder { letter-spacing: 4px; color: var(--text-secondary); }

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 24px;
  max-width: 200px;
  margin-left: auto;
  margin-right: auto;
}

.pin-key {
  background: var(--surface-secondary);
  border: none;
  border-radius: 50%;
  width: 60px;
  height: 60px;
  font-size: 1.4rem;
  font-weight: 400;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: background 0.12s, transform 0.1s;
  font-family: var(--font-display);
}

.pin-key:active { transform: scale(0.92); background: var(--border); }

.pin-key.delete { font-size: 1rem; }

.pin-error {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 20px;
}

/* ─── Settings ─── */

.settings-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.settings-section h4 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
  font-family: var(--font-display);
}

.settings-desc {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.settings-loc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  font-size: 0.85rem;
}

.settings-loc-item .loc-name { color: var(--text); }

.settings-loc-item .loc-del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.12s;
}

.settings-loc-item .loc-del:hover { opacity: 1; }

.add-loc-btn {
  background: var(--surface-secondary);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--accent);
  width: 100%;
  text-align: center;
  margin-top: 6px;
  transition: background 0.12s;
}

.add-loc-btn:active { background: var(--border); }

.loc-group { margin-bottom: 12px; }

.settings-nested { margin-left: 16px; margin-top: 4px; }

.import-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 12px;
}

.import-zone:hover { border-color: var(--accent); background: var(--surface-secondary); }

.import-zone-icon { display: block; font-size: 1.5rem; margin-bottom: 4px; }

.import-preview {
  max-height: 200px;
  overflow: auto;
  font-size: 0.78rem;
  margin-bottom: 12px;
}

.import-preview table { width: 100%; border-collapse: collapse; }

.import-preview th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.import-preview td { padding: 6px 8px; border-bottom: 1px solid var(--border); }

/* ─── User Form (generated by JS) ─── */

.user-form { border-radius: var(--radius); }

/* ─── Responsive ─── */

@media (max-width: 480px) {
  .stat-card-mobile { min-width: 90px; }
  .product-row { flex-direction: column; gap: 4px; }
  .pin-key { width: 56px; height: 56px; }
}
