/* ===== Utility ===== */
.hidden { display: none !important; }

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

:root {
  --bg: #f1f5fb;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #10b981;
  --success-hover: #059669;
  --danger: #ef4444;
  --ghost-hover: #f1f5f9;
  --cal-color: #f59e0b;
  --carb-color: #3b82f6;
  --prot-color: #10b981;
  --fat-color: #f97316;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ===== Auth screens (login + register) ===== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-emoji { font-size: 2.5rem; margin-bottom: 12px; display: block; }

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 28px;
}

.login-card .form-group {
  text-align: left;
  margin-bottom: 16px;
}

.login-error {
  margin-top: 12px;
  color: var(--danger);
  font-size: .875rem;
}

.btn-full { width: 100%; }

/* ===== Header ===== */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo { font-size: 1.4rem; }
.app-title { font-size: 1.1rem; font-weight: 700; flex: 1; }

/* User menu */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
  flex-shrink: 0;
}
.user-name {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-sm { padding: 5px 12px; font-size: .78rem; }
@media (max-width: 480px) { .user-name { display: none; } }

.nav { display: flex; gap: 4px; }

.nav-btn {
  background: none;
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-btn:hover { background: var(--ghost-hover); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }

/* ===== Layout ===== */
.view.hidden { display: none; }

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

/* ===== Date Nav ===== */
.date-nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.date-btn:hover:not(:disabled) { background: var(--ghost-hover); color: var(--text); }
.date-btn:disabled { opacity: .35; cursor: default; }

.date-label {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
  text-transform: capitalize;
}

/* ===== Macros Grid ===== */
.macros-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 600px) { .macros-grid { grid-template-columns: repeat(2, 1fr); } }

.macro-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.macro-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.macro-name { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.macro-goal { font-size: .7rem; color: var(--text-muted); }

.macro-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.progress-bar { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; }

.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
  width: 0%;
}
.progress-fill.cal  { background: var(--cal-color); }
.progress-fill.carb { background: var(--carb-color); }
.progress-fill.prot { background: var(--prot-color); }
.progress-fill.fat  { background: var(--fat-color); }
.progress-fill.over { background: var(--danger); }

/* ===== Section title ===== */
.section-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 14px;
}

/* ===== Search / Add Food ===== */
.search-wrap { position: relative; }

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
  background: var(--bg);
}
.search-input:focus { border-color: var(--primary); background: #fff; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  overflow: hidden;
}

.suggestion-item {
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: .9rem;
  transition: background .1s;
}
.suggestion-item:hover { background: var(--ghost-hover); }
.suggestion-item.no-result { color: var(--text-muted); cursor: default; }
.sug-name { font-weight: 500; }
.sug-info { font-size: .78rem; color: var(--text-muted); }

.add-form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

.selected-food-name { font-weight: 600; font-size: 1rem; margin-bottom: 10px; }

.qty-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.qty-input {
  width: 130px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}
.qty-input:focus { border-color: var(--primary); }

.qty-unit { font-size: .875rem; color: var(--text-muted); font-weight: 500; min-width: 20px; }

.food-preview { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== Chips ===== */
.chip { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.chip-cal  { background: #fef3c7; color: #92400e; }
.chip-carb { background: #dbeafe; color: #1e40af; }
.chip-prot { background: #d1fae5; color: #065f46; }
.chip-fat  { background: #ffedd5; color: #9a3412; }

/* ===== Meals List ===== */
.meal-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.meal-item:last-child { border-bottom: none; }

.meal-info { flex: 1; min-width: 0; }
.meal-name { font-weight: 500; font-size: .95rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-qty  { font-size: .78rem; color: var(--text-muted); }

.meal-macros { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }

.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  font-size: 1rem;
  line-height: 1;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.btn-remove:hover { color: var(--danger); background: #fee2e2; }

.empty-state { text-align: center; color: var(--text-muted); padding: 24px 0; font-size: .9rem; }

/* ===== Finalize ===== */
.finalize-wrap { display: flex; justify-content: center; }

.finalized-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #d1fae5;
  color: #065f46;
  padding: 10px 24px;
  border-radius: 99px;
  font-weight: 600;
  font-size: .95rem;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: var(--success-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--ghost-hover); color: var(--text); }

.btn-icon { background: none; border: none; cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 1rem; transition: background .15s; }
.btn-icon:hover { background: var(--ghost-hover); }

.btn-lg { padding: 12px 32px; font-size: 1rem; border-radius: 99px; }

/* ===== Histórico ===== */
.view-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }

#history-list { display: flex; flex-direction: column; gap: 12px; }

.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.history-date { font-weight: 600; font-size: .95rem; text-transform: capitalize; margin-bottom: 10px; }

.history-macros { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
@media (max-width: 500px) { .history-macros { grid-template-columns: repeat(2, 1fr); } }

.history-macro { display: flex; flex-direction: column; gap: 2px; }
.h-label { font-size: .7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.h-value { font-size: .95rem; font-weight: 600; }
.h-value small { font-weight: 400; color: var(--text-muted); font-size: .78rem; }
.h-value.over  { color: var(--danger); }
.h-value.under { color: var(--text-muted); }
.h-value.ok    { color: var(--success); }

/* ===== Alimentos ===== */
.view-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }

.table-note { font-size: .78rem; color: var(--text-muted); margin-bottom: 4px; }

.food-ref-form h3 { margin-bottom: 14px; font-size: 1rem; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.form-group.full { grid-column: 1 / -1; }
@media (max-width: 580px) { .form-grid { grid-template-columns: repeat(2, 1fr); } }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: .78rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.form-group input,
.form-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
  background: var(--bg);
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); background: #fff; }

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

.table-wrap { overflow-x: auto; }

.foods-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.foods-table thead { background: var(--bg); }
.foods-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.foods-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.foods-table tbody tr:last-child td { border-bottom: none; }
.foods-table tbody tr:hover { background: var(--ghost-hover); }

.food-name-col { font-weight: 500; }
.actions-col { white-space: nowrap; text-align: right; }

/* ===== Food badges ===== */
.food-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
}
.badge-system   { background: #e0e7ff; color: #3730a3; }
.badge-personal { background: #d1fae5; color: #065f46; }

/* ===== Checkbox label ===== */
.checkbox-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: .875rem !important;
  color: var(--text) !important;
}
.checkbox-label input[type=checkbox] { width: auto; }

/* ===== Convites ===== */
.invite-form {
  display: flex;
  gap: 10px;
  margin-bottom: 0;
  flex-wrap: wrap;
}
.invite-form .search-input { flex: 1; min-width: 200px; }

.invite-link-box {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.invite-link-label { font-size: .8rem; color: var(--text-muted); margin-bottom: 8px; }
.invite-link-wrap  { display: flex; gap: 8px; }
.invite-link-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .8rem;
  background: var(--bg);
  color: var(--text-muted);
}

.invite-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.invite-item:last-child { border-bottom: none; }
.invite-info   { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.invite-email  { font-weight: 500; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invite-status {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.invite-status.pending  { background: #fef3c7; color: #92400e; }
.invite-status.used     { background: #d1fae5; color: #065f46; }
.invite-status.expired  { background: #f1f5f9; color: #94a3b8; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 22px;
  border-radius: 99px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  z-index: 999;
}
.toast.error   { background: var(--danger); }
.toast.success { background: var(--success); }
