:root {
  --bg: #f6f7f9; --fg: #1b1f24; --muted: #6a737d; --card: #fff; --border: #d8dde3;
  --accent: #2563eb; --accent-fg: #fff; --ok: #15803d; --err: #b91c1c; --warn: #b45309;
  --input: #fff; --code: #eef1f4;
  /* Radius scale: controls, cards/panels, large tiles; pills use --radius-pill. */
  --radius-sm: 6px; --radius: 8px; --radius-lg: 12px; --radius-xl: 18px; --radius-pill: 999px;
  /* Overlays drawn on top of images (crop frame) and shadows: theme-independent. */
  /* Theme switch knob: same in both themes (day = sun, night = moon). */
  --toggle-day-bg: #ffd76a; --toggle-day-fg: #8a5a00; --toggle-night-bg: #2b3245; --toggle-night-fg: #c9d4ff;
  /* Action button drawn over an image (avatar trash): translucent, same in both themes. */
  --avatar-action-bg: rgba(0, 0, 0, .38); --avatar-action-edge: rgba(255, 255, 255, .35);
  --overlay-line: #fff; --overlay-edge: #333; --overlay-dim: rgba(0, 0, 0, .55); --backdrop: rgba(0, 0, 0, .45); --shadow: 0 4px 14px rgba(0, 0, 0, .15);
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
/* Theme: data-theme="light"|"dark" is an explicit choice (set before first paint by
   theme-init.js); without the attribute the OS preference decides. */
:root[data-theme="dark"] {
    --bg: #111418; --fg: #e6e8eb; --muted: #9aa4af; --card: #1a1e24; --border: #2e353e;
    --accent: #3b82f6; --ok: #22c55e; --err: #f87171; --warn: #fbbf24; --input: #12161b; --code: #232932;
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --fg: #e6e8eb; --muted: #9aa4af; --card: #1a1e24; --border: #2e353e;
    --accent: #3b82f6; --ok: #22c55e; --err: #f87171; --warn: #fbbf24; --input: #12161b; --code: #232932;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); line-height: 1.45; }
a { color: var(--accent); }
header#top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 10px clamp(16px, 2.5vw, 40px); background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
/* Header tabs: plain text; the active one is bright and bold, no background or border. */
#nav { display: flex; gap: 22px; flex-wrap: wrap; flex: 1; }
#nav a { text-decoration: none; color: var(--muted); padding: 5px 0; font-size: 1.02rem; }
#nav a:hover { color: var(--fg); }
#nav a.active { color: var(--fg); font-weight: 700; }
#who { display: flex; gap: 10px; align-items: center; }
/* Full window width: no centred column, so wide monitors are used; grids add columns. */
main { margin: 0; padding: 20px clamp(16px, 2.5vw, 40px); }
h1 { font-size: 1.5rem; margin: 0 0 16px; } h2 { font-size: 1.2rem; margin: 24px 0 10px; } h3 { margin: 0; font-size: 1.1rem; }
.muted { color: var(--muted); } .small { font-size: .85em; } .err { color: var(--err); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); gap: 14px; }
.cards .card { margin: 0; display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: inherit; }
.cards a.card:hover { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
button, .btn { font: inherit; padding: 7px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--card); color: var(--fg); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover:not(:disabled) { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--err); border-color: var(--err); }
button.big { font-size: 1.15rem; padding: 12px 28px; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button.icon { border: none; background: none; font-size: 1.4rem; line-height: 1; padding: 0 6px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--input); color: var(--fg); width: 100%; }
input[type=checkbox] { width: auto; }
input:invalid { border-color: var(--err); }
textarea { min-height: 80px; font-family: ui-monospace, monospace; font-size: .9em; }
textarea.code { min-height: 320px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field .lbl { font-weight: 500; }
.field .help { font-size: .82em; color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 16px; }
/* Fields in one grid row share label / input / help rows, so inputs line up even when a long
   label wraps; a short label sits right above its input. */
.grid2 > .field { display: grid; grid-row: span 3; grid-template-rows: subgrid; row-gap: 4px; align-content: start; }
.grid2 > .field > .lbl { align-self: end; }
.grid2 > :not(.field) { grid-row: span 3; }
table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-weight: 600; font-size: .85em; color: var(--muted); background: var(--code); }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
code { background: var(--code); padding: 1px 4px; border-radius: var(--radius-sm); }
.badge { display: inline-block; font-size: .78em; padding: 1px 8px; border-radius: var(--radius-pill); background: var(--code); color: var(--muted); }
.badge.ok { color: var(--ok); } .badge.err { color: var(--err); } .badge.warn { color: var(--warn); }
.alert { white-space: pre-line; overflow-wrap: anywhere; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); margin: 10px 0; }
.alert.error { border-color: var(--err); color: var(--err); }
.alert.ok { border-color: var(--ok); color: var(--ok); }
.alert.warn { border-color: var(--warn); color: var(--warn); }
.log { background: var(--code); border-radius: var(--radius); padding: 10px; max-height: 360px; min-height: 120px; overflow: auto; font-size: .8em; white-space: pre-wrap; word-break: break-all; margin: 0; }
.log .l-error { color: var(--err); } .log .l-ok { color: var(--ok); } .log .l-warn { color: var(--warn); } .log .l-tx { color: var(--accent); }
.progress { height: 28px; border-radius: var(--radius-pill); background: var(--code); overflow: hidden; position: relative; border: 1px solid var(--border); }
.progress > .bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress.ok > .bar { background: var(--ok); } .progress.err > .bar { background: var(--err); }
.progress > .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .9em; }
.status { font-size: 1.25rem; font-weight: 600; margin: 12px 0; }
.status.ok { color: var(--ok); } .status.err { color: var(--err); } .status.warn { color: var(--warn); }
.steps { display: flex; gap: 12px; flex-wrap: wrap; margin: 14px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 8px 0; }
.kv > :nth-child(odd) { color: var(--muted); }
.notes { white-space: pre-wrap; }
dialog.modal { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--fg); padding: 0; width: min(720px, 95vw); max-height: 90vh; }
dialog.modal.wide { width: min(1000px, 96vw); }
dialog::backdrop { background: var(--backdrop); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card); }
.modal-body { padding: 16px; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { padding: 10px 14px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); max-width: 420px; }
.toast.error { border-color: var(--err); color: var(--err); } .toast.ok { border-color: var(--ok); color: var(--ok); }
.login { max-width: 360px; margin: 10vh auto; }
.parts-row { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.kv-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin-bottom: 8px; }
@media (max-width: 640px) {
  main { padding: 12px; }
  .parts-row, .kv-row { grid-template-columns: 1fr; }
  th, td { padding: 6px; }
}

