/* Базовый вид Google Календаря на компьютере, выполненный аккуратно.
   Белое поле, светлая разлиновка, синие блоки, кружок на сегодняшней дате,
   красная линия текущего времени. Отличие одно — строка ввода живым языком. */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #3c4043;
  --text-2: #70757a;
  --line: #dadce0;
  --line-soft: #e8eaed;
  --hover: #f1f3f4;
  --accent: #1a73e8;
  --accent-ink: #ffffff;
  --event: #039be5;
  --event-ink: #ffffff;
  --event-soft: #e1f5fe;
  --event-soft-ink: #01579b;
  --now: #ea4335;
  --danger: #d93025;

  --rail: 64px;
  --hour: 48px;

  --font: "Google Sans", Roboto, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}

/* Тема: системная по умолчанию, но ручной тумблер её перебивает в обе стороны. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #202124;
    --surface: #2a2b2e;
    --text: #e8eaed;
    --text-2: #9aa0a6;
    --line: #3c4043;
    --line-soft: #303134;
    --hover: #35363a;
    --accent: #8ab4f8;
    --accent-ink: #202124;
    --event: #0288d1;
    --event-soft: #17384f;
    --event-soft-ink: #a6d8f5;
    --danger: #f28b82;
  }
}

:root[data-theme="dark"] {
    --bg: #202124;
    --surface: #2a2b2e;
    --text: #e8eaed;
    --text-2: #9aa0a6;
    --line: #3c4043;
    --line-soft: #303134;
    --hover: #35363a;
    --accent: #8ab4f8;
    --accent-ink: #202124;
    --event: #0288d1;
    --event-soft: #17384f;
    --event-soft-ink: #a6d8f5;
    --danger: #f28b82;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  color: var(--text);
  font: 14px/1.4 var(--font);
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

input, textarea, button, select { font-family: inherit; font-size: 16px; color: var(--text); }

/* --- кнопки --------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 16px;
  border-radius: 4px;
  border: 0;
  font: 500 14px/1 var(--font);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-outline { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-outline:hover { background: var(--hover); }
.btn-filled { background: var(--accent); color: var(--accent-ink); }
.btn-filled:hover { filter: brightness(1.06); }
.btn-filled:disabled { opacity: .6; cursor: default; }
.btn-text { background: transparent; color: var(--accent); padding: 0 12px; }
.btn-text:hover { background: var(--hover); }
.btn-danger { color: var(--danger); }
.btn-wide { width: 100%; height: 40px; }

.iconbtn {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-2);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.iconbtn:hover { background: var(--hover); }

.error {
  margin: 6px 16px 0;
  color: var(--danger);
  font-size: 13px;
}

.error:empty { display: none; }

/* --- экраны входа --------------------------------------------------------- */

.screen { height: 100dvh; display: flex; flex-direction: column; }
.screen.center { align-items: center; justify-content: center; padding: 24px 16px; }

.card {
  width: 100%;
  max-width: 400px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.card h1 { font: 400 22px/1.2 var(--font); margin: 0 0 16px; }
.muted { color: var(--text-2); margin: 0 0 20px; }

/* --- шапка ---------------------------------------------------------------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 64px;
  padding: calc(env(safe-area-inset-top)) 16px 0;
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0 0 0 8px;
  font: 400 22px/1 var(--font);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-spacer { flex: 1; }

/* заголовок периода — кнопка: открывает выбор даты */
.period {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  margin-left: 8px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font: 400 22px/1 var(--font);
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.period::after {
  content: '▾';
  font-size: 12px;
  color: var(--text-2);
}

.period:hover { background: var(--hover); }

/* --- выбор даты ----------------------------------------------------------- */

.datepicker {
  position: absolute;
  z-index: 30;
  top: 60px;
  left: 12px;
  width: 300px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
}

.dp-head { display: flex; align-items: center; gap: 4px; }

.dp-label {
  flex: 1;
  height: 36px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: 500 14px/1 var(--font);
  cursor: pointer;
}

.dp-label:hover { background: var(--hover); }
.dp-label::after { content: ' ▾'; color: var(--text-2); font-size: 11px; }

.dp-years {
  max-height: 232px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 2px;
}

.dp-year {
  height: 40px;
  border: 0;
  border-radius: 20px;
  background: transparent;
  color: var(--text);
  font: 400 14px/1 var(--font);
  cursor: pointer;
}

.dp-year:hover { background: var(--hover); }
.dp-year.is-current { background: var(--accent); color: var(--accent-ink); }

.dp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-top: 4px; }

.dp-dow {
  height: 24px;
  display: grid;
  place-items: center;
  font-size: 11px;
  color: var(--text-2);
}

.dp-day {
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font: 400 13px/1 var(--font);
  cursor: pointer;
}

.dp-day:hover { background: var(--hover); }
.dp-day.is-out { color: var(--text-2); opacity: .55; }
.dp-day.is-today { box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.dp-day.is-picked { background: var(--accent); color: var(--accent-ink); }

/* --- голосовой ввод ------------------------------------------------------- */

.mic {
  flex: 0 0 40px;
  font-size: 18px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-2);
}

.mic.is-recording {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .55; } }

