/* Telegram's theme colors when they are there (light or dark), the mockup's otherwise. */
:root {
  --page: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #5f5f66);
  --accent: var(--tg-theme-link-color, #1d6fb8);
  --button: var(--tg-theme-button-color, #1d6fb8);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #b3261e);
  --header: var(--tg-theme-section-header-text-color, var(--hint));
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --soft: color-mix(in srgb, var(--hint) 16%, transparent);
  --ok: #2b7a3d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.35 -apple-system, "SF Pro Text", Roboto, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 640px;
  margin: 0 auto;
}

h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.3px; }
h2 { margin: 0; font-size: 22px; font-weight: 700; }
p { margin: 0; }

.hint { color: var(--hint); font-size: 14px; }
.caption { color: var(--hint); font-size: 13px; padding: 0 4px; }
.section { display: flex; flex-direction: column; gap: 6px; }
.section-title { color: var(--header); font-size: 13px; text-transform: uppercase; padding: 0 4px; }
.card { background: var(--card); border-radius: 12px; }
.error { color: var(--danger); font-size: 14px; padding: 0 4px; }

.segmented { display: flex; gap: 4px; padding: 3px; background: var(--soft); border-radius: 10px; }
.segmented button {
  flex: 1; min-height: 36px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text); font: inherit; font-size: 14px;
}
.segmented button[aria-pressed="true"] { background: var(--card); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile { background: var(--card); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile span:first-child { color: var(--hint); font-size: 12px; }
.tile span:last-child { font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.tiles:not(.three) .tile span:last-child { font-size: 26px; }

.chart { padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; height: 100%; }
.bar i { display: block; width: 100%; min-height: 2px; background: color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 4px 4px 0 0; }
.bar.today i { background: var(--accent); }
.bar b { font-weight: 400; font-size: 11px; color: var(--hint); }
.days { display: flex; gap: 4px; font-size: 11px; color: var(--hint); }
.days span { flex: 1; text-align: center; min-width: 0; overflow: hidden; }

.list { display: flex; flex-direction: column; }
.row {
  display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; min-height: 44px;
  color: var(--text); text-decoration: none; border: 0; background: none; font: inherit; text-align: left; width: 100%;
}
.row + .row { border-top: 1px solid var(--line); }
.row-top { display: flex; align-items: baseline; gap: 8px; }
.row-top .name { flex: 1; font-weight: 600; font-size: 16px; min-width: 0; overflow-wrap: anywhere; }
.row-top .name small { font-weight: 400; color: var(--hint); font-size: 14px; }
.row-top .num { color: var(--hint); font-size: 14px; white-space: nowrap; }
.meter { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.meter .track { flex: 1; height: 6px; background: var(--soft); border-radius: 3px; display: flex; overflow: hidden; }
.meter .fill { background: var(--accent); border-radius: 3px; }
.meter.full .fill { background: var(--danger); }
.meter.full span { color: var(--danger); font-weight: 600; }

input[type="search"] {
  height: 40px; border: 0; border-radius: 10px; background: var(--soft); padding: 0 12px;
  font: inherit; color: var(--text); width: 100%;
}

.primary {
  min-height: 48px; border: 0; border-radius: 12px; background: var(--button); color: var(--button-text);
  font: inherit; font-size: 16px; font-weight: 600;
}
.danger-button {
  min-height: 48px; border: 0; border-radius: 12px; background: var(--card); color: var(--danger);
  font: inherit; font-size: 16px; font-weight: 600;
}
.link-button { border: 0; background: none; color: var(--accent); font: inherit; min-height: 44px; padding: 0 4px; text-align: left; }

.stepper { display: flex; align-items: center; gap: 10px; padding: 6px 14px; min-height: 48px; }
.stepper + .stepper, .stepper + .toggle, .toggle + .stepper { border-top: 1px solid var(--line); }
.stepper > span:first-child { flex: 1; font-size: 16px; }
.stepper button {
  width: 44px; height: 36px; border: 0; border-radius: 8px; background: var(--soft); color: var(--text);
  font: inherit; font-size: 20px;
}
.stepper output { width: 36px; text-align: center; font-weight: 600; font-size: 16px; }
.toggle { display: flex; align-items: center; gap: 10px; padding: 6px 14px; min-height: 48px; font-size: 16px; }
.toggle span { flex: 1; }
.toggle input { width: 22px; height: 22px; }

.person-head { display: flex; align-items: center; gap: 14px; }
.avatar {
  width: 56px; height: 56px; border-radius: 28px; background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; flex: none;
}
.person-head > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }

.request-top { display: flex; gap: 8px; }
.request-top .site { flex: 1; font-weight: 600; }
.request-top .when { color: var(--hint); font-size: 13px; }
.request-line { font-size: 14px; color: var(--hint); }
.request-line .ok { color: var(--ok); font-weight: 600; }
.request-line .bad { color: var(--danger); font-weight: 600; }
.plain { padding: 14px; font-size: 16px; }
.preview { padding: 12px 14px; color: var(--hint); }

.notice { padding: 48px 16px; text-align: center; display: flex; flex-direction: column; gap: 8px; }

nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
nav#tabs[hidden] { display: none; }
nav#tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px; color: var(--hint); font-size: 12px; text-decoration: none;
}
nav#tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
