/* ── Variables ─────────────────────────────────────────────────────────── */
:root {
  --bg:       #0D1117;
  --surface:  #161B22;
  --surface2: #1C2128;
  --border:   #30363D;
  --text:     #E6EDF3;
  --text2:    #8B949E;
  --accent:   #58A6FF;
  --green:    #3FB950;
  --amber:    #D29922;
  --red:      #F85149;
  --nav-h:    64px;
  --header-h: 56px;
  --radius:   12px;
  --radius-sm: 8px;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; background: var(--bg); }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; color: var(--text); -webkit-font-smoothing: antialiased; }
button { background: none; border: none; cursor: pointer; color: inherit; font: inherit; -webkit-tap-highlight-color: transparent; }
input, select, textarea { font: inherit; color: inherit; }
img { display: block; max-width: 100%; }

/* ── App shell ─────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100dvh; height: 100vh; }

/* ── Header ────────────────────────────────────────────────────────────── */
#app-header {
  display: flex; align-items: center; justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding-top: env(safe-area-inset-top);
}
#page-title { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.btn-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); transition: background 0.15s, color 0.15s;
}
.btn-icon:hover, .btn-icon:active { background: var(--surface2); color: var(--text); }
.btn-icon.hidden { visibility: hidden; pointer-events: none; }

/* ── View container ────────────────────────────────────────────────────── */
#view-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 16px;
}

/* ── Bottom nav ────────────────────────────────────────────────────────── */
#bottom-nav {
  display: flex; align-items: center; justify-content: space-around;
  height: var(--nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  flex: 1; height: 100%; padding: 8px 0;
  color: var(--text2); font-size: 11px; font-weight: 500;
  transition: color 0.15s;
}
.nav-item.active { color: var(--accent); }
.nav-item .nav-icon { opacity: 0.7; transition: opacity 0.15s; }
.nav-item.active .nav-icon { opacity: 1; }
.nav-add {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(88, 166, 255, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.nav-add:active { transform: scale(0.93); box-shadow: 0 2px 8px rgba(88, 166, 255, 0.3); }

/* ── Sheet overlay ─────────────────────────────────────────────────────── */
#sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  z-index: 100; backdrop-filter: blur(2px);
  transition: opacity 0.2s;
}
#sheet-overlay.hidden { display: none; }

#bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  z-index: 101;
  max-height: 92dvh; max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}
#bottom-sheet.hidden { display: none; }

/* ── Sheet content ─────────────────────────────────────────────────────── */
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 20px 12px;
  position: sticky; top: 0; background: var(--surface); z-index: 1;
  border-bottom: 1px solid var(--border);
}
.sheet-header h3 { font-size: 17px; font-weight: 700; }
.sheet-drag { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 12px auto 0; }

/* ── Type selector ─────────────────────────────────────────────────────── */
.type-select-row {
  display: flex; gap: 8px; padding: 16px 16px 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.type-select-row::-webkit-scrollbar { display: none; }
.type-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  color: var(--text2); font-size: 12px; font-weight: 600;
  white-space: nowrap; flex-shrink: 0;
  transition: all 0.15s;
}
.type-btn .type-emoji { font-size: 20px; }
.type-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.08); }

/* ── Form ──────────────────────────────────────────────────────────────── */
.form-body { padding: 8px 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { font-size: 13px; font-weight: 600; color: var(--text2); }
.form-input {
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 12px;
  color: var(--text); font-size: 15px;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus { outline: none; border-color: var(--accent); }
textarea.form-input { min-height: 80px; resize: vertical; }
select.form-input { appearance: none; -webkit-appearance: none; }

/* Chip selector */
.chip-select { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 7px 12px; border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 13px; font-weight: 500; color: var(--text2);
  transition: all 0.15s;
}
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.1); }

/* Toggle group */
.toggle-group { display: flex; gap: 0; border-radius: var(--radius-sm); overflow: hidden; border: 1.5px solid var(--border); }
.toggle-btn {
  flex: 1; padding: 10px; font-size: 14px; font-weight: 500;
  color: var(--text2); border-right: 1px solid var(--border);
  transition: all 0.15s;
}
.toggle-btn:last-child { border-right: none; }
.toggle-btn.active { background: rgba(88,166,255,0.15); color: var(--accent); }

/* Photo upload */
.photo-upload {
  border: 2px dashed var(--border); border-radius: var(--radius);
  min-height: 120px; display: flex; align-items: center; justify-content: center;
  overflow: hidden; transition: border-color 0.15s;
}
.photo-upload:hover { border-color: var(--accent); }
.photo-btn {
  padding: 20px; color: var(--text2); font-size: 15px;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 100%; height: 100%;
}
.photo-preview { width: 100%; max-height: 200px; object-fit: cover; cursor: pointer; }
.hidden { display: none !important; }

