*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #059669;
  --primary-light:  #ecfdf5;
  --success:        #10b981;
  --success-light:  #ecfdf5;
  --warning:        #f59e0b;
  --warning-light:  #fffbeb;
  --danger:         #ef4444;
  --danger-light:   #fef2f2;
  --info:           #3b82f6;
  --info-light:     #eff6ff;
  --bg:             #f8fafc;
  --surface:        #ffffff;
  --border:         #e2e8f0;
  --text:           #1e293b;
  --text-muted:     #64748b;
  --sidebar-w:      220px;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08);
  --shadow:         0 4px 12px rgba(0,0,0,0.08);
  --radius:         10px;
  --radius-sm:      6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ─── LOGIN ─── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  width: 340px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.07);
  text-align: center;
}
.login-card .brand-icon { width: 80px; height: 80px; display: block; margin: 0 auto 12px; }
.login-card .brand-name { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-card .brand-sub  { font-size: 13px; color: var(--text-muted); margin-bottom: 28px; }
.btn-google {
  width: 100%;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
}
.login-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--danger-light, #fef2f2);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.4;
}

/* ─── SIDEBAR USER ─── */
.sidebar-user {
  margin-top: auto;
  padding: 10px 8px;
  border-top: 1px solid var(--border);
}
.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}
.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.sidebar-user-name {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-signout {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-signout:hover { background: var(--bg); color: var(--text); }

/* ─── LAYOUT ─── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ─── SIDEBAR ─── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
}

.brand-icon { width: 36px; height: 36px; flex-shrink: 0; }

.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.3px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-nav {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg); color: var(--text); }

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item .material-icons { font-size: 18px; }

/* ─── MAIN ─── */
.main {
  padding: 32px;
  max-width: 1160px;
  width: 100%;
}

/* ─── PAGE HEADER ─── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── CARDS ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ─── STAT GRID ─── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -1.5px;
  line-height: 1;
}

.stat-value-currency {
  font-size: 22px;
  letter-spacing: -0.5px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon .material-icons { font-size: 20px; }
.stat-icon.blue   { background: var(--info-light);    color: var(--info); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.amber  { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger); }
.stat-icon.purple { background: var(--primary-light); color: var(--primary); }

/* ─── SECTION ─── */
.section { margin-bottom: 24px; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.section-title { font-size: 14px; font-weight: 700; }

/* ─── TABLE ─── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--border); }

tbody td {
  padding: 12px 16px;
  font-size: 13.5px;
}

.text-muted  { color: var(--text-muted); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.font-mono   { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 13px; }
.font-medium { font-weight: 600; }

/* ─── BADGE ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: capitalize;
  white-space: nowrap;
}

.badge-blue   { background: var(--info-light);    color: var(--info); }
.badge-green  { background: var(--success-light); color: var(--success); }
.badge-amber  { background: var(--warning-light); color: var(--warning); }
.badge-red    { background: var(--danger-light);  color: var(--danger); }
.badge-gray   { background: #f1f5f9;              color: #64748b; }
.badge-purple { background: var(--primary-light); color: var(--primary); }

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  font-family: inherit;
}

.btn .material-icons { font-size: 16px; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #047857; }

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 5px;
  border-radius: 4px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  transition: all 0.15s;
  font-family: inherit;
}

.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-light); color: var(--danger); }
.btn-icon .material-icons { font-size: 16px; }

.actions { display: flex; gap: 4px; align-items: center; }

/* ─── TABS ─── */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-sm);
  width: fit-content;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.tab {
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  border: none;
  background: none;
  transition: all 0.15s;
  font-family: inherit;
}

.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ─── FORMS ─── */
.form-group { margin-bottom: 16px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.1);
}

input[readonly] { background: var(--bg); color: var(--text-muted); cursor: default; }
textarea { resize: vertical; min-height: 72px; }

/* ─── SEARCH SELECT ─── */
.search-select { position: relative; }
.search-select .ss-input { width: 100%; }
.ss-list {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
  z-index: 300;
}
.ss-option {
  padding: 7px 12px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.4;
}
.ss-option:hover { background: var(--primary-light); color: var(--primary); }
.ss-empty { padding: 8px 12px; color: var(--text-muted); font-size: 13px; font-style: italic; }

/* ─── INGREDIENT ROWS ─── */
.ingredient-section { margin-top: 4px; }

.ingredient-header {
  display: grid;
  grid-template-columns: 24px 2.5fr 1fr 80px 80px 32px;
  gap: 8px;
  padding: 0 0 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
}

.ingredient-row {
  display: grid;
  grid-template-columns: 24px 2.5fr 1fr 80px 80px 32px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.ingredient-row input, .ingredient-row select, .ingredient-row .search-select { margin: 0; }

.ingredient-row.ingredient-done > *:not(:first-child),
tr.ingredient-done td:not(:first-child) { opacity: 0.4; text-decoration: line-through; }
.ingredient-row.ingredient-done input[type="checkbox"],
tr.ingredient-done td:first-child { opacity: 1; text-decoration: none; }

/* ─── TABLE TOOLBAR ─── */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 0;
  flex-wrap: wrap;
}
.toolbar-filters {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  flex-wrap: wrap;
}
.toolbar-filters select {
  padding: 6px 10px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
}
.toolbar-filters select:focus { outline: none; border-color: var(--primary); }
.toolbar-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  min-width: 200px;
}
.toolbar-search .material-icons { font-size: 16px; color: var(--text-muted); }
.toolbar-search input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 13px;
  color: var(--text);
  width: 100%;
  font-family: inherit;
}
.toolbar-search input::placeholder { color: var(--text-muted); }

