:root {
  color-scheme: light;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
  scroll-padding-bottom: calc(96px + var(--safe-bottom));
}

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

.main-content,
.view,
.panel,
.workout-layout > *,
.water-actions > * {
  min-width: 0;
}

.bottom-nav {
  display: none;
}

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

.water-progress {
  height: 10px;
  margin: 14px 0;
}

.water-progress i {
  background: #367b85;
}

.water-actions,
.profile-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.water-actions form {
  display: flex;
  flex: 1 1 200px;
  gap: 8px;
  min-width: 0;
}

.water-actions form input {
  width: 100%;
  min-width: 0;
}

.workout-layout,
.workout-side {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.workout-side {
  grid-template-columns: minmax(0, 1fr);
  margin-top: 0;
}

.workout-form {
  display: grid;
  align-content: start;
  gap: 12px;
}

.workout-form h2,
.workout-side h2 {
  margin-top: 0;
}

.workout-form label {
  display: grid;
  gap: 6px;
}

.workout-form input,
.workout-form select,
.water-actions input,
.profile-form input,
.profile-form select {
  max-width: 100%;
  min-height: 48px;
  font-size: 16px;
}

.check-field {
  display: flex !important;
  align-items: center;
  min-height: 48px;
}

.check-field input {
  width: 24px;
  height: 24px;
}

.workout-set-list {
  padding-left: 20px;
}

.workout-set-list li,
.workout-history-row {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.workout-history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.workout-history-row p {
  margin-bottom: 0;
  color: var(--muted);
}

.profile-tools a {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  color: var(--deep);
}

.pwa-update-banner {
  position: fixed;
  z-index: 50;
  right: 16px;
  bottom: calc(20px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .18);
}

.pwa-update-banner button {
  min-height: 48px;
  padding: 8px 14px;
  border: 0;
  background: var(--deep);
  color: #fff;
}

button,
a,
input,
select,
textarea {
  scroll-margin-bottom: calc(112px + var(--safe-bottom));
}

:focus-visible {
  outline: 3px solid #145b72;
  outline-offset: 3px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: #17201c;
    --surface: #202a25;
    --ink: #edf3ee;
    --muted: #b4c0b8;
    --line: #46534a;
    --deep: #b7d5c2;
    --green: #92c6ad;
  }

  :root:not([data-theme="light"]) body,
  :root:not([data-theme="light"]) .app-shell {
    color: var(--ink);
    background: #17201c;
  }

  :root:not([data-theme="light"]) .panel,
  :root:not([data-theme="light"]) .macro-card,
  :root:not([data-theme="light"]) .week-day,
  :root:not([data-theme="light"]) .profile-form input,
  :root:not([data-theme="light"]) .profile-form select,
  :root:not([data-theme="light"]) .workout-form input,
  :root:not([data-theme="light"]) .workout-form select,
  :root:not([data-theme="light"]) .water-actions input {
    background: var(--surface);
    color: var(--ink);
  }

  :root:not([data-theme="light"]) .tip-panel {
    background: #294d45;
    color: #fff;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #17201c;
  --surface: #202a25;
  --ink: #edf3ee;
  --muted: #b4c0b8;
  --line: #46534a;
  --deep: #b7d5c2;
  --green: #92c6ad;
}

:root[data-theme="dark"] body,
:root[data-theme="dark"] .app-shell {
  color: var(--ink);
  background: #17201c;
}

:root[data-theme="dark"] .panel,
:root[data-theme="dark"] .macro-card,
:root[data-theme="dark"] .week-day,
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea {
  background: var(--surface);
  color: var(--ink);
}

:root[data-theme="dark"] .tip-panel {
  background: #294d45;
  color: #fff;
}

@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .main-content {
    max-width: none;
    padding: calc(8px + var(--safe-top)) 24px calc(96px + var(--safe-bottom));
  }

  .bottom-nav {
    position: fixed;
    z-index: 40;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 6px 8px calc(6px + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
  }

  .bottom-nav .nav-item {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 2px;
    min-width: 0;
    min-height: 54px;
    padding: 4px 2px;
    font-size: 10px;
    text-align: center;
    white-space: nowrap;
  }

  .bottom-nav .nav-item span {
    width: auto;
    font-size: 18px;
  }

  .workout-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 620px) {
  .sidebar {
    display: none;
  }

  .main-content {
    width: 100%;
    max-width: none;
    padding: calc(10px + var(--safe-top)) 14px calc(96px + var(--safe-bottom));
  }

  .topbar {
    height: 56px;
    border: 0;
  }

  .view {
    padding-top: 18px;
  }

  .bottom-nav {
    box-shadow: 0 -5px 20px rgba(25, 43, 35, .08);
  }

  .bottom-nav .nav-item {
    display: grid;
    align-content: center;
    justify-items: center;
    gap: 2px;
    min-width: 0;
    min-height: 54px;
    padding: 4px 2px;
    border-radius: 4px;
    font-size: 10px;
    text-align: center;
    white-space: nowrap;
  }

  .bottom-nav .nav-item span {
    width: auto;
    font-size: 18px;
  }

  button,
  .primary-btn,
  .outline-btn,
  .text-btn,
  .nav-item,
  .week-day,
  .category {
    min-height: 48px;
  }

  input,
  select,
  textarea,
  .profile-form input,
  .profile-form select,
  .workout-form input,
  .workout-form select {
    min-height: 48px;
    font-size: 16px !important;
  }

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

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

  .water-actions form {
    grid-column: 1 / -1;
  }

  .water-actions .outline-btn {
    padding-inline: 4px;
    font-size: 12px;
  }

  .workout-layout,
  .workout-side {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-heading h1 {
    font-size: 32px;
  }

  .pwa-update-banner {
    right: 12px;
    bottom: calc(82px + var(--safe-bottom));
    left: 12px;
    justify-content: space-between;
  }
}

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