.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; flex-wrap: wrap; margin-top: 10px; }
select.page-size { width: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: -4px 0 14px; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 8px 14px; }
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }

.avatar { display: inline-flex; align-items: center; justify-content: center; flex: none; border-radius: var(--radius-lg); object-fit: cover; color: var(--accent-fg); font-weight: 600; line-height: 1; vertical-align: middle; user-select: none; }
.titled { display: flex; align-items: center; gap: 10px; }
.titled > h1, .titled > h3 { margin: 0; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; overflow: hidden; user-select: none; line-height: 0; }
.crop-img { display: block; max-width: min(560px, 100%); max-height: 60vh; }
.crop-box { position: absolute; box-sizing: border-box; border: 2px solid var(--overlay-line); box-shadow: 0 0 0 9999px var(--overlay-dim); cursor: move; touch-action: none; }
.crop-handle { position: absolute; width: 14px; height: 14px; background: var(--overlay-line); border: 1px solid var(--overlay-edge); border-radius: 3px; touch-action: none; }
.crop-handle.nw { left: -1px; top: -1px; cursor: nwse-resize; } .crop-handle.se { right: -1px; bottom: -1px; cursor: nwse-resize; }
.crop-handle.ne { right: -1px; top: -1px; cursor: nesw-resize; } .crop-handle.sw { left: -1px; bottom: -1px; cursor: nesw-resize; }
.avatar-pick { padding: 0; border: 0; background: none; cursor: pointer; border-radius: var(--radius-lg); }
.avatar-pick:hover .avatar, .avatar-pick:focus-visible .avatar { outline: 2px solid var(--accent); outline-offset: 2px; }
.avatar-wrap { position: relative; display: inline-block; line-height: 0; }
/* Trash in the centre of the avatar, shown only while the pointer is over the avatar (or it has
   focus); a click on it removes the image, a click elsewhere on the avatar picks a new one. */
.avatar-del { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 36px; height: 36px; padding: 0; border-radius: 50%; border: 1px solid var(--avatar-action-edge); background: var(--avatar-action-bg); backdrop-filter: blur(2px); font-size: 16px; line-height: 1; cursor: pointer; opacity: 0; pointer-events: none; transition: opacity .15s; box-shadow: var(--shadow); }
.avatar-wrap:hover .avatar-del, .avatar-wrap:focus-within .avatar-del { opacity: 1; pointer-events: auto; }
.avatar-del:hover { border-color: var(--err); }
/* Touch screens have no hover: keep the trash visible there. */
@media (hover: none) { .avatar-del { opacity: .9; pointer-events: auto; } }
.cards .project-card { flex-direction: row; align-items: flex-start; gap: 16px; }
.cards .project-card .avatar { border-radius: var(--radius-xl); }
.project-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.project-body h3 { margin: 0; overflow-wrap: anywhere; }

