:root {
  --bg: #f5f5f2;
  --card: #ffffff;
  --text: #151514;
  --muted: #6b6b66;
  --line: #e3e3de;
  --line-strong: #cfcfc8;
  --primary: #151514;
  --on-primary: #ffffff;
  --hover: #f0f0eb;
  --ok: #1f9d55;
  --down: #d93a3a;
  --unknown: #b4b4ad;
  --ok-bg: #e7f6ec;
  --down-bg: #fdecec;
  --down-text: #a32222;
  --warn-bg: #fff6e0;
  --focus: #2b6cdf;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --card: #1b1b1a;
    --text: #ededea;
    --muted: #9b9b95;
    --line: #2c2c2a;
    --line-strong: #3d3d3a;
    --primary: #ededea;
    --on-primary: #121212;
    --hover: #242423;
    --ok: #3ccf7a;
    --down: #ff6b6b;
    --unknown: #6b6b66;
    --ok-bg: #12301f;
    --down-bg: #3a1717;
    --down-text: #ff9b9b;
    --warn-bg: #33290f;
    --focus: #7aa7ff;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 8px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 10px; font-weight: 600; }
p { margin: 0 0 8px; }
a { color: inherit; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.loading, .noscript, .empty { color: var(--muted); padding: 40px 16px; text-align: center; }
.hint { color: var(--muted); font-size: 13px; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ── кнопки и поля ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--text);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary); opacity: 0.88; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--down-text); border-color: var(--down-bg); }
.btn-danger:hover { background: var(--down-bg); }
.btn-small { min-height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-wide { width: 100%; }

.input {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--card); color: var(--text); font: inherit;
}
textarea.input { resize: vertical; min-height: 80px; }
select.input { appearance: auto; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 550; font-size: 14px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form > .hint:empty { display: none; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.fieldset legend { font-weight: 550; font-size: 14px; padding: 0 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 8px; }

.msg:empty { display: none; }
.msg { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 4px; }
.msg-error { background: var(--down-bg); color: var(--down-text); }
.msg-ok { background: var(--ok-bg); color: var(--ok); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--hover); color: var(--muted); margin-left: 6px; vertical-align: middle; }

/* ── вход ── */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 28px 24px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.auth-title { font-size: 20px; margin: 4px 0 0; }
.step { display: flex; flex-direction: column; gap: 10px; }
.step:empty { display: none; }
.step-text { margin: 0; }

/* ── шапка ── */
.logo { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; }
.logo-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: var(--on-primary); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.logo-text { font-size: 16px; letter-spacing: -0.01em; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px; padding: 10px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav-link { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 550; white-space: nowrap; }
.nav-link:hover { background: var(--hover); color: var(--text); }
.nav-link.is-active { color: var(--text); background: var(--hover); }
.who { display: flex; align-items: center; gap: 8px; }
.who-name { font-weight: 600; }
.who-role { color: var(--muted); font-size: 13px; }

.main { max-width: 1120px; margin: 0 auto; padding: 24px 24px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.back { display: inline-block; color: var(--muted); text-decoration: none; margin-bottom: 14px; }
.back:hover { color: var(--text); }

/* ── главная ── */
.home-head { margin-bottom: 18px; display: flex; gap: 10px; align-items: center; }
.edit-hint { margin: -6px 0 18px; max-width: 720px; }
.search { max-width: 420px; }
.banner { display: flex; align-items: center; gap: 10px; background: var(--down-bg); color: var(--down-text); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 18px; font-weight: 550; }
.shelf { margin-bottom: 26px; }
.shelf-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 650; margin-bottom: 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }

.tile {
  position: relative; display: flex; align-items: stretch;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.tile:hover { border-color: var(--line-strong); }
.tile.is-down { border-color: var(--down); }
.tile-main { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: flex-start; padding: 14px 4px 14px 14px; text-decoration: none; }
.tile-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.tile-name { font-weight: 650; display: flex; align-items: center; gap: 7px; }
.tile-purpose { color: var(--muted); font-size: 13px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile-side { display: flex; flex-direction: column; gap: 2px; padding: 8px 8px 8px 0; }
.tile-btn {
  width: 30px; height: 30px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; font: 600 15px/1 inherit; text-decoration: none; cursor: pointer;
}
.tile-btn:hover { background: var(--hover); color: var(--text); }
.pin.is-on { color: #d99a00; }
.tile-btn.info { width: 20px; height: 20px; margin: 5px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px currentColor; font: italic 700 12px/1 Georgia, "Times New Roman", serif; }
.tile .badge { position: absolute; left: 14px; bottom: -9px; margin: 0; background: var(--card); border: 1px solid var(--line); }
.tile-add { align-items: center; justify-content: center; gap: 8px; min-height: 76px; border-style: dashed; color: var(--muted); text-decoration: none; box-shadow: none; }
.tile-add:hover { color: var(--text); }
.tile-add-plus { font-size: 20px; }
button.tile-add { font: inherit; cursor: pointer; background: transparent; }

/* ── разделы: сворачивание ── */
.shelf-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 6px 2px 0; margin: 0;
  border: 0; background: none; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer;
}
.shelf-toggle:hover { color: var(--text); }
.chev { display: inline-block; transition: transform 0.15s; font-size: 11px; }
.is-closed .chev { transform: rotate(-90deg); }
.shelf-count { background: var(--hover); border-radius: 99px; padding: 0 7px; font-size: 11px; letter-spacing: 0; }
.is-closed { margin-bottom: 14px; }

/* ── режим «Настроить» ── */
.shelf-edit { border: 1px dashed var(--line-strong); border-radius: 16px; padding: 12px 14px 14px; }
.section-head { display: flex; align-items: center; gap: 10px 14px; flex-wrap: wrap; margin-bottom: 12px; }
.section-head .shelf-title { margin: 0; }
.section-name { max-width: 280px; min-height: 34px; font-weight: 650; }
.section-who { color: var(--muted); font-size: 13px; flex: 1; min-width: 160px; }
.section-tools { display: flex; gap: 2px; margin-left: auto; }
.tile.is-edit { align-items: stretch; }
.tile.is-edit .tile-main { padding-left: 4px; }
.drag {
  flex-shrink: 0; width: 26px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1;
  cursor: grab; touch-action: none; border-radius: 10px 0 0 10px;
}
.drag:hover { background: var(--hover); color: var(--text); }
.drag-spacer { width: 10px; flex-shrink: 0; }
.tile.is-dragging { opacity: 0.35; border-style: dashed; }
.drag-ghost {
  position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; margin: 0;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18); opacity: 0.95;
}
body.is-dragging-tile { cursor: grabbing; user-select: none; -webkit-user-select: none; }
body.is-dragging-tile .shelf-edit:has(.can-drop) { border-color: var(--focus); }
.tile-btn.del:hover { color: var(--down-text); background: var(--down-bg); }
.new-section-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.new-section-row .input { max-width: 320px; }
.trash details { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; background: var(--card); }
.trash summary { cursor: pointer; color: var(--muted); font-weight: 550; }
.trash-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.trash-row:last-child { border-bottom: 0; }

/* ── сообщение внизу ── */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: center; gap: 14px; max-width: min(560px, calc(100vw - 32px));
  background: var(--primary); color: var(--on-primary); border-radius: 12px; padding: 12px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); font-size: 14px;
}
.toast-btn { border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; white-space: nowrap; padding: 0; }

/* ── окно «Новый сайт» ── */
.sheet {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto;
  border: 1px solid var(--line); border-radius: 16px; padding: 22px 22px 18px;
  background: var(--card); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet h2 { font-size: 18px; margin: 0; }
.icon-picker { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; }
.file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

.icon { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; object-fit: cover; background: var(--hover); }
.icon-letter { display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 17px; }
.av-0 { background: #e3ecfb; color: #1d4b9a; } .av-1 { background: #e5f4ea; color: #1d6b3c; }
.av-2 { background: #fbeadf; color: #8f3f12; } .av-3 { background: #efe7fb; color: #5a2f9a; }
.av-4 { background: #fbe6ef; color: #932c57; } .av-5 { background: #e2f3f4; color: #17656b; }
.av-6 { background: #f6f0d9; color: #6d5a0e; } .av-7 { background: #ebebe7; color: #3c3c38; }
@media (prefers-color-scheme: dark) {
  .av-0 { background: #1d2c47; color: #a9c6ff; } .av-1 { background: #183324; color: #9fe0b6; }
  .av-2 { background: #3b2416; color: #f6b88e; } .av-3 { background: #2c2142; color: #cdb5ff; }
  .av-4 { background: #3d1c2b; color: #f5a8c8; } .av-5 { background: #15363a; color: #9fdfe4; }
  .av-6 { background: #36301a; color: #e8d38a; } .av-7 { background: #2a2a28; color: #cfcfca; }
}

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-ok { background: var(--ok); }
.dot-down { background: var(--down); box-shadow: 0 0 0 3px var(--down-bg); }
.dot-unknown { background: var(--unknown); }

.suggest { margin-top: 18px; }
.suggest-form { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; max-width: 560px; align-items: flex-start; }

/* ── карточка ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.card-head .icon { width: 56px; height: 56px; border-radius: 14px; font-size: 24px; }
.card-title { flex: 1; min-width: 200px; }
.card-title h1 { margin: 2px 0 4px; }
.card-purpose { color: var(--muted); margin: 0; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.card-section:last-of-type { border-bottom: 0; }
.card-section ul { margin: 0; padding-left: 20px; }
.card-section ul.plain { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px 20px; }
.fact { display: flex; flex-direction: column; gap: 2px; }
.fact-k { color: var(--muted); font-size: 13px; }
.status-line { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.detail { background: var(--hover); border-radius: 8px; padding: 8px 10px; white-space: pre-wrap; overflow-wrap: anywhere; margin: 6px 0; }
.pulse { display: flex; gap: 3px; margin-top: 8px; }
.pulse span { width: 10px; height: 22px; border-radius: 3px; }
.pulse-ok { background: var(--ok); opacity: 0.75; }
.pulse-down { background: var(--down); }
.shots { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.shot { margin: 0; flex-shrink: 0; }
.shot img { display: block; height: 320px; width: auto; border-radius: 12px; border: 1px solid var(--line); }
.shot figcaption { color: var(--muted); font-size: 13px; margin-top: 6px; max-width: 200px; }
.links { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.link-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.link-kind { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.link-url { overflow-wrap: anywhere; }
.link-url.is-empty { color: var(--muted); }

.form-card { max-width: 720px; }
.link-edit { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.link-edit-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; }

/* ── люди, журнал, мой вход ── */
.people { padding: 6px 24px; }
.person { padding: 14px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border-bottom: 0; }
.person.is-off { opacity: 0.6; }
.person-top { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.person-info { min-width: 0; }
.person-name { font-weight: 650; }
.person-meta { color: var(--muted); font-size: 13px; }
.person-state { font-size: 13px; }
.state-ok { color: var(--ok); }
.state-invited { color: #b07a00; }
.state-off { color: var(--muted); }
.person-actions { display: flex; gap: 6px; }
.person-edit { margin-top: 14px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; gap: 12px; }
.add-person { max-width: 560px; }
.invite { background: var(--warn-bg); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.invite h2 { margin: 0; }
.invite-url { overflow-wrap: anywhere; background: var(--card); padding: 8px 10px; border-radius: 8px; width: 100%; }
.dept-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.dept-row:last-of-type { border-bottom: 0; }
.dept-row .input { max-width: 320px; }
.card > .btn, .card > .field { margin-top: 10px; }
.log { padding: 4px 20px; }
.log-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.log-row:last-child { border-bottom: 0; }
.log-row.is-warn .log-text { color: var(--down-text); }
.log-time, .log-ip { color: var(--muted); font-size: 13px; }
.log-text { overflow-wrap: anywhere; }

/* ── телефон ── */
@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .nav { order: 3; width: 100%; flex: none; }
  .who { margin-left: auto; }
  .who-role { display: none; }
  .main { padding: 16px 16px 48px; }
  .card { padding: 18px 16px; border-radius: 14px; }
  .people, .log { padding: 4px 16px; }
  .tiles { grid-template-columns: 1fr; }
  .tile-add { min-height: 48px; }
  .search { max-width: none; }
  .shelf-edit { padding: 10px; }
  .section-tools { margin-left: 0; }
  .toast { bottom: 16px; }
  .shot img { height: 260px; }
  .link-edit-row { grid-template-columns: 1fr; }
  .log-row { grid-template-columns: 1fr; gap: 2px; }
  .card-actions { width: 100%; }
}
