:root {
  --td-canvas: #f6f7fb;
  --td-panel: #fff;
  --td-soft: #f2f3f9;
  --td-text: #232437;
  --td-muted: #626579;
  --td-line: #dedfe9;
  --td-accent: #5944c5;
  --td-accent-soft: #eeebff;
  --td-shadow: 0 2px 6px #22223b08;
  --bs-border-color: var(--td-line);
  --bs-body-color: var(--td-text);
  --bs-body-bg: var(--td-panel);
  --bs-link-color: var(--td-accent);
  --bs-border-radius: .55rem;
}
[data-bs-theme=dark] {
  --td-canvas: #15151d;
  --td-panel: #1e1e29;
  --td-soft: #262634;
  --td-text: #efeef6;
  --td-muted: #b1aec2;
  --td-line: #393849;
  --td-accent: #b4a4ff;
  --td-accent-soft: #322b4b;
  --td-shadow: 0 2px 6px #0002;
  --bs-body-color: var(--td-text);
  --bs-body-bg: var(--td-panel);
  --bs-border-color: var(--td-line);
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--td-text); background: var(--td-canvas); font-family: Inter, "Segoe UI", system-ui, sans-serif; }
button, input, textarea, select { font: inherit; }
button, a, input, select, textarea { touch-action: manipulation; }
a { color: var(--td-accent); }
:focus-visible { outline: 3px solid var(--td-accent); outline-offset: 3px; }
[hidden] { display: none !important; }
.btn { font-weight: 600; --bs-btn-border-radius: .5rem; }
.btn-primary, .button.primary {
  --bs-btn-bg: #604ace; --bs-btn-border-color: #604ace; --bs-btn-hover-bg: #4e39b7; --bs-btn-hover-border-color: #4e39b7;
  --bs-btn-active-bg: #4935ac; --bs-btn-active-border-color: #4935ac; --bs-btn-disabled-bg: #776ac1; color: white;
}
.btn-outline-secondary { --bs-btn-color: var(--td-text); --bs-btn-border-color: var(--td-line); --bs-btn-hover-bg: var(--td-soft); --bs-btn-hover-color: var(--td-text); --bs-btn-hover-border-color: var(--td-muted); background-color: var(--td-panel); }
.button, .icon-button, .brand, .wordmark, .nav-link, .stat-label, .section-heading, .page-actions, .breadcrumbs, .theme-field, .account-link, .project-card-head, .project-meta, .review-row, .column-heading, .task-card-head, .dialog-actions, .agents-dialog-actions, .agents-dialog-header, .dialog-header, .mode-picker, .account-actions { display: flex; align-items: center; }
.button { display: inline-flex; justify-content: center; gap: .5rem; min-height: 2.5rem; padding-inline: .85rem; font-size: .9rem; }
.icon-button { justify-content: center; width: 2.15rem; height: 2.15rem; border: 0; border-radius: .45rem; background: transparent; color: var(--td-muted); }
.icon-button:hover { background: var(--td-soft); color: var(--td-text); }
.ui-icon { flex: 0 0 auto; }
.form-control, .form-select { border-color: var(--td-line); color: var(--td-text); background-color: var(--td-panel); }
.form-control:focus, .form-select:focus { border-color: var(--td-accent); box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--td-accent) 17%, transparent); }
.form-control::placeholder { color: var(--td-muted); }
.skip-link:focus { position: fixed; z-index: 20; top: .5rem; left: .5rem; padding: .7rem; background: var(--td-panel); }
.app-shell { min-height: 100dvh; display: grid; grid-template-columns: 15rem minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; display: flex; flex-direction: column; height: 100dvh; background: var(--td-panel); border-right: 1px solid var(--td-line); }
.brand-row, .topbar { height: 4.5rem; display: flex; align-items: center; flex-shrink: 0; border-bottom: 1px solid var(--td-line); }
.brand-row { padding: 0 1.4rem; justify-content: space-between; }
.brand, .wordmark { gap: .65rem; color: var(--td-text); font-size: 1.35rem; font-weight: 750; letter-spacing: -.06em; text-decoration: none; }
.brand-mark { width: 2rem; height: 2rem; border-radius: .5rem; display: grid; place-items: center; background: url(/favicon.svg) center/contain no-repeat; }
.brand-mark svg { visibility: hidden; }
.sidebar-main { padding: 1.65rem .85rem .9rem; flex: 1; overflow-y: auto; }
.nav-label { font-size: .75rem; font-weight: 700; letter-spacing: .065em; text-transform: uppercase; color: var(--td-muted); }
.sidebar-main > .nav-label, .nav-group-heading { padding-inline: .75rem; }
.nav-group { display: grid; gap: .2rem; margin-top: .55rem; }
.nav-group-heading { display: flex; align-items: center; justify-content: space-between; margin-top: 1.6rem; }
.nav-link { gap: .7rem; padding: .62rem .75rem; border-radius: .48rem; color: var(--td-muted); font-size: .9rem; font-weight: 550; }
.nav-link:hover { background: var(--td-soft); color: var(--td-text); }
.nav-link.active { background: var(--td-accent-soft); color: var(--td-accent); }
.nav-text, .account-label strong, .breadcrumb-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-dot, .status-dot { width: .52rem; height: .52rem; border-radius: 50%; flex: none; }
.project-dot { background: #9b8ce5; margin-inline: .29rem; }
.nav-footer { border-top: 1px solid var(--td-line); padding: .8rem 1.15rem 1.15rem; }
.theme-field { gap: .55rem; color: var(--td-muted); font-size: .85rem; margin-bottom: .7rem; }
.theme-select { width: auto; margin-left: auto; padding-block: .25rem; font-size: .85rem; }
.account-link { gap: .65rem; text-decoration: none; color: var(--td-text); }
.account-link > svg { margin-left: auto; color: var(--td-muted); }
.avatar, .project-icon, .stat-icon, .review-icon { display: inline-grid; place-items: center; border-radius: .5rem; flex: none; }
.avatar { width: 2.2rem; height: 2.2rem; background: var(--td-accent-soft); color: var(--td-accent); font-weight: 700; }
.account-label { display: grid; min-width: 0; font-size: .88rem; }
.account-label small, .muted, .record-meta, .page-description, .project-meta, .project-description, .task-excerpt, .task-id, .auth-subtitle, .auth-hint, .breadcrumbs, .empty-state, .column-empty { color: var(--td-muted); }
.nav-scrim, .mobile-nav-toggle, .mobile-nav-close { display: none; }
.workspace { min-width: 0; }
.topbar { padding: 0 clamp(1rem, 3vw, 3.2rem); gap: .75rem; background: var(--td-panel); }
.breadcrumbs { gap: .6rem; font-size: .87rem; min-width: 0; }
.breadcrumbs a { color: var(--td-muted); text-decoration: none; }
.breadcrumbs svg { width: .85rem; height: .85rem; }
.breadcrumb-current { color: var(--td-text); font-weight: 600; }
.main-content { max-width: 115rem; margin-inline: auto; padding: clamp(1.4rem, 3.2vw, 3.2rem); }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.85rem; }
.page-heading-text { min-width: 0; }
.page-title, .auth-card h1 { font-size: clamp(1.65rem, 2.4vw, 2.35rem); letter-spacing: -.045em; font-weight: 720; margin: 0; }
.page-description { margin: .4rem 0 0; max-width: 68ch; white-space: pre-line; }
.page-title, .project-name, .project-description, .page-description, .task-title, .task-excerpt, .token-row, .review-text, .record-list { overflow-wrap: anywhere; }
.page-actions, .dialog-actions { gap: .55rem; flex-wrap: wrap; }
.stats-grid, .projects-grid, .board-grid, .form-grid { display: grid; gap: 1rem; }
.stats-grid, .board-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat-card, .project-card, .review-list, .tokens-list, .empty-state { border: 1px solid var(--td-line); border-radius: .8rem; background: var(--td-panel); box-shadow: var(--td-shadow); }
.stat-card { padding: 1.05rem 1.2rem 1.15rem; }
[data-status=backlog] { --status: #777f94; --tint: #8994ad22; }
[data-status=in_progress] { --status: #557ede; --tint: #558bed22; }
[data-status=review] { --status: #bb862d; --tint: #dc9c3626; }
[data-status=done] { --status: #328c71; --tint: #399c7c22; }
[data-bs-theme=dark] [data-status=backlog] { --status: #b2b7cb; }
[data-bs-theme=dark] [data-status=in_progress] { --status: #85abff; }
[data-bs-theme=dark] [data-status=review] { --status: #eabb6b; }
[data-bs-theme=dark] [data-status=done] { --status: #83d7b6; }
.stat-label { gap: .6rem; font-size: .92rem; font-weight: 600; color: var(--td-muted); }
.stat-icon { width: 2rem; height: 2rem; background: var(--tint); color: var(--status); }
.stat-value { display: block; font-size: 2rem; line-height: 1.25; letter-spacing: -.05em; margin-top: .7rem; }
.dashboard-section { margin-top: 2.35rem; }
.section-heading { gap: .55rem; margin-bottom: .85rem; }
.section-heading h2, .dialog-body h3 { margin: 0; font-size: 1.12rem; font-weight: 700; letter-spacing: -.025em; }
.count { padding: .1rem .45rem; color: var(--td-muted); background: var(--td-soft); border: 1px solid var(--td-line); border-radius: .45rem; font-size: .75rem; font-variant-numeric: tabular-nums; font-weight: 600; }
.projects-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr)); }
.project-card { display: flex; flex-direction: column; color: var(--td-text); text-decoration: none; padding: 1.15rem; }
.project-card:hover, .task-card:hover { border-color: var(--td-accent); }
.project-card-head, .project-meta, .task-card-head, .dialog-header, .agents-dialog-header, .account-actions { justify-content: space-between; gap: .7rem; }
.project-card-head > svg { color: var(--td-muted); }
.project-icon, .review-icon { width: 2.25rem; height: 2.25rem; background: var(--td-accent-soft); color: var(--td-accent); }
.project-name { font-size: 1.1rem; font-weight: 680; margin: 1rem 0 .2rem; }
.project-description, .task-excerpt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-description, .project-meta { font-size: .85rem; }
.project-meta { margin-top: auto; padding-top: 1rem; }
.project-progress { height: .28rem; width: 100%; margin-top: .5rem; border-radius: 1rem; overflow: hidden; border: 0; background: var(--td-soft); color: var(--td-accent); }
.project-progress::-webkit-progress-bar { background: var(--td-soft); }
.project-progress::-webkit-progress-value { background: var(--td-accent); }
.project-progress::-moz-progress-bar { background: var(--td-accent); }
.review-row, .token-row { gap: .8rem; padding: .9rem 1rem; }
.review-row { color: var(--td-text); text-decoration: none; }
.review-row:hover { background: var(--td-soft); }
.review-row + .review-row, .token-row + .token-row { border-top: 1px solid var(--td-line); }
.review-text { display: grid; flex: 1; }
.review-text small, .record-meta { color: var(--td-muted); font-size: .82rem; }
.empty-state { padding: 1.5rem; font-size: .94rem; }
.board-toolbar { margin-bottom: 1.1rem; }
.board-filters, .search-field { display: flex; align-items: center; gap: .65rem; }
.board-filters > select { width: auto; }
.search-field { position: relative; }
.search-field > svg { position: absolute; left: .7rem; color: var(--td-muted); }
.search-field input { padding-left: 2.25rem; }
.board-grid { align-items: stretch; gap: .8rem; }
.board-column { min-width: 0; min-height: 20rem; background: var(--td-soft); border: 1px solid var(--td-line); border-radius: .8rem; padding: .75rem; }
.board-column.drop-target { outline: 2px solid var(--td-accent); background: var(--td-accent-soft); }
.column-heading { gap: .45rem; margin-bottom: .65rem; }
.status-dot { background: var(--status); }
.column-heading h2 { font-size: .96rem; font-weight: 700; margin: 0; }
.column-add { margin-left: auto; width: 1.6rem; height: 1.6rem; }
.column-cards { display: grid; gap: .6rem; }
.column-empty { text-align: center; font-size: .84rem; padding: 1.1rem .4rem; border: 1px dashed var(--td-line); border-radius: .5rem; }
.task-card { display: grid; gap: .55rem; width: 100%; text-align: start; padding: .84rem; border: 1px solid var(--td-line); border-radius: .6rem; background: var(--td-panel); color: var(--td-text); box-shadow: var(--td-shadow); cursor: grab; }
.task-card.dragging { opacity: .5; }
.task-title { font-size: .95rem; line-height: 1.4; }
.task-excerpt, .task-meta { font-size: .84rem; }
.task-id { font-family: ui-monospace, monospace; font-size: .77rem; }
.priority, .task-meta { width: fit-content; border-radius: .35rem; padding: .1rem .4rem; background: var(--td-soft); color: var(--td-muted); }
.priority { font-size: .72rem; font-weight: 650; }
.priority[data-priority=high] { color: #a73b32; background: #ffebe7; }
[data-bs-theme=dark] .priority[data-priority=high] { color: #ffb7a8; background: #472e30; }
.page-notice:not(:empty) { margin: .8rem 1rem 0; }
dialog { color: var(--td-text); background: var(--td-panel); border: 1px solid var(--td-line); border-radius: .9rem; padding: 0; max-height: 91dvh; box-shadow: 0 1.5rem 5rem #12132740; }
dialog::backdrop { background: #11132285; }
.form-dialog { width: min(32rem, calc(100% - 2rem)); }
.dialog-header, .agents-dialog-header { padding: 1.25rem 1.4rem 1rem; border-bottom: 1px solid var(--td-line); }
.dialog-header h2, .agents-dialog h2, .form-dialog h2 { margin: 0; font-size: 1.35rem; font-weight: 690; letter-spacing: -.03em; }
.dialog-body, .dialog-form { padding: 1.2rem 1.4rem; }
.form-field { display: grid; font-size: .9rem; font-weight: 600; gap: .35rem; margin: 0 0 .9rem; }
.form-field :is(input,textarea,select) { font-weight: 400; }
.dialog-actions { justify-content: flex-end; margin-top: 1rem; }
.form-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
dialog.drawer { margin: 0 0 0 auto; height: 100dvh; max-height: 100dvh; width: min(32rem, 100%); border-radius: .75rem 0 0 .75rem; }
.drawer .dialog-header { position: sticky; z-index: 1; top: 0; background: var(--td-panel); }
.dialog-body section { margin-top: 1.4rem; padding-top: 1.35rem; border-top: 1px solid var(--td-line); }
.record-list { display: grid; gap: .7rem; padding: 0; margin: .8rem 0; list-style: none; }
.record-list p { white-space: pre-line; margin: .15rem 0 0; }
.token-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.token-secret, .agents-dialog-text { font-family: ui-monospace, "Cascadia Mono", monospace; font-size: .88rem; }
.agents-dialog { width: min(49rem, calc(100% - 2rem)); }
.agents-dialog-intro { margin: 1rem 1.4rem .75rem; color: var(--td-muted); }
.agents-dialog-text { display: block; width: calc(100% - 2.8rem); height: min(43dvh, 25rem); min-height: 7rem; margin: 0 1.4rem; padding: 1rem; line-height: 1.55; color: var(--td-text); background: var(--td-soft); border: 1px solid var(--td-line); border-radius: .6rem; resize: vertical; }
.agents-dialog-actions { padding: 1rem 1.4rem; justify-content: flex-end; gap: .7rem; flex-wrap: wrap; }
.agents-dialog-status { color: var(--td-muted); font-size: .87rem; margin: 0; }
.loading-message, .loading-state, .error-page { margin: 3rem; }
.auth-layout { min-height: 100dvh; }
.auth-nav { display: flex; justify-content: space-between; align-items: center; padding: 1rem clamp(1rem, 4vw, 4rem); background: var(--td-panel); border-bottom: 1px solid var(--td-line); }
.mode-picker { gap: .55rem; font-size: .85rem; color: var(--td-muted); }
.auth-main { margin: clamp(1.25rem, 7vh, 5rem) auto 2rem; width: min(29rem, calc(100% - 2rem)); border: 1px solid var(--td-line); border-radius: 1rem; overflow: hidden; background: var(--td-panel); box-shadow: 0 .7rem 2.5rem #2822480b; }
.auth-art { position: relative; height: 6.25rem; overflow: hidden; background-color: #322765; background-image: radial-gradient(#9988da60 1px, transparent 1px); background-size: 13px 13px; color: #dcd5ff; }
.art-heading { display: flex; gap: .22rem; padding: .65rem; }
.art-heading i { width: .28rem; height: .28rem; border-radius: 50%; background: #c9bafa90; }
.art-board { position: absolute; width: 75%; display: grid; grid-template-columns: repeat(4, 1fr); gap: .45rem; right: 3%; top: 1.3rem; transform: rotate(-6deg); }
.art-column { border-radius: .4rem; border: 1px solid #a69ad063; background: #4b4081; padding: .5rem; min-height: 5rem; }
.art-column span { display: block; width: 60%; height: .22rem; background: #ddd5f7; margin-bottom: .5rem; border-radius: .2rem; }
.art-column i { display: block; background: #665ba1; height: 1.3rem; margin-bottom: .3rem; border-radius: .22rem; }
.art-column:nth-child(2n) i:nth-child(3) { visibility: hidden; }
.auth-card { padding: clamp(1.4rem, 4vw, 2.2rem); }
.auth-card h1 { font-size: 1.8rem; }
.auth-subtitle { margin: .65rem 0 1.3rem; }
.auth-field { font-size: .92rem; font-weight: 600; margin: .9rem 0 .3rem; }
.auth-hint { font-size: .82rem; }
.auth-submit { display: block; width: 100%; margin-top: 1.45rem; padding: .6rem; }
.account-actions { border-top: 1px solid var(--td-line); margin-top: 1.2rem; padding-top: 1rem; font-size: .9rem; }
.install-note { font-size: .9rem; }
@media (max-width: 1100px) and (min-width: 761px) {
  .app-shell { grid-template-columns: 12.5rem minmax(0,1fr); }
  .board-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; width: min(17rem, 85vw); z-index: 6; inset: 0 auto 0 0; display: none; }
  .nav-open .sidebar { display: flex; }
  .nav-open .nav-scrim { display: block; position: fixed; z-index: 5; inset: 0; border: 0; background: #14132188; }
  .mobile-nav-toggle, .mobile-nav-close { display: flex; }
  .topbar, .brand-row { height: 3.6rem; }
  .stats-grid, .board-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: .65rem; }
  .stat-card { padding: .85rem; }
  .page-heading { margin-bottom: 1.2rem; }
  .board-column { min-height: 12rem; }
  .main-content { padding: 1.25rem 1rem; }
}
@media (max-width: 520px) {
  .board-grid { grid-template-columns: 1fr; }
  .board-column { min-height: 0; }
  .board-filters { flex-wrap: wrap; }
  .board-filters > * { min-width: 0; flex: 1 1 9rem; }
  .stat-value { margin-top: .35rem; }
  .agents-dialog-actions { justify-content: flex-start; }
}

/* Project totals and scoped key management */
.project-counts { justify-content: flex-start; flex-wrap: wrap; column-gap: .8rem; row-gap: .2rem; }
.project-counts + .project-meta { margin-top: 0; padding-top: .35rem; font-size: .78rem; }
.tokens-list > .empty-state { margin: 0; border: 0; box-shadow: none; }
.token-row > div { min-width: 0; }
.token-row h3 { margin: 0; font-size: 1rem; font-weight: 650; }
.token-row p { margin: .25rem 0; font-size: .9rem; }
.form-dialog fieldset legend { margin-bottom: .45rem; font-size: .9rem; font-weight: 600; }
.project-checklist { max-height: 32dvh; overflow-y: auto; padding: .65rem .8rem; background: var(--td-soft); border: 1px solid var(--td-line); border-radius: .5rem; }
.project-checklist .form-check { margin-bottom: .25rem; overflow-wrap: anywhere; }
.project-checklist .form-check:last-child { margin-bottom: 0; }
.agents-dialog-status:empty { display: none; }
.task-meta { max-width: 100%; overflow-wrap: anywhere; }
