:root {
  --bg: #0d1117;
  --bg-elev: #161b22;
  --bg-elev2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #1f6feb;
  --accent-h: #388bfd;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--accent-h); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Header --- */
header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 10px 18px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
header h1 { font-size: 18px; margin: 0; white-space: nowrap; }
.header-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-btn, .primary-btn, .modal button {
  background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.toolbar-btn:hover { border-color: var(--accent); }
.toolbar-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary-btn { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary-btn:hover { background: var(--accent-h); }
.toolbar-link { font-size: 13px; padding: 6px 4px; color: var(--text-dim); }
.toolbar-link:hover { color: var(--text); text-decoration: none; }
.user-chip { font-size: 12px; color: var(--text-dim); white-space: nowrap; }

select, input, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px; font-family: inherit;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--accent); }

/* --- Search --- */
.search-wrapper { position: relative; }
#search-input { width: 200px; }
.search-results {
  position: absolute; top: 110%; left: 0; width: 360px; max-height: 420px; overflow-y: auto;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 8px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.search-result { padding: 8px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.search-result:hover { background: var(--bg-elev2); }
.search-result-header { display: flex; align-items: center; gap: 6px; }
.search-result-title { font-weight: 500; }
.search-result-meta { display: flex; gap: 6px; margin-top: 4px; }
.search-empty { padding: 12px; color: var(--text-dim); }
.status-pill-inline { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--bg-elev2); color: var(--text-dim); }

/* --- Board --- */
.board { display: flex; gap: 12px; padding: 14px; align-items: flex-start; overflow-x: auto; }
.column {
  flex: 1 1 0; min-width: 240px; max-width: 420px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px;
  display: flex; flex-direction: column; max-height: calc(100vh - 88px);
}
.column-header {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); font-weight: 600; position: sticky; top: 0;
}
.column-title { flex: 1; }
.column-header.backlog { color: #8b949e; }
.column-header.in_progress { color: #58a6ff; }
.column-header.blocked { color: #f85149; }
.column-header.in_review { color: #d29922; }
.column-header.done { color: #3fb950; }
.count { background: var(--bg-elev2); color: var(--text-dim); font-size: 12px; padding: 1px 8px; border-radius: 10px; font-weight: 600; }
.column-sort-btn, .done-toggle {
  font-size: 11px; padding: 2px 7px; border-radius: 5px; cursor: pointer;
  background: var(--bg-elev2); color: var(--text-dim); user-select: none;
}
.column-sort-btn.sort-active { background: var(--accent); color: #fff; }
.card-list { padding: 10px; overflow-y: auto; flex: 1; min-height: 60px; display: flex; flex-direction: column; gap: 9px; }
.card-list.drop-target { background: rgba(31,111,235,0.12); outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 8px; }

/* --- Card --- */
.card {
  background: var(--bg-elev2); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; cursor: grab; transition: border-color .12s;
}
.card:hover { border-color: #58a6ff; }
.card.dragging { opacity: 0.5; cursor: grabbing; }
.card-header { display: flex; align-items: center; gap: 6px; }
.card-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-dim); }
.card-chevron { margin-left: auto; color: var(--text-dim); font-size: 10px; }
.card-title { font-size: 13px; font-weight: 500; margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card.collapsed .card-details { display: none; }
.card.collapsed .card-title { margin-bottom: 0; -webkit-line-clamp: 1; }
.card-details { margin-top: 8px; }
.card-description { font-size: 12px; color: var(--text-dim); white-space: pre-wrap; margin-bottom: 8px; max-height: 160px; overflow-y: auto; }
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.blocked-reason { font-size: 12px; color: #f85149; background: rgba(248,81,73,0.1); border-left: 2px solid #f85149; padding: 5px 8px; border-radius: 4px; margin-bottom: 6px; }
.review-notes { font-size: 12px; color: #d29922; background: rgba(210,153,34,0.1); border-left: 2px solid #d29922; padding: 5px 8px; border-radius: 4px; margin-bottom: 6px; white-space: pre-wrap; }
.card-actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity .1s; }
.card:hover .card-actions { opacity: 1; }
.card-actions button { background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.card-actions button:hover { border-color: var(--accent); }
.card-actions .delete-btn:hover { border-color: #f85149; color: #f85149; }

/* --- Badges --- */
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); }
.badge-priority-critical { background: #5a1e1e; color: #ff7b72; border-color: #8e2a2a; }
.badge-priority-high { background: #5a3a1e; color: #f0a85a; border-color: #8e5a2a; }
.badge-priority-medium { background: #1e3a5a; color: #79c0ff; border-color: #2a5a8e; }
.badge-priority-low { background: #21262d; color: #8b949e; }
.badge-project { background: #21262d; color: #a5d6ff; }
.badge-actor { background: #21262d; color: #c9d1d9; }
.badge-actor-agent { background: #2d2438; color: #d2a8ff; border-color: #5a3a8e; }
.badge-time { background: transparent; border-color: transparent; }
.badge-wall-time { background: #21262d; }
.badge-wall-in_progress { color: #58a6ff; }
.badge-wall-blocked { color: #f85149; }
.badge-wall-in_review { color: #d29922; }
.badge-wall-done { color: #3fb950; }

/* --- Focus mode (column visibility) --- */
body.focus-mode .column[data-status="done"] { display: none; }
body.focus-mode .column[data-status="blocked"] { display: none; }
body.backlog-view .column[data-status="in_progress"],
body.backlog-view .column[data-status="blocked"],
body.backlog-view .column[data-status="in_review"],
body.backlog-view .column[data-status="done"] { display: none; }
body.backlog-view .column[data-status="backlog"] { max-width: 720px; }

/* --- Modal --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 22px; width: 460px; max-width: calc(100vw - 32px); max-height: calc(100vh - 64px); overflow-y: auto; }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.modal label { display: block; margin-bottom: 12px; font-size: 12px; color: var(--text-dim); }
.modal label input, .modal label textarea, .modal label select { display: block; width: 100%; margin-top: 4px; color: var(--text); }
.form-row { display: flex; gap: 12px; }
.form-row label { flex: 1; }
.new-project-fields { border-left: 2px solid var(--accent); padding-left: 10px; margin-bottom: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.hidden { display: none !important; }

/* --- Deleted tasks panel --- */
.deleted-tasks-panel { position: fixed; right: 14px; bottom: 14px; width: 360px; max-height: 50vh; overflow-y: auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.deleted-tasks-header { display: flex; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; }
.deleted-tasks-list { padding: 6px; }
.deleted-task-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.deleted-task-title { flex: 1; font-size: 13px; }
.deleted-tasks-empty { padding: 14px; color: var(--text-dim); text-align: center; }
.restore-btn { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.restore-btn:hover { border-color: #3fb950; color: #3fb950; }

/* --- Login --- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; padding: 32px; width: 320px; }
.login-card h1 { margin: 0; font-size: 24px; }
.login-sub { color: var(--text-dim); margin: 4px 0 22px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 12px; color: var(--text-dim); }
.login-card label input { display: block; width: 100%; margin-top: 5px; padding: 9px; }
.login-card button { width: 100%; background: var(--accent); color: #fff; border: none; border-radius: 6px; padding: 10px; font-size: 14px; cursor: pointer; margin-top: 6px; }
.login-card button:hover { background: var(--accent-h); }
.login-error { color: #ff7b72; font-size: 13px; margin-bottom: 12px; }

/* --- Generic page (keys, dashboard) --- */
.page { max-width: 920px; margin: 0 auto; padding: 24px 18px; }
.page h2 { font-size: 20px; }
.panel { background: var(--bg-elev); border: 1px solid var(--border); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--text-dim); font-weight: 600; }
.key-reveal { font-family: ui-monospace, monospace; background: var(--bg); border: 1px dashed var(--accent); padding: 10px; border-radius: 6px; word-break: break-all; margin-top: 10px; }
.muted { color: var(--text-dim); }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); }
.revoke-btn { background: var(--bg-elev2); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 10px; font-size: 12px; cursor: pointer; }
.revoke-btn:hover { border-color: #f85149; color: #f85149; }
.dash-bars { display: flex; gap: 4px; align-items: center; }
.dash-seg { height: 14px; border-radius: 3px; }
.seg-backlog { background: #6e7681; } .seg-in_progress { background: #1f6feb; }
.seg-blocked { background: #f85149; } .seg-in_review { background: #d29922; } .seg-done { background: #3fb950; }
