:root {
  color-scheme: dark;
  --bg: #050706;
  --panel: #0b100d;
  --panel-2: #101712;
  --line: #1d2b22;
  --text: #eef8f0;
  --muted: #8ca094;
  --green: #37e878;
  --green-2: #0fb85a;
  --amber: #ffcf66;
  --red: #ff6b6b;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 18% 0%, rgba(55, 232, 120, 0.12), transparent 28rem),
    linear-gradient(135deg, #050706 0%, #070b08 58%, #020302 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid rgba(55, 232, 120, 0.46);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--green), var(--green-2));
  color: #031006;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

.secondary-button {
  border-color: var(--line);
  background: #070b08;
  color: var(--text);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(55, 232, 120, 0.3);
  outline-offset: 2px;
}

.auth-screen {
  display: grid;
  min-height: 100svh;
  place-items: center;
  padding: 22px;
}

.auth-panel {
  display: grid;
  gap: 22px;
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(11, 16, 13, 0.96);
  box-shadow: var(--shadow);
  padding: clamp(22px, 5vw, 34px);
}

.auth-panel h1 {
  margin-bottom: 10px;
}

.auth-form,
.auth-actions {
  display: grid;
  gap: 12px;
}

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

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  place-items: center;
  border: 1px solid rgba(55, 232, 120, 0.38);
  border-radius: 8px;
  background: #07100a;
  box-shadow: inset 0 0 24px rgba(55, 232, 120, 0.08);
}

.brand-mark svg {
  width: 38px;
  height: 38px;
  fill: none;
  stroke: var(--green);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3.25;
}

.brand strong {
  display: block;
  font-size: 1.2rem;
  line-height: 1.1;
}

.brand small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.user-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.account-name {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.user-switcher label {
  color: var(--muted);
  font-size: 0.86rem;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 1.4rem;
}

select,
input {
  min-height: 42px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070b08;
  color: var(--text);
  padding: 0 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.hero-grid,
.workspace,
.charts-grid,
.history-grid {
  display: grid;
  gap: 16px;
}

.hero-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr);
  align-items: stretch;
}

.summary-panel,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(11, 16, 13, 0.92);
  box-shadow: var(--shadow);
}

.summary-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: clamp(20px, 4vw, 34px);
  min-height: 260px;
  overflow: hidden;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2.6rem, 8vw, 5.5rem);
  line-height: 0.92;
}

h2 {
  font-size: 1.08rem;
}

.muted,
.hint-line {
  color: var(--muted);
}

.ring-wrap {
  position: relative;
  display: grid;
  flex: 0 0 clamp(142px, 24vw, 180px);
  place-items: center;
}

.ring-wrap canvas {
  width: 100%;
  height: auto;
}

.ring-label {
  position: absolute;
  display: grid;
  place-items: center;
  text-align: center;
}

.ring-label strong {
  font-size: 1.55rem;
}

.ring-label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.metric-card {
  display: grid;
  align-content: center;
  gap: 8px;
  min-height: 76px;
  padding: 18px;
}

.metric-card span,
.metric-card small {
  color: var(--muted);
}

.metric-card strong {
  font-size: 1.45rem;
}

.workspace {
  grid-template-columns: minmax(320px, 1.25fr) minmax(260px, 0.75fr) minmax(280px, 0.9fr);
  margin-top: 16px;
}

.panel {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.collapse-toggle {
  display: inline-grid;
  flex: 0 0 34px;
  width: 34px;
  min-height: 34px;
  place-items: center;
  border-color: var(--line);
  background: #070b08;
  color: var(--green);
  padding: 0;
  line-height: 1;
}

.panel.is-collapsed {
  align-self: start;
}

.panel.is-collapsed .section-heading {
  margin-bottom: 0;
}

.panel.is-collapsed .panel-body {
  display: none;
}

.panel.is-collapsed .button-row,
.panel.is-collapsed .segmented,
.panel.is-collapsed .section-heading > button {
  display: none;
}

.section-heading button {
  padding: 0 16px;
  white-space: nowrap;
}

.section-heading .collapse-toggle {
  padding: 0;
}

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

.form-grid,
.food-form {
  display: grid;
  gap: 12px;
}

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

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

.food-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.food-search-field {
  grid-column: 1 / -1;
}

.input-unit {
  position: relative;
  display: block;
}

.input-unit input {
  padding-right: 48px;
}

.input-unit small {
  position: absolute;
  right: 12px;
  top: 50%;
  color: var(--muted);
  transform: translateY(-50%);
}

.hint-line {
  min-height: 18px;
  margin-top: 8px;
  font-size: 0.84rem;
}

.food-matches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr));
  gap: 8px;
  margin-top: 8px;
}

