:root {
    --paper: #F6F6F4;
    --card: #FFFFFF;
    --line: #D9DDD7;
    --line-soft: #EAEDE8;
    --ink: #27508A;
    --ink-dark: #1E3F6E;
    --ink-soft: #E8EEF6;
    --graphite: #24282A;
    --pencil: #6E746F;
    --pencil-light: #9AA09B;
    --red: #B8372B;
    --red-soft: #F6E7E5;
    --green: #2F6F45;
    --green-soft: #E6F0E9;
    --amber: #8F6B1F;
    --amber-soft: #F7F0DF;
    --radius: 4px;
    --font: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[x-cloak] { display: none !important; }

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--graphite);
    background: var(--paper);
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-weight: 600; line-height: 1.25; color: var(--graphite); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
h4 { font-size: 0.8125rem; color: var(--pencil); font-weight: 500; }

a { color: var(--ink); }

button {
    font: inherit;
    color: inherit;
    cursor: pointer;
    background: none;
    border: none;
    border-radius: var(--radius);
}

button:disabled { cursor: default; opacity: 0.45; }

input, select, textarea {
    font: inherit;
    color: var(--graphite);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.4375rem 0.625rem;
}

input::placeholder, textarea::placeholder { color: var(--pencil-light); }

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 2px var(--ink-soft);
}

:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

input[type="checkbox"], input[type="radio"] { accent-color: var(--ink); width: auto; padding: 0; }

.num { font-variant-numeric: tabular-nums; }

.row { display: flex; align-items: center; gap: 0.5rem; }
.row.spread { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; }
.muted { color: var(--pencil); }
.faint { color: var(--pencil-light); }
.plus { color: var(--green); }
.minus { color: var(--red); }
.dim { opacity: 0.5; }
.mt { margin-top: 0.5rem; }
.small { font-size: 0.75rem; }
.row label { margin: 0; }
.team-pick > h2 { margin-bottom: 1rem; }

.btn-primary, .btn-cancel, .btn-secondary, .btn-danger {
    padding: 0.4375rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    border-radius: var(--radius);
    white-space: nowrap;
}

.btn-primary { background: var(--ink); color: #fff; border: 1px solid var(--ink); }
.btn-primary:hover:not(:disabled) { background: var(--ink-dark); border-color: var(--ink-dark); }

.btn-cancel, .btn-secondary { background: var(--card); color: var(--graphite); border: 1px solid var(--line); }
.btn-cancel:hover:not(:disabled), .btn-secondary:hover:not(:disabled) { border-color: var(--pencil); }

.btn-danger { background: var(--card); color: var(--red); border: 1px solid var(--line); }
.btn-danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-soft); }

.btn-small { padding: 0.1875rem 0.5rem; font-size: 0.8125rem; }
.sort-toggle { display: inline-flex; gap: 0.75rem; align-items: center; }
.sort-toggle button { background: none; border: 0; padding: 0; color: var(--pencil); font-size: 0.8125rem; font-weight: 400; }
.sort-toggle button.active { color: var(--ink); font-weight: 600; }
.btn-block { width: 100%; }

.icon-btn {
    color: var(--pencil);
    padding: 0.125rem 0.375rem;
    font-size: 0.9375rem;
    line-height: 1;
}

.icon-btn:hover { color: var(--graphite); background: var(--line-soft); }
.icon-btn.delete:hover { color: var(--red); background: var(--red-soft); }

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    margin-bottom: 0.3125rem;
    font-size: 0.8125rem;
    color: var(--pencil);
}

.form-group input, .form-group select, .form-group textarea { width: 100%; }
.form-group textarea { resize: vertical; min-height: 4rem; }

.form-group .radio-list label {
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0; padding: 0.3125rem 0;
    font-size: 0.875rem; color: var(--graphite); cursor: pointer;
}

.form-group .check-row {
    display: flex; align-items: center; gap: 0.5rem;
    margin: 0; font-size: 0.875rem; color: var(--graphite); cursor: pointer;
}

.form-inline { display: flex; gap: 0.5rem; align-items: center; }
.form-inline input, .form-inline select { flex: 1; min-width: 0; }
.form-inline .narrow { flex: 0 0 7rem; }
.form-inline .tiny { flex: 0 0 3rem; padding: 0.125rem; height: 2.25rem; }

