:root {
  --bg: #f6f6fb;
  --card: #ffffff;
  --text: #17172b;
  --muted: #6b6b82;
  --line: #e6e6f0;
  --accent: #4f46e5;
  --accent-soft: #ecebff;
  --danger: #dc2626;
  --dot: #f59e0b;
  --radius: 16px;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f17;
    --card: #1b1b27;
    --text: #f1f1f7;
    --muted: #9a9ab2;
    --line: #2c2c3c;
    --accent: #8b85ff;
    --accent-soft: #26244a;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--danger); min-height: 1.2em; margin: 6px 0 0; font-size: 14px; }

/* ---------- кнопки ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); padding: 8px 4px; }
.link.strong { font-weight: 700; }

/* ---------- вход ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; align-items: stretch; text-align: center;
}
.login-card img { align-self: center; border-radius: 18px; }
.login-card h1 { margin: 4px 0 0; }
.login-card input {
  padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
}

/* ---------- каркас ---------- */
.view {
  max-width: 760px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; max-width: 200px; height: var(--tabbar-h); border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted);
}
.tab-ico { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); font-weight: 600; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 30px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 4px 8px; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; border: 1px solid var(--line); }
.next-card { background: var(--accent); color: #fff; border: 0; }
.next-card .label { opacity: .8; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.next-card .title { font-size: 20px; font-weight: 700; margin: 4px 0; overflow-wrap: anywhere; }
.next-card .when { opacity: .9; }

/* ---------- список событий ---------- */
.events { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; }
.events li + li { border-top: 1px solid var(--line); }
.event {
  width: 100%; display: flex; gap: 14px; align-items: flex-start; text-align: left;
  padding: 14px 16px; border: 0; background: none;
}
.event:hover { background: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.event-time { font-weight: 700; min-width: 48px; font-variant-numeric: tabular-nums; }
.event-body { flex: 1; min-width: 0; }
.event-title { display: block; overflow-wrap: anywhere; }
.event-meta { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.event.past { opacity: .5; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.fab-capture {
  position: fixed; right: max(16px, calc(50% - 380px + 16px)); z-index: 11;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  height: 52px; padding: 0 20px 0 16px; border-radius: 26px; border: 0;
  background: var(--accent); color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
  box-shadow: 0 6px 20px rgb(79 70 229 / .35);
}
.fab-capture span { font-size: 22px; line-height: 1; }

/* ---------- быстрая запись ---------- */
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 4px; border-radius: 12px; background: var(--bg); margin: 4px 0 12px; }
.segmented button { border: 0; background: none; padding: 9px 4px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--card); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .12); }
#capture-text {
  width: 100%; min-height: 96px; resize: vertical; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 17px; line-height: 1.4;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 12px; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-date input { border: 0; background: none; padding: 0; font-size: 14px; max-width: 140px; }
.chip-date input:not(:valid), .chip-date input[value=""] { color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.badge-dot {
  position: absolute; top: -2px; right: -10px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
  background: var(--danger); color: #fff; font-size: 10px; font-style: normal; font-weight: 700; line-height: 16px;
}
.tab-ico { position: relative; }

/* ---------- задачи ---------- */
.task-row { display: flex; align-items: center; gap: 4px; padding: 6px 8px 6px 6px; }
.task-check {
  flex: none; width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center;
}
.task-check::before {
  content: ""; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted); box-sizing: border-box;
}
.task-row.done .task-check::before { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 3px var(--card); }
.task-main { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 8px 4px; }
.task-row.done .event-title { text-decoration: line-through; color: var(--muted); }
.overdue { color: var(--danger); }
.today-btn {
  flex: none; border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 6px 10px; font-size: 13px; white-space: nowrap;
}
.today-btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.counter { font-weight: 600; color: var(--muted); text-transform: none; letter-spacing: 0; margin-left: 4px; }

/* ---------- входящие ---------- */
.note { padding: 14px 16px; }
.note-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.note-foot .muted { flex: 1; font-size: 13px; }
.mini { border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.mini.danger { background: transparent; color: var(--danger); }

/* ---------- черновик из фразы ---------- */
.parse-box { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; margin: 4px 0; font-size: 14px; }
.parse-box .src { font-weight: 600; overflow-wrap: anywhere; }
.parse-box ul { margin: 6px 0 0; padding-left: 18px; }
.parse-box .warn { color: var(--danger); }
.need { outline: 2px solid var(--dot); outline-offset: 1px; }

/* ---------- календарь ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.month-nav h1 { margin: 0; font-size: 26px; text-transform: capitalize; }
.month-nav .arrows { display: flex; gap: 4px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 18px; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.day {
  aspect-ratio: 1 / 1; max-height: 64px; border-radius: 12px; border: 0; background: var(--card);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-variant-numeric: tabular-nums; position: relative;
}
.day.other { opacity: .35; }
.day.today .num { color: var(--accent); font-weight: 800; }
.day.selected { background: var(--accent); color: #fff; }
.day.selected .num { color: #fff; }
.day .dots { display: flex; gap: 2px; height: 5px; }
.day .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--dot); }
.day.selected .dots i { background: #fff; }

/* ---------- настройки ---------- */
.settings .card + .card { margin-top: 12px; }
.settings h2 { font-size: 17px; margin: 0 0 6px; }
.settings p { margin: 6px 0; }
.settings .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.settings select { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); }
.steps { margin: 6px 0 0; padding-left: 20px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 13px; background: var(--accent-soft); color: var(--accent); }

/* ---------- форма события ---------- */
.sheet {
  border: 0; padding: 0; width: min(560px, 100%); max-width: 100%;
  background: var(--card); color: var(--text); border-radius: 20px;
}
.sheet::backdrop { background: rgb(0 0 0 / .4); }
@media (max-width: 600px) {
  .sheet { margin: auto 0 0; border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom); }
}
#event-form, #capture-form, #task-form { padding: 8px 16px 16px; }
textarea { font: inherit; color: inherit; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; margin-bottom: 8px; }
.sheet-head h2 { font-size: 17px; margin: 0; text-align: center; }
.sheet-head .link:first-child { justify-self: start; }
.sheet-head .link:last-child { justify-self: end; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); z-index: 50;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 84px);
  background: #17172b; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
