:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text: #1c2230;
  --muted: #6b7280;
  --faint: #9aa3b2;
  --accent: #2457d6;
  --accent-soft: #e8eefc;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.page { max-width: 1240px; margin: 0 auto; padding: 24px 20px 60px; }

/* ── шапка ─────────────────────────────────────────────── */
.masthead {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand svg { width: 36px; height: 36px; flex: none; }
.brand h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--card); color: var(--text); font-weight: 500; line-height: 1.2;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f8f9fb; border-color: #b9c0cb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e4bbd; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eceef2; color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 8px; font-size: 12.5px; border-radius: 6px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ── период ────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.period { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 11px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--card); color: var(--muted); font-size: 13px; font-weight: 500;
}
.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip.active { background: var(--accent-soft); border-color: #c5d4f7; color: var(--accent); }
.range { display: inline-flex; align-items: center; gap: 6px; margin-left: 6px; color: var(--muted); font-size: 13px; }
.range input[type="date"] {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--card);
  font-size: 13px; color: var(--text);
}
.period-note { color: var(--muted); font-size: 13px; }
.toolbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg.small button { padding: 5px 10px; font-size: 13px; }

/* ── вкладки ───────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  padding: 10px 14px; border: 0; background: none; color: var(--muted);
  font-weight: 500; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.view { display: none; }
.view.active { display: block; }

/* ── карточка и таблица ───────────────────────────────── */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head p { margin: 0; color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 10px 14px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.grid th:first-child, .grid td:first-child { text-align: left; padding-left: 18px; }
.grid th:last-child, .grid td:last-child { padding-right: 18px; }
.grid thead th {
  font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; background: #fafbfc; border-bottom: 1px solid var(--border);
}
.grid thead th .unit { text-transform: none; letter-spacing: 0; color: var(--faint); }
.grid tbody tr.project { cursor: pointer; }
.grid tbody tr.project:hover { background: #f8f9fb; }
.grid tbody tr.project.open { background: var(--accent-soft); }
.grid tbody tr.project td:first-child { font-weight: 500; }
.grid tbody tr.project td:first-child::before {
  content: "▸"; display: inline-block; width: 14px; color: var(--faint); font-size: 11px;
  transition: transform .15s;
}
.grid tbody tr.project.open td:first-child::before { transform: rotate(90deg); }
.grid tbody tr.archived td:first-child { color: var(--muted); }
.grid tbody tr.archived td:first-child::after { content: " · архив"; font-size: 12px; color: var(--faint); font-weight: 400; }
.grid tfoot td { font-weight: 600; background: #fafbfc; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.grid td.empty { color: var(--faint); }
.grid td.derived { color: var(--muted); }
.grid td.good { color: var(--good); }
.grid td.bad { color: var(--bad); }

/* раскрытые строки по дням */
.grid tr.day td { background: #fbfcfd; font-size: 13px; padding-top: 7px; padding-bottom: 7px; }
.grid tr.day td:first-child { padding-left: 40px; color: var(--muted); font-weight: 400; }
.grid tr.day td .note { color: var(--faint); margin-left: 8px; font-weight: 400; }
.grid tr.day .row-actions { display: inline-flex; gap: 4px; visibility: hidden; }
.grid tr.day:hover .row-actions { visibility: visible; }
.grid tr.day-empty td { background: #fbfcfd; color: var(--faint); font-size: 13px; padding-left: 40px !important; text-align: left; }

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state p { margin: 0 0 12px; }

/* ── модалки ───────────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; background: rgba(16, 24, 40, .35); display: flex;
  align-items: center; justify-content: center; padding: 20px; z-index: 20;
}
.modal {
  background: var(--card); border-radius: 12px; box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
  width: 100%; max-width: 480px; max-height: calc(100vh - 40px); overflow: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 16px 20px 20px; display: grid; gap: 12px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 20px; }
.field { display: grid; gap: 4px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid #c5d4f7; border-color: var(--accent); }
.fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { padding: 7px 12px; border: 0; background: #fff; color: var(--muted); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.active { background: var(--accent-soft); color: var(--accent); }
.form-error { color: var(--bad); font-size: 13px; min-height: 1.2em; }

.project-list { display: grid; gap: 6px; }
.project-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
}
.project-row span { flex: 1; font-weight: 500; }
.project-row.archived span { color: var(--muted); }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; }

.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
p.hint { margin: 0; line-height: 1.5; }
.vk-status { font-size: 13px; color: var(--muted); min-height: 1.2em; }
.vk-status.ok { color: var(--good); }
.vk-status.err { color: var(--bad); }
.tag {
  display: inline-block; margin-left: 8px; padding: 1px 6px; border-radius: 4px;
  font-size: 11px; font-weight: 500; letter-spacing: .02em; vertical-align: 1px;
  background: #e8eefc; color: var(--accent);
}
.tag.ym { background: #fdf3d8; color: #8a5a00; }
.goal-list { display: grid; gap: 4px; max-height: 220px; overflow: auto; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; }
.goal-list label { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.goal-list label .hint { margin-left: auto; }
.goal-list input { width: auto; }
.hint code { font-size: 12px; background: #f1f3f6; padding: 1px 4px; border-radius: 4px; word-break: break-all; }
.tag.warn { background: #fdf1e2; color: var(--warn); }
.project-row .tag { margin-left: 0; }
.modal-foot .danger { border-color: transparent; background: transparent; }
.modal-foot .danger:hover { background: #fdecec; }

/* ── тост ───────────────────────────────────────────────── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #1c2230; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .25); z-index: 30; opacity: 0; transition: opacity .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

/* ── вход ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
  padding: 32px 28px; width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center;
}
.login-card svg { width: 40px; height: 40px; margin: 0 auto; }
.login-card h1 { margin: 0; font-size: 20px; font-weight: 600; }
.login-card p { margin: -6px 0 6px; color: var(--muted); font-size: 13px; }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; width: 100%;
}
.login-card button { padding: 10px; border-radius: 8px; border: 0; background: var(--accent); color: #fff; font-weight: 500; }
.login-error { color: var(--bad); font-size: 13px; min-height: 1.2em; }

@media (max-width: 720px) {
  .page { padding: 16px 12px 40px; }
  .grid th, .grid td { padding: 8px 10px; }
  .fields-grid { grid-template-columns: 1fr; }
}
