/* ==========================================================================
   Darumi Design System — Mobile-first
   ========================================================================== */

/* ---------- Fonts ---------- */
@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=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- Variables ---------- */
:root {
  --bg: #0F1117;
  --bg-card: #181B24;
  --bg-card-hover: #1E2230;
  --bg-input: #232733;
  --border: #2A2E3B;
  --border-focus: #5B8DEF;
  --text: #E8EAED;
  --text-dim: #8B8FA3;
  --text-muted: #5A5E6E;
  --accent: #5B8DEF;
  --accent-glow: rgba(91,141,239,0.15);
  --green: #3DD68C;
  --green-dim: rgba(61,214,140,0.12);
  --orange: #F5A623;
  --orange-dim: rgba(245,166,35,0.12);
  --red: #EF5B5B;
  --red-dim: rgba(239,91,91,0.12);
  --purple: #A78BFA;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --bottom-nav: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 0.7rem 1.6rem;
  font-size: 0.95rem;
}
.btn-primary:hover { background: #4A7CE0; text-decoration: none; }

.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 0.7rem 1.6rem;
  font-size: 0.95rem;
}
.btn-outline:hover { border-color: var(--text-dim); color: var(--text); text-decoration: none; }

.btn-sm {
  padding: 0.45rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
}
.btn-sm:hover { border-color: var(--accent); color: var(--text); }
.btn-sm.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-sm.primary:hover { background: #4A7CE0; }
.btn-sm.danger { border-color: var(--red); color: var(--red); }
.btn-sm.danger:hover { background: var(--red-dim); }

.btn-block { width: 100%; }
.btn-icon { padding: 0.45rem; min-width: 36px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.35rem;
  font-weight: 500;
}
.form-group label .optional { color: var(--text-muted); font-weight: 400; }

.form-input,
.form-select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}
.form-input:focus,
.form-select:focus { border-color: var(--border-focus); }
.form-input::placeholder { color: var(--text-muted); }
.form-input.mono { font-family: var(--mono); font-size: 0.88rem; }

.form-row { display: flex; gap: 0.6rem; }
.form-row > .form-group { flex: 1; }

.form-error {
  color: var(--red);
  font-size: 0.78rem;
  margin-top: 0.3rem;
}
.form-hint {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 0.3rem;
}

/* Toggle group (Count / Length / Present) */
.toggle-group {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.toggle-group button {
  flex: 1;
  padding: 0.5rem;
  background: var(--bg-input);
  border: none;
  border-left: 1px solid var(--border);
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-group button:first-child { border-left: none; }
.toggle-group button.active { background: var(--accent); color: #fff; }

/* ---------- Badges ---------- */
.qty-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--mono);
}
.qty-badge.ok { background: var(--green-dim); color: var(--green); }
.qty-badge.low { background: var(--orange-dim); color: var(--orange); }
.qty-badge.out { background: var(--red-dim); color: var(--red); }

.type-pill, .tag-pill {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 20px;
  font-size: 0.72rem;
  background: var(--bg-input);
  color: var(--text-dim);
  border: 1px solid var(--border);
  margin-right: 0.25rem;
  margin-bottom: 0.15rem;
}
.item-tags { margin-top: 0.2rem; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
}
.card-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 0.8rem;
}
.card-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.8rem;
}

/* ---------- Container cards (list items) ---------- */
.container-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.container-card:active { background: var(--bg-card-hover); transform: scale(0.98); }
.container-card:hover { text-decoration: none; color: var(--text); }
.container-card .card-icon { font-size: 1.6rem; flex-shrink: 0; }
.container-card .card-body { flex: 1; min-width: 0; }
.container-card .card-title { font-size: 0.92rem; font-weight: 600; }
.container-card .card-meta { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.1rem; }
.container-card .card-counts { display: flex; gap: 0.8rem; margin-top: 0.3rem; font-size: 0.72rem; color: var(--text-muted); }
.container-card .card-counts strong { color: var(--text-dim); }
.container-card .card-chevron { color: var(--text-muted); font-size: 0.9rem; flex-shrink: 0; }

.container-grid { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.2rem; }