/* ─── LABEL WITH INLINE ACTION ─── */
.label-with-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.label-with-action .checkbox-label {
  font-size: 12px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

/* ─── CHECKBOX LABEL ─── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
  font-size: 13.5px;
}
.checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

.row-cost {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  font-family: 'SFMono-Regular', Consolas, monospace;
  white-space: nowrap;
}

.add-ingredient-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  border: none;
  background: none;
  padding: 6px 0;
  font-family: inherit;
}

.add-ingredient-btn:hover { color: #047857; }

/* ─── COST SUMMARY ─── */
.cost-summary {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-top: 12px;
  border: 1px solid var(--border);
}

.cost-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  padding: 3px 0;
  color: var(--text-muted);
}

.cost-row.total {
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

/* ─── RECIPE CARDS ─── */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.recipe-card {
  padding: 20px;
  cursor: pointer;
  transition: all 0.15s;
}

.recipe-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.recipe-card-name {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 3px;
}

.recipe-card-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.recipe-card-footer {
  display: flex;
  gap: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.recipe-stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin-bottom: 2px; }
.recipe-stat-value { font-size: 16px; font-weight: 700; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,0.18);
  width: 90%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
}

.modal.lg { max-width: 720px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h3 { font-size: 16px; font-weight: 700; }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── TOAST ─── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  color: white;
  z-index: 2000;
  box-shadow: var(--shadow);
  transition: opacity 0.3s;
}

.toast.hidden { display: none; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* ─── STATES ─── */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-muted);
}

.loading-screen .material-icons { font-size: 32px; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state .material-icons {
  font-size: 44px;
  display: block;
  margin-bottom: 10px;
  opacity: 0.35;
}

.empty-state h3 { font-size: 15px; margin-bottom: 5px; color: var(--text); }
.empty-state p  { font-size: 13px; }

/* ─── ALERTS ─── */
.alert {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 8px;
}

.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert .material-icons { font-size: 18px; flex-shrink: 0; }

/* ─── DIVIDER ─── */
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ─── ANIMATION ─── */
@keyframes spin { to { transform: rotate(360deg); } }
.spin { animation: spin 0.9s linear infinite; display: inline-block; }

/* ─── UTILS ─── */
.gap-8 { gap: 8px; }
.mb-0  { margin-bottom: 0; }
.low-stock { color: var(--danger); font-weight: 600; }

/* ─── HELP ─── */
.help-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: start;
}

.help-nav {
  padding: 8px;
  position: sticky;
  top: 0;
}

.help-nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.help-nav-item .material-icons { font-size: 16px; }
.help-nav-item:hover { background: var(--bg); color: var(--text); }
.help-nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.help-content {
  padding: 32px 36px;
  overflow-y: auto;
  max-height: calc(100vh - 140px);
}

.help-body { max-width: 760px; }

.help-body h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.help-body h2 { font-size: 1.1rem; font-weight: 700; margin: 28px 0 10px; color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.help-body h3 { font-size: 0.95rem; font-weight: 700; margin: 20px 0 8px; color: var(--text); }
.help-body p  { margin-bottom: 12px; line-height: 1.7; color: var(--text); }
.help-body ul, .help-body ol { margin: 0 0 12px 20px; line-height: 1.8; }
.help-body li { margin-bottom: 2px; }

.help-body table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 13px; }
.help-body thead th { background: var(--bg); font-weight: 600; text-align: left; padding: 8px 12px; border: 1px solid var(--border); }
.help-body tbody td { padding: 7px 12px; border: 1px solid var(--border); vertical-align: top; }
.help-body tbody tr:nth-child(even) { background: var(--bg); }

.help-body code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; font-family: 'Consolas', 'Menlo', monospace; color: var(--text); }
.help-body pre  { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 16px; overflow-x: auto; margin-bottom: 16px; }
.help-body pre code { background: none; border: none; padding: 0; font-size: 12px; }

.help-body blockquote { border-left: 3px solid var(--primary); margin: 0 0 12px; padding: 8px 16px; background: var(--primary-light); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; color: var(--text-muted); }
.help-body hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }
.help-body strong { font-weight: 600; }
