/* ─── Variables ──────────────────────────────────────────────── */
:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --text2: #64748b;
  --border: #e2e8f0;
  --green: #10b981;
  --green-dark: #059669;
  --nav-height: 68px;
  --header-safe: env(safe-area-inset-top, 0px);
  --bottom-safe: env(safe-area-inset-bottom, 0px);
}

/* ─── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; font-size: 16px; }
body {
  height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
  overflow: hidden; overscroll-behavior: none;
}
#root { height: 100%; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
input, select, textarea { font-family: inherit; outline: none; }

/* ─── App Layout ─────────────────────────────────────────────── */
.app-container {
  display: flex; flex-direction: column; height: 100%;
  max-width: 480px; margin: 0 auto; position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.1);
}
.app-main {
  flex: 1; overflow: hidden; display: flex; flex-direction: column;
  padding-bottom: calc(var(--nav-height) + var(--bottom-safe));
}

/* ─── Screen ─────────────────────────────────────────────────── */
.screen { flex: 1; display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.screen-header {
  padding: 12px 16px 12px;
  padding-top: calc(12px + var(--header-safe));
  flex-shrink: 0;
}
.screen-body {
  flex: 1; overflow-y: auto; padding: 12px 14px 0;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
}
.screen-body::-webkit-scrollbar { display: none; }

/* ─── Header ─────────────────────────────────────────────────── */
.header-content { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }

/* ─── Bottom Nav ─────────────────────────────────────────────── */
.bottom-nav {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: calc(var(--nav-height) + var(--bottom-safe));
  padding-bottom: var(--bottom-safe);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex; align-items: flex-start;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
  z-index: 100;
}
.nav-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 8px 4px; background: transparent; position: relative;
  min-height: var(--nav-height); transition: all 0.15s ease;
}
.nav-icon { font-size: 22px; line-height: 1; margin-bottom: 3px; transition: transform 0.15s ease; }
.nav-label { font-size: 10px; color: var(--text2); font-weight: 500; }
.nav-item.active .nav-icon { transform: translateY(-2px); }
.nav-item.active .nav-label { color: var(--green); font-weight: 700; }
.nav-indicator {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; background: var(--green); border-radius: 0 0 4px 4px;
}

/* ─── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--card); border-radius: 14px; padding: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06); margin-bottom: 12px; border: 1px solid var(--border);
}
.list-card { transition: transform 0.1s ease, box-shadow 0.1s ease; }
.list-card:active { transform: scale(0.99); box-shadow: 0 1px 6px rgba(0,0,0,0.08); }
.stock-card { padding: 14px; }
.stock-low { border-left: 4px solid #ef4444 !important; }

/* ─── Quick Stats ────────────────────────────────────────────── */
.quick-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  background: rgba(0,0,0,0.15); border-radius: 12px; padding: 10px 6px; margin-top: 8px;
}
.quick-stat { display: flex; flex-direction: column; align-items: center; gap: 3px; }

/* ─── Metrics ────────────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.metric-card {
  background: var(--card); border-radius: 12px; padding: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid var(--border);
}
.metric-icon { font-size: 22px; margin-bottom: 6px; }
.metric-value { font-size: 16px; font-weight: 700; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-label { font-size: 11px; color: var(--text2); }

/* ─── Section Title ──────────────────────────────────────────── */
.section-title {
  font-size: 13px; font-weight: 700; color: var(--text2); text-transform: uppercase;
  letter-spacing: 0.5px; margin: 14px 0 8px;
}

/* ─── Progress ───────────────────────────────────────────────── */
.progress-bar {
  height: 6px; background: var(--border); border-radius: 3px; overflow: hidden;
}
.progress-bar-white {
  height: 6px; background: rgba(255,255,255,0.3); border-radius: 3px; overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.4s ease; }

/* ─── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge.ativa { background: #d1fae5; color: #059669; }
.badge.concluida { background: #e0e7ff; color: #4338ca; }
.badge.arquivada { background: var(--border); color: var(--text2); }
.badge-danger { background: #fee2e2; color: #ef4444; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }

/* ─── Buttons ────────────────────────────────────────────────── */
.btn-primary {
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: white; border-radius: 12px; padding: 13px 20px;
  font-size: 15px; font-weight: 700; border: none; transition: opacity 0.15s, transform 0.1s;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }
