:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1b1f24; --muted: #6b7280; --line: #e3e6ea; --hover: #f1f4f8;
  --accent: #2f5bea; --accent-soft: #e8eeff;
  --red: #d92d20; --red-soft: #fde8e7; --orange: #c4570a; --orange-soft: #fdeedd;
  --yellow: #9a7400; --yellow-soft: #fbf3d0; --green: #13804b; --green-soft: #dff5e8; --gray-soft: #eef0f3;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e6e8eb; --muted: #9aa3ad; --line: #2b3139; --hover: #222831;
    --accent: #7b9bff; --accent-soft: #233056;
    --red: #ff7a70; --red-soft: #3d1d1b; --orange: #ffa05a; --orange-soft: #3b2715;
    --yellow: #e8c547; --yellow-soft: #352d10; --green: #4fd18b; --green-soft: #15301f; --gray-soft: #262b33;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 8px; padding: 6px 12px; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--hover); }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line); gap: 12px; flex-wrap: wrap; }
.brand strong { font-size: 16px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 16px 20px 0; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; text-align: left; color: var(--text); }
.tile:hover { background: var(--hover); }
.tile.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tile .n { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 12px; }

.toolbar { padding: 14px 20px 0; display: flex; flex-direction: column; gap: 10px; }
#q { width: 100%; padding: 9px 12px; font-size: 15px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 2px; }
.filters select { min-width: 130px; font-size: 13px; padding: 5px 8px; }
.filters select.active { border-color: var(--accent); background: var(--accent-soft); }
.actions { display: flex; gap: 8px; }
.count { padding: 8px 20px 0; margin: 0; }

.table-wrap { margin: 8px 20px 40px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: auto; max-height: calc(100vh - 150px); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
th { position: sticky; top: 0; background: var(--panel); font-size: 12px; color: var(--muted); font-weight: 600; cursor: pointer; user-select: none; z-index: 1; }
th.sorted { color: var(--text); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
td.web { white-space: normal; min-width: 200px; }
td.web .d { font-weight: 600; }
td.web .s { color: var(--muted); font-size: 12px; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--gray-soft); }
.red { background: var(--red-soft); color: var(--red); }
.orange { background: var(--orange-soft); color: var(--orange); }
.yellow { background: var(--yellow-soft); color: var(--yellow); }
.green { background: var(--green-soft); color: var(--green); }
.blue { background: var(--accent-soft); color: var(--accent); }
.overdue { color: var(--red); font-weight: 600; }

.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .3); z-index: 5; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--panel); border-left: 1px solid var(--line); z-index: 6; overflow: auto; }
.drawer-inner { padding: 18px 20px 40px; }
.drawer h2 { margin: 0 0 2px; font-size: 20px; }
.drawer h3 { margin: 22px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.drawer .close { float: right; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.crm-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.crm-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.crm-form .full { grid-column: 1 / -1; }
.saved { color: var(--green); font-size: 12px; margin-left: 8px; }
.note-add { display: flex; flex-direction: column; gap: 6px; }
.note-add textarea { min-height: 70px; resize: vertical; }
.note { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 8px; white-space: pre-wrap; }
.note .m { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.note .m button { padding: 0 6px; font-size: 12px; }
.plugins { width: 100%; font-size: 13px; }
.plugins td { padding: 4px 6px; }
.callout { padding: 10px 12px; border-radius: 8px; margin-top: 10px; }

body.login { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(340px, calc(100vw - 32px)); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.error { color: var(--red); margin: 0; }

@media (max-width: 700px) {
  .tiles, .toolbar { padding-left: 16px; padding-right: 16px; }
  .table-wrap { margin: 8px 16px 40px; }
  .kv { grid-template-columns: 1fr; }
  .crm-form { grid-template-columns: 1fr; }
}
