:root {
  --bg: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #6e6e73;
  --line: #e5e5ea;
  --hairline: #e5e5ea;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --green: #34c759;
  --danger: #ff3b30;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 17px; line-height: 1.47; color: var(--text); background: #fff;
  -webkit-font-smoothing: antialiased; min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-weight: 600; letter-spacing: -0.02em; margin: 0 0 0.5em; line-height: 1.1; }
h1 { font-size: 40px; font-weight: 700; }
h2 { font-size: 28px; }
h3 { font-size: 21px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
p { margin: 0 0 1em; }
hr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.88em; color: var(--text); }
mark { background: #fff3b0; border-radius: 3px; padding: 0 2px; }
img { max-width: 100%; }
strong { font-weight: 600; }

/* ---- Layout (8px scale) ---- */
.container { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 24px; }
main.page { flex: 1; padding: 64px 0 96px; }
main.page > .container > * + * { margin-top: 48px; }
main.page > .container > .flash + * { margin-top: 32px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: 8px 0 0; font-size: 19px; }
.page-head .note { color: var(--muted); margin: 8px 0 0; font-size: 15px; }
.grid { display: grid; gap: 24px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.sidebar-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 48px; align-items: start; }
@media (max-width: 860px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sidebar-layout { grid-template-columns: 1fr; gap: 24px; }
  h1 { font-size: 32px; }
  h2 { font-size: 24px; }
  main.page { padding: 40px 0 64px; }
  main.page > .container > * + * { margin-top: 32px; }
  .page-head .sub { font-size: 17px; }
}

/* ---- Nav ---- */
.nav { background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 50; }
.nav .container { display: flex; align-items: center; height: 56px; gap: 40px; }
.nav .brand { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; color: var(--text); white-space: nowrap; line-height: 1.1; }
.nav .brand small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); margin-top: 2px; }
.nav .brand:hover { text-decoration: none; }
.nav ul { list-style: none; margin: 0; padding: 0; display: flex; gap: 32px; flex: 1; }
.nav ul a { display: block; padding: 8px 0; color: var(--text); font-size: 15px; transition: color .15s; }
.nav ul a:hover { color: var(--accent); text-decoration: none; }
.nav ul a.active { color: var(--accent); }
.nav .right { display: flex; align-items: center; gap: 24px; font-size: 15px; color: var(--muted); }
.nav .right a { color: var(--text); }
.nav .right a.active { color: var(--accent); }
.nav .right form { margin: 0; }
.nav .right .btn.ghost { padding: 0; min-height: 0; font-size: 15px; font-weight: 400; }
.nav-toggle { display: none; background: none; border: 0; font-size: 22px; padding: 8px; cursor: pointer; color: var(--text); line-height: 1; }
@media (max-width: 860px) {
  .nav .container { flex-wrap: wrap; height: auto; padding-top: 12px; padding-bottom: 12px; gap: 16px; }
  .nav-toggle { display: block; margin-left: auto; }
  .nav ul { display: none; flex-direction: column; width: 100%; order: 10; gap: 0; padding-top: 8px; border-top: 1px solid var(--line); }
  .nav ul a { padding: 14px 0; font-size: 17px; border-bottom: 1px solid var(--line); }
  .nav ul li:last-child a { border-bottom: 0; }
  .nav.open ul { display: flex; }
  .nav .right { display: none; width: 100%; order: 11; justify-content: space-between; padding: 8px 0; }
  .nav.open .right { display: flex; }
}