.log-section { margin-top: 20px; }
.log-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.log-head h2 { margin: 0; }
/* Page header rows (title + actions): the title's bottom margin moves to the row so the
   buttons are centred on the title, not on its margin box. */
.row:has(> h1), .row:has(> .titled > h1) { margin-bottom: 16px; }
.row > h1, .row > .titled > h1 { margin-bottom: 0; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a.icon-btn.btn:hover { border-color: var(--accent); }
button.icon-btn:disabled { opacity: .45; cursor: not-allowed; }
.actions { display: flex; gap: 6px; flex-wrap: nowrap; justify-content: flex-end; }


button.danger.solid { background: var(--err); color: var(--accent-fg); border-color: var(--err); }
.confirm { min-width: min(380px, 80vw); }
.confirm-text { white-space: pre-line; margin-top: 0; }
/* Header: logo, theme switch and logout as icon buttons. */
.icon-btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.icon-btn.ghost:hover { color: var(--fg); border-color: var(--border); }
.who-name { text-decoration: none; }
.who-name:hover { color: var(--fg); }

/* Settings page: sidebar with groups, section content on the right; tabs on narrow screens. */
.settings-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 14px; }
.settings-group { display: flex; flex-direction: column; gap: 2px; }
.settings-group-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 0 10px 4px; }
.settings-nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--fg); text-decoration: none; }
.settings-nav a:hover { background: var(--code); }
.settings-nav a.active { background: var(--code); color: var(--accent); font-weight: 600; }
.settings-nav svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 800px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; gap: 4px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
  .settings-group { flex-direction: row; gap: 4px; }
  .settings-group-title { display: none; }
  .settings-nav a { white-space: nowrap; }
}

/* User cards (movie-portal style): avatar, name + tags, status, switch; actions on the right. */
.user-list { display: flex; flex-direction: column; gap: 12px; }
.user-card { display: flex; align-items: flex-start; gap: 14px; margin: 0; }
.user-card.inactive .avatar, .user-card.inactive .user-title b { opacity: .55; }
.user-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.user-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 1.05rem; }
.icon-btn.round { border-radius: 50%; width: 40px; height: 40px; }

/* Toggle switch: <label class="switch"><input type=checkbox role=switch><span class="switch-track"></span>text</label> */
.switch { display: inline-flex; align-items: center; gap: 10px; margin-top: 6px; cursor: pointer; width: fit-content; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 44px; height: 24px; border-radius: var(--radius-pill); background: var(--code); border: 1px solid var(--border); transition: background .15s; flex: none; }
.switch-track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: var(--accent-fg); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: .5; }
.switch:has(input:disabled) { cursor: not-allowed; }

/* User avatars are round (project icons are rounded squares). */
.avatar.round, .avatar-pick.round { border-radius: 50%; }
.who-name { display: inline-flex; align-items: center; gap: 8px; }
.profile-head { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.profile-head p { margin: 8px 0 0; }
/* Page "create" action: one round accent "+" button in the title row; the tooltip names it. */
.icon-btn.round.primary svg { width: 20px; height: 20px; stroke-width: 2.4; }
.icon-btn.round.primary:hover:not(:disabled) { filter: brightness(1.1); }

.row.secret code { font-size: 1.05em; user-select: all; overflow-wrap: anywhere; flex: 1; min-width: 0; }

.check-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 2px 16px; max-height: 260px; overflow: auto; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--input); }
.check-list .check { margin: 0; padding: 3px 0; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* Header theme switch: pill 50×26, knob slides left (sun, light) / right (moon, dark). */
.theme-toggle { position: relative; width: 50px; height: 26px; flex: none; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--code); cursor: pointer; transition: background .2s, border-color .2s; }
.theme-toggle:hover:not(:disabled) { border-color: var(--muted); }
.theme-toggle .knob { position: absolute; top: 2px; left: 26px; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--toggle-night-bg); color: var(--toggle-night-fg); transition: left .2s ease, background .2s, color .2s; }
.theme-toggle.light .knob { left: 2px; background: var(--toggle-day-bg); color: var(--toggle-day-fg); }
@media (prefers-reduced-motion: reduce) { .theme-toggle, .theme-toggle .knob { transition: none; } }

/* State-aware icon buttons: green = restore (e.g. «Розблокувати»), red on hover = stop. */
button.icon-btn.ok { color: var(--ok); border-color: var(--ok); }
button.icon-btn.warn-hover:hover:not(:disabled) { color: var(--err); border-color: var(--err); }
