:root {
  color-scheme: light dark;
  --bg: var(--tg-theme-bg-color, #f3f5f8);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #172033);
  --muted: var(--tg-theme-hint-color, #718096);
  --accent: var(--tg-theme-button-color, #3b6ef5);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: #d64545;
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 18px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(18px);
}
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; }
h1, h2, p { margin: 0; }
h1 { margin-top: 2px; font-size: 24px; }
h2 { font-size: 17px; }
main { max-width: 760px; margin: 0 auto; padding: 10px 16px 100px; }
.view { display: none; }
.view.active { display: block; animation: appear .18s ease-out; }
@keyframes appear { from { opacity: .4; transform: translateY(4px); } }

.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.card, .metric, .task, .entry, .setting, .banner {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 8px 24px color-mix(in srgb, var(--text) 6%, transparent);
}
.metric { min-height: 104px; padding: 16px; display: flex; flex-direction: column; justify-content: space-between; }
.metric strong { font-size: 28px; }
.metric.danger strong { color: var(--danger); }
.muted, .metric span, .task-meta, .entry-meta { color: var(--muted); font-size: 13px; }
.banner { margin-bottom: 12px; padding: 12px 14px; font-size: 14px; }
.banner.warning { border-color: color-mix(in srgb, #d69e2e 50%, transparent); }
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 24px 2px 10px; }
.link-button, .icon-button { border: 0; color: var(--accent); background: transparent; }
.icon-button { width: 38px; height: 38px; border-radius: 50%; font-size: 24px; }
.icon-button:active { background: var(--border); }

.task-list, .entry-list, .settings-list { display: grid; gap: 9px; }
.task { display: block; padding: 14px; color: inherit; text-decoration: none; }
.task-title { margin: 7px 0; font-size: 15px; font-weight: 700; line-height: 1.35; }
.task-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.badge { border-radius: 999px; padding: 4px 8px; background: color-mix(in srgb, var(--accent) 13%, transparent); color: var(--accent); font-size: 11px; font-weight: 750; text-transform: uppercase; }
.badge.bitrix24 { color: #1f78d1; background: color-mix(in srgb, #1f78d1 13%, transparent); }
.due.overdue { color: var(--danger); font-weight: 700; }
.empty { padding: 30px 14px; text-align: center; color: var(--muted); }

.filters { display: grid; gap: 10px; margin-bottom: 12px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
}
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border-radius: 12px; background: var(--surface); }
.segmented button { border: 0; border-radius: 9px; padding: 9px 4px; color: var(--muted); background: transparent; }
.segmented button.selected { color: var(--accent-text); background: var(--accent); }

.time-summary { display: flex; align-items: center; justify-content: space-between; padding: 14px; }
.time-summary strong { display: block; margin-top: 4px; font-size: 24px; }
.time-summary input { width: auto; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 12px; }
.day { min-height: 54px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); font-size: 12px; }
.day.outside { opacity: .3; }
.day strong { display: block; margin-top: 8px; color: var(--accent); font-size: 11px; }
.entry { padding: 12px 14px; }
.entry strong { display: block; margin-bottom: 5px; }
.primary-button { width: 100%; margin-top: 16px; border: 0; border-radius: 13px; padding: 13px; color: var(--accent-text); background: var(--accent); font-weight: 750; }

.setting { display: flex; align-items: center; justify-content: space-between; padding: 14px; }
.status { color: var(--danger); font-size: 13px; font-weight: 700; }
.status.connected { color: #278a58; }
.switch { position: relative; width: 46px; height: 26px; border: 0; border-radius: 99px; background: var(--border); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: white; transition: transform .18s; }
.switch.enabled { background: var(--accent); }
.switch.enabled::after { transform: translateX(20px); }

.bottom-nav {
  position: fixed;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
}
.bottom-nav button { border: 0; border-radius: 10px; padding: 9px 2px; color: var(--muted); background: transparent; font-size: 12px; }
.bottom-nav button.selected { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 750; }

dialog { width: min(92vw, 460px); border: 1px solid var(--border); border-radius: 20px; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(10, 18, 35, .5); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 13px; padding: 18px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.toast { position: fixed; left: 50%; bottom: 90px; z-index: 10; transform: translateX(-50%) translateY(20px); max-width: 90vw; padding: 11px 15px; border-radius: 12px; color: white; background: #172033; opacity: 0; pointer-events: none; transition: .2s; }
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (min-width: 680px) {
  .metrics { grid-template-columns: repeat(4, 1fr); }
  .filters { grid-template-columns: 1fr auto auto; align-items: center; }
}