.date-row { display: flex; gap: 0.75rem; }
.date-row .form-group { flex: 1; }

.error-msg, .story-error, .tally-error {
    background: var(--red-soft);
    border: 1px solid #E5C2BD;
    color: var(--red);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
}

.note-box {
    background: var(--amber-soft);
    border: 1px solid #E5D5A8;
    border-radius: var(--radius);
    padding: 0.5rem 0.625rem;
    margin-bottom: 1rem;
    font-size: 0.8125rem;
}

.mono { font-family: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8125rem; }

.login-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    z-index: 100;
    background: var(--paper);
}

.login-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-top: 3px solid var(--ink);
    border-radius: var(--radius);
    padding: 2rem;
    width: 100%; max-width: 22rem;
}

.login-card h1 { font-size: 1.625rem; font-weight: 600; letter-spacing: -0.01em; margin-bottom: 0.25rem; }
.login-card .tagline { color: var(--pencil); font-size: 0.8125rem; margin-bottom: 1.5rem; }
.login-card button[type="submit"] { width: 100%; padding: 0.625rem; margin-top: 0.25rem; }

.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(36, 40, 42, 0.35);
    display: flex; align-items: center; justify-content: center;
    z-index: 50;
}

.modal {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 16px 40px rgba(36, 40, 42, 0.18);
    padding: 1.5rem;
    width: 100%; max-width: 30rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
}

.modal h3 { margin-bottom: 1rem; }
.modal h3 + .form-group, .modal h3 + .row { margin-top: 0; }
.modal h3:not(:first-child) { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--line-soft); }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }
.modal-footer-left { display: flex; gap: 0.5rem; margin-right: auto; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.list-view { padding: 1.5rem; max-width: 56rem; }
.list-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.list-header + .list-header, .list-header.later { margin-top: 2.5rem; }

.list-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
}

.list-card.top { align-items: flex-start; }
.list-card-info { flex: 1; min-width: 0; }
.list-card-name { font-size: 0.9375rem; font-weight: 500; }
.list-card-sub { font-size: 0.8125rem; color: var(--pencil); margin-top: 0.125rem; }
.list-card-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }

.list-card-actions button {
    color: var(--pencil); font-size: 0.8125rem;
    padding: 0.3125rem 0.5rem;
}

.list-card-actions button:hover { background: var(--line-soft); color: var(--graphite); }
.list-card-actions button.delete:hover { background: var(--red-soft); color: var(--red); }

.tag {
    display: inline-block;
    font-size: 0.75rem; line-height: 1.3;
    padding: 0.0625rem 0.4375rem;
    border-radius: 2px;
    border: 1px solid var(--line);
    color: var(--pencil);
    background: var(--card);
    vertical-align: middle;
}

.tag.admin { color: var(--red); border-color: #E5C2BD; }
.tag.id { font-family: 'IBM Plex Mono', ui-monospace, monospace; font-size: 0.7rem; }

.chip {
    display: inline-flex; align-items: center; gap: 0.25rem;
    background: var(--line-soft);
    border-radius: 1rem;
    padding: 0.125rem 0.625rem;
    font-size: 0.8125rem;
}

.chip button { color: var(--pencil-light); padding: 0 0.125rem; font-size: 0.75rem; line-height: 1; }
.chip button:hover { color: var(--red); }

.kanban-card-tag, .task-card-tag {
    font-size: 0.75rem; line-height: 1.3;
    padding: 0.0625rem 0.4375rem;
    border-radius: 2px;
    background: var(--line-soft);
    color: var(--pencil);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 12rem;
}

.kanban-card-tag.customer, .task-card-tag.customer { border-left: 3px solid var(--pencil-light); padding-left: 0.3125rem; }
.kanban-card-tag.project, .task-card-tag.project { color: var(--green); background: var(--green-soft); }

.status-badge {
    font-size: 0.75rem; line-height: 1.3;
    padding: 0.0625rem 0.5rem;
    border-radius: 1rem;
    font-weight: 500;
    border: 1px solid transparent;
    white-space: nowrap;
}

.status-badge.cellar { background: var(--paper); color: var(--pencil-light); border-color: var(--line); }
.status-badge.backlog { background: var(--line-soft); color: var(--pencil); }
.status-badge.todo { background: var(--ink-soft); color: var(--ink); }
.status-badge.today { background: var(--amber-soft); color: var(--amber); }
.status-badge.done { background: var(--green-soft); color: var(--green); }
.status-badge.archived { background: var(--line-soft); color: var(--pencil-light); }

.view-toggle, .sort-tabs { display: flex; }

.view-toggle button, .sort-tabs button {
    padding: 0.3125rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--pencil);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 0;
    margin-left: -1px;
    white-space: nowrap;
}