/* Save button */
.btn-save {
  background: var(--accent); color: #fff; border-radius: var(--radius);
  padding: 15px; font-size: 16px; font-weight: 700;
  width: 100%; margin-top: 8px;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-save:active { opacity: 0.85; transform: scale(0.98); }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
.view-dashboard { padding: 20px 16px; }
.dashboard-hero {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px;
}
.hero-logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--accent); color: #fff;
  font-size: 24px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.hero-text h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.5px; }
.hero-text p { color: var(--text2); font-size: 14px; margin-top: 2px; }

.alert-banner {
  display: flex; align-items: center; gap: 10px;
  background: rgba(210, 153, 34, 0.12); border: 1.5px solid rgba(210,153,34,0.3);
  border-radius: var(--radius-sm); padding: 12px 14px;
  margin-bottom: 20px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--amber);
}
.alert-arrow { margin-left: auto; }

.stats-row { display: flex; gap: 10px; margin-bottom: 24px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.stats-row::-webkit-scrollbar { display: none; }
.stat-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px;
  cursor: pointer; flex-shrink: 0;
  transition: border-color 0.15s;
}
.stat-card:hover, .stat-card:active { border-color: var(--accent); }
.stat-icon { font-size: 22px; }
.stat-count { font-size: 22px; font-weight: 800; }
.stat-label { font-size: 11px; color: var(--text2); font-weight: 600; }
.stat-empty { border-style: dashed; color: var(--text2); }

.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.section-header h3 { font-size: 15px; font-weight: 700; }
.btn-link { color: var(--accent); font-size: 14px; font-weight: 500; }

/* ── Items grid ────────────────────────────────────────────────────────── */
.items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}

