/* =====================
   DESIGN TOKENS
   ===================== */
:root {
  color-scheme: light only;
  --bg: #FAFAF8;
  --bg-subtle: #F3F2EF;
  --text: #1C1C1E;
  --text-secondary: #6E6E73;
  --line: #E5E5E7;
  --accent: #2F6FED;
  --accent-hover: #1A5FDF;

  /* Category palette — from the Autumn palette image */
  --cat-hortifruti: #A8AD6B;    /* sage/olive */
  --cat-acougue: #D4844A;       /* amber */
  --cat-laticinios: #C2522A;    /* terracotta */
  --cat-mercearia: #8B3A2A;     /* burnt red */
  --cat-outros: #5C2535;        /* bordeaux */

  --radius: 10px;
  --radius-sm: 6px;
  --max-w: 480px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;

  --transition: 150ms ease;
  --transition-med: 220ms ease;
}

/* =====================
   RESET & BASE
   ===================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button { font-family: var(--font); cursor: pointer; }
input, textarea {
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
  -webkit-text-fill-color: var(--text);
}
input::placeholder, textarea::placeholder {
  -webkit-text-fill-color: var(--text-secondary);
  opacity: 0.6;
}
ul { list-style: none; }

/* =====================
   LAYOUT
   ===================== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(250, 250, 248, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 12px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-logo { width: 22px; height: 22px; display: block; flex-shrink: 0; }

.app-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text);
}

/* =====================
   TAB NAV
   ===================== */
.tab-nav {
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  border-bottom: none;
}

.tab-nav::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  padding: 8px 14px 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  letter-spacing: -0.1px;
}

.tab-btn:hover { color: var(--text); }

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* =====================
   MAIN CONTENT
   ===================== */
.app-main {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* =====================
   SECTION HEADERS
   ===================== */
.section-header { margin-bottom: 24px; }

.section-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.5px;
  color: var(--text);
  line-height: 1.2;
}

.section-sub {
  margin-top: 4px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* =====================
   UPLOAD ZONE
   ===================== */
.upload-zone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(47, 111, 237, 0.03);
}

.upload-icon-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: #F5F5F7;
  margin-bottom: 10px;
}

.upload-icon {
  font-size: 20px;
  color: var(--text-secondary);
  font-style: normal;
  line-height: 1;
}

.upload-filename {
  margin-top: 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  word-break: break-all;
}

.upload-label {
  font-size: 14px;
  color: var(--text-secondary);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  opacity: 0.7;
}

/* =====================
   DIVIDER
   ===================== */
.divider-text {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 12px;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* =====================
   TEXTAREA
   ===================== */
.diet-textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  transition: border-color var(--transition);
  outline: none;
}

.diet-textarea:focus {
  border-color: var(--accent);
}

.diet-textarea::placeholder { color: var(--text-secondary); opacity: 0.6; }

/* =====================
   PREVIEW AREA
   ===================== */
.preview-area {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--line);
}

.preview-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.preview-text {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Menlo', monospace;
}

/* =====================
   SETTINGS ROW
   ===================== */
.settings-row {
  display: flex;
  gap: 16px;
  margin-top: 20px;
  margin-bottom: 20px;
}

.setting-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.field-input {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}

.field-input:focus { border-color: var(--accent); }

/* Stepper (− input +) */
.stepper {
  display: flex;
  align-items: stretch;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 48px;
  background: var(--bg);
  transition: border-color var(--transition);
}

.stepper:focus-within { border-color: var(--accent); }

.stepper-btn {
  width: 42px;
  flex-shrink: 0;
  background: var(--bg);
  border: none;
  font-size: 19px;
  font-weight: 400;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.stepper-btn:hover { background: #F5F5F7; color: var(--text); }
.stepper-btn:active { background: var(--line); }

.stepper-input {
  flex: 1;
  min-width: 0;
  border: none;
  text-align: center;
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
}

.stepper-input::-webkit-outer-spin-button,
.stepper-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.flex-grow { flex: 1; }
.stock-qty { max-width: 90px; }

/* =====================
   BUTTONS
   ===================== */
.primary-btn {
  width: 100%;
  height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: var(--radius);
  padding: 0 20px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.2px;
  transition: opacity var(--transition), transform var(--transition);
}

.primary-btn:hover { opacity: 0.85; }
.primary-btn:active { transform: scale(0.98); }

.primary-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  transform: none;
}

.btn-arrow {
  font-size: 16px;
  line-height: 1;
  transition: transform var(--transition);
}

.primary-btn:not(:disabled):hover .btn-arrow { transform: translateX(2px); }

.secondary-btn {
  background: var(--bg-subtle);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition);
}

