/* SweetHome. Монохромная графитовая гамма. Roboto Mono.
   --navy = тёмный заголовок, --copper = единый приглушённый акцент. */
:root {
  --navy: #2b3138;
  --navy-2: #272c32;
  --copper: #5e6b78;
  --copper-2: #434d57;
  --bg: #f4f4f2;
  --card: #ffffff;
  --ink: #2a2f35;
  --muted: #868d95;
  --line: #e4e4e1;
  --ok: #5a7a63;
  --shadow: 0 1px 4px rgba(20, 24, 28, .05);
  --radius: 10px;
  --side: 248px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy:#e6e8ea; --navy-2:#1d2126; --copper:#9aa7b2; --copper-2:#b6c0c9;
    --bg:#15181c; --card:#1c2025; --ink:#e3e6e9; --muted:#878e96; --line:#2a2f35;
    --shadow:0 1px 5px rgba(0,0,0,.3);
  }
}
:root[data-theme="dark"] {
  --navy:#e6e8ea; --navy-2:#1d2126; --copper:#9aa7b2; --copper-2:#b6c0c9;
  --bg:#15181c; --card:#1c2025; --ink:#e3e6e9; --muted:#878e96; --line:#2a2f35;
  --shadow:0 1px 5px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.6 "Roboto Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 700; letter-spacing: -.3px; }

/* ---------- Login ---------- */
.login { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 16px; }
.login[hidden] { display: none; }
.login-box { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; }
.login-brand { font-size: 22px; font-weight: 700; color: var(--navy); letter-spacing: -.3px; }
.login-sub { margin: -6px 0 8px; color: var(--muted); font-size: 12px; }
.login-box label { font-size: 12px; font-weight: 500; color: var(--ink); display: flex; flex-direction: column; gap: 5px; }
.login-box input { border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; padding: 10px 11px; }
.login-box input:focus { outline: 0; border-color: var(--copper); background: var(--card); }
.login-box .btn { justify-content: center; padding: 10px; margin-top: 4px; }
.login-err { color: #b06a62; font-size: 12px; min-height: 14px; text-align: center; }

/* Роль client — скрыть всё, связанное со сметой */
body[data-role="client"] .costs-only { display: none !important; }
body[data-role="client"] #page-costs { display: none !important; }

/* Блок пользователя в сайдбаре */
.user { display: flex; align-items: center; gap: 9px; padding: 10px 8px; margin-bottom: 8px; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.user-ava { width: 28px; height: 28px; flex: 0 0 auto; border-radius: 50%; background: var(--copper); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.user-name { flex: 1; font-size: 13px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-out { background: rgba(255,255,255,.1); color: #fff; border: 0; cursor: pointer; width: 30px; height: 30px; border-radius: 8px; font-size: 15px; flex: 0 0 auto; }
.user-out:hover { background: var(--copper-2); }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.side {
  width: var(--side); flex: 0 0 var(--side);
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
  background: var(--navy-2); color: #fff;
  border-right: 3px solid var(--copper);
  display: flex; flex-direction: column; padding: 20px 14px;
}
.brand { padding: 4px 8px 20px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 14px; }
.brand b { display: block; font-size: 19px; color: #fff; letter-spacing: 0; }
.brand b span { color: var(--copper); }
.brand small { display: block; color: #9fb4ca; font-size: 11px; letter-spacing: 2px; text-transform: uppercase; margin-top: 4px; }
.side nav { display: flex; flex-direction: column; gap: 4px; }
.side nav a {
  display: flex; align-items: center; gap: 10px;
  color: #d6e2ef; text-decoration: none; font-size: 13px;
  padding: 10px 12px; border-radius: 9px; border-left: 3px solid transparent;
}
.side nav a .ic { width: 18px; text-align: center; font-size: 15px; }
.side nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.side nav a.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--copper); font-weight: 700; }
.side .spacer { flex: 1; }
.side .foot { border-top: 1px solid rgba(255,255,255,.12); padding-top: 12px; display: flex; align-items: center; gap: 10px; }
.theme-btn {
  background: rgba(255,255,255,.1); color: #fff; border: 0; cursor: pointer;
  width: 34px; height: 34px; border-radius: 9px; font-size: 15px; flex: 0 0 auto;
}
.theme-btn:hover { background: rgba(255,255,255,.2); }
.side .foot small { color: #9fb4ca; font-size: 11px; line-height: 1.4; }

/* ---------- Content ---------- */
.content { flex: 1 1 auto; min-width: 0; padding: 32px 36px 80px; max-width: 1000px; }
.page { display: none; }
.page.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; gap: 12px; margin: 0 0 6px; }
.page-head h1 { margin: 0; font-size: 26px; color: var(--navy); }
.page-head .tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 24px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 8px 13px; border-radius: 9px; font-size: 12px; font-weight: 500; font-family: inherit;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--copper); color: var(--copper-2); }
.btn.primary { background: var(--copper); color: #fff; border-color: var(--copper); }
.btn.primary:hover { background: var(--copper-2); }
.btn.ghost { background: transparent; }

/* ---------- Overview ---------- */
.lead { font-size: 15px; color: var(--ink); max-width: 640px; line-height: 1.7; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin: 26px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; color: var(--copper-2); }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ov-links { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 12px; }
.ov-link { display: block; text-decoration: none; padding: 18px; }
.ov-link h3 { margin: 0 0 6px; color: var(--navy); font-size: 16px; }
.ov-link p { margin: 0; color: var(--muted); font-size: 12px; }
.ov-link .ic { font-size: 22px; }
.ov-link:hover { border-color: var(--copper); }

/* ---------- Plan ---------- */
.plan-wrap { display: grid; grid-template-columns: 1.1fr 1fr; gap: 16px; }
.plan-img { padding: 14px; text-align: center; }
.plan-img img { max-width: 100%; height: auto; border-radius: 8px; }
.plan-img figcaption { color: var(--muted); font-size: 12px; margin-top: 8px; }
.rooms { overflow: hidden; }
table.rooms-t { width: 100%; border-collapse: collapse; }
.rooms-t th, .rooms-t td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 13px; }
.rooms-t th { color: var(--muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.rooms-t td.num { font-weight: 700; color: var(--copper-2); width: 38px; }
.rooms-t td.area { text-align: right; width: 84px; color: var(--muted); white-space: nowrap; }
.rooms-t input { width: 100%; border: 0; background: transparent; color: var(--ink); font: inherit; padding: 4px 6px; border-radius: 6px; }
.rooms-t input:focus { outline: 2px solid var(--copper); background: var(--bg); }
.rooms-t tfoot td { font-weight: 700; color: var(--navy); border-bottom: 0; }

/* ---------- Costs ---------- */
.cost-t td { vertical-align: top; }
.cost-t .who { display: flex; flex-direction: column; gap: 2px; }
.cost-t input[type=number] { font-variant-numeric: tabular-nums; }
.cost-t .status-sel {
  border: 1px solid var(--line); border-radius: 7px; background: var(--bg); color: var(--ink);
  font: inherit; font-size: 12px; padding: 5px 7px; cursor: pointer;
}
.cost-t .status-sel:focus { outline: 0; border-color: var(--copper); }
.cost-t .del-row {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px 6px; border-radius: 6px;
}
.cost-t .del-row:hover { color: #fff; background: var(--copper-2); }
.cost-t tfoot #costs-paid { text-align: left; font-weight: 500; color: var(--ok); font-size: 12px; }

/* ---------- Brief ---------- */
.brief-groups { display: grid; gap: 16px; }
.group { padding: 18px 20px; }
.group > h3 { margin: 0 0 14px; font-size: 16px; color: var(--navy); display: flex; align-items: center; gap: 9px; }
.group > h3 .gi { font-size: 18px; }
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--ink); }
.draft-badge { display: inline-block; margin-left: 8px; font-size: 10px; font-weight: 500; color: var(--copper-2); background: color-mix(in srgb, var(--copper) 14%, transparent); border: 1px solid color-mix(in srgb, var(--copper) 30%, transparent); border-radius: 20px; padding: 1px 8px; vertical-align: middle; }
.field .is-draft { border-style: dashed; color: var(--muted); font-style: italic; }
.field .is-draft:focus { border-style: solid; color: var(--ink); font-style: normal; }
.field input[type=text], .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: 13px; padding: 9px 11px; resize: vertical;
}
.field textarea { min-height: 56px; }
.field input[type=text]:focus, .field textarea:focus { outline: 0; border-color: var(--copper); background: var(--card); }
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; border: 1px solid var(--line); border-radius: 9px; padding: 8px 13px; font-size: 13px; background: var(--bg); }
.chk input { accent-color: var(--copper); width: 16px; height: 16px; }
.chk:has(input:checked) { border-color: var(--copper); background: color-mix(in srgb, var(--copper) 12%, transparent); font-weight: 700; }
.save-hint { font-size: 12px; color: var(--muted); align-self: center; }
.save-hint b { color: var(--ok); }
.progress-bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; margin: 0 0 22px; }
.progress-bar > i { display: block; height: 100%; background: var(--copper); width: 0; transition: width .3s; }

/* ---------- References ---------- */
.ref-tabs { display: flex; flex-wrap: wrap; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.ref-tab {
  border: 1px solid transparent; border-bottom: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; cursor: pointer; padding: 9px 14px; border-radius: 9px 9px 0 0;
  display: inline-flex; align-items: center; gap: 7px; margin-bottom: -1px;
}
.ref-tab .ti { font-size: 15px; }
.ref-tab:hover { color: var(--ink); background: var(--bg); }
.ref-tab.active { color: var(--navy); font-weight: 700; background: var(--card); border-color: var(--line); border-bottom: 1px solid var(--card); }
.ref-tab .count { font-size: 11px; font-weight: 500; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 0 8px; }
.ref-tab.active .count { background: var(--card); }
.ref-block-sub { color: var(--muted); font-size: 12px; margin: 0 0 16px; }

.ref-row { display: grid; grid-template-columns: 300px 1fr; gap: 0; overflow: hidden; margin-bottom: 14px; }
.ref-ph { position: relative; background: var(--bg); }
.ref-ph img { display: block; width: 100%; height: 100%; max-height: 260px; object-fit: cover; }
.ref-ph .broken { display: flex; align-items: center; justify-content: center; min-height: 180px; color: var(--muted); font-size: 12px; text-align: center; padding: 12px; }
.ref-tag { position: absolute; top: 8px; left: 8px; background: rgba(20,24,28,.7); color: #fff; font-size: 11px; padding: 3px 9px; border-radius: 20px; }
.ref-ph .del { position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border-radius: 8px; border: 0; background: rgba(20,24,28,.6); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }
.ref-ph .del:hover { background: var(--copper-2); }

.ref-notes { display: grid; grid-template-rows: 1fr 1fr; }
.ref-notes .note { padding: 12px 14px; display: flex; flex-direction: column; }
.ref-notes .note.like { border-bottom: 1px solid var(--line); }
.ref-notes label { font-size: 12px; font-weight: 700; margin-bottom: 6px; }
.ref-notes .note.like label { color: var(--ok); }
.ref-notes .note.no label { color: #b06a62; }
.ref-notes textarea { flex: 1; min-height: 44px; border: 0; border-left: 3px solid var(--line); background: transparent; color: var(--ink); font: inherit; font-size: 13px; padding: 2px 10px; resize: vertical; }
.ref-notes textarea:focus { outline: none; background: var(--bg); }
.ref-notes .ta-like:focus { border-left-color: var(--ok); }
.ref-notes .ta-no:focus { border-left-color: #b06a62; }

.ref-add { padding: 16px 20px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.ref-add input { flex: 1 1 240px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); color: var(--ink); font: inherit; font-size: 13px; padding: 9px 11px; }
.ref-add input:focus { outline: 0; border-color: var(--copper); background: var(--card); }
.empty { padding: 28px; text-align: center; color: var(--muted); border: 2px dashed var(--line); border-radius: 12px; }

@media (max-width: 640px) {
  .ref-row { grid-template-columns: 1fr; }
  .ref-ph img { max-height: 220px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .app { flex-direction: column; }
  .side {
    width: 100%; flex: none; height: auto; position: sticky; top: 0; z-index: 30;
    flex-direction: row; align-items: center; padding: 10px 14px; border-right: 0; border-bottom: 3px solid var(--copper);
    gap: 10px; overflow-x: auto;
  }
  .brand { border: 0; padding: 0; margin: 0; flex: 0 0 auto; }
  .brand small { display: none; }
  .side nav { flex-direction: row; flex: 1; gap: 2px; }
  .side nav a { padding: 8px 10px; white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; }
  .side nav a.active { border-left: 0; border-bottom-color: var(--copper); }
  .side nav a .ic { display: none; }
  .side .spacer { display: none; }
  .side .foot { border: 0; padding: 0; flex: 0 0 auto; }
  .side .foot small { display: none; }
  .user { border: 0; padding: 0; margin: 0; flex: 0 0 auto; gap: 6px; }
  .user-name { display: none; }
  .content { padding: 20px 16px 70px; }
  .plan-wrap { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media print {
  .side, .theme-btn, .page-head .tools, .ref-add, .ref .del { display: none !important; }
  .content { max-width: none; }
  .page { display: block !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; }
}
