:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f3f5f4);
  --text: var(--tg-theme-text-color, #18201f);
  --muted: var(--tg-theme-hint-color, #66706d);
  --panel: var(--tg-theme-secondary-bg-color, #ffffff);
  --button: var(--tg-theme-button-color, #b85d3f);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(24, 32, 31, .11);
  --line-strong: rgba(24, 32, 31, .18);
  --field: #f9faf9;
  --soft: rgba(184, 93, 63, .12);
  --soft-strong: rgba(184, 93, 63, .25);
  --accent-coral: #b85d3f;
  --accent-honey: #b87924;
  --accent-rose: #ad4e68;
  --accent-sage: #6d8b62;
  --accent-plum: #835b80;
  --tint-coral: rgba(184, 93, 63, .13);
  --tint-honey: rgba(184, 121, 36, .14);
  --tint-rose: rgba(173, 78, 104, .12);
  --tint-sage: rgba(109, 139, 98, .13);
  --tint-plum: rgba(131, 91, 128, .12);
  --danger: #b42318;
  --warn: #8a5a10;
  --success: #157f3b;
  --radius: 8px;
  --shadow: 0 8px 22px rgba(18, 26, 31, .055);
  --shadow-quiet: 0 1px 2px rgba(18, 26, 31, .045);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--tg-theme-bg-color, #111816);
    --text: var(--tg-theme-text-color, #edf2ef);
    --muted: var(--tg-theme-hint-color, #a8b2ae);
    --panel: var(--tg-theme-secondary-bg-color, #18211f);
    --line: rgba(237, 242, 239, .12);
    --line-strong: rgba(237, 242, 239, .2);
    --field: #151c1a;
    --tint-coral: rgba(231, 127, 91, .17);
    --tint-honey: rgba(226, 158, 83, .17);
    --tint-rose: rgba(222, 118, 148, .16);
    --tint-sage: rgba(139, 174, 126, .16);
    --tint-plum: rgba(181, 135, 176, .16);
    --shadow: 0 10px 24px rgba(0, 0, 0, .18);
    --shadow-quiet: 0 1px 2px rgba(0, 0, 0, .22);
  }
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  text-rendering: optimizeLegibility;
}
button, input, textarea, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
h1 {
  font-size: 28px;
  line-height: 1.12;
  font-weight: 750;
}
h2 {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 740;
}
h3 {
  font-size: 14px;
  margin: 18px 0 9px;
  color: var(--muted);
  font-weight: 720;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }

.app-shell {
  width: min(760px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 14px 104px;
}
.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 1px 16px;
}
.app-header > div { min-width: 0; }
.app-header .muted {
  margin-top: 5px;
  max-width: 42rem;
}
.kicker {
  margin: 0 0 5px;
  color: var(--button);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}
.icon-button {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-quiet);
  font-size: 21px;
  line-height: 1;
}

.notice {
  margin: 0 0 13px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow-quiet);
  overflow-wrap: anywhere;
}
.notice.error { border-color: rgba(180, 35, 24, .32); color: var(--danger); }
.notice.success { border-color: rgba(21, 127, 59, .3); color: var(--success); }
.view { display: block; }

.hero-panel,
.details,
.item,
.info-block,
.empty-state,
.stat,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.hero-panel {
  padding: 18px;
  margin-bottom: 13px;
  display: grid;
  gap: 11px;
  border-color: rgba(22, 134, 111, .18);
  background:
    linear-gradient(0deg, var(--tint-coral), transparent 42%),
    var(--panel);
}
.hero-panel.compact { margin-top: 11px; }
.hero-panel h2 { margin-top: 1px; }
.week-card { box-shadow: none; }
.hero-panel .week-card {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 11px 0 0;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.badge {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 25px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--button);
  font-size: 12.5px;
  font-weight: 750;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.badge-row .badge:nth-child(2n) { background: var(--tint-honey); color: var(--accent-honey); }
.badge.warn { background: rgba(138, 90, 16, .12); color: var(--warn); }
.badge.danger { background: rgba(180, 35, 24, .12); color: var(--danger); }

.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.menu-item {
  width: 100%;
  min-height: 88px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  text-align: left;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.menu-item::before {
  content: "";
  width: 5px;
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent-coral);
}
.menu-item:nth-child(2)::before { background: var(--accent-honey); }
.menu-item:nth-child(3)::before { background: var(--accent-rose); }
.menu-item:nth-child(4)::before { background: var(--accent-sage); }
.menu-item:nth-child(5)::before { background: var(--accent-plum); }
.menu-item:nth-child(1) { background: linear-gradient(0deg, var(--tint-coral), transparent 62%), var(--panel); }
.menu-item:nth-child(2) { background: linear-gradient(0deg, var(--tint-honey), transparent 62%), var(--panel); }
.menu-item:nth-child(3) { background: linear-gradient(0deg, var(--tint-rose), transparent 62%), var(--panel); }
.menu-item:nth-child(4) { background: linear-gradient(0deg, var(--tint-sage), transparent 62%), var(--panel); }
.menu-item:nth-child(5) { background: linear-gradient(0deg, var(--tint-plum), transparent 62%), var(--panel); }
.menu-item strong {
  font-size: 16px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.menu-item span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.section-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 13px;
}
.section-row h2 { min-width: 0; overflow-wrap: anywhere; }
.details { overflow: hidden; }
.detail-row {
  display: grid;
  grid-template-columns: minmax(112px, 190px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: 0; }
.detail-row span {
  color: var(--muted);
  font-size: 14px;
}
.detail-row strong {
  font-weight: 680;
  overflow-wrap: anywhere;
}

.form-grid { display: grid; gap: 11px; }
.form-grid.panel { padding: 14px; }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 640;
}
input,
textarea,
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--text);
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04);
}
textarea {
  min-height: 92px;
  resize: vertical;
  line-height: 1.4;
}
select { cursor: pointer; }
.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--button);
  box-shadow: 0 0 0 3px var(--soft);
}
input:disabled {
  color: var(--muted);
  opacity: .82;
}