.item-card {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.item-card:active { transform: scale(0.97); }
.item-card.status-low { border-color: rgba(210,153,34,0.4); }
.item-card.status-empty { border-color: rgba(248,81,73,0.4); }

.card-photo {
  width: 100%; aspect-ratio: 1; background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
}
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.card-no-photo { }
.card-type-icon { font-size: 36px; }
.card-status-badge {
  position: absolute; top: 6px; right: 6px;
  padding: 3px 7px; border-radius: 20px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
}
.badge-low { background: rgba(210,153,34,0.85); color: #fff; }
.badge-empty { background: rgba(248,81,73,0.85); color: #fff; }

.card-body { padding: 10px 10px 8px; }
.card-name { font-size: 13px; font-weight: 600; line-height: 1.3; margin-bottom: 4px; }
.card-meta { margin-bottom: 8px; }
.card-location { font-size: 11px; color: var(--text2); }

/* ── Spool bar ─────────────────────────────────────────────────────────── */
.spool-bar-wrap { display: flex; align-items: center; gap: 6px; }
.spool-bar {
  flex: 1; height: 5px; background: var(--surface2); border-radius: 3px; overflow: hidden;
}
.spool-bar.big { height: 8px; border-radius: 4px; }
.spool-fill {
  height: 100%; border-radius: inherit;
  transition: width 0.3s ease;
}
.status-fill-ok { background: var(--green); }
.status-fill-low { background: var(--amber); }
.status-fill-empty { background: var(--red); }
.spool-qty { font-size: 11px; color: var(--text2); white-space: nowrap; }

/* ── Inventory view ────────────────────────────────────────────────────── */
.view-inventory { padding: 12px 16px; }
.search-bar { margin-bottom: 12px; }
.search-input {
  width: 100%; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px;
  color: var(--text); font-size: 15px;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.type-filters {
  display: flex; gap: 8px; margin-bottom: 16px;
  overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px;
  scrollbar-width: none;
}
.type-filters::-webkit-scrollbar { display: none; }
.filter-btn {
  padding: 7px 14px; border-radius: 20px;
  border: 1.5px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--text2);
  white-space: nowrap; flex-shrink: 0;
  transition: all 0.15s;
}
.filter-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.1); }

/* ── Item detail ───────────────────────────────────────────────────────── */
.view-detail { }
.detail-photo {
  width: 100%; aspect-ratio: 16/9; max-height: 240px;
  background: var(--surface2); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.detail-photo img { width: 100%; height: 100%; object-fit: cover; }
.detail-no-photo { }
.detail-type-icon { font-size: 64px; }
.detail-body { padding: 20px 16px; display: flex; flex-direction: column; gap: 16px; }
.detail-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.detail-header h2 { font-size: 22px; font-weight: 800; letter-spacing: -0.4px; line-height: 1.2; }
.detail-type-badge {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 10px;
  font-size: 11px; font-weight: 700; color: var(--text2);
  white-space: nowrap; flex-shrink: 0; margin-top: 4px;
}
.detail-location { color: var(--text2); font-size: 14px; }

.quantity-section { display: flex; flex-direction: column; gap: 10px; }
.quantity-display { display: flex; align-items: baseline; gap: 4px; }
.qty-number { font-size: 40px; font-weight: 900; letter-spacing: -1px; }
.status-ok .qty-number { color: var(--green); }
.status-low .qty-number { color: var(--amber); }
.status-empty .qty-number { color: var(--red); }
.qty-unit { font-size: 18px; font-weight: 600; color: var(--text2); }
.qty-full { font-size: 16px; color: var(--text2); margin-left: 2px; }
.low-stock-warning { font-size: 13px; color: var(--amber); font-weight: 600; }

.use-controls {
  display: flex; gap: 10px;
  background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.use-input {
  flex: 1; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 12px;
  font-size: 16px; color: var(--text);
}
.use-input:focus { outline: none; border-color: var(--accent); }
.btn-use {
  background: var(--accent); color: #fff;
  border-radius: var(--radius-sm); padding: 10px 18px;
  font-size: 15px; font-weight: 700;
  transition: opacity 0.15s;
}
.btn-use:active { opacity: 0.8; }

.detail-fields {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.detail-field {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.detail-field:last-child { border-bottom: none; }
.field-label { font-size: 13px; color: var(--text2); font-weight: 500; }
.field-value { font-size: 14px; font-weight: 600; text-align: right; }

.detail-supplier, .detail-notes {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.detail-notes { flex-direction: column; gap: 6px; }
.detail-notes .field-value { text-align: left; font-weight: 400; color: var(--text2); }

.usage-log { display: flex; flex-direction: column; gap: 0; }
.usage-log h4 { font-size: 13px; font-weight: 700; color: var(--text2); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.log-entry {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.log-entry:last-child { border-bottom: none; }
.log-date { color: var(--text2); flex: 1; }
.log-amount { font-weight: 700; color: var(--red); }
.log-note { color: var(--text2); font-size: 12px; }

.detail-actions { display: flex; gap: 10px; padding-top: 8px; }
.btn-secondary {
  flex: 1; padding: 13px; border-radius: var(--radius);
  border: 1.5px solid var(--border); font-size: 15px; font-weight: 600;
  color: var(--text2); transition: all 0.15s;
}
.btn-secondary:hover, .btn-secondary:active { border-color: var(--text); color: var(--text); }
.btn-danger {
  flex: 1; padding: 13px; border-radius: var(--radius);
  background: rgba(248,81,73,0.1); border: 1.5px solid rgba(248,81,73,0.3);
  color: var(--red); font-size: 15px; font-weight: 600;
  transition: all 0.15s;
}
.btn-danger:hover, .btn-danger:active { background: rgba(248,81,73,0.2); }

/* ── Reorder view ──────────────────────────────────────────────────────── */
.view-reorder { padding: 20px 16px; }
.view-heading { font-size: 22px; font-weight: 800; margin-bottom: 20px; letter-spacing: -0.4px; }
.reorder-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.reorder-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 12px;
}
.reorder-thumb {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  object-fit: cover; flex-shrink: 0;
  background: var(--surface2); display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.reorder-no-photo { }
.reorder-info { flex: 1; min-width: 0; }
.reorder-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reorder-status {
  display: inline-block; margin-top: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700;
}
.badge-low { background: rgba(210,153,34,0.2); color: var(--amber); }
.badge-empty { background: rgba(248,81,73,0.2); color: var(--red); }
.reorder-supplier { font-size: 12px; color: var(--text2); margin-top: 4px; }
.reorder-done {
  width: 40px; height: 40px; border-radius: 50%;
  background: rgba(63,185,80,0.15); border: 1.5px solid rgba(63,185,80,0.3);
  color: var(--green); font-size: 18px; flex-shrink: 0;
  transition: all 0.15s;
}
.reorder-done:active { background: rgba(63,185,80,0.3); }
.share-btn { width: 100%; }

/* ── Settings view ─────────────────────────────────────────────────────── */
.view-settings { padding: 20px 16px; display: flex; flex-direction: column; gap: 24px; }
.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section h3 { font-size: 13px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.location-list { display: flex; flex-direction: column; gap: 6px; }
.location-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  font-size: 15px;
}
.btn-icon-sm {
  width: 28px; height: 28px; border-radius: 6px;
  color: var(--text2); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon-sm:hover { background: var(--surface2); color: var(--red); }
.add-location { display: flex; gap: 8px; }
.input-sm {
  flex: 1; background: var(--surface2); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 14px; color: var(--text);
}
.input-sm:focus { outline: none; border-color: var(--accent); }
.btn-sm {
  background: var(--accent); color: #fff;
  border-radius: var(--radius-sm); padding: 9px 16px;
  font-size: 14px; font-weight: 700;
}
.settings-about { color: var(--text2); font-size: 13px; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 60px 20px; text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 4px; }
.empty-state h3 { font-size: 18px; font-weight: 700; }
.empty-state p { color: var(--text2); font-size: 14px; }
.btn-primary {
  margin-top: 12px; background: var(--accent); color: #fff;
  border-radius: var(--radius); padding: 13px 28px;
  font-size: 15px; font-weight: 700;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.85; }