.view-toggle button:first-child, .sort-tabs button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.view-toggle button:last-child, .sort-tabs button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

.view-toggle button.active, .sort-tabs button.active {
    color: var(--ink); background: var(--ink-soft); border-color: var(--ink); position: relative; z-index: 1;
}

.search-box { position: relative; }
.search-box input { width: 100%; padding-right: 1.75rem; }

.search-box .clear {
    position: absolute; right: 0.25rem; top: 50%; transform: translateY(-50%);
    color: var(--pencil-light); font-size: 0.75rem; padding: 0.25rem;
}

.search-box .clear:hover { color: var(--graphite); }

.filter-chip {
    display: block; width: 100%;
    text-align: left;
    padding: 0.375rem 0.625rem;
    margin-bottom: 0.25rem;
    border: 1px solid var(--line);
    border-left: 4px solid var(--line);
    border-radius: var(--radius);
    background: var(--card);
    font-size: 0.8125rem;
    color: var(--graphite);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.filter-chip:hover { border-color: var(--pencil-light); }
.filter-chip.active { color: var(--ink); background: var(--ink-soft); border-color: var(--ink); font-weight: 500; }
.filter-chip.center { text-align: center; }

.filter-clear {
    display: block; width: 100%;
    font-size: 0.8125rem; color: var(--ink);
    padding: 0.3125rem 0.625rem;
    margin-top: 0.125rem;
}

.filter-clear:hover { background: var(--ink-soft); }

.team-pick { padding: 1.5rem; max-width: 40rem; }
.team-pick-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.team-pick-head h2 { margin: 0; }

.team-pick-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-left: 4px solid var(--ink);
    border-radius: var(--radius);
    padding: 0.875rem 1rem;
    margin-bottom: 0.5rem;
    display: flex; align-items: center; gap: 1rem;
    cursor: pointer;
}

.team-pick-card:hover { border-color: var(--ink); }
.team-pick-name { flex: 1; font-weight: 500; font-size: 0.9375rem; }
.team-pick-meta { font-size: 0.8125rem; color: var(--pencil-light); }
.team-pick-saldo { font-weight: 600; font-variant-numeric: tabular-nums; }
.team-pick-empty { color: var(--pencil); padding: 0.5rem 0 1rem; max-width: 40ch; }

.team-back { color: var(--pencil); font-size: 0.8125rem; padding: 0; margin-bottom: 0.75rem; }
.team-back:hover { color: var(--ink); }

.tally-saldo {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-variant-numeric: tabular-nums;
}

.tally-saldo-value { font-weight: 600; text-align: right; }
.tally-bar { position: relative; height: 0.625rem; background: var(--line); border-radius: 999px; }
.tally-bar::before { content: ''; position: absolute; left: 50%; top: -0.1875rem; bottom: -0.1875rem; width: 1px; background: var(--pencil-light); }
.tally-bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.tally-bar-fill.plus { background: var(--green); }
.tally-bar-fill.minus { background: var(--red); }
.tally-saldo-paid { color: var(--pencil-light); font-size: 0.8125rem; }

.tally-transfer {
    margin-top: 0.5rem; padding-top: 0.5rem;
    border-top: 1px dashed var(--line);
    font-size: 0.8125rem;
}

.tally-members {
    display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.8125rem; color: var(--pencil);
}

.tally-member { display: inline-flex; align-items: center; gap: 0.25rem; background: var(--line-soft); border-radius: 1rem; padding: 0.125rem 0.625rem; color: var(--graphite); }
.tally-member-del { color: var(--pencil-light); font-size: 0.75rem; padding: 0; line-height: 1; }
.tally-member-del:hover { color: var(--red); }
.tally-member-input { width: 13rem; padding: 0.25rem 0.5rem; font-size: 0.8125rem; }
.tally-delete { margin-left: auto; color: var(--red); }