/* ---------- Item rows ---------- */
.item-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.15s;
  text-decoration: none;
  color: var(--text);
}
.item-row:active { background: var(--bg-card-hover); transform: scale(0.98); }
.item-row:hover { text-decoration: none; color: var(--text); }
.item-row .item-info { flex: 1; min-width: 0; }
.item-row .item-name { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-row .item-brand { font-size: 0.7rem; color: var(--text-muted); }
.item-row .item-type { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.item-row .item-qty { text-align: right; flex-shrink: 0; }
.item-row .item-chevron { color: var(--text-muted); font-size: 0.8rem; flex-shrink: 0; margin-left: 0.3rem; }
.item-list { display: flex; flex-direction: column; gap: 0.5rem; }

/* ---------- Detail rows ---------- */
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text-muted); font-size: 0.8rem; }
.detail-row .value { font-size: 0.85rem; font-weight: 500; text-align: right; }

/* ---------- Stats ---------- */
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-bottom: 1.2rem; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.9rem; }
.stat-card .stat-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 0.2rem; }
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; }
.stat-card .stat-sub { font-size: 0.7rem; color: var(--text-dim); margin-top: 0.1rem; }
.stat-card .stat-value.green { color: var(--green); }
.stat-card .stat-value.orange { color: var(--orange); }
.stat-card .stat-value.red { color: var(--red); }

/* ---------- Breadcrumb ---------- */
.breadcrumb { display: flex; align-items: center; gap: 0.3rem; margin-bottom: 1rem; font-size: 0.8rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:active { color: var(--accent); }
.breadcrumb .sep { color: var(--text-muted); }
.breadcrumb .current { color: var(--text); font-weight: 500; }

/* ---------- Page header ---------- */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.2rem; gap: 0.5rem; flex-wrap: wrap; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.5px; }
.page-header .actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* Section label */
.section-label {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* ---------- Audit log ---------- */
.log-entry { display: flex; gap: 0.6rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.log-entry:last-child { border-bottom: none; }
.log-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 0.35rem; flex-shrink: 0; }
.log-dot.add { background: var(--green); }
.log-dot.remove { background: var(--red); }
.log-dot.adjust { background: var(--orange); }
.log-dot.move { background: var(--purple); }
.log-dot.create { background: var(--accent); }
.log-text { font-size: 0.8rem; color: var(--text-dim); line-height: 1.35; }
.log-text strong { color: var(--text); font-weight: 500; }
.log-time { font-size: 0.68rem; color: var(--text-muted); margin-top: 0.1rem; }

/* ---------- QR ---------- */
.qr-wrap { text-align: center; padding: 0.5rem 0; }
.qr-img { background: white; border-radius: var(--radius); padding: 0.8rem; display: inline-block; }
.qr-img img { width: 140px; height: 140px; }

/* ---------- Quantity adjuster ---------- */
.adjust-controls { display: flex; align-items: center; gap: 0.6rem; justify-content: center; padding: 0.5rem 0; }
.adjust-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--bg-input);
  color: var(--text); font-size: 1.4rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.adjust-btn:active { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(0.9); }
.adjust-value { font-size: 2rem; font-weight: 700; font-family: var(--mono); min-width: 80px; text-align: center; }

