:root {
  color-scheme: light;
  --bg: #f2f4f1;
  --panel: #ffffff;
  --panel-alt: #eef2ef;
  --text: #111816;
  --muted: #6c7672;
  --line: #dce4e0;
  --accent: #0f766e;
  --accent-strong: #14536b;
  --good: #16824d;
  --bad: #be2f25;
  --warn: #c79316;
  --shadow: 0 16px 38px rgba(26, 39, 35, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #050706;
  --panel: #111614;
  --panel-alt: #1c2320;
  --text: #f4f7f5;
  --muted: #aab4af;
  --line: #2d3834;
  --accent: #18a98f;
  --accent-strong: #4f99b6;
  --good: #32b76d;
  --bad: #ff7167;
  --warn: #e7b84a;
  --shadow: 0 16px 38px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
  padding: calc(env(safe-area-inset-top) + 12px) 14px calc(env(safe-area-inset-bottom) + 88px);
}

.topbar {
  position: relative;
  max-width: 860px;
  margin: 0 auto 14px;
  min-height: 42px;
  text-align: center;
}

.topbar-title {
  padding: 0 48px;
}

.topbar p {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.18rem, 4vw, 1.55rem);
  line-height: 1.15;
}

.info-button {
  position: absolute;
  top: 0;
  right: 0;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--accent);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.12rem;
  font-style: italic;
  font-weight: 800;
  line-height: 1;
}

main {
  max-width: 860px;
  margin: 0 auto;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.header-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.header-tile {
  min-height: 58px;
  border: 1px solid transparent;
  border-radius: 16px;
  padding: 8px;
  font-weight: 800;
  line-height: 1.1;
}

.header-tile.plain {
  background: var(--panel);
  color: var(--text);
  border-color: var(--line);
}

.header-tile.primary,
.primary-action {
  background: var(--accent);
  color: white;
}

.header-tile.secondary {
  background: var(--accent-strong);
  color: white;
}

.service-filter,
.service-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
  padding: 6px;
  border-radius: 14px;
  background: var(--panel-alt);
}

.service-list {
  grid-template-columns: 1fr;
  background: transparent;
  padding: 0;
}

.chip,
.service-row,
.button-list button,
.button-like,
.file-row {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  min-height: 36px;
  padding: 8px 12px;
  font-weight: 700;
}

.chip.active,
.service-row.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.service-row {
  display: flex;
  justify-content: space-between;
  border-radius: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 12px;
}

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

.metric {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 72px;
  padding: 9px 7px;
  border-radius: 10px;
  background: var(--panel-alt);
  text-align: center;
}

.metric.good {
  background: var(--good);
  color: white;
}

.metric.bad {
  background: rgba(190, 47, 37, 0.12);
}

.metric span {
  color: inherit;
  opacity: 0.72;
  font-size: 0.75rem;
}

.metric strong {
  margin-top: 4px;
  font-size: 1rem;
  line-height: 1.05;
}

.panel {
  margin-bottom: 12px;
  padding: 14px;
  border-radius: 18px;
  background: var(--panel-alt);
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  text-align: center;
}

.panel p {
  margin: 0;
}

.chart {
  min-height: 190px;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 150px;
  color: var(--muted);
  text-align: center;
}

.shift-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 48px));
  gap: 7px;
}

.shift-tile,
.add-tile {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.add-tile {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-size: 1.45rem;
}

.shift-tile.peak {
  background: rgba(231, 184, 74, 0.28);
}

.shift-tile.low {
  background: rgba(190, 47, 37, 0.15);
}

.stack {
  display: grid;
  gap: 12px;
}

.row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.between {
  justify-content: space-between;
}

.history-card {
  padding: 15px;
  border: 0;
  border-radius: 18px;
  background: var(--panel-alt);
  color: var(--text);
  width: 100%;
}

.history-open {
  width: 100%;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.history-card header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 1.08rem;
  font-weight: 800;
}

.history-values {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.history-values div {
  text-align: center;
}

.history-values span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.history-delete {
  display: block;
  margin: 12px 0 0 auto;
  min-height: 32px;
  border: 0;
  border-radius: 10px;
  padding: 7px 12px;
  background: rgba(190, 47, 37, 0.12);
  color: var(--bad);
  font-weight: 800;
}

.field-row,
.file-row,
.readonly {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
}

.field-row span,
.field-column span {
  font-weight: 700;
}

.field-row small,
.hint,
.status,
.warning {
  color: var(--muted);
  font-size: 0.82rem;
}

.warning {
  color: var(--bad);
  font-weight: 700;
}

.field-row input:not([type="checkbox"]),
.field-row select {
  width: min(42vw, 180px);
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: right;
  font-weight: 700;
}

.field-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.field-column {
  display: grid;
  gap: 8px;
}

.field-column textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--panel);
  color: var(--text);
}

.file-row input {
  display: none;
}

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

.button-list button,
.button-like,
.full {
  width: 100%;
  border-radius: 12px;
  text-align: center;
}

.full {
  min-height: 46px;
  border: 0;
  padding: 10px 14px;
  font-weight: 800;
}

.switch input {
  display: none;
}

.switch span {
  display: block;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  transition: transform 0.18s ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 7px 8px calc(env(safe-area-inset-bottom) + 7px);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.tabbar button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.tabbar button span {
  display: none !important;
}

.tabbar button.active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

dialog {
  width: min(92vw, 520px);
  max-height: min(86vh, 760px);
  border: 0;
  border-radius: 20px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog form,
.detail-dialog {
  display: grid;
  gap: 12px;
  padding: 16px;
  max-height: min(86vh, 760px);
  overflow: auto;
}

.dialog-header,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.dialog-header button,
.dialog-actions button {
  border: 0;
  border-radius: 10px;
  padding: 9px 12px;
  background: var(--panel-alt);
  color: var(--text);
  font-weight: 800;
}

.dialog-actions .primary-action {
  color: white;
}

.about-text {
  display: grid;
  gap: 14px;
  max-height: min(62vh, 560px);
  overflow: auto;
  padding-right: 4px;
  line-height: 1.45;
}

.about-text details {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel-alt);
}

.about-text summary,
.about-text p,
.about-text ul {
  margin: 0;
}

.about-text summary {
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 800;
}

.about-text details[open] summary {
  margin-bottom: 8px;
}

.about-text ul {
  padding-left: 1.1rem;
}

.about-text li + li {
  margin-top: 4px;
}

.popup-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel-alt);
}

.popup-section h3 {
  margin: 0;
  text-align: center;
  font-size: 1rem;
}

.danger {
  color: white !important;
  background: var(--bad) !important;
}

.hidden,
.visually-hidden {
  display: none !important;
}

svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-dot {
  cursor: pointer;
}

@media (max-width: 560px) {
  #app {
    padding-left: 10px;
    padding-right: 10px;
  }

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

  .header-grid {
    gap: 6px;
  }

  .header-tile {
    min-height: 56px;
    font-size: 0.9rem;
  }

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