.food-match {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 7px 9px;
  color: var(--text);
}

.food-match span {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.food-match small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.food-match button {
  min-height: 34px;
  padding: 0 10px;
}

.charts-grid,
.history-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

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

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.segmented {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #070b08;
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.segmented button.active {
  background: rgba(55, 232, 120, 0.16);
  color: var(--green);
}

.entry-list {
  display: grid;
  gap: 10px;
  max-height: 360px;
  overflow: auto;
  padding-right: 3px;
}

.entry-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  padding: 10px 12px;
}

.entry-row strong,
.entry-row span {
  overflow-wrap: anywhere;
}

.entry-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.entry-row .danger {
  width: 34px;
  min-height: 34px;
  border-color: rgba(255, 107, 107, 0.4);
  background: rgba(255, 107, 107, 0.1);
  color: var(--red);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  padding: 20px;
  text-align: center;
}

.source-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

@media (max-width: 940px) {
  .hero-grid,
  .workspace,
  .charts-grid,
  .history-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  body {
    background: #050706;
  }

  .app-shell {
    width: 100%;
    padding: 10px 10px 28px;
  }

  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  .brand {
    gap: 10px;
  }

  .brand-mark {
    flex-basis: 42px;
    width: 42px;
    height: 42px;
  }

  .brand-mark svg {
    width: 30px;
    height: 30px;
  }

  .brand strong {
    font-size: 1rem;
  }

  .brand small {
    display: none;
  }

  .user-switcher {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 42px auto;
    align-items: end;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(11, 16, 13, 0.92);
    padding: 10px;
  }

  .account-name,
  .user-switcher label {
    grid-column: 1 / -1;
  }

  .account-name {
    line-height: 1.2;
  }

  .user-switcher label {
    display: none;
  }

  .user-switcher select,
  .user-switcher button {
    min-height: 40px;
  }

  .hero-grid,
  .workspace,
  .charts-grid,
  .history-grid {
    gap: 10px;
  }

  .summary-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 112px;
    align-items: center;
    gap: 12px;
    min-height: auto;
    padding: 16px;
  }

  .summary-panel h1 {
    font-size: clamp(2.15rem, 13vw, 3.4rem);
  }

  .summary-panel .muted {
    margin-bottom: 0;
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .ring-wrap {
    flex-basis: 112px;
    width: 112px;
    justify-self: end;
  }

  .ring-label strong {
    font-size: 1.15rem;
  }

  .ring-label span {
    font-size: 0.66rem;
  }

  .metric-grid,
  .form-grid,
  .food-form {
    grid-template-columns: 1fr;
  }

  .metric-grid {
    gap: 8px;
  }

  .metric-card {
    min-height: 0;
    padding: 12px 14px;
  }

  .metric-card strong {
    font-size: 1.22rem;
  }

  .panel {
    padding: 14px;
    box-shadow: none;
  }

  .section-heading {
    gap: 10px;
    margin-bottom: 12px;
  }

  .section-heading h2 {
    font-size: 1rem;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    justify-content: stretch;
  }

  .button-row button,
  .section-heading > button {
    width: 100%;
  }

  .hint-line {
    line-height: 1.35;
  }

  .food-matches {
    grid-template-columns: 1fr;
  }

  .food-match {
    min-height: 58px;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .entry-row {
    grid-template-columns: 1fr auto;
    gap: 6px 10px;
    min-height: 0;
    padding: 9px 10px;
  }

  .entry-row span {
    grid-column: 1;
  }

  .entry-row .danger {
    grid-row: 1 / span 2;
    grid-column: 2;
    align-self: center;
  }

  .entry-list {
    max-height: 300px;
  }

  .chart-panel canvas {
    height: 220px;
  }

  .source-note {
    margin: 14px 2px 0;
  }
}

@media (max-width: 390px) {
  .summary-panel {
    grid-template-columns: 1fr;
  }

  .ring-wrap {
    width: 104px;
    justify-self: start;
  }

  .button-row {
    grid-template-columns: 1fr;
  }
}