/* ---------- Reorder link ---------- */
.reorder-link {
  display: flex; align-items: center; gap: 0.6rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.7rem 0.9rem;
  text-decoration: none; color: var(--text); transition: border-color 0.15s;
}
.reorder-link:hover { border-color: var(--accent); text-decoration: none; }
.reorder-link .reorder-icon { font-size: 1.2rem; }
.reorder-link .reorder-body { flex: 1; min-width: 0; }
.reorder-link .reorder-title { font-size: 0.88rem; font-weight: 500; }
.reorder-link .reorder-domain { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reorder-link .reorder-arrow { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Scan ---------- */
.scan-tabs {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.2rem;
}
.scan-tab {
  flex: 1; padding: 0.65rem; text-align: center;
  font-size: 0.82rem; font-weight: 500;
  cursor: pointer; color: var(--text-dim);
  transition: all 0.15s; border: none;
  background: none; font-family: var(--font);
}
.scan-tab.active { background: var(--accent); color: #fff; }

.scan-viewfinder {
  width: 100%; max-width: 320px; aspect-ratio: 1;
  border-radius: var(--radius); background: var(--bg-card);
  border: 2px dashed var(--border);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.8rem;
  margin: 0 auto 1rem; position: relative; overflow: hidden;
}
.scan-viewfinder .corners { position: absolute; inset: 10px; }
.scan-viewfinder .corners::before, .scan-viewfinder .corners::after {
  content: ''; position: absolute; width: 28px; height: 28px; border-color: var(--accent); border-style: solid;
}
.scan-viewfinder .corners::before { top: 0; left: 0; border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.scan-viewfinder .corners::after { top: 0; right: 0; border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.scan-viewfinder .corners-bottom { position: absolute; inset: 10px; pointer-events: none; }
.scan-viewfinder .corners-bottom::before, .scan-viewfinder .corners-bottom::after {
  content: ''; position: absolute; width: 28px; height: 28px; border-color: var(--accent); border-style: solid;
}
.scan-viewfinder .corners-bottom::before { bottom: 0; left: 0; border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.scan-viewfinder .corners-bottom::after { bottom: 0; right: 0; border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }
.scan-line {
  position: absolute; left: 10px; right: 10px; height: 2px;
  background: var(--accent); box-shadow: 0 0 12px var(--accent);
  animation: scanMove 2.5s ease-in-out infinite;
}
@keyframes scanMove { 0%,100% { top: 15%; } 50% { top: 82%; } }
.scan-icon { font-size: 2rem; color: var(--text-muted); z-index: 1; }
.scan-hint { color: var(--text-dim); font-size: 0.82rem; z-index: 1; text-align: center; padding: 0 1rem; }

.scan-result {
  background: var(--bg-card); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 1rem; margin-top: 1rem;
  max-width: 320px; margin-left: auto; margin-right: auto;
  display: none;
}
.scan-result.show { display: block; animation: fadeIn 0.2s ease; }

/* ---------- Callout ---------- */
.callout {
  background: var(--accent-glow);
  border: 1px solid rgba(91,141,239,0.2);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.4;
  margin-bottom: 1rem;
}
.callout strong { color: var(--accent); }

/* ---------- App Shell: Top bar (mobile) ---------- */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky; top: 0; z-index: 50;
}
.top-bar .logo { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.5px; }
.top-bar .logo span { color: var(--accent); }
.top-bar-back { cursor: pointer; font-size: 1.2rem; color: var(--text-dim); padding: 0.2rem; }
.top-bar-title { font-weight: 600; font-size: 0.9rem; }
.top-bar-right { display: flex; align-items: center; gap: 0.8rem; }

.org-pill {
  display: flex; align-items: center; gap: 0.4rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 20px; padding: 0.3rem 0.7rem 0.3rem 0.3rem; cursor: pointer;
}
.org-dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 0.6rem; font-weight: 700; color: #fff;
}
.org-pill .org-label { font-size: 0.78rem; font-weight: 500; }

.avatar-sm {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg-input); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 600; color: var(--accent); cursor: pointer;
}

/* ---------- App Shell: Bottom nav (mobile) ---------- */
.bottom-nav {
  display: flex; justify-content: space-around; align-items: center;
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding: 0.4rem 0 calc(0.4rem + var(--safe-bottom));
  position: sticky; bottom: 0; z-index: 50;
}
.bnav-item {
  display: flex; flex-direction: column; align-items: center; gap: 0.15rem;
  padding: 0.4rem 0.8rem; cursor: pointer; color: var(--text-muted);
  transition: color 0.15s; min-width: 56px;
  text-decoration: none;
}
.bnav-item.active { color: var(--accent); }
.bnav-item:active { transform: scale(0.92); }
.bnav-item:hover { text-decoration: none; }
.bnav-item .nav-icon { font-size: 1.3rem; line-height: 1; }
.bnav-item .nav-label { font-size: 0.62rem; font-weight: 500; letter-spacing: 0.3px; }
.bnav-item.scan-btn { margin-top: -18px; }
.bnav-item.scan-btn .nav-icon {
  width: 48px; height: 48px; background: var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; color: #fff; box-shadow: 0 4px 16px rgba(91,141,239,0.35);
}

.app-content { flex: 1; overflow-y: auto; padding: 1rem; -webkit-overflow-scrolling: touch; }

/* ---------- App Shell: Sidebar (desktop) ---------- */
.sidebar { display: none; }

/* ---------- Modal (bottom sheet on mobile) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  z-index: 200; display: none; align-items: flex-end; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem 1.2rem calc(1.5rem + var(--safe-bottom));
  width: 100%; max-width: 500px; max-height: 85vh; overflow-y: auto;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 1.2rem; }
.modal h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }
.modal .form-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.modal .form-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(var(--bottom-nav) + 16px + var(--safe-bottom));
  left: 50%; transform: translateX(-50%) translateY(100px);
  background: var(--bg-card); border: 1px solid var(--green);
  border-radius: var(--radius); padding: 0.7rem 1.2rem;
  font-size: 0.85rem; color: var(--green); box-shadow: var(--shadow);
  z-index: 300; opacity: 0; transition: all 0.3s ease; white-space: nowrap;
}
.toast.error { border-color: var(--red); color: var(--red); }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---------- Org tree ---------- */
.org-tree { display: flex; flex-direction: column; align-items: center; gap: 1.2rem; padding: 1rem 0; }
.org-node { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem 1.2rem; text-align: center; min-width: 140px; }
.org-node.admin { border-color: var(--accent); }
.org-node .node-name { font-weight: 600; font-size: 0.88rem; }
.org-node .node-role { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.org-connector { width: 1px; height: 1rem; background: var(--border); }
.org-level { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }

/* ---------- Type list ---------- */
.type-row {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.9rem 1rem;
  display: flex; align-items: center; justify-content: space-between;
}
.type-row .type-name { font-weight: 600; font-size: 0.9rem; }
.type-row .type-meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 0.1rem; }
.type-row .type-method { font-size: 0.72rem; }
.type-row .type-alert { font-size: 0.72rem; color: var(--orange); margin-top: 0.1rem; }
.type-list { display: flex; flex-direction: column; gap: 0.5rem; }

/* ---------- AI cleanup indicator ---------- */
.ai-indicator { margin-bottom: 0.8rem; }
.ai-indicator .ai-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 0.3rem; }
.ai-indicator .ai-original { font-size: 0.72rem; color: var(--text-muted); text-decoration: line-through; }
.ai-indicator .ai-arrow { font-size: 0.72rem; color: var(--green); margin-top: 0.15rem; }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-dim);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 0.8rem; }
.empty-state p { font-size: 0.9rem; margin-bottom: 1rem; }

