:root {
  --bg: #e8e4dc;
  --graphite: #383b45;
  --graphite-light: #4d505c;
  --graphite-alt: #40434e;
  --graphite-raised: #4a4d59;
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.85'/%3E%3C/svg%3E");
  --border-dark: #545763;
  --text-light: #f2f1ee;
  --text-muted-light: #a7a9b3;
  --text-dark: #24252b;
  --text-muted-dark: #75726a;
  --accent: #0abab5;
  --accent-2: #6fe3d6;
  --accent-contrast: #ffffff;
  --danger: #ff5470;
  --warning: #ffa733;
  --warning-bg: #40300f;
  --success: #2be387;
  --radius: 14px;
  --shadow: 0 6px 22px rgba(30,20,10,0.14);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 10% 0%, rgba(10,186,181,0.10), transparent 40%),
    radial-gradient(circle at 100% 15%, rgba(111,227,214,0.10), transparent 38%);
  background-attachment: fixed;
  color: var(--text-dark);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent-2); text-decoration: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px calc(10px + env(safe-area-inset-top));
  padding-top: max(16px, env(safe-area-inset-top));
  background-color: var(--graphite);
  background-image: var(--noise), linear-gradient(155deg, var(--graphite-light), var(--graphite) 70%);
  background-blend-mode: overlay, normal;
  background-size: 180px 180px, 100% 100%;
}
.brand {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.logout {
  font-size: 18px;
  color: var(--text-muted-light);
  width: 34px; height: 34px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--graphite-alt);
}

