/* Freelance OS — один акцент, монохром, светлая и тёмная тема */
:root {
  --bg: #FAFAF9; --surface: #FFFFFF; --text: #18181B; --muted: #52525B; --faint: #71717A;
  --border: #E4E4E7; --line: #F0F0EE; --hover: #F0F0EE; --input: #D4D4D8;
  --accent: #2563EB; --accent-text: #FFFFFF; --accent-soft: #EEF3FE;
  --warn: #C2410C; --warn-soft: #FFF4ED; --ok: #15803D; --ok-soft: #EEFBF2;
  --radius: 12px; --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121214; --surface: #1B1B1F; --text: #F4F4F5; --muted: #A1A1AA; --faint: #8B8B94;
    --border: #2E2E33; --line: #26262B; --hover: #26262B; --input: #3F3F46;
    --accent: #5B8DEF; --accent-text: #0B1220; --accent-soft: #1C2740;
    --warn: #FB923C; --warn-soft: #2A1A10; --ok: #4ADE80; --ok-soft: #102417;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
a.link, .link { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 28px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); }
p { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); font-weight: 600; }
.ok { color: var(--ok); }
.accent { color: var(--accent); }
.strong { font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }

/* каркас */
.app { display: flex; flex-wrap: wrap; min-height: 100vh; }
.nav { flex: 1 1 200px; max-width: 240px; padding: 28px 16px; border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 17px; padding: 0 12px 20px; }
.nav a { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 8px; min-height: 40px; }
.nav a.on { background: var(--hover); font-weight: 600; }
.nav a .count { font-size: 12px; color: var(--warn); font-weight: 600; }
.nav .spacer { flex: 1 1 auto; }
.nav .foot { padding: 8px 12px; font-size: 12px; color: var(--faint); display: flex; gap: 8px; align-items: center; }
.main { flex: 999 1 560px; min-width: 0; padding: 32px 40px 64px; display: flex; flex-direction: column; gap: 24px; max-width: 1140px; }

@media (max-width: 760px) {
  .app { flex-direction: column; }
  .nav { max-width: 100%; min-width: 0; width: 100%; flex: none; flex-direction: row; overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border); gap: 2px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
  .brand, .nav .spacer, .nav .foot { display: none; }
  .nav a { white-space: nowrap; padding: 8px 12px; }
  .main { padding: 20px 16px 48px; gap: 18px; width: 100%; max-width: 100%; }
  h1 { font-size: 24px; }
}

/* заголовок страницы */
.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.head .sub { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* карточки и сетки */
.card { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 20px; min-width: 0; }
.card.tight { padding: 20px 20px 8px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 24px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; white-space: nowrap; }
.kpis.inline { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.empty { color: var(--muted); padding: 12px 0; }

/* списки */
.list { list-style: none; margin: 0; padding: 0; }
.list > li, .rowline { display: flex; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); min-height: 44px; }
.list > li:first-child, .rowline:first-child { border-top: 0; }
.card-head + .list > li:first-child { border-top: 1px solid var(--line); }
.list .title { font-size: 14px; overflow-wrap: anywhere; }
.list .meta { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.list li.done .title { color: var(--faint); text-decoration: line-through; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.kv:first-of-type { border-top: 0; }
.kv > :first-child { color: var(--muted); }
.amount { font-weight: 600; white-space: nowrap; text-align: right; }

/* чекбокс-кнопка */
.check-form { display: contents; }
.check { flex: none; width: 22px; height: 22px; border: 1.5px solid var(--input); border-radius: 6px; background: var(--surface); cursor: pointer; padding: 0; position: relative; }
.check:hover { border-color: var(--text); }
.check.on { background: var(--text); border-color: var(--text); }
.check.on::after { content: ""; position: absolute; left: 6px; top: 2px; width: 6px; height: 11px; border: solid var(--surface); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.check::before { content: ""; position: absolute; inset: -11px; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 5px; background: var(--text); }
.dot.open { background: transparent; border: 1.5px solid var(--faint); }
.dot.current { background: transparent; border: 2px solid var(--accent); }

/* метки */
.tag { font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag.urgent, .tag.overdue { color: var(--warn); }
.tag.paid { color: var(--ok); }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 16px; border: 1px solid var(--input); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--text); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--warn); }
.btn.icon { width: 44px; padding: 0; font-size: 22px; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linkbtn.muted { color: var(--muted); }
.linkbtn:hover { text-decoration: underline; }
.inline-form { display: inline; }

input[type=text], input[type=number], input[type=date], input[type=time], input[type=password], input[type=search], select, textarea {
  height: 44px; padding: 0 12px; border: 1px solid var(--input); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; font-size: 14px; width: 100%; min-width: 0;
}
textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .check:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.f { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); min-width: 0; }
label.f.check-label { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--text); min-height: 44px; }
label.f.check-label input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.form-grid .wide { grid-column: 1 / -1; }
.form-row { display: flex; gap: 8px; align-items: center; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--input); border-radius: 10px; overflow: hidden; height: 44px; }
.seg label { display: flex; align-items: center; padding: 0 14px; cursor: pointer; font-size: 14px; color: var(--text); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { font-weight: 600; color: var(--accent); }
.seg label + label { border-left: 1px solid var(--input); }

/* быстрая запись */
.quick { display: flex; gap: 8px; flex: 1 1 320px; max-width: 480px; }
.quick input { flex: 1 1 auto; }

/* раскрывающиеся формы */
details.add > summary { list-style: none; cursor: pointer; display: inline-flex; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { margin-bottom: 14px; }
details.add .panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 18px; }
details.inline > summary { list-style: none; cursor: pointer; color: var(--accent); font-size: 13px; }
details.inline > summary::-webkit-details-marker { display: none; }
details.inline[open] > summary { margin-bottom: 10px; }
details.danger-zone > summary { color: var(--warn); }

/* вкладки */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { display: inline-flex; align-items: center; height: 36px; padding: 0 14px; border: 1px solid var(--input); border-radius: 18px; background: var(--surface); font-size: 13px; white-space: nowrap; }
.tab.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.tab.on:hover { color: var(--bg); }

/* таблица */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table-wrap table { min-width: 720px; }
th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 500; padding: 14px 12px; }
td { padding: 14px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
tr.rowlink:hover td { background: var(--hover); }
td .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* прогресс */
.bar { display: flex; align-items: center; gap: 8px; }
progress { -webkit-appearance: none; appearance: none; width: 80px; height: 6px; border: 0; border-radius: 3px; background: var(--line); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 3px; }
progress::-webkit-progress-value { background: var(--text); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--text); border-radius: 3px; }
progress.wide { width: 100%; height: 8px; }
progress.accent::-webkit-progress-value { background: var(--accent); }
progress.accent::-moz-progress-bar { background: var(--accent); }