.secondary-btn:hover { background: var(--line); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: inherit;
  font-weight: 500;
  padding: 0;
  transition: opacity var(--transition);
}

.link-btn:hover { opacity: 0.7; }

.icon-btn {
  background: none;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition), border-color var(--transition);
}

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

/* =====================
   LIST TOOLBAR
   ===================== */
.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 12px;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  margin-top: 4px;
}

/* =====================
   SHOPPING LIST
   ===================== */
.shopping-list { display: flex; flex-direction: column; gap: 32px; }

.category-block {}

.category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.category-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.category-name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.category-items { display: flex; flex-direction: column; }

.list-item {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  transition: opacity var(--transition);
}

.list-item:last-child { border-bottom: none; }

.item-checkbox {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  flex-shrink: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  top: 1px;
  transition: background var(--transition), border-color var(--transition);
}

.item-checkbox:checked {
  background: var(--text);
  border-color: var(--text);
}

.item-checkbox:checked::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 5px;
  width: 5px;
  height: 8px;
  border: 1.5px solid var(--bg);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

.list-item.checked .item-name,
.list-item.checked .item-qty {
  opacity: 0.35;
  text-decoration: line-through;
}

.item-qty {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  min-width: 70px;
  letter-spacing: -0.2px;
}

.item-name {
  font-size: 15px;
  color: var(--text);
  line-height: 1.4;
}

/* =====================
   ADD STOCK ROW
   ===================== */
.add-stock-row {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  align-items: flex-end;
}

/* =====================
   STOCK LIST
   ===================== */
.stock-list { display: flex; flex-direction: column; }

.stock-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stock-item:last-child { border-bottom: none; }

.stock-item-name { font-size: 15px; color: var(--text); }

.stock-item-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stock-item-qty {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.remove-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  line-height: 1;
  opacity: 0.5;
  transition: opacity var(--transition);
  padding: 0 2px;
}

.remove-btn:hover { opacity: 1; }

/* =====================
   HISTORY LIST
   ===================== */
.history-list { display: flex; flex-direction: column; gap: 1px; }

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: opacity var(--transition);
}

.history-item:last-child { border-bottom: none; }
.history-item:hover .history-date { color: var(--text); }

.history-left { display: flex; flex-direction: column; gap: 2px; }

.history-date {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.history-meta { font-size: 13px; color: var(--text-secondary); }

.history-actions { display: flex; gap: 8px; }

/* =====================
   EMPTY STATE
   ===================== */
.empty-state {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
  padding: 32px 0;
  line-height: 1.6;
}

/* =====================
   ERROR
   ===================== */
.error-msg {
  margin-top: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(220, 53, 69, 0.06);
  border: 1px solid rgba(220, 53, 69, 0.2);
  font-size: 13px;
  color: #C0392B;
  line-height: 1.5;
}

/* =====================
   TOAST
   ===================== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 100px;
  z-index: 999;
  animation: toast-in var(--transition-med) ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =====================
   RESPONSIVE
   ===================== */
@media (max-width: 480px) {
  .app-main { padding: 24px 16px 48px; }
  .header-inner { padding: 12px 16px 0; }
  .tab-btn { padding: 8px 12px 10px; font-size: 13px; }
  .list-toolbar { flex-direction: column; }
  .toolbar-actions { align-self: flex-start; }
  .settings-row { gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0ms !important; animation-duration: 0ms !important; }
}

/* =====================
   SAFE AREA (iPhone)
   ===================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .app-main { padding-bottom: calc(48px + env(safe-area-inset-bottom)); }
}