button {
  min-height: 44px;
  max-width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  background: var(--button);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 750;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: var(--shadow-quiet);
}
button.secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}
button.ghost {
  min-height: 40px;
  background: transparent;
  color: var(--button);
  padding-inline: 6px;
  box-shadow: none;
}
button.danger { color: var(--danger); }
button:disabled {
  opacity: .55;
  cursor: wait;
}
@media (hover: hover) {
  button:not(:disabled):hover { filter: brightness(.98); }
  .menu-item:hover,
  .item.with-actions:hover {
    border-color: var(--line-strong);
  }
}

.action-list,
.stack {
  display: grid;
  gap: 10px;
}
.action-list { margin-top: 13px; }
.item {
  display: grid;
  gap: 7px;
  padding: 14px;
}
.item strong {
  font-size: 15px;
  line-height: 1.28;
  overflow-wrap: anywhere;
}
.item span,
.item p {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.item.with-actions {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}
.inline-actions button { min-width: 96px; }
.info-block {
  display: grid;
  gap: 6px;
  padding: 14px;
  border-left: 5px solid var(--accent-honey);
  background: linear-gradient(0deg, var(--tint-honey), transparent 68%), var(--panel);
}
.info-block span {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.empty-state {
  padding: 24px 16px;
  text-align: center;
}
.empty-state h2 { font-size: 19px; }
.empty-state p {
  margin: 6px auto 0;
  max-width: 28rem;
  color: var(--muted);
}
.empty-state button { margin-top: 14px; }
.details > .empty-state,
.hero-panel > .empty-state {
  border: 0;
  box-shadow: none;
  background: transparent;
}
.danger-zone { margin-top: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.stat {
  display: grid;
  gap: 4px;
  padding: 13px;
}
.stat strong {
  font-size: 24px;
  line-height: 1.1;
}
.stat span {
  color: var(--muted);
  font-size: 13px;
}
.attention-panel { padding: 14px; }
.attention-panel h3 { margin-top: 0; }
.attention-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}
.attention-item {
  min-height: 68px;
  display: grid;
  gap: 2px;
  align-content: center;
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--button);
  text-align: left;
}
.attention-item strong { font-size: 22px; }
.attention-item span {
  color: var(--text);
  font-size: 13px;
}
.attention-item.quiet {
  background: var(--panel);
  color: var(--muted);
}
.inline-details {
  display: grid;
  border-top: 1px solid var(--line);
}
.inline-details .detail-row { padding-inline: 0; }

.preview-box {
  display: grid;
  gap: 6px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soft);
}
.preview-box.error {
  background: rgba(180, 35, 24, .08);
  border-color: rgba(180, 35, 24, .3);
}
.preview-box.ok {
  background: rgba(21, 127, 59, .08);
  border-color: rgba(21, 127, 59, .3);
}
.preview-box span,
.preview-box li {
  color: var(--muted);
  overflow-wrap: anywhere;
}
.preview-box ul {
  margin: 0;
  padding-left: 18px;
}
.segmented {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 2px 0 10px;
  scrollbar-width: none;
}
.segmented button {
  white-space: nowrap;
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
}
.segmented button.active {
  background: var(--soft);
  color: var(--button);
  border-color: var(--soft-strong);
}
.admin-content { display: grid; gap: 13px; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: end;
}
.toolbar > * { flex: 1 1 150px; }
.table-list {
  display: grid;
  gap: 9px;
}
.code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  width: min(760px, 100%);
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 -8px 22px rgba(18, 26, 31, .055);
}
.bottom-nav button {
  min-width: 0;
  min-height: 50px;
  padding: 7px 4px;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
  box-shadow: none;
  white-space: normal;
  display: flex;
  align-items: center;
  justify-content: center;
}
.bottom-nav button.active {
  background: var(--soft);
  color: var(--button);
}
.bottom-nav button:nth-child(2).active { background: var(--tint-honey); color: var(--accent-honey); }
.bottom-nav button:nth-child(3).active { background: var(--tint-rose); color: var(--accent-rose); }
.bottom-nav button:nth-child(4).active { background: var(--tint-sage); color: var(--accent-sage); }
.bottom-nav button:nth-child(5).active { background: var(--tint-plum); color: var(--accent-plum); }

@media (max-width: 720px) {
  .app-shell { padding: 14px 12px 100px; }
  .app-header { padding-bottom: 14px; }
  h1 { font-size: 24px; }
  .menu-grid,
  .admin-grid,
  .stats,
  .attention-grid {
    grid-template-columns: 1fr;
  }
  .hero-panel { padding: 16px; }
  .detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .item.with-actions { grid-template-columns: 1fr; }
  .inline-actions { justify-content: stretch; }
  .inline-actions button {
    flex: 1 1 128px;
    min-width: 0;
  }
}

@media (max-width: 380px) {
  body { font-size: 14px; }
  .app-shell { padding-inline: 10px; }
  .section-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .section-row button { width: 100%; }
  .bottom-nav {
    gap: 3px;
    padding-inline: 5px;
  }
  .bottom-nav button {
    min-height: 52px;
    font-size: 11px;
    padding-inline: 2px;
  }
}
