:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #171923; --muted: #6b7083; --line: #e4e6ee; --soft: #eef0f7;
  --accent: #4f46e5; --accent-soft: #eef0ff; --danger: #e5484d; --ok: #12a150;
  --work: #f76b15; --work-soft: #fff1e7; --personal: #3e63dd; --personal-soft: #edf1fd;
  --q-do: #e5484d; --q-plan: #3e63dd; --q-delegate: #f76b15; --q-drop: #8b8d98;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --card: #181b24; --text: #eceef4; --muted: #9aa0b4; --line: #2a2f3d; --soft: #212534;
    --accent: #8b85ff; --accent-soft: #24234a; --work-soft: #3a2515; --personal-soft: #1b2546;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 4px 10px 18px; }
.brand img { width: 30px; height: 30px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; border: 0; background: none; cursor: pointer; width: 100%; text-align: left; }
.nav-item:hover { background: var(--soft); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 22px; text-align: center; font-size: 17px; }
.sidebar .spacer { flex: 1; }
.main { min-width: 0; padding: 24px 32px 40px; max-width: 1200px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.bottom-nav { display: none; }
.mobile-head { display: none; }

@media (max-width: 899px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 12px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .mobile-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); z-index: 40; }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); text-decoration: none; background: none; border: 0; }
  .bottom-nav .ico { font-size: 20px; }
  .bottom-nav .active { color: var(--accent); font-weight: 600; }
  h1 { font-size: 21px; }
}

/* ---------- элементы ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 899px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 500; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); font-size: 16px; line-height: 1; }
.icon-btn:hover { background: var(--soft); color: var(--text); }

input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=number], input[type=search], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); outline: none; min-height: 42px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 90px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 599px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.seg { display: inline-flex; background: var(--soft); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; background: var(--soft); color: var(--muted); border: 1px solid transparent; white-space: nowrap; }
.chip.work { background: var(--work-soft); color: var(--work); }
.chip.personal { background: var(--personal-soft); color: var(--personal); }
.chip.do { background: color-mix(in srgb, var(--q-do) 14%, transparent); color: var(--q-do); }
.chip.plan { background: color-mix(in srgb, var(--q-plan) 14%, transparent); color: var(--q-plan); }
.chip.delegate { background: color-mix(in srgb, var(--q-delegate) 14%, transparent); color: var(--q-delegate); }
.chip.overdue { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
button.chip { cursor: pointer; }
button.chip.on { border-color: currentColor; }

/* ---------- быстрый ввод ---------- */
.quick { display: flex; flex-direction: column; gap: 10px; }
.quick-row { display: flex; gap: 8px; }
.quick-row input { font-size: 16px; min-height: 48px; }
.quick-row .btn { min-height: 48px; }
.parse-chips { display: flex; gap: 6px; flex-wrap: wrap; min-height: 26px; }

/* ---------- задачи ---------- */
.task { display: flex; gap: 12px; align-items: flex-start; padding: 11px 4px; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task .tick { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); background: none; cursor: pointer; flex: 0 0 auto; margin-top: 1px; display: grid; place-items: center; color: #fff; font-size: 13px; padding: 0; }
.task .tick:hover { border-color: var(--accent); }
.task.done .tick { background: var(--ok); border-color: var(--ok); }
.task.done .t-title { text-decoration: line-through; color: var(--muted); }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .t-title { font-weight: 500; overflow-wrap: anywhere; }
.task .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }
.task .bar { width: 4px; align-self: stretch; border-radius: 4px; flex: 0 0 auto; }
.empty { color: var(--muted); padding: 18px 4px; text-align: center; font-size: 14px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 0 4px; }

.priority-item { display: flex; gap: 12px; padding: 12px; border-radius: 12px; background: var(--soft); align-items: flex-start; }
.priority-item .num { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
.tips { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; }
.tips li { margin: 3px 0; }

/* ---------- матрица ---------- */
.matrix { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.quad { min-height: 220px; border-top: 4px solid var(--q); }
.quad.drag-over { outline: 2px dashed var(--q); outline-offset: -6px; }
.quad .task { cursor: grab; }
@media (max-width: 699px) { .matrix { grid-template-columns: 1fr; } .quad { min-height: 0; } }

/* ---------- календарь ---------- */
.cal-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.cal-title { font-size: 18px; font-weight: 600; min-width: 160px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--line); border-top: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); }
.cal-dow { padding: 8px; font-size: 12px; color: var(--muted); text-align: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--soft); }
.cal-cell { min-height: 108px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-cell:hover { background: var(--soft); }
.cal-cell.other { color: var(--muted); background: color-mix(in srgb, var(--soft) 50%, transparent); }
.cal-cell.selected { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell .d { font-size: 13px; font-weight: 600; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.cal-cell.today .d { background: var(--accent); color: #fff; }
.cal-ev { font-size: 12px; padding: 2px 6px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-ev.personal { background: var(--personal-soft); color: var(--personal); }
.cal-ev.work { background: var(--work-soft); color: var(--work); }
.cal-ev.done { opacity: .5; text-decoration: line-through; }
.cal-more { font-size: 11px; color: var(--muted); padding-left: 4px; }
.dots { display: none; gap: 3px; justify-content: center; flex-wrap: wrap; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.dot.personal { background: var(--personal); } .dot.work { background: var(--work); }
.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
@media (max-width: 1099px) { .cal-layout { grid-template-columns: 1fr; } }
@media (max-width: 699px) {
  .cal-cell { min-height: 54px; align-items: center; padding: 4px 2px; }
  .cal-cell .cal-ev, .cal-cell .cal-more { display: none; }
  .cal-cell .dots { display: flex; }
}

/* ---------- заметки ---------- */
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.note { cursor: pointer; display: flex; flex-direction: column; gap: 8px; min-height: 140px; border-top: 4px solid var(--nc, var(--line)); }
.note .n-body { white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 7; -webkit-box-orient: vertical; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.color { width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.color.on { border-color: var(--text); }

/* ---------- карточки людей ---------- */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.person { display: flex; flex-direction: column; gap: 8px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: 0 0 auto; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--soft); font-weight: 600; font-size: 13px; color: var(--muted); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tr:last-child td { border-bottom: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.export-list { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- модальные окна, уведомления ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); display: grid; place-items: center; z-index: 100; padding: 16px; animation: fade .12s; }
.modal { background: var(--card); border-radius: 18px; width: min(620px, 100%); max-height: calc(100vh - 32px); overflow: auto; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
@media (max-width: 599px) {
  .overlay { place-items: end stretch; padding: 0; }
  .modal { border-radius: 18px 18px 0 0; max-height: 92vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
@media (max-width: 899px) { #toasts { bottom: calc(var(--nav-h) + 12px); left: 16px; right: 16px; } }
.toast { background: #1d1f2b; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fade .15s; font-size: 14px; }
.toast.error { background: #b4232a; }
.toast.ok { background: #13734a; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth { width: min(420px, 100%); }
.auth .brand { justify-content: center; padding-bottom: 8px; font-size: 22px; }
.slots { display: flex; gap: 6px; flex-wrap: wrap; }
.banner { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.banner.warn { background: var(--work-soft); color: var(--work); }
.sheet-menu { display: flex; flex-direction: column; gap: 4px; }