.story-save { background: var(--ink); color: #fff; padding: 0.3125rem 0.75rem; font-size: 0.8125rem; font-weight: 500; }
.story-save:hover:not(:disabled) { background: var(--ink-dark); }

.story-icon-btn { color: var(--pencil); padding: 0.125rem 0.375rem; font-size: 0.9375rem; line-height: 1; }
.story-icon-btn:hover { color: var(--graphite); background: var(--line-soft); }

.story-meta { font-size: 0.75rem; color: var(--pencil-light); }
.story-unproven { color: var(--amber); font-size: 0.9375rem; flex-shrink: 0; cursor: default; }

.story-unproven-count {
    font-size: 0.75rem; color: var(--amber);
    background: var(--amber-soft); border: 1px solid #E5D5A8;
    border-radius: var(--radius); padding: 0.125rem 0.5rem;
}

.story-filter { padding: 0.3125rem 0.5rem; font-size: 0.8125rem; }

.story-history-list { max-height: 60vh; overflow-y: auto; }

.story-history-entry {
    display: flex; gap: 0.75rem; font-size: 0.8125rem;
    padding: 0.375rem 0; border-bottom: 1px solid var(--line-soft);
}

.story-history-when { width: 9rem; flex-shrink: 0; color: var(--pencil-light); font-variant-numeric: tabular-nums; }
.story-history-who { width: 7rem; flex-shrink: 0; color: var(--ink); }
.story-history-what { flex: 1; }

.time-show-all { display: flex; align-items: center; gap: 0.3125rem; font-size: 0.8125rem; color: var(--pencil); cursor: pointer; }
.time-show-all input { cursor: pointer; }

.time-table {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    font-variant-numeric: tabular-nums;
}

.time-table-row {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--line-soft);
    cursor: pointer;
}

.time-table-row:last-child { border-bottom: none; }
.time-table-row:hover { background: var(--paper); }
.time-table-row.invoiced { color: var(--pencil-light); }
.time-table-row.invoiced .time-col-name, .time-table-row.invoiced .time-row-name { text-decoration: line-through; text-decoration-color: var(--line); }

.time-entry-check { font-size: 1rem; flex-shrink: 0; padding: 0; color: var(--ink); line-height: 1; }

.time-customer-block { margin-bottom: 1.5rem; }

.time-customer-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.5rem 0; margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--graphite);
    cursor: pointer;
}

.time-customer-left { display: flex; align-items: baseline; gap: 0.625rem; flex-wrap: wrap; }
.time-toggle { font-size: 0.625rem; color: var(--pencil-light); }
.time-customer-name { font-weight: 600; font-size: 1rem; }
.time-customer-open { font-size: 0.8125rem; color: var(--red); font-variant-numeric: tabular-nums; }
.time-customer-total { font-size: 0.8125rem; color: var(--pencil); font-variant-numeric: tabular-nums; }

.notes-list-item {
    padding: 0.5rem 0.625rem;
    cursor: pointer;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius) var(--radius) 0;
    margin-bottom: 0.125rem;
}

.notes-list-item:hover { background: var(--line-soft); }
.notes-list-item.active { background: var(--ink-soft); border-left-color: var(--ink); }
.notes-list-item-name { font-weight: 500; font-size: 0.875rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notes-list-item-date { font-size: 0.75rem; color: var(--pencil-light); margin-top: 0.0625rem; font-variant-numeric: tabular-nums; }

.notes-preview a { color: var(--ink); }
.notes-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--pencil-light); padding: 2rem; text-align: center; }

.empty { color: var(--pencil-light); text-align: center; padding: 1.5rem 1rem; font-size: 0.8125rem; }

.placeholder { padding: 4rem 2rem; text-align: left; color: var(--pencil); max-width: 40ch; }
.placeholder .glyph { font-size: 2.5rem; margin-bottom: 0.75rem; }
.placeholder h2 { margin-bottom: 0.25rem; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

.tally-quick { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.tally-quick input[type="text"] { flex: 1; min-width: 0; }
.tally-quick .photo { cursor: pointer; font-size: 1.25rem; }
.tally-quick .hidden-file { display: none; }
.tally-quick .busy { font-size: 0.8125rem; color: var(--pencil); }
input.missing { border-color: var(--amber); background: var(--amber-soft); }
.tally-detected { font-size: 0.75rem; color: var(--amber); margin-top: 0.25rem; }
