:root {
  color-scheme: dark;
  --bg: #080b12;
  --bg-soft: #0b1019;
  --panel: rgba(16, 22, 34, 0.9);
  --panel-solid: #101622;
  --panel-raised: #141b2a;
  --ink: #f4f7fb;
  --ink-inverse: #05070b;
  --muted: #8b97ad;
  --line: rgba(36, 48, 68, 0.92);
  --line-strong: rgba(53, 68, 94, 0.96);
  --green: #49d8ff;
  --green-soft: rgba(73, 216, 255, 0.12);
  --blue: #6b8cff;
  --violet: #8D6BFF;
  --red: #ff6b7a;
  --amber: #f6c15a;
  --shadow: 0 22px 42px rgba(0, 0, 0, 0.38);
  --glow: 0 18px 38px rgba(73, 216, 255, 0.14);
  --radius-card: 20px;
  --radius-control: 12px;
  font-family: Manrope, "SF Pro Display", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  min-width: 0;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 78% -12%, rgba(73, 216, 255, 0.18), transparent 30rem),
    radial-gradient(circle at 12% 8%, rgba(127, 107, 255, 0.12), transparent 26rem),
    linear-gradient(180deg, #080b12 0%, #0a0f18 48%, #080b12 100%);
  color: var(--ink);
}

button,
input,
textarea,
select {
  font: inherit;
  max-width: 100%;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  line-height: 1.15;
  text-align: center;
  text-wrap: balance;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(1180px, 100%);
  max-width: 100vw;
  margin: 0 auto;
  overflow-x: clip;
  padding: max(18px, env(safe-area-inset-top)) 18px max(24px, env(safe-area-inset-bottom));
}

.main-view {
  display: grid;
  gap: 14px;
}

.main-view > *,
.page-view > *,
.topbar > *,
.hero-grid > *,
.toolbar > *,
.charts-grid > *,
.summary-grid > *,
.recommend-panel > *,
.section-heading > *,
.metric-row > *,
.split > *,
.photo-row > *,
.product-grid > *,
.macro-editor > *,
.form-actions > * {
  min-width: 0;
}

.topbar,
.hero-grid,
.summary-grid,
.charts-grid {
  display: grid;
  gap: 12px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.page-view {
  display: grid;
  gap: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
}

h2 {
  font-size: 18px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.icon-button,
.version-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 42px;
  border-radius: var(--radius-control);
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}

.icon-button {
  width: 42px;
  height: 42px;
}

.version-badge {
  gap: 8px;
  padding: 5px 10px 5px 6px;
}

.brand-mark-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: var(--green);
  color: var(--ink-inverse);
  font-size: 14px;
  font-weight: 900;
}

.version-text {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.progress-panel,
.weight-panel,
.entry-panel,
.recommend-panel,
.day-panel,
.chart-panel,
.analysis-panel,
.streak-panel,
.library-panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.progress-panel {
  padding: 18px;
}

.weight-panel,
.entry-panel,
.recommend-panel,
.day-panel,
.chart-panel,
.analysis-panel,
.library-panel {
  padding: 14px;
  backdrop-filter: blur(18px);
}

.view-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.22);
}

.view-tabs button {
  min-height: 36px;
  padding: 0 8px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 760;
  white-space: normal;
}

.view-tabs button.active {
  background: var(--ink);
  color: var(--ink-inverse);
}

.streak-panel {
  display: grid;
  gap: 6px;
  padding: 16px;
  background:
    radial-gradient(circle at 88% -16%, rgba(73, 216, 255, 0.16), transparent 16rem),
    var(--panel-solid);
  color: var(--ink);
  border-color: rgba(73, 216, 255, 0.16);
}

.streak-panel p,
.streak-panel small {
  color: var(--muted);
}

.streak-panel div {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
}

.streak-panel strong {
  font-size: 48px;
  line-height: 0.95;
}

.metric-row,
.split,
.section-heading,
.photo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading {
  flex-wrap: wrap;
}

.section-heading h2 {
  overflow-wrap: anywhere;
}

.big-number {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 52px;
  font-weight: 760;
  line-height: 1;
}

.big-number small {
  font-size: 18px;
  color: var(--muted);
}

.goal-pill {
  flex: 0 0 auto;
  max-width: 100%;
  padding: 9px 10px;
  border: 1px solid rgba(73, 216, 255, 0.22);
  border-radius: var(--radius-control);
  background: var(--green-soft);
  color: var(--green);
  font-weight: 700;
  overflow-wrap: anywhere;
  text-align: center;
}