.content {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

h1 { font-size: 22px; margin: 0 0 16px; font-weight: 800; letter-spacing: -0.01em; color: var(--text-dark); }
h2 { font-size: 14px; margin: 24px 0 10px; color: var(--text-muted-dark); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 700; }

.filter-row { display: flex; gap: 8px; margin-bottom: 18px; }
.filter-row a {
  padding: 8px 16px;
  border-radius: 24px;
  background: var(--graphite);
  color: var(--text-muted-light);
  font-size: 13px;
  font-weight: 600;
}
.filter-row a.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.card {
  background-color: var(--graphite);
  background-image: var(--noise), linear-gradient(155deg, var(--graphite-light), var(--graphite) 70%);
  background-blend-mode: overlay, normal;
  background-size: 180px 180px, 100% 100%;
  color: var(--text-light);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card.done { opacity: 0.5; }
.card-title { font-weight: 700; font-size: 15px; margin-bottom: 6px; color: var(--text-light); }
.card-meta { font-size: 13px; color: var(--text-muted-light); display: flex; gap: 10px; flex-wrap: wrap; }
.card-note { font-size: 13px; color: var(--text-muted-light); margin-top: 8px; white-space: pre-wrap; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; align-items: center; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 700;
  background: var(--graphite-alt);
  color: var(--text-muted-light);
}
.badge.soon { background: var(--warning-bg); color: var(--warning); }
.badge.critical { background: #4a1420; color: var(--danger); }
.badge.google { background: var(--graphite-raised); color: var(--accent-2); }

button, .btn {
  border: none;
  background: var(--graphite-raised);
  color: var(--text-light);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
button.danger { color: var(--danger); }
button:active { transform: scale(0.97); }
input[type="date"] {
  border: 1px solid var(--border-dark);
  border-radius: 10px;
  padding: 7px 10px;
  background: var(--graphite-alt);
  color: var(--text-light);
  font-size: 13px;
}
input[type="password"] {
  border: 1px solid var(--border-dark);
  border-radius: 10px;
  padding: 7px 10px;
  background: var(--graphite-alt);
  color: var(--text-light);
  font-size: 13px;
}

.empty { color: var(--text-muted-dark); padding: 40px 0; text-align: center; }

.login-wrap {
  max-width: 320px;
  margin: 20vh auto;
  padding: 28px;
  background-color: var(--graphite);
  background-image: var(--noise), linear-gradient(155deg, var(--graphite-light), var(--graphite) 70%);
  background-blend-mode: overlay, normal;
  background-size: 180px 180px, 100% 100%;
  color: var(--text-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-wrap h1 {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.login-wrap input[type="password"] { width: 100%; padding: 12px; margin: 14px 0; }
.login-wrap button { width: 100%; padding: 12px; }
.error { color: var(--danger); font-size: 13px; font-weight: 600; }

/* bottom nav */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  background-color: rgba(42, 44, 51, 0.94);
  background-image: var(--noise), linear-gradient(0deg, var(--graphite), var(--graphite-light));
  background-blend-mode: overlay, normal;
  background-size: 180px 180px, 100% 100%;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 100;
}
.bottom-nav a {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 2px;
  border-radius: 12px;
  color: var(--text-muted-light);
  font-size: 10.5px;
  font-weight: 600;
}
.bottom-nav a .icon { font-size: 19px; line-height: 1; }
.bottom-nav a.active { color: var(--accent-2); }
.bottom-nav a.active .icon { transform: scale(1.1); }

/* calendar — сетка в духе Google Calendar: сплошные тонкие границы,
   без зазоров/скруглений между днями, кружок на "сегодня", компактные
   плашки-события. */
/* Страница календаря целиком помещается на экран без прокрутки: сетка
   получает фиксированную высоту (100svh минус шапка/нижняя панель/навигация
   по месяцу), строки недель делят её поровну (grid-template-rows,
   выставляется инлайн в шаблоне по числу недель месяца), внутри ячейки
   overflow скрыт — лишние пункты уходят в "+N ещё". */
.content.cal-page {
  padding-top: 12px;
  padding-bottom: 10px;
  display: flex;
  flex-direction: column;
  height: calc(100svh - 168px);
}
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex: 0 0 auto; }
.cal-grid {
  display: flex;
  flex-direction: column;
  background: var(--graphite);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  flex: 1 1 auto;
  min-height: 0;
}
.cal-weekday-row { display: grid; grid-template-columns: repeat(7, 1fr); flex: 0 0 auto; }
.cal-weekday {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted-light);
  padding: 8px 0;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background-color: var(--graphite-raised);
  background-image: var(--noise);
  background-blend-mode: overlay;
  background-size: 180px 180px;
  border-bottom: 1px solid var(--border-dark);
}

/* Каждая неделя — отдельная grid-сетка 7 колонок x (номер дня + N полос +
   строка переполнения). Фон/границы дня (.cal-day-bg) растянуты на все
   строки (grid-row: 1/-1) под остальным содержимым; полосы событий
   (.cal-bar) кладутся поверх в нужных колонках/строках — так многодневное
   событие рисуется одной протянутой плашкой, как в Google Calendar. */
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex: 1 1 0;
  min-height: 0;
  position: relative;
}
.cal-day-bg {
  grid-row: 1 / -1;
  display: block;
  color: var(--text-light);
  background-color: var(--graphite);
  background-image: var(--noise), linear-gradient(155deg, var(--graphite-light), var(--graphite) 80%);
  background-blend-mode: overlay, normal;
  background-size: 180px 180px, 100% 100%;
  border-right: 1px solid var(--border-dark);
  border-bottom: 1px solid var(--border-dark);
  cursor: pointer;
  transition: filter 0.1s;
  z-index: 0;
}
.cal-day-bg:active { filter: brightness(1.18); }
.cal-day-bg:nth-child(7n) { border-right: none; }
.cal-day-bg.other-month { background-color: var(--graphite-alt); opacity: 0.5; }
.cal-day-num {
  display: flex; align-items: center; justify-content: center;
  width: 16px; height: 16px;
  margin: 2px auto 0 3px;
  border-radius: 50%;
  font-weight: 600;
  font-size: 10px;
  color: var(--text-light);
}
.cal-day-bg.today .cal-day-num {
  background: var(--accent);
  color: #08302e;
  font-weight: 800;
}

.cal-bar {
  position: relative;
  z-index: 1;
  align-self: center;
  margin: 0 2px;
  display: flex;
  align-items: center;
  background: rgba(10, 186, 181, 0.85);
  border-radius: 4px;
  padding: 0 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #06231f;
  font-weight: 700;
  font-size: 9.5px;
  line-height: 1.9;
  pointer-events: none;
}
.cal-bar.cont-before { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: 0; }
.cal-bar.cont-after { border-top-right-radius: 0; border-bottom-right-radius: 0; margin-right: 0; }
.cal-bar.mod-serbia        { background: rgba(10, 186, 181, 0.85); color: #06231f; }
.cal-bar.mod-travel        { background: rgba(255, 167, 51, 0.85); color: #341c00; }
.cal-bar.mod-finance       { background: rgba(255, 84, 112, 0.85); color: #37020c; }
.cal-bar.mod-subscriptions { background: rgba(124, 140, 255, 0.85); color: #0a0e33; }
.cal-bar.mod-health        { background: rgba(43, 227, 135, 0.85); color: #04331b; }
.cal-bar.mod-general       { background: var(--graphite-raised); color: var(--text-light); }

.cal-overflow {
  position: relative;
  z-index: 1;
  font-size: 8.5px;
  font-weight: 700;
  color: var(--text-muted-light);
  padding-left: 4px;
  align-self: center;
}

/* subscriptions table (обёрнута в .card) */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--border-dark); font-size: 13px; color: var(--text-light); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 18px; white-space: normal; }
th:last-child, td:last-child { padding-right: 18px; }
tr:first-child th { padding-top: 16px; }
th { color: var(--text-muted-light); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
tr:last-child td { border-bottom: none; }

/* knowledge */
.module-tabs { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.module-tabs a { padding: 8px 16px; border-radius: 24px; background: var(--graphite); color: var(--text-muted-light); font-size: 13px; font-weight: 600; }
.module-tabs a.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.kentry { margin-bottom: 14px; }
.kentry-title { font-weight: 700; color: var(--text-light); }
.kentry-source { font-size: 12px; color: var(--text-muted-light); margin-top: 6px; }

/* trips */
.trip-card { display: block; }
.trip-count { color: var(--text-muted-light); font-size: 13px; margin-top: 2px; }

@media (max-width: 640px) {
  .cal-bar { font-size: 8.5px; }
  .cal-weekday { font-size: 9px; padding: 5px 0; }
  .cal-day-num { width: 16px; height: 16px; font-size: 9.5px; margin: 2px auto 0 2px; }
  .cal-overflow { font-size: 8px; }
  .content { padding: 16px 10px 100px; }
  .content.cal-page { padding: 10px 6px 8px; height: calc(100svh - 156px); }
}
