:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --border: #e1e4ea;
  --accent: #2457d6;
  --accent-soft: #e8eefc;
  --green: #1f9d55;
  --green-soft: #e3f5ea;
  --yellow: #c98a00;
  --yellow-soft: #fdf3d8;
  --red: #d64040;
  --red-soft: #fbe5e5;
  --radius: 10px;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 15px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.hidden { display: none !important; }

/* --- каркас --- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 18px; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: 12px; }
.main { max-width: 1200px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 20px;
}
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid2 > * { min-width: 0; }
.scroll { overflow-x: auto; }

/* Подсказка «i» */
h2 .info, h1 .info { margin-left: 8px; }
.info {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--muted); color: var(--muted);
  font: 700 11px/1 Georgia, serif; font-style: italic; cursor: help; vertical-align: middle;
}
.info:hover, .info:focus { border-color: var(--accent); color: var(--accent); outline: none; }
.info .tip {
  display: none; position: absolute; left: -10px; top: calc(100% + 10px); width: 360px; max-width: 80vw;
  background: #1d2330; color: #fff; padding: 10px 12px; border-radius: 8px; z-index: 30;
  font: 400 13px/1.45 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-style: normal;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.info .tip::before {
  content: ""; position: absolute; top: -6px; left: 14px; border: 6px solid transparent;
  border-top: 0; border-bottom-color: #1d2330;
}
.info:hover .tip, .info:focus .tip { display: block; }

/* Сворачиваемые таблицы */
table:not(.expanded) tr.more { display: none; }
button.expand { margin-top: 10px; }
.add-link { margin-top: 12px; }

/* Карточка человека */
.person-name { cursor: pointer; color: var(--text); font-weight: 600; }
.person-name:hover { color: var(--accent); text-decoration: underline; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }
.card-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } }

/* --- элементы --- */
button, .btn {
  font: inherit; border: 1px solid var(--border); background: var(--surface);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; color: var(--text);
}
button:hover { border-color: #c6cbd6; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1c47b3; }
button.danger { color: var(--red); }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text); min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form .wide { grid-column: 1 / -1; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 13px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #fafbfc; }
tr.struck td { color: var(--muted); text-decoration: line-through; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px;
  border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.yellow { background: var(--yellow-soft); color: var(--yellow); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.grey { background: var(--bg); color: var(--muted); }
.count { background: var(--red); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.tiles.tiles5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 900px) { .tiles, .tiles.tiles5 { grid-template-columns: 1fr 1fr; } }
.help { color: var(--muted); font-size: 13px; margin: 0 0 12px; max-width: 900px; line-height: 1.45; }
.form .help { grid-column: 1 / -1; margin: 0; }
fieldset.checks { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
fieldset.checks legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; padding: 4px 0; }
label.check input { width: 16px; height: 16px; }
details summary { cursor: pointer; margin-top: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.tile .value { font-size: 28px; font-weight: 700; }
.tile.green .value { color: var(--green); }
.tile.yellow .value { color: var(--yellow); }
.tile.red .value { color: var(--red); }

.error { background: var(--red-soft); color: var(--red); padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.notice { background: var(--accent-soft); color: var(--accent); padding: 10px 14px; border-radius: 8px; margin: 10px 0; }
.empty { color: var(--muted); padding: 20px 0; text-align: center; }

/* --- вход --- */
.login { max-width: 380px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login .brand { font-size: 26px; text-align: center; margin-bottom: 4px; }

/* --- модальное окно --- */
.modal-bg { position: fixed; inset: 0; background: rgba(20, 25, 40, .4); display: flex; align-items: center; justify-content: center; z-index: 20; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 24px; width: min(640px, 92vw); max-height: 90vh; overflow: auto; }