.btn-secondary {
  background: var(--border); color: var(--text); border-radius: 12px;
  padding: 13px 16px; font-size: 14px; font-weight: 600;
}
.btn-icon-white {
  background: rgba(255,255,255,0.2); border-radius: 10px; width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center; color: white; font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.btn-danger-sm {
  background: #fee2e2; color: #ef4444; border-radius: 8px;
  padding: 5px 8px; font-size: 12px; transition: background 0.15s;
}
.btn-danger-sm:active { background: #fecaca; }
.btn-sm-outline {
  background: var(--bg); border: 1px solid var(--border); color: var(--text2);
  border-radius: 8px; padding: 5px 8px; font-size: 13px;
}
.back-btn {
  background: rgba(255,255,255,0.2); color: white; border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-weight: 600; flex-shrink: 0;
}

/* ─── FAB ────────────────────────────────────────────────────── */
.fab {
  position: fixed; bottom: calc(var(--nav-height) + var(--bottom-safe) + 14px);
  right: max(16px, calc(50vw - 240px + 16px));
  width: 54px; height: 54px; border-radius: 27px;
  background: linear-gradient(135deg, var(--green) 0%, var(--green-dark) 100%);
  color: white; font-size: 28px; font-weight: 300;
  box-shadow: 0 4px 20px rgba(16,185,129,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 99; transition: transform 0.15s, box-shadow 0.15s;
  line-height: 1;
}
.fab:active { transform: scale(0.92); box-shadow: 0 2px 10px rgba(16,185,129,0.3); }

/* ─── Search ─────────────────────────────────────────────────── */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.2); border-radius: 10px;
  padding: 8px 12px; margin: 8px 0 4px;
}
.search-input {
  flex: 1; background: transparent; border: none; color: white;
  font-size: 14px; outline: none;
}
.search-input::placeholder { color: rgba(255,255,255,0.6); }

/* ─── Filter Tabs ────────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 6px; padding: 8px 0 4px; }
.filter-tab {
  padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.8); transition: all 0.15s;
}
.filter-tab.active { background: white; color: var(--green); }

/* ─── Category Header ────────────────────────────────────────── */
.category-header {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase;
  letter-spacing: 0.3px; padding: 10px 4px 6px; margin-top: 4px;
}

/* ─── Item Row ───────────────────────────────────────────────── */
.item-row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border-radius: 10px; margin-bottom: 4px; background: var(--card);
  border: 1px solid var(--border); transition: opacity 0.2s;
}
.item-row.item-done { opacity: 0.65; }
.item-row:active { background: var(--bg); }
.check-btn {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 14px;
  color: white; flex-shrink: 0; transition: all 0.2s ease; background: transparent;
}
.check-btn.checked { background: var(--green); border-color: var(--green); }

/* ─── List Row ───────────────────────────────────────────────── */
.list-row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.rank-badge {
  width: 24px; height: 24px; border-radius: 50%; background: var(--green);
  color: white; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* ─── Price button ───────────────────────────────────────────── */
.price-btn {
  background: rgba(16,185,129,0.1); color: var(--green);
  border-radius: 8px; padding: 4px 8px; font-size: 13px; font-weight: 700; border: 1px solid rgba(16,185,129,0.2);
}
.price-input {
  background: var(--bg); border: 1.5px solid var(--green); border-radius: 8px;
  padding: 4px 8px; font-size: 13px; font-weight: 700; color: var(--text);
}

/* ─── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; z-index: 200; backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--card); border-radius: 20px 20px 0 0; width: 100%; max-width: 480px;
  margin: 0 auto; max-height: 90vh; display: flex; flex-direction: column;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; }
.modal-title { font-size: 17px; font-weight: 700; color: var(--text); }
.modal-close {
  width: 30px; height: 30px; border-radius: 50%; background: var(--bg);
  color: var(--text2); font-size: 14px; display: flex; align-items: center; justify-content: center;
}
.modal-body { padding: 0 16px 16px; overflow-y: auto; padding-bottom: calc(16px + var(--bottom-safe)); }

/* ─── Forms ──────────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text2); }
.form-input {
  background: var(--bg); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 14px; color: var(--text); width: 100%; transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--green); }

/* ─── Suggestions ────────────────────────────────────────────── */
.suggestions-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12); overflow: hidden; margin-top: 4px;
}
.suggestion-item { padding: 10px 12px; font-size: 14px; color: var(--text); border-bottom: 1px solid var(--border); }
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:active { background: var(--bg); }

/* ─── Total Preview ──────────────────────────────────────────── */
.total-preview {
  text-align: center; font-size: 16px; font-weight: 700; color: var(--green);
  background: rgba(16,185,129,0.1); border-radius: 10px; padding: 10px;
}

/* ─── Qty Buttons ────────────────────────────────────────────── */
.qty-btn {
  width: 32px; height: 32px; border-radius: 50%; background: var(--bg); border: 1.5px solid var(--border);
  font-size: 18px; font-weight: 700; display: flex; align-items: center; justify-content: center; color: var(--text);
  flex-shrink: 0;
}
.qty-btn:active { background: var(--border); }

/* ─── Alert Banner ───────────────────────────────────────────── */
.alert-banner {
  background: rgba(239,68,68,0.2); color: white; border-radius: 8px;
  padding: 8px 12px; font-size: 13px; font-weight: 600; margin-bottom: 8px;
}

/* ─── Settings ───────────────────────────────────────────────── */
.settings-card { padding: 4px 14px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; }
.settings-divider { height: 1px; background: var(--border); }
.settings-action {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px 0;
  background: transparent; text-align: left;
}

/* ─── Toggle ─────────────────────────────────────────────────── */
.toggle {
  width: 48px; height: 28px; border-radius: 14px; background: var(--border);
  position: relative; transition: background 0.2s; flex-shrink: 0;
}
.toggle::after {
  content: ''; position: absolute; left: 3px; top: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: white;
  transition: transform 0.2s; box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.toggle.on { background: var(--green); }
.toggle.on::after { transform: translateX(20px); }

/* ─── Skeleton ───────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--card) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Dark Theme ─────────────────────────────────────────────── */
[data-theme="dark"] .form-input { background: #0f172a; }
[data-theme="dark"] .item-row { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .item-row:active { background: #0f172a; }
[data-theme="dark"] .check-btn { border-color: #475569; }
[data-theme="dark"] .suggestions-dropdown { background: #1e293b; border-color: #334155; }
[data-theme="dark"] .suggestion-item:active { background: #0f172a; }
[data-theme="dark"] .modal-content { background: #1e293b; }
[data-theme="dark"] .search-bar { background: rgba(0,0,0,0.3); }
[data-theme="dark"] .qty-btn { background: #0f172a; border-color: #334155; }

/* ─── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 0; }

/* ─── Responsive ─────────────────────────────────────────────── */
@media (min-width: 480px) {
  .app-container { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
