@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --primary:       #BC7C67;
  --primary-dark:  #A66A56;
  --primary-ghost: rgba(188,124,103,0.12);
  --primary-light: rgba(188,124,103,0.15);
  --success:       #1e8e3e;
  --success-light: #e6f4ea;
  --error:         #d93025;
  --error-light:   #fce8e6;
  --warning:       #f29900;
  --warning-light: #fef7e0;
  --surface:       #ffffff;
  --bg:            #121212;
  --nav-bg:        #1A1A1A;
  --border:        #E0D4CE;
  --text:          #2D2D2D;
  --text-muted:    #9E9E9E;
  --radius:        20px;
  --radius-sm:     12px;
  --radius-pill:   999px;
  --shadow:        0 2px 8px rgba(0,0,0,0.18);
  --shadow-md:     0 6px 20px rgba(0,0,0,0.22);
  --blocked:       #C0392B;
  --blocked-light: rgba(192,57,43,0.12);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}

/* ── Login ─────────────────────────────────────────────────── */
.login-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.login-screen.hidden { display: none; }
.login-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 36px 28px;
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 24px;
}
.login-card h1 { font-size: 22px; font-weight: 700; color: var(--primary); text-align: center; }
.login-error { font-size: 13px; color: var(--error); background: var(--error-light); padding: 10px 14px; border-radius: var(--radius-sm); }

