:root {
  --ink: #132823;
  --muted: #66716e;
  --line: #dce3df;
  --surface: #ffffff;
  --surface-hover: #f7f8f7;
  --soft: #f0f4f2;
  --accent: #177765;
  --accent2: #2c8b78;
  --green: #2f7654;
  --red: #9b3445;
  --shadow: 0 16px 45px rgba(14, 39, 48, 0.08);
  --navy: #0e2730;
  --teal: #177765;
  --blue: #206b8f;
  --amber: #b56b00;
  --coral: #d57856;
  --pale-green: #e4f3ed;
  --pale-blue: #e8eef3;
  --pale-amber: #fff2d6;
  --pale-red: #fbe7eb;
  --pale-gray: #e9edf1;
  --pale-green-hover: #e8f4ee;
  --pale-blue-hover: #e0eeff;
  --pale-amber-hover: #fef3c7;
  color-scheme: light;
}

/* Тёмная тема (переключается кнопкой в шапке, хранится в localStorage) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7e9f5;
  --muted: #9298bd;
  --line: #2c2f4f;
  --surface: #1b1e37;
  --surface-hover: #242848;
  --soft: #191c34;
  --accent: #33b696;
  --accent2: #45c9a8;
  --green: #4caf82;
  --red: #e0708a;
  --shadow: 0 16px 45px rgba(0, 0, 0, 0.45);
  --navy: #cfe4de;
  --teal: #33b696;
  --blue: #6fb3dd;
  --amber: #e0aa4e;
  --coral: #e69878;
  --pale-green: #1c3229;
  --pale-blue: #1b2c38;
  --pale-amber: #3a2f18;
  --pale-red: #3a1e26;
  --pale-gray: #262a49;
  --pale-green-hover: #21372c;
  --pale-blue-hover: #22354a;
  --pale-amber-hover: #453720;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  background: var(--soft);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(circle at 12% -8%, rgba(99, 91, 214, 0.16), transparent 42%),
    radial-gradient(circle at 100% 105%, rgba(58, 96, 199, 0.14), transparent 48%),
    var(--soft);
}

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

.panel {
  min-width: 0;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

/* Авторизация */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(circle at 10% 10%, #eee3ed, transparent 36%),
              radial-gradient(circle at 90% 85%, #e8ece5, transparent 34%), #f5f4f1;
}
:root[data-theme="dark"] .login-shell {
  background: radial-gradient(circle at 10% 10%, rgba(99, 91, 214, 0.12), transparent 36%),
              radial-gradient(circle at 90% 85%, rgba(58, 96, 199, 0.1), transparent 34%), #101222;
}
.login-card {
  width: min(430px, 100%);
  display: grid;
  gap: 18px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 24px 70px rgba(54, 39, 56, 0.12);
}
:root[data-theme="dark"] .login-card { background: rgba(27, 30, 55, 0.92); }
.login-card h1 { margin: 5px 0 6px; font-size: 30px; }
.login-card p { margin: 0; color: var(--muted); line-height: 1.5; }

/* Шапка и навигация */
.brand-mark {
  width: 50px;
  height: 50px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--accent), var(--accent2));
  color: white;
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 10px 25px rgba(23, 119, 101, 0.25);
}
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; font-size: 17px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); font-size: 11px; font-weight: 850; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px max(18px, calc((100vw - 1420px) / 2));
  background: rgba(249, 250, 249, 0.92);
  border-bottom: 1px solid rgba(223, 228, 224, 0.95);
  backdrop-filter: blur(14px);
}
:root[data-theme="dark"] .topbar {
  background: rgba(27, 30, 55, 0.82);
  border-bottom-color: rgba(44, 47, 79, 0.9);
}
.brand, .top-actions { display: flex; align-items: center; gap: 11px; }
.brand > div:last-child { display: grid; }
.brand span { font-size: 12px; color: var(--muted); }
.user-pill { font-size: 12px; background: #e7efeb; padding: 8px 11px; border-radius: 99px; color: #405b53; }
:root[data-theme="dark"] .user-pill { background: #262a4d; color: #b2b9e6; }

.user-menu { position: relative; }
.user-menu-trigger { border: none; cursor: pointer; }
.user-menu-popover {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 46;
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 22px 70px rgba(30, 20, 32, 0.25);
  overflow: hidden;
}
.user-menu-item { display: block; width: 100%; text-align: left; padding: 10px 14px; border: 0; background: none; font-weight: 700; color: var(--ink); }
.user-menu-item:hover { background: var(--line); }

.reminders-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.reminder-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; transition: background-color 0.4s ease; }
.reminder-card.just-saved { background-color: rgba(16, 150, 90, 0.14); }
.reminder-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.reminder-card-head .close { width: 28px; height: 28px; font-size: 16px; border-radius: 8px; }
.reminder-days { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.reminder-freq { display: flex; gap: 6px; }
.reminder-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.reminder-summary-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.reminder-summary-text { font-size: 14px; line-height: 1.4; word-break: break-word; }
.reminder-summary-switch { flex: 0 0 auto; white-space: nowrap; }
.reminder-summary-meta { margin-top: 6px; font-size: 12px; color: var(--muted); }
.reminder-limit-note { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

.site-nav {
  position: sticky;
  top: 63px;
  z-index: 9;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 9px max(18px, calc((100vw - 1420px) / 2));
  background: rgba(243, 245, 243, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-overflow-scrolling: touch;
}
:root[data-theme="dark"] .site-nav {
  background: rgba(35, 39, 70, 0.88);
}
.nav-tab {
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.nav-tab:hover { background: var(--surface-hover); color: var(--ink); }
.nav-tab.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(54, 39, 56, 0.06);
}

.page {
  width: min(1420px, calc(100% - 32px));
  margin: 20px auto 60px;
  min-width: 0;
  max-width: 100%;
}
.app-page { display: grid; gap: 14px; min-width: 0; max-width: 100%; }
.hero { padding: 22px 24px; display: flex; justify-content: space-between; align-items: center; gap: 24px; }
.hero h1 { margin: 4px 0 6px; font-size: 28px; }
.hero p, .section-head p { margin: 0; color: var(--muted); font-size: 13px; }
.primary, .ghost { border-radius: 11px; padding: 10px 15px; font-weight: 800; border: 1px solid transparent; }
.primary { background: var(--accent); color: white; box-shadow: 0 7px 18px rgba(105, 69, 102, 0.18); }
.primary:hover { background: #105f51; }
:root[data-theme="dark"] .primary:hover { background: #2a9c81; }
.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.wide { width: 100%; }

.period-tabs, .calendar-toolbar { display: flex; gap: 8px; align-items: center; }
.period-tabs .active { background: var(--accent); color: white; border-color: var(--accent); }

/* Диалоговые окна и модалки */
dialog {
  width: min(900px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 0;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 28px 90px rgba(30, 20, 32, 0.28);
}
dialog::backdrop { background: rgba(32, 27, 34, 0.48); backdrop-filter: blur(3px); }
.dialog-body { padding: 0; }
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 15px;
  padding: 20px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 4px 0; font-size: 21px; }
.dialog-head p { margin: 0; color: var(--muted); font-size: 12px; }
.close { width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 22px; }
.form-section { margin: 14px 18px 0; padding: 15px; border: 1px solid var(--line); border-radius: 14px; }
.form-section h3 { margin: 0 0 12px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label, .login-card label { font-size: 12px; font-weight: 750; color: var(--muted); display: grid; gap: 6px; }
.span-2 { grid-column: 1 / -1; }
.checkbox { display: flex !important; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
.dialog-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 18px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  margin-top: 14px;
}
.form-error { min-height: 18px; color: var(--red); font-size: 12px; font-weight: 750; padding: 0 18px; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 12px;
  background: #2c2930;
  color: white;
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 750;
}

/* Адаптив шапки, навигации, форм и диалогов */
@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 8px;
    padding: 12px 14px;
  }
  .top-actions {
    flex-wrap: wrap;
    width: 100%;
  }
  .site-nav {
    position: static;
    flex-wrap: wrap;
    overflow-x: visible;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }
  .hero > button.primary { width: 100%; }

  .period-tabs { flex-wrap: wrap; }
  .period-tabs > * { flex: 1 1 auto; }

  .form-grid { grid-template-columns: 1fr; }