/* --- строка ввода --------------------------------------------------------- */

.omnibar {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 16px;
}

.omnibar input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  font-size: 16px;
}

.omnibar input:focus { border-color: var(--accent); }
.omnibar input::placeholder { color: var(--text-2); }
.omnibar .btn { height: 40px; }

/* --- ряд дней ------------------------------------------------------------- */

.dayhead {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: var(--rail) repeat(7, 1fr);
  align-items: end;
  border-bottom: 1px solid var(--line);
}

.tzlabel {
  padding: 0 6px 6px 0;
  text-align: right;
  font-size: 10px;
  color: var(--text-2);
}

.daycell {
  padding: 8px 0 6px;
  text-align: center;
  cursor: pointer;
}

.daycell .dow {
  display: block;
  font-size: 11px;
  line-height: 1;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 4px;
}

.daycell.is-today .dow { color: var(--accent); }

.daycell .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font: 400 26px/1 var(--font);
  color: var(--text);
}

.daycell:hover .num { background: var(--hover); }
.daycell.is-today .num { background: var(--accent); color: var(--accent-ink); }
.daycell.is-today:hover .num { background: var(--accent); }

/* --- сетка ---------------------------------------------------------------- */

.gridscroll {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}

.grid { display: grid; grid-template-columns: var(--rail) 1fr; }

.hourrail { position: relative; }

.hourrail span {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 10px;
  line-height: 1;
  color: var(--text-2);
  white-space: nowrap;
}

.cols {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background-image: repeating-linear-gradient(
    to bottom,
    var(--line) 0 1px,
    transparent 1px var(--hour)
  );
}

.daycol { position: relative; border-left: 1px solid var(--line); cursor: pointer; }

.ev {
  position: absolute;
  z-index: 1;
  left: 1px;
  right: 1px;
  padding: 2px 6px;
  border: 1px solid var(--bg);
  border-radius: 4px;
  background: var(--event);
  color: var(--event-ink);
  text-align: left;
  overflow: hidden;
  cursor: pointer;
}

.ev .t {
  display: block;
  font: 500 12px/1.25 var(--font);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ev .h {
  display: block;
  font: 400 11px/1.25 var(--font);
  opacity: .92;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ev.whole { z-index: 0; }

.ev.compact { padding: 1px 6px; }
.ev.compact .t { font-size: 11.5px; }

/* чужое или повторяющееся: только чтение, правится в Google */
.ev.readonly {
  background: var(--event-soft);
  color: var(--event-soft-ink);
  border: 1px solid var(--event);
}

.nowline {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px solid var(--now);
  pointer-events: none;
  z-index: 3;
}

.nowline::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -6px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--now);
}

.empty-note {
  position: absolute;
  left: 12px;
  right: 12px;
  color: var(--text-2);
  font-size: 13px;
  pointer-events: none;
}

/* --- выбор режима --------------------------------------------------------- */

.viewmenu {
  position: absolute;
  z-index: 30;
  top: 60px;
  right: 12px;
  min-width: 160px;
  padding: 6px 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .28);
}

.viewmenu button {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: 400 14px/1 var(--font);
  text-align: left;
  cursor: pointer;
}

.viewmenu button:hover { background: var(--hover); }
.viewmenu button[aria-current="true"] { background: var(--hover); font-weight: 500; color: var(--accent); }

/* --- месяц ---------------------------------------------------------------- */

.monthview {
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: auto repeat(6, minmax(0, 1fr));
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom);
}

.month-dowrow, .month-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }

.month-dowrow div {
  padding: 6px 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--text-2);
  border-bottom: 1px solid var(--line);
}

.month-cell {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 2px 3px 4px;
  border-left: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  cursor: pointer;
}

.month-cell:first-child { border-left: 0; }
.month-cell.is-out .month-num { color: var(--text-2); opacity: .55; }

.month-num {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 12px;
  font-size: 12px;
  color: var(--text);
}