/* график */
.chart svg { width: 100%; height: 150px; display: block; }
.chart .b { fill: var(--input); }
.chart .b.cur { fill: var(--accent); }
.chart text { fill: var(--muted); font-family: var(--font); }
.chart text:not(.scaled) { font-size: 14px; }
.chart text.cur { fill: var(--text); font-weight: 600; }

/* сообщения */
.flash { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; padding: 12px 16px; border-radius: 10px; background: var(--accent-soft); color: var(--text); }
.flash.err { background: var(--warn-soft); color: var(--warn); }
.hint { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); line-height: 1.55; }
.hint svg { flex: none; margin-top: 1px; color: var(--accent); }
.codebox { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; background: var(--hover); border-radius: 8px; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }

/* календарь */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.cal .wd { padding: 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.cal .day { min-height: 112px; padding: 8px; border-top: 1px solid var(--line); border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cal .day:nth-child(7n+1) { border-left: 0; }
.cal .day.out { background: var(--bg); }
.cal .day.out .num { color: var(--faint); }
.cal .num { font-size: 13px; font-weight: 600; }
.cal .day.today .num { color: var(--accent-text); background: var(--accent); border-radius: 12px; padding: 0 7px; align-self: flex-start; }
.cal .wdname { display: none; }
.chip { display: block; font-size: 12px; line-height: 1.35; padding: 3px 6px; border-radius: 6px; background: var(--hover); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.event { background: var(--accent-soft); color: var(--accent); }
.chip.deadline { background: var(--warn-soft); color: var(--warn); }
.chip.done { color: var(--faint); text-decoration: line-through; }
@media (max-width: 760px) {
  .cal { display: block; }
  .cal .wd, .cal .day.out, .cal .day.empty { display: none; }
  .cal .day { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 6px 8px; padding: 12px 14px; border-left: 0; }
  .cal .day .num { min-width: 28px; }
  .cal .wdname { display: inline; font-size: 12px; color: var(--muted); width: calc(100% - 40px); }
  .cal .chip { white-space: normal; flex: 1 1 100%; }
}

/* вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.login h1 { font-size: 26px; }
.pre { white-space: pre-line; }
.pad { height: 12px; }

/* ожидание ответа Claude (htmx ставит класс htmx-request на форму) */
.busy { display: none; font-size: 13px; color: var(--muted); align-self: center; white-space: nowrap; }
form.htmx-request .busy { display: inline; }
form.htmx-request button { opacity: .5; pointer-events: none; }
.quick { position: relative; }
.quick .busy { position: absolute; top: 100%; left: 2px; margin-top: 4px; }
.hint-form { display: flex; gap: 8px; align-items: center; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-bad { color: var(--warn); font-weight: 600; }
.pad-top { margin-top: 14px; }
.chip.deadline.done { text-decoration: line-through; opacity: .7; }
.chart svg.tall { height: auto; max-height: 260px; }

/* выбор налогового режима */
.regimes { display: flex; flex-direction: column; gap: 10px; }
.regime { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.regime:hover { border-color: var(--input); }
.regime.on, .regime:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.regime input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.regime .meta { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
input.narrow { max-width: 220px; }
details > summary.strong { cursor: pointer; }

/* тип проекта: переключатель и поля формы без JS */
.seg-links { display: inline-flex; border: 1px solid var(--input); border-radius: 10px; overflow: hidden; align-self: flex-start; }
.seg-links a { padding: 10px 16px; font-size: 14px; min-height: 44px; display: flex; align-items: center; }
.seg-links a + a { border-left: 1px solid var(--input); }
.seg-links a.on { background: var(--text); color: var(--bg); font-weight: 600; }
.project-form .internal-only-text { display: none; }
.project-form:has(select[name=kind] option[value=internal]:checked) .client-only { display: none; }
.project-form:has(select[name=kind] option[value=internal]:checked) .client-only-text { display: none; }
.project-form:has(select[name=kind] option[value=internal]:checked) .internal-only-text { display: inline; }
.form-grid .grow-2 { grid-column: span 2; }
@media (max-width: 760px) { .form-grid .grow-2 { grid-column: auto; } }
progress.over::-webkit-progress-value { background: var(--warn); }
progress.over::-moz-progress-bar { background: var(--warn); }