/* ---------- Loading ---------- */
.spinner {
  width: 24px; height: 24px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.6s linear infinite; margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Utilities ---------- */
.text-dim { color: var(--text-dim); }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.text-mono { font-family: var(--mono); }
.text-sm { font-size: 0.82rem; }
.text-xs { font-size: 0.72rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* ==========================================================================
   Desktop (768px+)
   ========================================================================== */
@media (min-width: 768px) {
  .top-bar { display: none; }
  .bottom-nav { display: none; }

  .sidebar {
    display: flex; flex-direction: column;
    width: 240px; background: var(--bg-card);
    border-right: 1px solid var(--border);
    flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  }
  .sidebar .logo { padding: 1.2rem; font-size: 1.2rem; font-weight: 700; letter-spacing: -0.5px; }
  .sidebar .logo span { color: var(--accent); }

  .sidebar .org-switcher {
    margin: 0 0.8rem 1.2rem; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0.55rem 0.8rem; display: flex; align-items: center; gap: 0.5rem; cursor: pointer;
  }
  .sidebar .org-switcher:hover { border-color: var(--accent); }
  .sidebar .org-switcher .org-avatar {
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex; align-items: center; justify-content: center;
    font-size: 0.7rem; font-weight: 700; color: #fff; flex-shrink: 0;
  }
  .sidebar .org-switcher .org-name { font-size: 0.85rem; font-weight: 500; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .org-switcher .org-chevron { color: var(--text-muted); font-size: 0.7rem; }

  .sidebar .nav-section { margin-bottom: 1.2rem; }
  .sidebar .nav-section-title { font-size: 0.62rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-muted); padding: 0 1.2rem; margin-bottom: 0.3rem; }
  .sidebar .nav-item {
    display: flex; align-items: center; gap: 0.7rem;
    padding: 0.5rem 1.2rem; cursor: pointer; color: var(--text-dim);
    font-size: 0.88rem; transition: all 0.15s;
    border-left: 2px solid transparent; text-decoration: none;
  }
  .sidebar .nav-item:hover { background: var(--bg-card-hover); color: var(--text); text-decoration: none; }
  .sidebar .nav-item.active { color: var(--accent); border-left-color: var(--accent); background: var(--accent-glow); }
  .sidebar .nav-item .icon { font-size: 1rem; width: 20px; text-align: center; }

  .sidebar-footer { margin-top: auto; padding: 0.8rem 1.2rem; border-top: 1px solid var(--border); }
  .sidebar-footer .user-info { display: flex; align-items: center; gap: 0.6rem; }
  .sidebar-footer .user-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: var(--bg-input); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem; font-weight: 600; color: var(--accent);
  }
  .sidebar-footer .user-name { font-size: 0.85rem; font-weight: 500; }
  .sidebar-footer .user-role { font-size: 0.68rem; color: var(--text-muted); }

  .app-content { padding: 1.6rem 2rem; }
  .page-header h1 { font-size: 1.6rem; }
  .stats-row { grid-template-columns: repeat(4, 1fr); }
  .container-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  .container-card { flex-direction: column; align-items: start; gap: 0; padding: 1.2rem; }
  .container-card .card-icon { font-size: 1.8rem; margin-bottom: 0.6rem; }
  .container-card .card-chevron { display: none; }

  .modal { border-radius: var(--radius); max-width: 440px; }
  .modal-overlay { align-items: center; }
  .toast { bottom: 2rem; }
}

/* ==========================================================================
   Darumi UI V2 Additions
   ========================================================================== */

/* ---------- Item/Container Toggle (Add page) ---------- */
.add-type-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.2rem;
}
.add-type-btn {
  flex: 1; padding: 0.7rem; text-align: center;
  font-size: 0.88rem; font-weight: 600;
  cursor: pointer; color: var(--text-dim);
  transition: all 0.15s; border: none;
  background: none; font-family: var(--font);
}
.add-type-btn.active { background: var(--accent); color: #fff; }

/* ---------- Scan Trigger Button ---------- */
.scan-trigger {
  display: flex; align-items: center; gap: 1rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.2rem;
  cursor: pointer; transition: all 0.15s;
  margin-bottom: 0.8rem;
  -webkit-tap-highlight-color: transparent;
}
.scan-trigger:hover { border-color: var(--accent); }
.scan-trigger:active { background: var(--bg-card-hover); transform: scale(0.98); }

.scan-trigger-icon {
  width: 48px; height: 48px;
  background: var(--accent-glow); border: 1px solid rgba(91,141,239,0.25);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); flex-shrink: 0;
}
.scan-trigger-text { flex: 1; }
.scan-trigger-title { font-weight: 600; font-size: 0.95rem; }
.scan-trigger-sub { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.1rem; }
.scan-trigger-arrow { color: var(--text-muted); font-size: 1.4rem; font-weight: 300; flex-shrink: 0; }

