:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-soft: #eef2f6;
  --text: #1f2933;
  --muted: #657282;
  --line: #d8e0e8;
  --brand: #ff6b35;
  --blue: #2368a2;
  --green: #21855b;
  --red: #c24135;
  --yellow: #f4b63f;
  --shadow: 0 10px 28px rgba(20, 31, 44, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.hidden {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}

.brand-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--brand);
  color: #fff;
  font-size: 2rem;
  font-weight: 800;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-form {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.1rem, 4vw, 1.6rem);
}

.app-header p {
  margin: 3px 0 0;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.tab {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.tab.active {
  background: var(--text);
  color: #fff;
}

main {
  max-width: 1220px;
  margin: 0 auto;
  padding: 18px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metrics article,
.panel,
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metrics article {
  padding: 14px;
}

.metrics strong {
  display: block;
  font-size: 1.45rem;
}

.metrics span {
  color: var(--muted);
  font-size: 0.9rem;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel {
  padding: 14px;
  margin-bottom: 14px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.08rem;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.panel-title h2 {
  margin: 0;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 180px auto;
  gap: 10px;
  margin-bottom: 14px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 11px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 104, 162, 0.14);
}

.btn {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
  background: var(--text);
  color: #fff;
  white-space: nowrap;
}

.btn.primary {
  background: var(--brand);
}

.btn.success {
  background: var(--green);
}

.btn.danger {
  background: var(--red);
}

.btn.ghost {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line);
}

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-row.end {
  justify-content: flex-end;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}

.card {
  padding: 12px;
}

.card.low {
  border-left: 4px solid var(--brand);
}

.card.expiring {
  border-left: 4px solid var(--red);
}

.card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.list {
  display: grid;
  gap: 8px;
}

.list-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.scanner-frame {
  min-height: 320px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #101820;
}

.scanner-frame video,
.scanner-frame canvas {
  width: 100%;
  max-height: 360px;
  object-fit: cover;
}

.recipe-grid,
.meal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.recipe-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 6px;
  background: var(--surface-soft);
}

.meal-day {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}

.meal-day h3 {
  margin: 0 0 10px;
}

.meal-day label,
.dialog label {
  display: grid;
  gap: 5px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
}

.dialog::backdrop {
  background: rgba(20, 31, 44, 0.5);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(20, 31, 44, 0.55);
  padding: 18px;
  overflow: auto;
}

.modal-content {
  max-width: 760px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-4px);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

@media (max-width: 860px) {
  .app-header,
  .panel-title,
  .grid.two,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .app-header,
  .panel-title {
    display: grid;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  main,
  .tabs,
  .app-header {
    padding-left: 12px;
    padding-right: 12px;
  }

  .metrics,
  .cards,
  .recipe-grid,
  .meal-grid {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
  }
}
