:root {
  color-scheme: dark;
  --bg: #0e1118;
  --surface: rgba(19, 24, 35, 0.84);
  --surface-soft: rgba(255, 255, 255, 0.055);
  --surface-strong: rgba(255, 255, 255, 0.105);
  --border: rgba(255, 255, 255, 0.13);
  --border-strong: rgba(255, 255, 255, 0.22);
  --text: #f7f8fc;
  --muted: #a9b0c1;
  --subtle: #788197;
  --accent: #4ed7ca;
  --accent-strong: #94f2b8;
  --warning: #f2c66d;
  --danger: #ff7f9a;
  --shadow: 0 22px 64px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% -10%, rgba(78, 215, 202, 0.24), transparent 26rem),
    radial-gradient(circle at 92% 4%, rgba(255, 127, 154, 0.16), transparent 22rem),
    linear-gradient(145deg, #0e1118 0%, #151a24 52%, #10151d 100%);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

.hero {
  min-height: 188px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.045)),
    rgba(12, 16, 24, 0.76);
  box-shadow: var(--shadow);
}

.hero h1,
.section-header h2,
.entry-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.hero h1 {
  max-width: 760px;
  font-size: clamp(2.4rem, 6vw, 4.8rem);
  line-height: 0.98;
  font-weight: 900;
}

.intro {
  max-width: 620px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.section-copy {
  max-width: 46rem;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.status-message {
  min-height: 0;
  margin: 10px 0 -8px;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 750;
}

.status-message:empty {
  display: none;
}

.status-message[data-tone="error"] {
  color: var(--danger);
}

.data-menu {
  position: relative;
  flex: 0 0 auto;
}

.data-menu summary {
  min-height: 40px;
  display: grid;
  place-items: center;
  padding: 0 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  font-size: 0.9rem;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
}

.data-menu summary::-webkit-details-marker {
  display: none;
}

.data-menu summary:hover,
.data-menu summary:focus-visible,
.data-menu[open] summary {
  color: var(--text);
  border-color: rgba(78, 215, 202, 0.42);
  background: rgba(255, 255, 255, 0.09);
  outline: none;
  box-shadow: 0 0 0 3px rgba(70, 214, 201, 0.18);
}

.data-menu-panel {
  position: absolute;
  z-index: 10;
  right: 0;
  top: calc(100% + 8px);
  width: 180px;
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(16, 20, 30, 0.98);
  box-shadow: var(--shadow);
}

.tabs {
  position: sticky;
  top: env(safe-area-inset-top);
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 14px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(14, 18, 28, 0.86);
  backdrop-filter: blur(18px);
}

.tab-button {
  min-height: 44px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  font-weight: 850;
}

.tab-button.active {
  color: #08110f;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 8px 18px rgba(78, 215, 202, 0.17);
}

.tab-button:not(.active):hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
}

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

.tab-panel[hidden] {
  display: none;
}

.entry-panel,
.chart-panel,
.trend-panel,
.history-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
}

.entry-panel {
  padding: 22px;
}

.entry-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
}

.save-count {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 900;
  padding: 8px 11px;
  border: 1px solid rgba(124, 247, 178, 0.32);
  border-radius: 999px;
  background: rgba(124, 247, 178, 0.09);
}

.measurement-form {
  display: grid;
  gap: 18px;
  margin-top: 22px;
}

.form-top {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 12px;
}

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

label span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.075);
  padding: 0 12px;
  outline: none;
  font-size: 16px;
}

input:hover,
select:hover {
  border-color: var(--border-strong);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(70, 214, 201, 0.18);
  outline: none;
}

select option {
  color: #111720;
}

input[type="range"] {
  min-height: 38px;
  padding: 0;
  accent-color: var(--accent);
}

input[type="range"]:focus-visible {
  box-shadow: none;
  outline: 2px solid rgba(78, 215, 202, 0.7);
  outline-offset: 3px;
}

output {
  color: var(--accent-strong);
  font-size: 1.5rem;
  font-weight: 900;
}

.number-input {
  max-width: 108px;
  text-align: right;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, opacity 160ms ease;
}

.primary-button {
  color: #07110f;
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 10px 26px rgba(78, 215, 202, 0.2);
}

.primary-button:not(:disabled):hover,
.secondary-button:not(:disabled):hover,
.danger-button:not(:disabled):hover,
.icon-button:not(:disabled):hover {
  transform: translateY(-1px);
}

.secondary-button {
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.075);
  padding: 0 16px;
}

.secondary-button:hover {
  border-color: rgba(78, 215, 202, 0.42);
  background: rgba(255, 255, 255, 0.105);
}

.compact-button {
  min-height: 40px;
  padding: 0 12px;
}

.save-button {
  min-height: 54px;
  font-size: 1rem;
}

.batch-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.body-inputs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.body-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px 14px;
  align-items: center;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

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

.body-row.selected {
  border-color: rgba(70, 214, 201, 0.72);
  background:
    linear-gradient(135deg, rgba(70, 214, 201, 0.13), rgba(255, 255, 255, 0.07)),
    rgba(255, 255, 255, 0.06);
}

.body-row.invalid {
  border-color: rgba(255, 127, 154, 0.72);
  background:
    linear-gradient(135deg, rgba(255, 127, 154, 0.12), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.055);
}

.row-check {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
  line-height: 1.2;
}

.info-button {
  width: 28px;
  min-height: 28px;
  flex: 0 0 auto;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.82rem;
  font-weight: 900;
  line-height: 1;
  text-transform: lowercase;
}

.info-button:hover,
.info-button:focus-visible {
  color: #07110f;
  border-color: var(--accent);
  background: var(--accent);
}