/* ---------- Camera Panel ---------- */
.camera-panel { margin-bottom: 1rem; animation: fadeIn 0.2s ease; }

/* ---------- URL Import Row ---------- */
.url-import-row { margin-bottom: 1rem; }

/* ---------- Add Form Section ---------- */
.add-form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  margin-bottom: 1rem;
}

/* ---------- New Type Inline ---------- */
.new-type-inline {
  padding: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  animation: fadeIn 0.15s ease;
}

/* ---------- Direct Quantity Input (item detail page) ---------- */
.qty-direct-input {
  text-align: center !important;
  font-size: 1.5rem !important;
  font-weight: 700 !important;
  padding: 0.4rem 0.5rem !important;
  max-width: 140px;
  flex: none !important;
}

/* ---------- Fuzzy Match Suggestions ---------- */
.fuzzy-matches {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.8rem;
  overflow: hidden;
  animation: fadeIn 0.15s ease;
}
.fuzzy-label {
  font-size: 0.7rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.8px;
  padding: 0.6rem 0.9rem 0.3rem; font-weight: 500;
}
.fuzzy-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.9rem; cursor: pointer;
  transition: background 0.1s; border-top: 1px solid var(--border);
}
.fuzzy-item:hover { background: var(--bg-card-hover); }
.fuzzy-item:active { background: var(--bg-input); }
.fuzzy-item-info { flex: 1; min-width: 0; }
.fuzzy-item-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fuzzy-item-meta { font-size: 0.7rem; color: var(--text-muted); }