/* ---- Cards ---- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; }
.card.tight { padding: 0; overflow: hidden; }
.card h2, .card h3 { margin-top: 0; }
.card h3 { margin-bottom: 16px; }
a.card { display: block; color: inherit; transition: border-color .15s; }
a.card:hover { text-decoration: none; border-color: var(--text); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.card-head h3 { margin: 0; }
.card-head a.more { font-size: 15px; white-space: nowrap; }
.stat { font-size: 44px; font-weight: 600; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 15px; margin-top: 12px; line-height: 1.4; }
.card > form > .btn, .card > form > .actions, .card > .btn { margin-top: 8px; }

/* ---- Lists ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 16px 0; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.list .meta { color: var(--muted); font-size: 14px; white-space: nowrap; padding-top: 3px; font-variant-numeric: tabular-nums; }
.list .title { font-weight: 500; color: var(--text); }
a.title:hover { color: var(--accent); text-decoration: none; }
.list .desc { color: var(--muted); font-size: 15px; margin-top: 4px; }
.muted { color: var(--muted); } .faint { color: var(--muted); } .small { font-size: 15px; } .tiny { font-size: 13px; }
.empty { color: var(--muted); padding: 48px 0; text-align: center; margin: 0; }
.card .empty { padding: 48px 0; }
td.empty { padding: 48px 16px; }

/* ---- Chips: tiny text labels, no fills ---- */
.chip { display: inline-block; font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; line-height: 1.4; padding: 1px 7px; border: 1px solid var(--line); border-radius: 6px; vertical-align: 1px; }
.chip.green { color: var(--green); border-color: var(--green); }
.chip.gray { color: var(--muted); }
.chip.red { color: var(--danger); border-color: var(--danger); }
.chip.amber { color: var(--muted); }
.chip.plain { border: 0; padding: 0; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 980px; padding: 0 24px; font: inherit; font-size: 16px; font-weight: 500; cursor: pointer; transition: background 0.15s, border-color .15s, color .15s, opacity .15s; white-space: nowrap; line-height: 1.2; min-height: 44px; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--accent); border-color: var(--accent); }
.btn.secondary:hover { background: #fff; opacity: .75; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent); padding: 0 8px; min-height: 0; line-height: 1.4; }
.btn.ghost:hover { background: transparent; text-decoration: underline; }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #fff; opacity: .75; }
.btn.sm { padding: 0 16px; font-size: 14px; min-height: 32px; }
.btn.ghost.sm { padding: 0 4px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.actions { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline; }

/* ---- Forms ---- */
form { max-width: 640px; }
.card.tight form, form.searchbar, form.dir-search, form#bulk, .nav form, .glass form, form.actions { max-width: none; }
label { display: block; font-size: 13px; font-weight: 400; color: var(--muted); margin-bottom: 8px; }
.field { margin-bottom: 20px; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], input[type=date], input[type=datetime-local], input[type=number], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 0 16px; height: 44px; outline: none; transition: border-color 0.15s, box-shadow 0.15s; -webkit-appearance: none; appearance: none;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.18); }
textarea { min-height: 140px; height: auto; padding: 12px 16px; resize: vertical; line-height: 1.5; }
select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 16px center; padding-right: 40px; }
.check { display: flex; align-items: center; gap: 12px; font-size: 16px; font-weight: 400; color: var(--text); cursor: pointer; margin-bottom: 16px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
input[type=checkbox] { accent-color: var(--accent); width: 18px; height: 18px; -webkit-appearance: checkbox; appearance: checkbox; }
.help { font-size: 14px; color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
input[type=file] { font: inherit; font-size: 15px; color: var(--muted); }
.searchbar { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.searchbar input[type=search] { flex: 1 1 200px; width: auto; min-width: 160px; }
.searchbar select { width: auto !important; flex: 0 0 auto; }
.searchbar + .card, .searchbar + .doc-list, .searchbar + form { margin-top: 24px; }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 14px 12px; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; font-size: 12px; color: var(--muted); font-weight: 400; padding-top: 16px; padding-bottom: 12px; }
.card.tight th:first-child, .card.tight td:first-child { padding-left: 24px; }
.card.tight th:last-child, .card.tight td:last-child { padding-right: 24px; }
.card:not(.tight) thead th, .card:not(.tight) td { padding-left: 0; }
.card:not(.tight) th:last-child, .card:not(.tight) td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td .sub { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
td .chip + .chip { margin-left: 4px; }
td a { color: var(--accent); }
td .actions { flex-wrap: wrap; justify-content: flex-end; gap: 4px 16px; }
td .actions .btn.ghost { padding: 0; font-size: 14px; }

/* ---- Flash ---- */
.flash { padding: 16px 24px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 16px; color: var(--text); }
.flash.success { border-color: var(--green); color: var(--text); }
.flash.error { border-color: var(--danger); color: var(--danger); }

/* ---- Side list (documents / newsletter) ---- */
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list a { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 10px 0; color: var(--text); font-size: 15px; border-bottom: 1px solid var(--line); }
.side-list li:last-child a { border-bottom: 0; }
.side-list a:hover { color: var(--accent); text-decoration: none; }
.side-list a.active { color: var(--accent); font-weight: 500; }
.side-list .count { color: var(--muted); font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; text-align: right; min-width: 2ch; flex: 0 0 auto; }
.side-title { font-size: 13px; color: var(--muted); font-weight: 400; margin: 0 0 8px; }
@media (max-width: 860px) {
  .side-list { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .side-list::-webkit-scrollbar { display: none; }
  .side-list li { flex: 0 0 auto; }
  .side-list a, .side-list li:last-child a { border: 1px solid var(--line); border-radius: 980px; padding: 8px 16px; font-size: 15px; white-space: nowrap; }
  .side-list a.active { border-color: var(--accent); color: var(--accent); font-weight: 400; }
  .side-list .count { display: none; }
  .side-title { display: none; }
}

/* ---- Documents ---- */
.doc-list { margin-top: 24px; }
.doc-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 20px; align-items: center; padding: 20px 0; border-top: 1px solid var(--line); }
.doc-list > .doc-row:first-child, .doc-list > p + .doc-row { border-top: 0; padding-top: 0; }
.doc-icon { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: .02em; }
.doc-title { font-weight: 500; color: var(--text); font-size: 17px; }
.doc-title:hover { color: var(--accent); text-decoration: none; }
.doc-meta { color: var(--muted); font-size: 14px; margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.doc-snippet { color: var(--muted); font-size: 15px; margin-top: 4px; }
.doc-actions { display: flex; gap: 20px; align-items: center; font-size: 15px; white-space: nowrap; }
@media (max-width: 600px) { .doc-row { grid-template-columns: 1fr; gap: 8px; } .doc-icon { display: none; } }

/* ---- Directory (contact list) ---- */
.dir-search { position: relative; }
.dir-search input[type=search] { width: 100%; padding-right: 72px; }
.dir-search .clear { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 14px; }
.dir-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.dir-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) minmax(0, 280px); gap: 24px; padding: 20px 0; border-bottom: 1px solid var(--line); align-items: start; }
.dir-num { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.dir-names { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }
.dir-members { color: var(--muted); font-size: 15px; margin-top: 4px; }
.dir-note { color: var(--muted); font-size: 14px; font-style: italic; margin-top: 8px; }
.dir-contacts { display: flex; flex-direction: column; gap: 4px; font-size: 15px; line-height: 1.4; }
.dir-contacts .phone { color: var(--muted); }
.dir-contacts .phone:hover { color: var(--accent); text-decoration: none; }
.dir-contacts .phone .lbl { font-size: 12px; color: var(--muted); margin-right: 2px; }
.dir-contacts .email { color: var(--accent); overflow-wrap: anywhere; }
.dir-contacts .phone + .email { margin-top: 4px; }
.dir-foot { color: var(--muted); font-size: 14px; margin: 24px 0 0; }
@media (max-width: 700px) {
  .dir-row { grid-template-columns: 56px minmax(0, 1fr); gap: 8px 16px; }
  .dir-contacts { grid-column: 2; }
}

/* ---- Prose ---- */
.prose { font-size: 18px; line-height: 1.6; max-width: 720px; }
.prose h2 { font-size: 24px; margin-top: 1.4em; }
.prose h3 { font-size: 20px; margin-top: 1.2em; }
.prose ul, .prose ol { padding-left: 1.4em; margin: 0 0 1em; }
.prose a { text-decoration: underline; }

/* ---- Hero / login (approved; unchanged) ---- */
.hero { position: relative; min-height: 100vh; display: flex; flex-direction: column; background: #1b2a38 url("/img/hero.jpg") center / cover no-repeat; }
.hero::before { content: ""; position: absolute; inset: 0; background: linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.15) 55%, rgba(0, 0, 0, 0.35)); }
.hero .inner { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 24px; text-align: center; color: #fff; }
.hero h1 { font-size: clamp(40px, 7vw, 64px); font-weight: 700; letter-spacing: -0.025em; margin: 0 0 10px; color: #fff; text-shadow: 0 2px 24px rgba(0, 0, 0, 0.45), 0 1px 3px rgba(0, 0, 0, 0.35); }
.hero .tagline { font-size: clamp(17px, 2.6vw, 22px); font-weight: 600; color: #fff; letter-spacing: -0.01em; margin: 0 0 40px; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.5), 0 1px 3px rgba(0, 0, 0, 0.4); }
.glass { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18); padding: 32px; text-align: left; color: var(--text); }
.glass h2 { font-size: 24px; font-weight: 600; margin-bottom: 20px; }
.glass label { color: var(--text); font-size: 14px; font-weight: 500; }
.glass .links { display: flex; justify-content: center; margin-top: 18px; font-size: 15px; }
.glass .flash { margin-bottom: 16px; padding: 12px 16px; }
.hero-foot { position: relative; text-align: center; color: rgba(255, 255, 255, 0.75); font-size: 13px; padding: 16px; text-shadow: 0 1px 8px rgba(0, 0, 0, 0.5); }

/* ---- Footer ---- */
footer.site { border-top: 1px solid var(--line); padding: 32px 0; color: var(--muted); font-size: 13px; }
footer.site .container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

/* ---- Admin ---- */
.admin-tabs { display: flex; gap: 32px; border-bottom: 1px solid var(--line); }
.admin-tabs a { padding: 0 0 12px; font-size: 15px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.admin-tabs a:hover { color: var(--text); text-decoration: none; }
.admin-tabs a.active { color: var(--text); border-bottom-color: var(--text); }
main.page > .container > .admin-tabs { margin-top: 32px; }
main.page > .container > .admin-tabs + * { margin-top: 40px; }
@media (max-width: 860px) {
  .admin-tabs { overflow-x: auto; gap: 24px; scrollbar-width: none; }
  .admin-tabs::-webkit-scrollbar { display: none; }
}
.preview-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.dropzone { border: 1px dashed var(--line); border-radius: 12px; padding: 32px; text-align: center; color: var(--muted); background: #fff; font-size: 15px; }
.dropzone input { margin-top: 16px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: 15px; }
.text-dump { max-height: 360px; overflow: auto; white-space: pre-wrap; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }

/* ---- Utilities (inline styles are blocked by CSP) ---- */
.mb-8 { margin-bottom: 8px; } .mb-10 { margin-bottom: 8px; } .mb-12 { margin-bottom: 16px; } .mb-14 { margin-bottom: 16px; } .mb-16 { margin-bottom: 16px; } .mb-20 { margin-bottom: 24px; } .mb-28 { margin-bottom: 32px; }
.mt-8 { margin-top: 8px; } .mt-10 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-18 { margin-top: 24px; } .mt-20 { margin-top: 24px; } .mt-24 { margin-top: 24px; } .mb-24 { margin-bottom: 24px; }
.m-0 { margin: 0; }
.w-auto { width: auto !important; } .w-520 { max-width: 520px; } .w-560 { max-width: 560px; } .w-600 { max-width: 600px; } .w-640 { max-width: 640px; } .w-760 { max-width: 640px; }
textarea.h-64 { min-height: 64px; } textarea.h-70 { min-height: 72px; } textarea.h-84 { min-height: 88px; } textarea.h-90 { min-height: 88px; } textarea.h-96 { min-height: 96px; } textarea.h-240 { min-height: 240px; } textarea.h-320 { min-height: 320px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14px; }
.nowrap { white-space: nowrap; } .pre-line { white-space: pre-line; }
.actions.end { justify-content: flex-end; }
.pad-sm { padding: 8px 0; }
.error-card { max-width: 520px; margin: 40px auto; text-align: center; }
.ellipsis { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub-ul { margin: 8px 0 0 18px; padding: 0; }
.section-title { margin: 0 0 16px; }
.section-title .help { display: inline; font-size: 14px; }
.divider-top { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 16px; }
.grid-side { grid-template-columns: minmax(0, 380px) minmax(0, 1fr); }
@media (max-width: 860px) { .grid-side { grid-template-columns: 1fr; } }
.span-all { grid-column: 1 / -1; }
.fw-400 { font-weight: 400; }
.stat-md { font-size: 32px; } .stat-sm { font-size: 22px; padding-top: 12px; }
.text-danger { color: var(--danger); }
.card.tight table { min-width: 820px; }
.nowrap-row { flex-wrap: wrap !important; }
.stack > * + * { margin-top: 24px; }
main.page > .container > .grid + .grid { margin-top: 24px; }
main.page > .container > .searchbar + *, main.page > .container > form + .card, main.page > .container > .card + .card { margin-top: 24px; }
main.page > .container > .section-title { margin-top: 48px; }
.mt-32 { margin-top: 32px; }
td .actions.nowrap-row { flex-wrap: nowrap !important; gap: 16px; }
td .sub + .sub { margin-top: 2px; }
.card.tight table { min-width: 760px; }
.card.tight td:first-child strong { font-variant-numeric: tabular-nums; }
.card .actions .btn.ghost { padding: 0; }
td.nowrap { white-space: nowrap; }
.text-success { color: var(--green); }
.grid.start { align-items: start; }
@media (max-width: 600px) {
  .card { padding: 24px; }
  .list li { flex-direction: column; gap: 4px; }
  .list .meta { padding-top: 0; order: -1; }
  .card-head { flex-direction: column; align-items: flex-start; gap: 4px; }
}