.month-cell.is-today .month-num { background: var(--accent); color: var(--accent-ink); }

.month-chip {
  display: block;
  width: 100%;
  padding: 1px 4px;
  border: 0;
  border-radius: 3px;
  background: var(--event);
  color: #fff;
  font: 500 10px/1.4 var(--font);
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.month-more {
  padding-left: 4px;
  font-size: 10px;
  color: var(--text-2);
}

/* --- год ------------------------------------------------------------------ */

.yearview {
  flex: 1 1 auto;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 20px;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px);
}

.mini h3 {
  margin: 0 0 6px 4px;
  font: 500 14px/1 var(--font);
  color: var(--accent);
}

.mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }

.mini-dow {
  display: grid;
  place-items: center;
  height: 20px;
  font-size: 10px;
  color: var(--text-2);
}

.mini-day {
  display: grid;
  place-items: center;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  font: 400 11px/1 var(--font);
  cursor: pointer;
}

.mini-day:hover { background: var(--hover); }
.mini-day.is-out { visibility: hidden; }
.mini-day.is-today { background: var(--accent); color: var(--accent-ink); }

@media (max-width: 719px) {
  .yearview { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; padding: 14px; }
  .mini-day { height: 22px; font-size: 10px; }
  .month-chip { font-size: 9px; padding: 1px 3px; }
  .month-num { min-width: 20px; height: 20px; font-size: 11px; }
}

/* --- кнопка добавления ---------------------------------------------------- */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 15;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-ink);
  font: 300 30px/1 var(--font);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

.fab:hover { filter: brightness(1.06); }
.fab:active { transform: translateY(1px); }

/* --- окно диктовки -------------------------------------------------------- */

.dict-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.dict-head h2 { margin: 0; }

.dict-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.1s ease-in-out infinite;
}

.dict-dot.is-idle { background: var(--text-2); animation: none; }

/* Текст растёт вниз в отдельном поле, а не в однострочной строке ввода:
   иначе к началу длинной фразы не вернуться. */
.dict-text {
  min-height: 96px;
  max-height: 34dvh;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.dict-text:empty::before {
  content: 'Говори…';
  color: var(--text-2);
}

.dict-hint { margin: 10px 2px 0; color: var(--text-2); font-size: 12px; }

/* --- карточка события ----------------------------------------------------- */

.sheet { position: fixed; inset: 0; z-index: 20; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(32, 33, 36, .5); }

.sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 16px);
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 -2px 12px rgba(0, 0, 0, .28);
}

.sheet-card h2 { margin: 0 0 18px; font: 400 20px/1.2 var(--font); }

.field { display: block; margin-bottom: 16px; }

.field > span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-2);
}

.field input, .field textarea, .field select {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  outline: none;
  appearance: none;
  font-size: 16px;
}

.field textarea { height: auto; padding: 10px 12px; resize: none; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent); }

.colorpick { display: flex; gap: 8px; }

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 40px;
  padding: 0 12px 0 10px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: transparent;
  color: var(--text);
  font: 400 13px/1 var(--font);
  cursor: pointer;
}

.swatch i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--dot);
}

.swatch[aria-checked="true"] {
  border-color: var(--dot);
  box-shadow: inset 0 0 0 1px var(--dot);
  font-weight: 500;
}

.field-row { display: flex; gap: 12px; align-items: flex-end; }
.grow { flex: 1; }

.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  height: 44px;
  font-size: 14px;
  white-space: nowrap;
}

.switch input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }

.sheet-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.spacer { flex: 1; }

.footlink {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
}

.footlink:hover { text-decoration: underline; }

/* --- телефон -------------------------------------------------------------- */

@media (max-width: 719px) {
  :root { --rail: 44px; --hour: 52px; }

  .topbar { height: 56px; gap: 0; padding-inline: 8px; }
  .period { font-size: 18px; margin-left: 2px; padding: 0 6px; }
  .btn { padding: 0 12px; }
  .omnibar { padding: 8px 12px; }
  .datepicker { left: 8px; right: 8px; width: auto; top: 52px; }
  .dp-years { grid-template-columns: repeat(3, 1fr); }

  .daycell .num { width: 32px; height: 32px; font-size: 18px; }
  .daycell .dow { font-size: 10px; }

  .ev { padding: 1px 3px; }
  .ev .t { font-size: 10px; line-height: 1.2; }
  .ev .h { display: none; }
}

@media (min-width: 720px) {
  .sheet-card {
    left: 50%;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 480px;
    border-radius: 8px;
  }
}
