/* Планер — календарь. Оформление под iOS: системная типографика, живые нажатия. */

:root {
  --bg: #fff;
  --bg-2: #f2f2f7;
  --bg-elev: rgba(255, 255, 255, .82);
  --label: #000;
  --label-2: rgba(60, 60, 67, .6);
  --label-3: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .18);
  --sep-strong: rgba(60, 60, 67, .29);
  --accent: #007aff;
  --today: #ff3b30;
  --fill: rgba(120, 120, 128, .12);
  --fill-2: rgba(120, 120, 128, .2);
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --ease: cubic-bezier(.32, .72, 0, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000;
    --bg-2: #1c1c1e;
    --bg-elev: rgba(28, 28, 30, .82);
    --label: #fff;
    --label-2: rgba(235, 235, 245, .6);
    --label-3: rgba(235, 235, 245, .3);
    --sep: rgba(84, 84, 88, .4);
    --sep-strong: rgba(84, 84, 88, .65);
    --accent: #0a84ff;
    --today: #ff453a;
    --fill: rgba(120, 120, 128, .24);
    --fill-2: rgba(120, 120, 128, .36);
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--label);
  font: 400 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- вход ---------- */

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 24px; background: var(--bg-2);
}
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-icon {
  width: 76px; height: 76px; margin: 0 auto 20px; border-radius: 18px;
  background: linear-gradient(160deg, #ff453a, #ff9f0a);
  box-shadow: var(--shadow);
  position: relative;
}
.login-icon::after {
  content: "31"; position: absolute; inset: 0; display: grid; place-items: center;
  color: #fff; font-size: 34px; font-weight: 700; letter-spacing: -1px;
}
.login h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.login p { margin: 4px 0 28px; color: var(--label-2); font-size: 15px; }
.login input {
  display: block; width: 100%; margin-bottom: 10px; padding: 14px 16px;
  background: var(--bg); border: 0; border-radius: 12px; outline: none;
}
.login button {
  width: 100%; margin-top: 8px; padding: 15px; border-radius: 12px;
  background: var(--accent); color: #fff; font-weight: 600;
  transition: transform .12s var(--ease), opacity .12s;
}
.login button:active { transform: scale(.97); opacity: .85; }
.login-err { min-height: 20px; margin-top: 12px; color: var(--today); font-size: 14px; }

/* ---------- каркас ---------- */

.app { display: flex; flex-direction: column; height: 100%; }

.hdr {
  flex: none; padding: calc(var(--safe-t) + 8px) 12px 0;
  background: var(--bg-elev); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--sep);
}
.hdr-top { display: flex; align-items: center; gap: 2px; height: 40px; }
.spacer { flex: 1; }

.title {
  font-size: 21px; font-weight: 700; letter-spacing: -.4px;
  padding: 4px 6px; border-radius: 8px; white-space: nowrap;
  transition: background .15s;
}
.title:active { background: var(--fill); }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 50%; color: var(--accent);
  transition: background .15s, transform .1s var(--ease);
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active { background: var(--fill); transform: scale(.9); }

.today-btn {
  padding: 7px 14px; border-radius: 999px; background: var(--fill);
  font-size: 15px; font-weight: 600; color: var(--accent);
  transition: transform .1s var(--ease);
}
.today-btn:active { transform: scale(.94); }

.segmented {
  position: relative; display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 0; margin: 10px 0; padding: 2px; border-radius: 9px;
  background: var(--fill); isolation: isolate;
}
.seg {
  position: relative; z-index: 1; padding: 7px 0; border-radius: 7px;
  font-size: 14px; font-weight: 600; color: var(--label);
  transition: color .2s, opacity .2s;
}
.seg:not(.on) { color: var(--label-2); font-weight: 500; }
.seg-thumb {
  position: absolute; z-index: 0; top: 2px; bottom: 2px; left: 2px;
  width: calc((100% - 4px) / 3); border-radius: 7px;
  background: var(--bg); box-shadow: 0 3px 8px rgba(0, 0, 0, .12);
  transition: transform .28s var(--ease);
}

.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; }

/* ---------- месяц ---------- */

.weekdays {
  flex: none; display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 6px 4px; border-bottom: .5px solid var(--sep);
}
.weekdays span {
  text-align: center; font-size: 11px; font-weight: 600;
  letter-spacing: .4px; text-transform: uppercase; color: var(--label-2);
}
.weekdays span.we { color: var(--label-3); }

