:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e1e4ea;
  --text: #1b1f27;
  --muted: #646b78;
  --accent: #3a5bd9;
  --accent-hover: #2f4cc0;
  --accent-soft: #e8edfc;
  --danger: #c6383b;
  --danger-soft: #fcebeb;
  --ok: #1f8a5b;
  --warn: #a5650b;
  --cat-open: #5a6272;
  --cat-open-bg: #eceef2;
  --cat-active: #2f55c9;
  --cat-active-bg: #e6ecfc;
  --cat-done: #1d7a51;
  --cat-done-bg: #e3f4ec;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .18);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1e26;
    --surface-2: #222733;
    --border: #2e3442;
    --text: #e6e9ef;
    --muted: #9aa2b1;
    --accent: #6b8cff;
    --accent-hover: #86a0ff;
    --accent-soft: #232d4d;
    --danger: #f06d6f;
    --danger-soft: #3a2224;
    --ok: #4cc58f;
    --warn: #e0a548;
    --cat-open: #b3bac7;
    --cat-open-bg: #2a303c;
    --cat-active: #94adff;
    --cat-active-bg: #243055;
    --cat-done: #5fd2a0;
    --cat-done-bg: #1b3a2e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; line-height: 1.3; }
h2, h3 { margin: 0; }
p { margin: 0 0 8px; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
#topbar {
  display: flex; align-items: center; gap: 20px;
  height: 52px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo { width: 24px; height: 24px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
#topbar nav { display: flex; gap: 4px; }
#topbar nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; font-weight: 500; }
#topbar nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
#topbar nav a.active { color: var(--text); background: var(--surface-2); }
.spacer { flex: 1; }

#main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 64px; }
#main.public { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.narrow { max-width: 720px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
section { margin-bottom: 28px; }
.section-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

/* ---------- user menu ---------- */
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.user-menu .menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 180px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow-lg);
  padding: 6px; display: flex; flex-direction: column;
}
.user-menu .menu a, .user-menu .menu button {
  text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--text); background: none; border: 0; font: inherit; cursor: pointer;
}
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--surface-2); text-decoration: none; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 650; flex: none;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.95); }
.btn.danger-text { color: var(--danger); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn {
  width: 28px; height: 28px; border: 1px solid transparent; border-radius: 6px; background: none; color: var(--muted);
  cursor: pointer; font-size: 14px; line-height: 1; display: inline-grid; place-items: center; padding: 0;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover:not(:disabled) { color: var(--danger); background: var(--danger-soft); }
.icon-btn:disabled { opacity: .3; cursor: default; }

input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; }
input[type=file] { font: inherit; color: var(--muted); max-width: 100%; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }

.field { margin-bottom: 14px; }
.field > label { display: block; font-weight: 550; margin-bottom: 5px; }
.req { color: var(--danger); margin-left: 3px; }
.help { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-weight: 400; }
.checks { display: flex; flex-direction: column; }
.form-error { background: var(--danger-soft); color: var(--danger); padding: 9px 12px; border-radius: 8px; margin: 8px 0 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 200px; width: auto; }
.inline-form select { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 4px 0 0; }
legend { font-weight: 600; padding: 0 6px; }
.sub { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 0 4px; }
.sub:first-child { margin-top: 0; }
.checklist { max-height: 180px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; background: var(--surface); }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.card-h { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.card-head .card-h { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.space-card { display: block; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); transition: border-color .15s; }
.space-card:hover { border-color: var(--accent); text-decoration: none; }
.space-key { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--accent); }
.card-title { font-weight: 600; font-size: 15px; margin: 2px 0 4px; }
.card-meta { margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.form-card { padding: 22px 24px; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; word-break: break-word; }
.empty { padding: 28px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty.small { padding: 14px; }
.empty.error { color: var(--danger); border-color: var(--danger); }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.warn { color: var(--warn); font-weight: 550; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.cat-open { color: var(--cat-open); background: var(--cat-open-bg); }
.cat-active { color: var(--cat-active); background: var(--cat-active-bg); }
.cat-done { color: var(--cat-done); background: var(--cat-done-bg); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; font-weight: 600; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-weight: 600; margin-right: 6px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.card .table th { background: none; padding: 8px 8px; }
.card .table td { padding: 6px 8px; }
.title-link { color: var(--text); font-weight: 500; }
.row-actions { display: flex; gap: 2px; justify-content: flex-end; white-space: nowrap; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1 1 220px; width: auto; }
.toolbar select { width: auto; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 0 14px; height: 34px; font: inherit; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 0 2px; }
.col-count { color: var(--muted); font-size: 12px; font-weight: 600; }
.board-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; color: var(--text); box-shadow: var(--shadow); }
.board-card:hover { border-color: var(--accent); text-decoration: none; }
.board-card .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.board-card .t { font-weight: 500; margin: 2px 0 8px; }
.board-card .foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); }

/* ---------- request page ---------- */
.req-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.req-title { font-size: 22px; margin-bottom: 16px; }
.req-title .muted { font-weight: 500; margin-right: 6px; }
.details { display: grid; grid-template-columns: 180px 1fr; gap: 10px 16px; margin: 0; }
.details dt { color: var(--muted); font-weight: 500; }
.details dd { margin: 0; min-width: 0; }
.details.compact { grid-template-columns: 150px 1fr; gap: 6px 12px; margin-top: 8px; }
.meta { display: grid; grid-template-columns: 90px 1fr; gap: 10px 12px; margin: 0; align-items: center; }
.meta dt { color: var(--muted); font-size: 13px; }
.meta dd { margin: 0; }
.side-status { margin-bottom: 12px; }
.side-status .badge { font-size: 13px; padding: 4px 12px; }
.action-list { display: flex; flex-direction: column; gap: 8px; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.file { word-break: break-all; }
.file::before { content: ""; display: inline-block; width: 10px; height: 12px; margin-right: 6px; border: 1.5px solid currentColor; border-radius: 2px; vertical-align: -1px; }
.files-inline { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }

.timeline { list-style: none; margin: 0 0 16px; padding: 0 0 0 18px; border-left: 2px solid var(--border); }
.ev { position: relative; margin-bottom: 16px; }
.ev::before { content: ""; position: absolute; left: -25px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); }
.ev-transition::before { border-color: var(--accent); background: var(--accent); }
.ev-comment::before { border-color: var(--muted); }
.ev-body { margin-top: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.comment-form textarea { margin-bottom: 8px; }
.comment-form .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- settings ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }
.action-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.action-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.style-primary { background: var(--accent); }
.dot.style-danger { background: var(--danger); }
.flow { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 8px; padding: 12px; background: var(--surface-2); border-radius: 8px; }
.flow-row { display: grid; grid-template-columns: 160px 1fr; gap: 12px; align-items: start; }
.flow-row .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.flow-chip { font-size: 12.5px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; }
.flow-chip b { font-weight: 600; }
.who-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.role-help { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; margin: 0; }
.role-help dt { font-weight: 600; }
.role-help dd { margin: 0; color: var(--muted); }
.danger-zone { border-color: var(--danger); }
.fb-row { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: var(--surface-2); }
.fb-main { display: grid; grid-template-columns: 1fr 150px auto auto; gap: 8px; align-items: center; }
.fb-extra { display: grid; gap: 6px; margin-top: 6px; }

/* ---------- auth ---------- */
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; box-shadow: var(--shadow-lg); }
.auth-card .brand { margin-bottom: 18px; }

/* ---------- modal ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.modal.wide { width: min(780px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(10, 14, 22, .45); }
.modal-form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-form header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-form header h2 { font-size: 17px; }
.modal-body { padding: 18px 20px 4px; overflow: auto; }
.modal-form .form-error { margin: 0 20px 12px; }
.modal-form footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out; max-width: 360px; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 860px) {
  .req-layout { grid-template-columns: 1fr; }
  .req-side { order: -1; }
  .details, .details.compact { grid-template-columns: 1fr; gap: 2px; }
  .details dd { margin-bottom: 8px; }
  .grid2, .who-grid { grid-template-columns: 1fr; }
  .fb-main { grid-template-columns: 1fr 1fr; }
  .flow-row { grid-template-columns: 1fr; gap: 4px; }
  #topbar { gap: 10px; padding: 0 12px; }
  .user-menu .name { display: none; }
  #main { padding: 16px 16px 48px; }
}