/* ---------- Drag & Drop Reorder ---------- */
.item-row.reorderable {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
.item-row.reorderable:active { cursor: grabbing; }

.item-row.dragging {
  opacity: 0.4;
  border-style: dashed;
}

.item-row.drag-over {
  border-color: var(--accent);
  background: var(--accent-glow);
}

.drag-handle {
  color: var(--text-muted);
  font-size: 1rem;
  padding: 0 0.3rem;
  flex-shrink: 0;
  cursor: grab;
}
.drag-handle:active { cursor: grabbing; }

/* Accent text color utility */
.text-accent { color: var(--accent); }
.text-accent a { color: var(--accent); text-decoration: underline; }

/* ==========================================================================
   Home (Consumer) Theme  — [data-app="home"]
   Overrides CSS variables. All components inherit automatically.
   Forest green primary · Terracotta accent · Warm light backgrounds
   ========================================================================== */

[data-app="home"] {
  --bg: #F5F8F4;
  --bg-card: #FFFFFF;
  --bg-card-hover: #EDF3EC;
  --bg-input: #EDF3EC;
  --border: #D6E4D4;
  --border-focus: #2D6A3F;
  --text: #1A2618;
  --text-dim: #5C7258;
  --text-muted: #9DB09A;
  --accent: #2D6A3F;
  --accent-glow: rgba(45, 106, 63, 0.12);
  --green: #2D6A3F;
  --green-dim: rgba(45, 106, 63, 0.10);
  --orange: #C4693A;
  --orange-dim: rgba(196, 105, 58, 0.12);
  --red: #B85450;
  --red-dim: rgba(184, 84, 80, 0.12);
  --purple: #7A6E9E;
  --shadow: 0 2px 12px rgba(26, 38, 24, 0.08);

  /* Home-only extras */
  --home-bg-warm: #EDF3EC;
  --home-bg-warm2: #DFE9DD;
  --home-terracotta: #C4693A;
  --home-terracotta-light: #F5DDD0;
  --home-terracotta-glow: rgba(196, 105, 58, 0.11);
  --home-forest: #2D6A3F;
  --home-forest-dark: #1A2E1C;
  --radius: 12px;
}

/* Bottom nav tint */
[data-app="home"] .bottom-nav {
  background: rgba(245, 248, 244, 0.95);
  border-top-color: var(--border);
}

/* Primary button uses forest green */
[data-app="home"] .btn-primary,
[data-app="home"] .btn-sm.primary {
  background: var(--home-forest);
  border-color: var(--home-forest);
}
[data-app="home"] .btn-primary:hover,
[data-app="home"] .btn-sm.primary:hover {
  background: #245534;
  border-color: #245534;
}

/* Stat cards — terracotta for warning states */
[data-app="home"] .stat-card:has(.orange) {
  background: var(--home-terracotta-light);
}

/* Page header accent line */
[data-app="home"] .page-header {
  border-bottom-color: var(--border);
}

/* Logo dot on home mode */
[data-app="home"] .app-logo .dot { color: var(--home-terracotta); }
