:root {
  --bg: #f6f5fa;
  --surface: #ffffff;
  --text: #1c2321;
  --muted: #5d6965;
  --line: #dfe3e0;
  --brand: #5b2fc9;
  --brand-ink: #ffffff;
  --brand-soft: #efeaff;
  --warn: #9a5b00;
  --warn-soft: #fdf0dc;
  --danger: #b3261e;
  --focus: #5b2fc9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
}
body.theme-dark {
  --bg: #1f1f1f;
  --surface: #292929;
  --text: #f0f0f0;
  --muted: #b3b3b3;
  --line: #3d3d3d;
  --brand: #b9a4ff;
  --brand-ink: #1e1240;
  --brand-soft: #2a2142;
  --warn: #f2b75c;
  --warn-soft: #3a2c14;
  --danger: #ff8a80;
  --focus: #b9a4ff;
  --shadow: none;
}
body.theme-contrast {
  --bg: #000000;
  --surface: #000000;
  --text: #ffffff;
  --muted: #ffffff;
  --line: #ffffff;
  --brand: #ffff00;
  --brand-ink: #000000;
  --brand-soft: #000000;
  --warn: #ffff00;
  --warn-soft: #000000;
  --danger: #ff6b6b;
  --focus: #00ffff;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; border-radius: 9px; display: block; flex: none; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 700; }
.tagline { margin: 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 210px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  padding: 4px; display: flex; flex-direction: column;
}
.menu button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu button:hover { background: var(--brand-soft); }

main { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 20px 24px; }

.state { text-align: center; padding: 64px 16px; max-width: 560px; margin: 0 auto; }
.state h2 { margin: 0 0 8px; font-size: 20px; }
.state p { color: var(--muted); margin: 0 0 20px; }
.state-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto 14px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
#search {
  width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); font-size: 15px;
}
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px;
  cursor: pointer; font-weight: 600; color: var(--muted);
}
.chip span { font-weight: 700; margin-left: 4px; }
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--text); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.card.attention { border-left: 4px solid var(--warn); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card h3 { margin: 0; font-size: 16px; word-break: break-word; }
.cat {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--brand); background: var(--brand-soft); padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.desc { margin: 0; color: var(--muted); white-space: pre-wrap; word-break: break-word; }
.person { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.person-info { min-width: 0; flex: 1; }
.role { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pmeta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag { color: var(--warn); background: var(--warn-soft); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; display: inline-block; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.link-btn {
  background: none; border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.link-btn:hover { border-color: var(--brand); color: var(--brand); }
.link-btn.edit { margin-left: auto; }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 14px; }
.foot a { color: var(--muted); }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
#itemForm { padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
#itemForm h2 { margin: 0 0 4px; font-size: 18px; }
#itemForm label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
#itemForm input, #itemForm textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: var(--bg); font-weight: 400;
}
.req { color: var(--danger); }
.person-field { position: relative; }
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30; list-style: none; margin: 4px 0 0; padding: 4px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
  max-height: 220px; overflow: auto;
}
.suggest li { padding: 7px 9px; border-radius: 6px; cursor: pointer; }
.suggest li:hover, .suggest li.active { background: var(--brand-soft); }
.suggest .s-meta { color: var(--muted); font-size: 12px; }
.chosen { font-size: 12px; color: var(--brand); font-weight: 600; margin-top: 2px; }
.form-error { color: var(--danger); margin: 0; font-weight: 600; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-weight: 600;
  max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

@media (max-width: 560px) {
  .topbar, main { padding-left: 16px; padding-right: 16px; }
  .cards { grid-template-columns: 1fr; }
}