.progress-track {
  height: 14px;
  margin: 16px 0 10px;
  overflow: hidden;
  background: rgba(36, 48, 68, 0.78);
  border-radius: 999px;
}

.progress-track div {
  width: 0;
  height: 100%;
  background: var(--green);
  box-shadow: 0 0 18px rgba(73, 216, 255, 0.35);
  transition: width 220ms ease;
}

.weight-panel {
  display: grid;
  align-content: center;
  gap: 10px;
}

.weight-panel label {
  color: var(--muted);
  font-size: 13px;
}

.inline-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input,
textarea,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.25;
  padding: 10px 11px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(73, 216, 255, 0.16);
}

button[type="submit"],
.inline-control button,
#sendFoodButton {
  min-height: 44px;
  border-radius: var(--radius-control);
  padding: 0 15px;
  background: var(--green);
  color: var(--ink-inverse);
  font-weight: 720;
  white-space: normal;
  overflow-wrap: anywhere;
}

.toolbar {
  display: grid;
  grid-template-columns: 170px 1fr;
  gap: 10px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.segmented button,
.range-buttons button {
  min-height: 34px;
  padding: 0 7px;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 720;
  white-space: normal;
}

.segmented button.active,
.range-buttons button.active {
  background: var(--green);
  color: var(--ink-inverse);
}

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

.recommend-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  position: relative;
  overflow: hidden;
  border-color: rgba(73, 216, 255, 0.32);
  box-shadow: var(--glow), var(--shadow);
}

.recommend-panel button {
  min-height: 44px;
  max-width: 100%;
  padding: 0 14px;
  border-radius: 8px;
  background: var(--green);
  color: var(--ink-inverse);
  font-weight: 760;
  white-space: normal;
  overflow-wrap: anywhere;
}

.recommend-box {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}

.recommend-box article,
.recommend-box > p {
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(20, 27, 42, 0.88);
  overflow-wrap: anywhere;
}

.recommend-box article {
  display: grid;
  gap: 5px;
}

.recommend-box small,
.recommend-box em {
  color: var(--muted);
  font-size: 13px;
}

.recommend-box em {
  font-style: normal;
}

.macro-card {
  min-width: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.18);
}

.macro-card span,
.macro-card small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.macro-card strong {
  display: block;
  margin: 5px 0 2px;
  font-size: 22px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.food-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.product-hints {
  display: flex;
  gap: 7px;
  overflow-x: auto;
}

.product-hint {
  flex: 0 0 auto;
  width: min(230px, 78vw);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--panel-raised);
  color: var(--ink);
  font-size: 13px;
  text-align: left;
}

.product-hint small {
  display: block;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-check {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid rgba(73, 216, 255, 0.28);
  border-radius: 16px;
  background:
    radial-gradient(circle at 100% 0%, rgba(141, 107, 255, 0.16), transparent 12rem),
    rgba(20, 27, 42, 0.72);
}

.product-check-head {
  display: grid;
  gap: 2px;
}

.product-check-head span,
.product-check-grid span {
  color: var(--muted);
  font-size: 12px;
}

.product-check-head strong {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.product-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.product-check-grid article {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(16, 22, 34, 0.82);
}

.product-check-grid strong {
  font-size: 18px;
  line-height: 1.1;
}

.product-check-grid small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.check-ok,
.check-warning {
  font-size: 12px;
  line-height: 1.35;
}

.check-ok {
  color: var(--green);
}

.check-warning {
  color: var(--amber);
}

.file-button input {
  display: none;
}

.file-button span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 14px;
  border: 1px dashed var(--green);
  border-radius: var(--radius-control);
  color: var(--green);
  font-weight: 760;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
}

.photo-preview {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 6px;
  overflow-x: auto;
}

.photo-preview img {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-line,
.form-error {
  min-height: 18px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  color: var(--red);
}

.table-wrap {
  margin-top: 10px;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 500px;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  white-space: nowrap;
  min-width: 0;
}

th:first-child,
td:first-child {
  width: 100%;
  max-width: none;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
}

th:not(:first-child),
td:not(:first-child) {
  width: 58px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.meal-cell {
  padding-right: 10px;
}

.meal-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.meal-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.macro-cell {
  font-variant-numeric: tabular-nums;
}

.delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(255, 107, 122, 0.12);
  color: var(--red);
}

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

svg {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin-top: 8px;
  overflow: visible;
}

.chart-axis {
  stroke: rgba(139, 151, 173, 0.42);
  stroke-width: 1;
}

.chart-line {
  fill: none;
  stroke: var(--green);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-goal {
  stroke: var(--violet);
  stroke-width: 2;
  stroke-dasharray: 5 5;
}

.chart-bar {
  fill: rgba(73, 216, 255, 0.62);
}

.chart-bar.over {
  fill: rgba(141, 107, 255, 0.82);
}

.analysis-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel-raised);
  color: var(--ink);
  line-height: 1.45;
}

.range-buttons {
  display: grid;
  grid-template-columns: repeat(3, minmax(36px, 1fr));
  gap: 5px;
  max-width: 132px;
}

.range-buttons button {
  min-height: 32px;
  background: var(--panel-raised);
}

.library-panel {
  box-shadow: var(--shadow);
}

#newProductButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-control);
  background: var(--green);
  color: var(--ink-inverse);
  font-weight: 760;
}

#manualMealButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-control);
  background: var(--green);
  color: var(--ink-inverse);
  font-weight: 760;
}

.product-form {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(20, 27, 42, 0.7);
}

.product-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
}

.product-grid,
.macro-editor,
.form-actions {
  display: grid;
  gap: 8px;
}

.product-grid {
  grid-template-columns: 1fr 120px;
}

.macro-editor {
  grid-template-columns: 86px repeat(4, minmax(0, 1fr));
  align-items: center;
}

.macro-editor span {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.form-actions {
  grid-template-columns: 1fr 1fr;
}

.form-actions button {
  min-height: 44px;
  border-radius: var(--radius-control);
  font-weight: 760;
  padding: 0 12px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.form-actions button:first-child {
  background: var(--panel-raised);
  color: var(--ink);
  border: 1px solid var(--line-strong);
}

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

.product-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-solid);
  overflow-wrap: anywhere;
}

.product-item strong,
.product-item small {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.product-item small {
  margin-top: 4px;
  color: var(--muted);
}

.product-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.product-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
}

.product-actions button:last-child {
  color: var(--red);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  overflow-wrap: anywhere;
}

.checkbox-label input {
  width: auto;
  min-height: 0;
}

.meal-actions {
  display: inline-flex;
  max-width: 100%;
  gap: 5px;
}

.meal-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
}

.meal-actions button:last-child {
  color: var(--red);
}

.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 0 max(16px, env(safe-area-inset-bottom));
}

.login-panel {
  width: min(360px, 100%);
  padding: 22px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 14px;
  background: var(--green);
  color: var(--ink-inverse);
  font-weight: 800;
}

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

@media (min-width: 760px) {
  .hero-grid {
    grid-template-columns: minmax(0, 1.7fr) minmax(260px, 0.7fr);
  }
}

@media (max-width: 759px) {
  .app-shell {
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  .toolbar,
  .charts-grid,
  .macro-editor {
    grid-template-columns: 1fr;
  }

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

  .recommend-panel {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .recommend-panel button {
    width: 100%;
  }

  .big-number {
    font-size: 46px;
  }

  .metric-row {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .segmented button {
    font-size: 13px;
  }

  .product-grid {
    grid-template-columns: 1fr 1fr;
  }

  .product-form {
    padding: 10px;
  }

  .table-wrap {
    max-width: 100%;
    overflow-x: visible;
  }

  table {
    min-width: 0;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 8px;
  }

  tr {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel-solid);
    overflow: hidden;
  }

  td {
    min-width: 0;
    padding: 0;
    border-bottom: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }

  td:first-child {
    grid-column: 1 / -1;
    max-width: none;
    overflow: visible;
    text-overflow: clip;
  }

  .meal-title-row {
    align-items: flex-start;
  }

  .meal-title {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .meal-actions {
    flex: 0 0 auto;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .totals-row,
  .remaining-row {
    background: rgba(20, 27, 42, 0.92);
  }
}

@media (max-width: 390px) {
  h1 {
    font-size: 25px;
  }

  .streak-panel strong {
    font-size: 42px;
  }

  .big-number {
    font-size: 40px;
  }

  .summary-grid {
    gap: 8px;
  }

  .macro-card {
    padding: 10px;
  }

  .photo-row {
    display: grid;
    grid-template-columns: auto 1fr;
  }

  #sendFoodButton {
    grid-column: 1 / -1;
  }

  .product-grid,
  .form-actions {
    grid-template-columns: 1fr;
  }

  .range-buttons {
    width: 100%;
    max-width: none;
  }

  .product-check-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 375px) {
  .app-shell {
    padding-left: 10px;
    padding-right: 10px;
  }

  .view-tabs {
    gap: 3px;
  }

  .view-tabs button {
    padding: 0 5px;
    font-size: 12px;
  }

  .segmented {
    gap: 3px;
  }

  .segmented button {
    padding: 0 5px;
    font-size: 12px;
  }

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