:root {
  --bg: #f6f3ee; --surface: #ffffff; --surface-2: #efebe4; --line: #e2ddd4;
  --text: #1d2125; --muted: #6b7178;
  --kolya: #1f6f78; --kolya-soft: #d9eeee;
  --me: #d0603f; --me-soft: #fbe3da;
  --both: #7b4fa0;
  --warn: #c56a00; --warn-soft: #fff0d9;
  --danger: #b3261e;
  --pa: #f2d43a; --pb: #3aa7d9; --pc: #8cc63f; --pd: #c58bd8;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c; --surface: #1f2228; --surface-2: #2a2e35; --line: #343841;
    --text: #eceef1; --muted: #9aa1aa;
    --kolya: #5cc2c9; --kolya-soft: #1c3a3d;
    --me: #f08a6a; --me-soft: #43281f;
    --both: #b48ad6;
    --warn: #f0a640; --warn-soft: #3d2d14;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; text-align: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 20px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand b { display: block; font-size: 17px; }
.brand span { font-size: 12px; color: var(--muted); }
.tabs { display: none; }
.main { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.bottom {
  position: fixed; inset: auto 0 0 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.bottom button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 9px; font-size: 11px; color: var(--muted); }
.bottom i { font-style: normal; font-size: 20px; line-height: 1; }
.bottom button[aria-current="true"] { color: var(--kolya); font-weight: 600; }

.card { background: var(--surface); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--line); margin-bottom: 14px; }
.card h2 + .form, .card h2 + p { margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 2px 10px; }
.empty { color: var(--muted); text-align: center; padding: 32px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 12px; background: var(--surface-2); font-weight: 600; }
.btn.primary { background: var(--kolya); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0d2224; } }
.btn.danger { color: var(--danger); background: transparent; }
.btn.wide { width: 100%; }
.icon { width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--muted); }
.icon:hover { background: var(--surface-2); }

/* ---------- цвета периодов ---------- */
.p-a { --pc-: var(--pa); } .p-b { --pc-: var(--pb); } .p-c { --pc-: var(--pc); } .p-d { --pc-: var(--pd); } .p-me { --pc-: var(--me); }

/* ---------- периоды ---------- */
.pchips { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 12px; }
.pchip {
  display: flex; flex-direction: column; align-items: center; padding: 8px 0 7px; border-radius: 14px;
  background: var(--surface); border: 2px solid var(--line); position: relative; overflow: hidden;
}
.pchip::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--pc-); }
.pchip b { font-size: 20px; }
.pchip span { font-size: 12px; color: var(--muted); }
.pchip[aria-pressed="true"] { border-color: var(--pc-); background: color-mix(in srgb, var(--pc-) 16%, var(--surface)); }

.period-head { border-top: 6px solid var(--pc-); }
.ph-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.rule { margin: 6px 0 12px; font-weight: 500; }
.progress { position: relative; background: var(--surface-2); border-radius: 10px; padding: 8px 12px; font-size: 13px; font-weight: 600; overflow: hidden; }
.progress i { position: absolute; inset: 0 auto 0 0; width: var(--w); background: color-mix(in srgb, var(--kolya) 22%, transparent); transition: width .3s; }
.progress span { position: relative; }
.progress.ok { color: var(--kolya); }
.period-head .tripline { margin-top: 8px; }