.info-button[aria-expanded="true"] {
  color: #07110f;
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.row-check input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.checkmark {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.08);
}

.row-check input:checked + .checkmark {
  border-color: var(--accent);
  background:
    linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 0 0 3px rgba(70, 214, 201, 0.16);
}

.row-check input:focus-visible + .checkmark {
  box-shadow: 0 0 0 3px rgba(70, 214, 201, 0.22);
}

.row-check input:checked + .checkmark::after {
  content: "";
  display: block;
  width: 11px;
  height: 6px;
  margin: 6px 0 0 5px;
  border-left: 3px solid #07110f;
  border-bottom: 3px solid #07110f;
  transform: rotate(-45deg);
}

.row-control {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 10px;
  align-items: center;
}

.body-row output {
  color: var(--accent-strong);
  font-size: 1.1rem;
  font-weight: 900;
  white-space: nowrap;
}

.row-tip {
  grid-column: 1 / -1;
  margin: 0;
  padding: 10px 11px;
  color: #d8deec;
  border: 1px solid rgba(78, 215, 202, 0.22);
  border-radius: 8px;
  background: rgba(78, 215, 202, 0.075);
  font-size: 0.88rem;
  line-height: 1.4;
}

.number-input[aria-invalid="true"] {
  border-color: rgba(255, 127, 154, 0.86);
  background: rgba(255, 127, 154, 0.09);
}

.danger-button {
  color: #ffe8ee;
  border: 1px solid rgba(255, 111, 143, 0.45);
  background: rgba(255, 111, 143, 0.105);
  padding: 0 14px;
}

.danger-button:hover,
.icon-button:hover {
  border-color: rgba(255, 127, 154, 0.62);
  background: rgba(255, 127, 154, 0.16);
}

.icon-button {
  width: 38px;
  color: #ffdce6;
  border: 1px solid rgba(255, 111, 143, 0.36);
  background: rgba(255, 111, 143, 0.1);
}

.content {
  display: grid;
  gap: 18px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.trend-panel .summary-grid {
  padding: 16px;
}

.metric-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  padding: 15px;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}

.metric-card:hover,
.metric-card.active {
  border-color: rgba(70, 214, 201, 0.72);
  background: var(--surface-strong);
}

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

.metric-value {
  font-size: 1.65rem;
  font-weight: 900;
}

.metric-delta {
  color: var(--accent-strong);
  font-size: 0.84rem;
  font-weight: 800;
}

.metric-delta.neutral {
  color: var(--muted);
}

.section-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 0;
}

.section-header select {
  max-width: 260px;
}

.chart-wrap {
  position: relative;
  min-height: 380px;
  padding: 8px 16px 18px;
}

canvas {
  width: 100%;
  height: 380px;
  display: block;
}

.table-wrap {
  position: relative;
  overflow-x: auto;
  padding: 12px 16px 18px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  color: #eef1fb;
}

.empty-state {
  margin: 20px auto;
  max-width: 34rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.45;
}

.chart-wrap .empty-state {
  position: absolute;
  inset: 48% 20px auto;
  margin: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 16px, 760px);
    padding: 8px 0 22px;
  }

  .hero,
  .section-header {
    display: grid;
  }

  .hero {
    min-height: 0;
    gap: 16px;
    padding: 18px;
  }

  .hero h1 {
    font-size: clamp(2.05rem, 12vw, 3.2rem);
    line-height: 1;
  }

  .intro {
    margin-top: 10px;
    font-size: 0.98rem;
    line-height: 1.45;
  }

  .section-header {
    justify-content: stretch;
  }

  .data-menu {
    width: max-content;
    justify-self: start;
  }

  .data-menu-panel {
    left: 0;
    right: auto;
  }

  .entry-panel,
  .chart-panel,
  .trend-panel,
  .history-panel {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.24);
  }

  .entry-panel {
    padding: 15px;
  }

  .entry-heading {
    align-items: start;
  }

  .form-top,
  .body-inputs {
    grid-template-columns: 1fr;
  }

  .body-row {
    padding: 12px;
  }

  .batch-toolbar {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

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

  .metric-card {
    min-height: 98px;
    padding: 12px;
    gap: 9px;
  }

  .metric-name,
  .metric-delta {
    font-size: 0.75rem;
  }

  .metric-value {
    font-size: 1.32rem;
  }

  .section-header {
    padding: 17px 16px 0;
  }

  .section-header select {
    max-width: none;
  }

  .chart-wrap {
    min-height: 292px;
    padding: 6px 8px 12px;
  }

  canvas {
    height: 292px;
  }

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

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tr {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-soft);
  }

  tr + tr {
    margin-top: 10px;
  }

  td {
    display: grid;
    grid-template-columns: 104px 1fr;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.76rem;
    font-weight: 850;
    text-transform: uppercase;
  }

  td:last-child {
    display: flex;
    justify-content: flex-end;
    padding-top: 10px;
  }

  td:last-child::before {
    content: "";
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: min(100% - 12px, 430px);
  }

  .hero {
    padding: 16px;
  }

  .entry-heading {
    display: grid;
  }

  .save-count {
    width: max-content;
  }

  .section-copy {
    font-size: 0.86rem;
  }

  .row-control {
    grid-template-columns: 1fr 88px;
    gap: 9px;
  }

  .number-input {
    max-width: 88px;
  }

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

  .batch-toolbar {
    gap: 8px;
  }

  .tabs {
    margin-top: 10px;
    padding: 5px;
  }

  .tab-button {
    min-height: 42px;
    font-size: 0.92rem;
  }

  .secondary-button,
  .danger-button {
    padding-inline: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