/* ── App Shell ─────────────────────────────────────────────── */
.app {
  max-width: 600px; margin: 0 auto; min-height: 100vh;
  display: flex; flex-direction: column; padding-bottom: 72px;
}
.app.hidden { display: none; }

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  background: #fff; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 0 #f0e8e4, 0 2px 8px rgba(0,0,0,0.06);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
}
.header-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.btn-icon-header {
  background: transparent; border: none; color: var(--text-muted);
  padding: 8px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.btn-icon-header:hover { background: var(--primary-ghost); color: var(--primary); }

/* ── Bottom Nav ──────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 600px; margin: 0 auto;
  background: var(--nav-bg); border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 4px; padding: 12px 8px;
  background: transparent; color: #555; border: none;
  font-size: 11px; font-weight: 500; font-family: inherit; cursor: pointer; transition: color 0.15s;
}
.nav-btn svg { width: 22px; height: 22px; fill: currentColor; }
.nav-btn.active { color: var(--primary); font-weight: 700; }
.nav-btn:not(.active):hover { color: #aaa; }

/* ── Main & Tabs ─────────────────────────────────────────── */
.app-main { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.tab-panel { display: none; flex-direction: column; gap: 12px; }
.tab-panel.active { display: flex; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; }
.card h2 { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-sub { font-size: 13px; color: var(--text-muted); margin-top: -8px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 8px; padding: 12px 22px; border-radius: var(--radius-pill);
  font-size: 15px; font-weight: 600; font-family: inherit;
  cursor: pointer; border: none; transition: all 0.15s; white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:not(:disabled):hover { background: var(--primary-dark); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:not(:disabled):hover { background: var(--primary-ghost); }
.btn-danger { background: var(--error); color: white; }
.btn-danger:not(:disabled):hover { background: #b71c1c; }
.btn-danger-outline {
  background: transparent; color: var(--error); border: 1.5px solid var(--border);
  font-size: 13px; padding: 6px 14px; border-radius: var(--radius-pill);
}
.btn-ghost {
  background: transparent; border: 1.5px solid var(--border);
  color: var(--text); font-size: 13px; padding: 8px 14px; border-radius: var(--radius-pill);
}
.btn-ghost:hover { background: #f5f0ee; }
.btn-sm { font-size: 13px; padding: 7px 14px; }
.full-width { width: 100%; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.btn-icon-sm {
  background: transparent; border: none; color: var(--text-muted);
  padding: 4px 6px; border-radius: 8px; cursor: pointer; font-size: 13px; font-family: inherit;
  transition: background 0.15s;
}
.btn-icon-sm:hover { background: #f0ece9; }

/* ── Badge ──────────────────────────────────────────────── */
.badge {
  background: var(--primary-light); color: var(--primary);
  font-size: 12px; font-weight: 600; padding: 2px 10px;
  border-radius: 20px; border: 1px solid var(--border);
}
.badge-mono {
  background: #1e1e1e; color: #e0e0e0;
  font-family: 'SF Mono', 'Fira Code', monospace; font-size: 13px; font-weight: 600;
  padding: 4px 12px; border-radius: 8px; letter-spacing: 0.5px;
}
.badge-count {
  background: var(--primary); color: white;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
}

/* ── Loading ─────────────────────────────────────────────── */
.loading { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 40px; color: var(--text-muted); font-size: 14px; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Form ────────────────────────────────────────────────── */
.form-section { display: flex; flex-direction: column; gap: 10px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input, .form-group textarea, .form-group select {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 15px; color: var(--text);
  background: var(--surface); outline: none; transition: border-color 0.15s; font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group textarea { resize: vertical; min-height: 72px; }
.form-group select:disabled { opacity: 0.45; cursor: not-allowed; }
.form-group input.error, .form-group select.error { border-color: var(--error); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Toast ───────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: #1e1e1e; color: white; font-size: 14px; font-weight: 500;
  padding: 12px 20px; border-radius: var(--radius-pill);
  box-shadow: 0 4px 16px rgba(0,0,0,0.35); z-index: 2000;
  max-width: calc(100% - 32px); text-align: center;
  transition: opacity 0.3s; pointer-events: none;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--error); }
.toast.hidden  { opacity: 0; pointer-events: none; }

/* ── Modal / Sheet ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 500;
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.18s ease;
}
.modal-overlay.hidden { display: none; }
.modal-sheet {
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 600px; max-height: 92vh; overflow-y: auto;
  padding: 20px 16px 32px;
  animation: slideUp 0.22s cubic-bezier(0.22,1,0.36,1);
}
.modal-fullscreen {
  position: fixed; inset: 0; z-index: 600; background: var(--surface);
  overflow-y: auto; padding: 0;
  animation: slideUp 0.22s cubic-bezier(0.22,1,0.36,1);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 16px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
}
.modal-header h3 { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  background: transparent; border: none; color: var(--text-muted);
  font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 8px; line-height: 1;
  font-family: inherit;
}
.modal-close:hover { background: #f0ece9; color: var(--text); }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }

/* ── Section header ─────────────────────────────────────── */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid #f0ece9; margin-bottom: 4px;
}
.section-title { font-size: 13px; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: 0.5px; }

/* ── Divider ─────────────────────────────────────────────── */
.section-divider {
  display: flex; align-items: center; gap: 10px;
  color: var(--text-muted); font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.section-divider::before, .section-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Overview Tab ────────────────────────────────────────── */
.total-hero {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0;
}
.total-number {
  font-size: 56px; font-weight: 700; color: var(--primary); line-height: 1;
}
.total-label { font-size: 14px; color: var(--text-muted); }

.model-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 0; border-bottom: 1px solid #f5f0ee; cursor: pointer;
  transition: background 0.15s;
}
.model-row:last-child { border-bottom: none; }
.model-row-left { display: flex; align-items: center; gap: 10px; }
.model-name { font-size: 15px; font-weight: 600; color: var(--text); }
.model-chevron { color: var(--text-muted); font-size: 14px; transition: transform 0.2s; }
.model-chevron.open { transform: rotate(90deg); }
.color-breakdown { padding: 8px 0 4px 16px; display: flex; flex-direction: column; gap: 8px; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-swatch { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid rgba(0,0,0,0.1); flex-shrink: 0; }
.color-name-text { font-size: 14px; color: var(--text); flex: 1; }
.color-count { font-size: 14px; font-weight: 600; color: var(--text-muted); }

.history-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid #f5f0ee;
}
.history-item:last-child { border-bottom: none; }
.history-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); flex-shrink: 0; margin-top: 6px; }
.history-info { flex: 1; }
.history-id { font-size: 14px; font-weight: 600; color: var(--text); }
.history-meta { font-size: 12px; color: var(--text-muted); }
.history-action { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; background: var(--error-light); color: var(--error); text-transform: uppercase; }
.history-action.sold { background: var(--success-light); color: var(--success); }

/* ── Zone Tabs ───────────────────────────────────────────── */
.zone-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.zone-tab {
  padding: 8px 18px; border-radius: var(--radius-pill);
  border: 1.5px solid var(--border); background: transparent;
  color: var(--text-muted); font-size: 14px; font-weight: 600; font-family: inherit;
  cursor: pointer; transition: all 0.15s;
}
.zone-tab.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── Zone Grid (top-down view) ───────────────────────────── */
.zone-grid-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.zone-grid {
  display: grid; gap: 3px;
  grid-template-columns: 36px repeat(var(--cols), minmax(40px, 1fr));
  width: max-content; min-width: 100%;
}
.grid-corner { width: 36px; height: 36px; }
.grid-col-header {
  height: 36px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--surface);
  border-radius: 6px;
}
.grid-row-label {
  width: 36px; height: 48px; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--primary); cursor: pointer;
  background: var(--primary-ghost); border-radius: 8px; transition: background 0.15s;
}
.grid-row-label:hover { background: var(--primary-light); }
.grid-cell {
  height: 48px; border-radius: 8px; border: 1.5px dashed #ddd;
  display: flex; align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; transition: border-color 0.15s;
  background: #faf8f7;
}
.grid-cell:hover { border-color: var(--primary); background: var(--primary-ghost); }
.grid-cell.blocked { background: var(--blocked-light); border: 1.5px solid var(--blocked); cursor: default; }
.grid-cell.blocked:hover { background: rgba(192,57,43,0.18); }
.stack-dot {
  width: 10px; height: 10px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15); flex-shrink: 0;
}
.blocked-icon { font-size: 16px; }

/* ── Lateral Side View ──────────────────────────────────── */
.lateral-view {
  position: fixed; inset: 0; z-index: 550; background: var(--surface);
  display: flex; flex-direction: column; overflow: hidden;
}
.lateral-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.lateral-header h3 { font-size: 16px; font-weight: 700; flex: 1; }
.lateral-scroll { flex: 1; overflow-x: auto; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }
.lateral-columns { display: flex; gap: 10px; align-items: flex-end; padding-bottom: 12px; }
.lateral-col { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 80px; }
.lateral-col-label {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  background: #f5f0ee; padding: 2px 8px; border-radius: 6px; margin-bottom: 4px;
}
.lateral-stack { display: flex; flex-direction: column-reverse; align-items: stretch; width: 100%; gap: 3px; }
.fridge-block {
  border-radius: 8px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  padding: 6px 4px; cursor: pointer; transition: opacity 0.15s;
  border: 2px solid rgba(0,0,0,0.08); width: 100%;
}
.fridge-block:hover { opacity: 0.85; }
.fridge-block .fridge-id { font-size: 11px; font-weight: 700; text-align: center; }
.fridge-block .fridge-model { font-size: 10px; opacity: 0.8; text-align: center; }
.fridge-empty {
  border-radius: 8px; border: 2px dashed #ccc; background: #faf8f7;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted); font-size: 20px;
  transition: border-color 0.15s, background 0.15s;
}
.fridge-empty:hover { border-color: var(--primary); background: var(--primary-ghost); color: var(--primary); }
.fridge-blocked-col {
  position: absolute; inset: 0; background: var(--blocked-light);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.lateral-col-blocked { opacity: 0.6; pointer-events: none; }

/* ── Item Detail ─────────────────────────────────────────── */
.item-detail-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 16px;
}
.item-detail-swatch {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.12); flex-shrink: 0;
}
.item-detail-id { font-size: 20px; font-weight: 700; color: var(--text); }
.item-detail-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.detail-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.detail-value { font-size: 14px; color: var(--text); }

/* ── Add Item Tab ────────────────────────────────────────── */
.location-preview {
  text-align: center; padding: 10px 0 4px;
}
.location-preview .label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }

/* ── Settings Tab ────────────────────────────────────────── */
.settings-list { display: flex; flex-direction: column; gap: 0; }
.settings-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid #f5f0ee;
}
.settings-item:last-child { border-bottom: none; }
.settings-item-left { display: flex; align-items: center; gap: 10px; }
.settings-item-icon {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--primary-ghost); display: flex; align-items: center; justify-content: center;
}
.settings-item-name { font-size: 15px; font-weight: 600; color: var(--text); }
.settings-item-sub  { font-size: 12px; color: var(--text-muted); }
.settings-actions { display: flex; gap: 6px; }
.inline-form {
  background: #faf8f7; border-radius: var(--radius-sm); padding: 14px;
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px;
  margin-top: 4px;
}

/* ── Color picker ────────────────────────────────────────── */
.color-picker-group { display: flex; align-items: center; gap: 10px; }
.color-picker-group input[type="color"] { width: 44px; height: 36px; border: 1.5px solid var(--border); border-radius: 8px; cursor: pointer; padding: 2px; }
.color-picker-group input[type="text"] { flex: 1; }

/* ── Utilities ───────────────────────────────────────────── */
.hidden          { display: none !important; }
.text-muted      { color: var(--text-muted); font-size: 13px; }
.text-center     { text-align: center; }
.mt-4            { margin-top: 4px; }
.mt-8            { margin-top: 8px; }

/* ── Scrollbar (desktop) ─────────────────────────────────── */
@media (min-width: 600px) {
  ::-webkit-scrollbar { width: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
  .bottom-nav { left: 50%; transform: translateX(-50%); width: 600px; }
}
