:root {
  --bg: #f4f5f9;
  --card: #ffffff;
  --line: #e9ebf1;
  --text: #1f2937;
  --muted: #7c8398;
  --green: #22c55e;
  --green-dark: #16a34a;
  --green-soft: #e9f9ef;
  --red: #ef4444;
  --red-soft: #fdecec;
  --amber: #f59e0b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 4px 16px rgba(20, 30, 60, .04);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--green-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.green { color: var(--green-dark); }
.red { color: var(--red); }
.hidden { display: none !important; }

/* ---------- каркас ---------- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 22px 18px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; padding: 6px 10px 26px; }
.brand .logo { width: 30px; height: 30px; border-radius: 50%; background: conic-gradient(var(--green) 0 70%, var(--amber) 70% 100%); position: relative; }
.brand .logo::after { content: ""; position: absolute; inset: 7px; background: #fff; border-radius: 50%; }
.sidebar .group { font-size: 11px; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--text); font-weight: 500; }
.nav a svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; opacity: .75; }
.nav a:hover { background: #f6f7fa; text-decoration: none; }
.nav a.active { background: var(--green-soft); color: var(--green-dark); }
.nav a.active svg { opacity: 1; }
.nav .sub a { padding-left: 34px; font-weight: 400; font-size: 13px; }
.nav .sub a::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--line); margin-left: -18px; }
.nav .sub a.active::before { background: var(--green); }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.topbar h1 { flex: 1; }
.topbar .crumbs { font-size: 13px; color: var(--muted); }
.topbar .crumbs a { color: var(--muted); }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--green-soft); color: var(--green-dark); display: grid; place-items: center; font-weight: 600; }

/* ---------- карточки / сетки ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid { display: grid; gap: 18px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: 2fr 1fr; }
.grid.half { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: 18px; }

.stat { display: flex; justify-content: space-between; align-items: flex-start; }
.stat .label { color: var(--text); font-weight: 500; margin-bottom: 6px; }
.stat .value { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.stat .value.bad { color: var(--red); }
.stat .value.good { color: var(--green-dark); }
.stat .icon { width: 50px; height: 50px; border-radius: 50%; background: #f3f4f8; display: grid; place-items: center; color: #8b93a9; flex: none; }
.stat .icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.stat .icon.good { background: var(--green-soft); color: var(--green-dark); }
.stat .icon.bad { background: var(--red-soft); color: var(--red); }
.stat-foot { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; font-size: 13px; color: var(--muted); }

/* ---------- таблицы ---------- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 13px; padding: 10px 12px; background: #f6f7fa; }
th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: #fafbfd; }
.thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; background: #f0f1f5; border: 1px solid var(--line); }
.thumb-empty { width: 42px; height: 42px; border-radius: 8px; border: 1px dashed var(--line); display: grid; place-items: center; color: #c7cbd6; font-size: 11px; }

/* ---------- кнопки / формы ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 9px; border: 1px solid transparent; background: var(--green); color: #fff; font-weight: 500; cursor: pointer; transition: background .12s; white-space: nowrap; }
.btn:hover { background: var(--green-dark); }
.btn.secondary { background: #fff; border-color: var(--line); color: var(--text); }
.btn.secondary:hover { background: #f6f7fa; }
.btn.danger { background: #fff; border-color: var(--line); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-icon { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; }
.btn-icon:hover { background: #f3f4f8; color: var(--text); }
.btn-icon svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; display: block; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; }
.input { padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; width: 100%; outline: none; }
.input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(34,197,94,.15); }
textarea.input { min-height: 70px; resize: vertical; }
.form-row { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.form-row.three { grid-template-columns: 2fr 1fr 1fr; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.file-drop { border: 1px dashed #cfd3dd; border-radius: 9px; padding: 14px; text-align: center; color: var(--muted); cursor: pointer; }
.file-drop:hover { border-color: var(--green); color: var(--green-dark); }
.file-drop input { display: none; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; background: #f3f4f8; color: var(--muted); }
.pill.good { background: var(--green-soft); color: var(--green-dark); }
.pill.bad { background: var(--red-soft); color: var(--red); }
.pill.work { background: #eef2ff; color: #4f46e5; }
.linkbox { display: flex; gap: 8px; align-items: center; }
.linkbox .input { font-size: 13px; color: var(--muted); }

/* ---------- прогресс бюджета ---------- */
.budget-bar { height: 10px; border-radius: 999px; background: #eef0f5; overflow: hidden; margin: 10px 0 6px; }
.budget-bar i { display: block; height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }
.budget-bar i.bad { background: var(--red); }
.budget-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* ---------- галерея ---------- */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery .ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eef0f5; }
.gallery .ph img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; }
.gallery .ph .del { position: absolute; top: 6px; right: 6px; background: rgba(255,255,255,.9); border-radius: 6px; opacity: 0; }
.gallery .ph:hover .del { opacity: 1; }
.gallery .ph .tag { position: absolute; left: 6px; bottom: 6px; font-size: 11px; background: rgba(0,0,0,.5); color: #fff; padding: 2px 7px; border-radius: 6px; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- модалка / тосты ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(17,24,39,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.2); max-height: 92vh; overflow: auto; }
.modal h2 { margin-bottom: 16px; }
.modal .stack > * + * { margin-top: 12px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; object-fit: contain; border-radius: 6px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 70; font-size: 13px; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast.err { background: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty b { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- логин ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login { width: 360px; }
.login .brand { padding-bottom: 12px; justify-content: center; }

/* ---------- публичная страница ---------- */
.public { max-width: 980px; margin: 0 auto; padding: 28px 18px 60px; }
.public .head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; background: #eceef4; padding: 4px; border-radius: 10px; }
.tabs button { border: 0; background: none; padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

@media (max-width: 1000px) {
  .grid.cols-3, .grid.cols-4, .grid.two, .grid.half { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px; }
  .sidebar .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar .group, .sidebar .sub { display: none; }
  .main { padding: 12px; }
  .grid { gap: 10px; }
  .grid > *, .stack > * { min-width: 0; }
  .grid.two, .grid.half, .form-row, .form-row.three { grid-template-columns: 1fr; }
  /* цифры компактной плиткой 2×2, а не простынёй в столбик */
  .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .grid.cols-3 .card, .grid.cols-4 .card { padding: 14px; }
  .grid.cols-3 .stat .icon, .grid.cols-4 .stat .icon { display: none; }
  .grid.cols-3 .stat .label, .grid.cols-4 .stat .label { font-size: 13px; }
  .stat .value { font-size: 20px; }
  .stat-foot { margin-top: 10px; padding-top: 8px; font-size: 12px; }
  .card { padding: 16px 14px; }
  /* таблица прокручивается внутри карточки и не растягивает страницу */
  .card { overflow-x: auto; }
  .card-head { flex-wrap: wrap; }
  table { font-size: 13px; }
  td, th { padding: 8px 6px; }
  .thumb, .thumb-empty { width: 34px; height: 34px; }
  .hide-m { display: none; }
  .topbar { margin-bottom: 14px; }
  h1 { font-size: 19px; }
  .public { padding: 14px 12px 50px; }
}