.tripline {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; width: 100%;
  padding: 10px 12px; border-radius: 12px; background: var(--kolya-soft); font-size: 14px;
}
.tripline.me { background: var(--me-soft); }
.tl-dates { font-weight: 700; white-space: nowrap; }
.tl-note { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.tl-budget { font-weight: 600; white-space: nowrap; }

.weeks { display: grid; gap: 8px; }
.week {
  display: grid; grid-template-columns: 38px 1fr 30px; align-items: center; gap: 10px; width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; min-height: 58px;
}
.wk-num { font-size: 12px; color: var(--muted); font-weight: 600; text-align: center; background: var(--surface-2); border-radius: 8px; padding: 4px 0; }
.wk-dates { display: block; font-weight: 600; }
.wk-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.wk-tags:empty { display: none; }
.wk-state { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); font-weight: 700; }
.week.taken { border-color: var(--kolya); background: var(--kolya-soft); }
.week.taken .wk-state { background: var(--kolya); color: #fff; }
.week.taken .wk-num { background: var(--kolya); color: #fff; }
.week.conflict:not(.taken) { border-color: color-mix(in srgb, var(--warn) 50%, var(--line)); }
.week.blocked { background: repeating-linear-gradient(135deg, var(--surface-2) 0 8px, var(--surface) 8px 16px); color: var(--muted); }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag.kolya { background: var(--kolya); color: #fff; }
.tag.me { background: var(--me); color: #fff; }
.tag.busy-same { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.tag.closed { background: transparent; border: 1px dashed var(--muted); }
@media (prefers-color-scheme: dark) { .tag.kolya, .tag.me, .week.taken .wk-state, .week.taken .wk-num { color: #111; } }

/* ---------- списки отпусков ---------- */
.intro .btn { margin-top: 12px; }
.list { display: grid; gap: 10px; }
.tripcard {
  display: grid; grid-template-columns: 52px 1fr; gap: 12px; width: 100%; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow);
  border-left: 5px solid var(--kolya);
}
.tripcard.me { border-left-color: var(--me); }
.tc-side { display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 12px; padding: 6px 0; }
.tc-side b { font-size: 20px; line-height: 1; }
.tc-side span { font-size: 12px; color: var(--muted); }
.tc-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tc-top { display: flex; justify-content: space-between; gap: 8px; }
.who { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--kolya); }
.who.me { color: var(--me); }
.tc-budget { font-weight: 700; }
.tc-dates { font-weight: 600; }
.tc-note { color: var(--muted); white-space: pre-line; font-size: 14px; }
.tc-warn { font-size: 12px; color: var(--warn); }
.total { text-align: right; color: var(--muted); }

/* ---------- год ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 6px 0 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat b { font-size: 22px; margin: 2px 0; }
.stat small { color: var(--muted); font-size: 12px; }
.stat.kolya b { color: var(--kolya); } .stat.me b { color: var(--me); }
.stat.money { grid-column: 1 / -1; }
.cal { padding: 14px 12px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin: 0 0 10px 34px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.mrow { display: grid; grid-template-columns: 30px 1fr; align-items: center; gap: 4px; margin: 3px 0; }
.mrow > span { font-size: 11px; color: var(--muted); }
.mcells { display: grid; grid-template-columns: repeat(31, 1fr); gap: 2px; }
.mcells i, .legend i { background: var(--surface-2); }
.mcells i { height: 14px; border-radius: 3px; }
.mcells i.we { opacity: .6; }
i.k { background: var(--kolya) !important; opacity: 1 !important; }
i.m { background: var(--me) !important; opacity: 1 !important; }
i.both { background: var(--both) !important; opacity: 1 !important; }

/* ---------- настройки ---------- */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  padding: 10px 12px; font-size: 16px; font-weight: 400; color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--kolya); outline-offset: 0; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 8px; justify-content: space-between; }
.actions .primary { flex: 1; }
.colls { list-style: none; padding: 0; margin: 0; }
.colls li { display: grid; grid-template-columns: 1fr 64px 36px; gap: 8px; align-items: center; padding: 4px 0; border-bottom: 1px solid var(--line); }
.colls select { min-height: 36px; padding: 4px 8px; }
.inline { display: grid; grid-template-columns: 1fr 64px auto; gap: 8px; margin-top: 14px; }

/* ---------- шторка ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; animation: fade .2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 18px calc(24px + env(safe-area-inset-bottom));
  animation: up .25s cubic-bezier(.2,.8,.2,1);
}
.still { animation: none; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.close { position: absolute; top: 10px; right: 10px; }
.sh-head { border-left: 5px solid var(--pc-); padding: 4px 0 4px 12px; margin: 6px 40px 6px 0; }
.badge { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.sh-head h2 { font-size: 22px; margin-top: 2px; }
.sheet section > .tripline { margin-top: 6px; }
.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.ctoggles { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.glabel { font-size: 12px; color: var(--muted); width: 100%; }
.ctoggle { padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 14px; }
.ctoggle[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.ctoggle.same[aria-pressed="true"] { background: var(--warn); border-color: var(--warn); color: #fff; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; justify-items: center; }
.login img { border-radius: 18px; }
.login p { margin: 0; color: var(--muted); }
.login input, .login button { width: 100%; }
.err { color: var(--danger) !important; min-height: 1.4em; }

/* ---------- большой экран ---------- */
@media (min-width: 820px) {
  .bottom { display: none; }
  .main { padding-bottom: 40px; }
  .top { padding: 14px 24px; }
  .tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
  .tabs button { padding: 7px 14px; border-radius: 9px; font-weight: 600; color: var(--muted); }
  .tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
  .main { padding-left: 24px; padding-right: 24px; }
  .weeks { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat.money { grid-column: auto; }
  .mcells i { height: 18px; }
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: min(560px, 92vw);
    border-radius: 22px; max-height: 86vh; animation: pop .2s;
  }
  .grip { display: none; }
  #toast { bottom: 24px; }
  @keyframes pop { from { opacity: 0; transform: translate(-50%, -48%); } }
}
.sheet.still, .backdrop.still { animation: none; }