.month-grid {
  flex: none; display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 2px 4px 6px; gap: 1px 0;
  border-bottom: .5px solid var(--sep);
  transition: transform .26s var(--ease), opacity .2s;
}
.month-grid.slide-l { transform: translateX(-8%); opacity: 0; }
.month-grid.slide-r { transform: translateX(8%); opacity: 0; }

.cell {
  min-height: 48px; padding-top: 4px; display: flex; flex-direction: column;
  align-items: center; gap: 3px; border-radius: 10px;
  transition: background .15s;
}
.cell:active { background: var(--fill); }
.cell.out .num { color: var(--label-3); }
.cell .num {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 50%; font-size: 16px; font-variant-numeric: tabular-nums;
  transition: background .18s var(--ease), color .18s, transform .18s var(--ease);
}
.cell.today .num { color: var(--today); font-weight: 700; }
.cell.sel .num { background: var(--label); color: var(--bg); font-weight: 600; }
.cell.today.sel .num { background: var(--today); color: #fff; }
.dots { display: flex; gap: 3px; height: 5px; align-items: center; }
.dot { width: 5px; height: 5px; border-radius: 50%; }

.day-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.day-panel-head {
  flex: none; padding: 12px 20px 6px; font-size: 13px; font-weight: 600;
  letter-spacing: .3px; text-transform: uppercase; color: var(--label-2);
}
.day-list {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(var(--safe-b) + 130px);
}

.ev {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 11px 12px; margin-bottom: 6px; border-radius: 12px;
  background: var(--bg-2);
  transition: transform .12s var(--ease), background .15s;
}
.ev:active { transform: scale(.985); background: var(--fill-2); }
.ev-bar { flex: none; width: 4px; align-self: stretch; border-radius: 2px; min-height: 34px; }
.ev-when {
  flex: none; width: 52px; font-size: 14px; font-variant-numeric: tabular-nums;
  color: var(--label-2); padding-top: 1px;
}
.ev-main { flex: 1; min-width: 0; }
.ev-title { font-size: 16px; font-weight: 500; }
.ev-notes {
  margin-top: 2px; font-size: 14px; color: var(--label-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.empty { padding: 40px 20px; text-align: center; color: var(--label-3); font-size: 15px; }

/* ---------- неделя / день ---------- */

.tl-head {
  flex: none; display: grid; padding: 6px 0 8px 46px;
  border-bottom: .5px solid var(--sep);
}
.tl-head div { text-align: center; }
.tl-head .wd {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .4px; color: var(--label-2);
}
.tl-head .dn {
  margin: 3px auto 0; width: 30px; height: 30px; display: grid; place-items: center;
  border-radius: 50%; font-size: 16px; font-variant-numeric: tabular-nums;
}
.tl-head .today .dn { background: var(--today); color: #fff; font-weight: 600; }

.tl-allday {
  flex: none; display: flex; gap: 4px; flex-wrap: wrap;
  padding: 6px 8px 6px 46px; border-bottom: .5px solid var(--sep);
}
.allday-pill {
  padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 500;
  color: #fff; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.tl-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--safe-b) + 120px);
  scrollbar-width: none;
}
.tl-scroll::-webkit-scrollbar, .day-list::-webkit-scrollbar { width: 0; height: 0; }
.day-list { scrollbar-width: none; }
.tl-body { position: relative; }
.tl-hours { position: absolute; inset: 0 auto 0 0; width: 46px; }
.tl-hours div {
  position: absolute; right: 8px; transform: translateY(-50%);
  font-size: 11px; font-variant-numeric: tabular-nums; color: var(--label-2);
}
.tl-cols { display: grid; margin-left: 46px; margin-right: 6px; position: relative; }
.tl-col { position: relative; border-left: .5px solid var(--sep); }
.tl-col:first-child { border-left: 0; }
.hour-line {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: .5px solid var(--sep); pointer-events: none;
}

.tev {
  position: absolute; overflow: hidden;
  padding: 3px 6px; border-radius: 6px; color: #fff;
  font-size: 12px; line-height: 1.22; min-height: 18px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
  transition: transform .12s var(--ease);
  display: flex; flex-direction: column; gap: 1px;
}
.tev:active { transform: scale(.97); }
.tev b {
  font-weight: 600; min-width: 0;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden; overflow-wrap: break-word;
}
.tev i { font-style: normal; opacity: .85; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tev.narrow { font-size: 11px; padding: 2px 4px; }
.tev.narrow b { -webkit-line-clamp: 3; }

.now-line { position: absolute; left: 46px; right: 6px; height: 0; border-top: 2px solid var(--today); z-index: 5; pointer-events: none; }
.now-line i { position: absolute; left: -5px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--today); }

/* ---------- фильтры ---------- */

.filters {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 8px; justify-content: center; flex-wrap: wrap;
  padding: 10px 16px calc(var(--safe-b) + 10px);
  background: var(--bg-elev); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--sep);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 999px; background: var(--fill);
  font-size: 14px; font-weight: 500;
  transition: opacity .18s, transform .12s var(--ease), background .18s;
}
.chip:active { transform: scale(.94); }
.chip.off { opacity: .38; }
.chip i { width: 9px; height: 9px; border-radius: 50%; }

/* ---------- кнопка + ---------- */

.fab {
  position: fixed; right: 18px; z-index: 30;
  bottom: calc(var(--safe-b) + 74px);
  width: 54px; height: 54px; display: grid; place-items: center;
  border-radius: 50%; background: var(--accent); color: #fff;
  box-shadow: 0 6px 20px rgba(0, 122, 255, .4);
  transition: transform .16s var(--ease), box-shadow .16s;
}
.fab svg { width: 26px; height: 26px; }
.fab:active { transform: scale(.9); box-shadow: 0 3px 12px rgba(0, 122, 255, .35); }

/* ---------- редактор ---------- */

.sheet-bg {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4);
  opacity: 0; transition: opacity .3s var(--ease);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.sheet-bg.on { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 40px rgba(0, 0, 0, .22);
  transform: translateY(100%); transition: transform .38s var(--ease);
  padding-bottom: var(--safe-b);
}
.sheet.on { transform: translateY(0); }
.sheet-grab { width: 36px; height: 5px; margin: 8px auto 2px; border-radius: 3px; background: var(--fill-2); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px 12px; border-bottom: .5px solid var(--sep);
}
.sheet-head strong { font-size: 16px; font-weight: 600; }
.link { color: var(--accent); font-size: 16px; padding: 4px; }
.link.strong { font-weight: 600; }
.link:active { opacity: .5; }

.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; }

.f-title {
  width: 100%; padding: 14px 16px; margin-bottom: 14px;
  background: var(--bg-2); border: 0; border-radius: 12px; outline: none;
  font-size: 18px; font-weight: 500;
}
.chips { display: flex; gap: 8px; margin-bottom: 16px; }
.chips .chip { flex: 1; justify-content: center; background: var(--bg-2); }
.chips .chip.on { color: #fff; }

.rows { background: var(--bg-2); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: .5px solid var(--sep); font-size: 16px;
}
.row:last-child { border-bottom: 0; }
.row-inputs { display: flex; gap: 8px; }
.row input[type=date], .row input[type=time] {
  background: var(--fill); border: 0; border-radius: 8px; padding: 6px 10px;
  outline: none; font-size: 15px; font-variant-numeric: tabular-nums;
}

.switch {
  appearance: none; -webkit-appearance: none;
  width: 51px; height: 31px; border-radius: 999px; background: var(--fill-2);
  position: relative; transition: background .25s var(--ease); flex: none;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #fff; box-shadow: 0 2px 5px rgba(0, 0, 0, .25);
  transition: transform .25s var(--ease);
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.f-notes {
  width: 100%; padding: 14px 16px; background: var(--bg-2);
  border: 0; border-radius: 12px; outline: none; resize: none;
  font-size: 16px; margin-bottom: 14px;
}
.danger {
  width: 100%; padding: 14px; border-radius: 12px;
  background: var(--bg-2); color: var(--today); font-size: 16px; font-weight: 500;
}
.danger:active { background: var(--fill-2); }

/* ---------- тост ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 150px); z-index: 60;
  transform: translate(-50%, 12px); opacity: 0;
  padding: 11px 20px; border-radius: 999px;
  background: rgba(0, 0, 0, .82); color: #fff; font-size: 14px; font-weight: 500;
  backdrop-filter: blur(10px); pointer-events: none;
  transition: opacity .25s, transform .25s var(--ease);
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- широкий экран ---------- */

@media (min-width: 760px) {
  .app { max-width: 860px; margin: 0 auto; border-left: .5px solid var(--sep); border-right: .5px solid var(--sep); }
  .filters { position: static; border-top: .5px solid var(--sep); }
  .fab { bottom: 28px; right: calc(50% - 430px + 24px); }
  .cell { min-height: 74px; }
  .day-list { padding-bottom: 24px; }
  .tl-scroll { padding-bottom: 24px; }
  .sheet { left: 50%; transform: translate(-50%, 100%); max-width: 520px; border-radius: 14px; bottom: 24px; }
  .sheet.on { transform: translate(-50%, 0); }
}
@media (min-width: 760px) and (max-width: 940px) {
  .fab { right: 24px; }
}
