:root {
    color-scheme: dark;
    --bg: #0f1117;
    --panel: #171923;
    --panel-alt: #1c1f2b;
    --text: #e6e8ee;
    --text-muted: #9096a8;
    --border: #2a2e3d;
    --sidebar-bg: #0b0c12;
    --sidebar-text: #b7bccb;
    --sidebar-text-active: #ffffff;
    --sidebar-active-bg: #232738;
    --accent: #6366f1;
    --accent-hover: #7376f5;
    --accent-soft: #232445;
    --success: #34d399;
    --success-soft: #10251c;
    --warn: #f5a623;
    --warn-soft: #2b2110;
    --danger: #f87171;
    --danger-soft: #2e1414;
    --pill-text: #0f1117;
    --pill-idle: #9aa0b4;
    --pill-info: #60a5fa;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 10px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
}

a { color: inherit; }

/* ---------- App layout: top bar + hamburger nav ---------- */

.layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.topbar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem;
    padding: 0.7rem 1.25rem;
}

.hamburger {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    padding: 0;
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 7px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    cursor: pointer;
}

.hamburger:hover { background: rgba(255, 255, 255, 0.08); }

.hamburger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--sidebar-text-active);
    border-radius: 2px;
}

.brand-logo {
    max-width: 130px;
    height: auto;
    display: block;
    flex-shrink: 0;
}

.page-heading {
    padding: 1.5rem 2rem 0;
}

.page-heading h1 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 650;
}

.page-heading-subtitle {
    margin: 0.2rem 0 0;
    color: var(--text-muted);
    font-size: 0.88rem;
}

.site-nav {
    display: none;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.6rem;
    position: absolute;
    top: calc(100% + 6px);
    right: 1.25rem;
    min-width: 200px;
    width: max-content;
    max-width: calc(100vw - 2.5rem);
    border-radius: var(--radius);
    background: var(--sidebar-bg);
    box-shadow: var(--shadow);
    max-height: calc(100vh - 100%);
    overflow-y: auto;
}

.site-nav.open { display: flex; }

.nav-user {
    padding: 0.45rem 0.7rem 0.6rem;
    margin-bottom: 0.3rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.9rem;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-link {
    display: block;
    padding: 0.55rem 0.7rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    color: var(--sidebar-text);
    transition: background 0.12s ease, color 0.12s ease;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
}

.nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-text-active);
    font-weight: 600;
}

.nav-link--muted {
    color: #7d839a;
    font-size: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 0.3rem;
    padding-top: 0.7rem;
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.content {
    padding: 1.75rem 2rem 3rem;
    max-width: none;
    width: 100%;
}

.content--wide {
    max-width: none;
}

/* ---------- Cards ---------- */

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.4rem 1.5rem;
    margin-bottom: 1.25rem;
}

.card h2 {
    margin-top: 0;
    font-size: 1rem;
    font-weight: 650;
}

.card > p:first-child, .card h2 + p {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 0.1rem;
}

/* ---------- Collapsible settings cards ---------- */

.card-collapsible {
    padding: 0;
}

.card-collapsible summary {
    list-style: none;
    cursor: pointer;
    padding: 1.4rem 1.5rem;
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.card-collapsible summary::-webkit-details-marker { display: none; }

.card-collapsible summary::before {
    content: '\25B8';
    display: inline-block;
    margin-right: 0.3rem;
    color: var(--text-muted);
    transition: transform 0.12s ease;
}

.card-collapsible[open] > summary::before {
    transform: rotate(90deg);
}

.card-collapsible summary h2 {
    margin: 0;
    display: inline;
}

.card-collapsible-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.card-collapsible-body {
    padding: 0 1.5rem 1.4rem;
}

.card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* ---------- Forms ---------- */

label {
    display: block;
    margin: 0.9rem 0 0.3rem;
    font-size: 0.85rem;
    font-weight: 550;
    color: var(--text-muted);
}

label:first-child { margin-top: 0; }

input[type=text], input[type=password], input[type=email], select, textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 0.92rem;
    background: var(--panel-alt);
    color: var(--text);
    font-family: inherit;
}

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

label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text);
    font-weight: 400;
}

label.checkbox-label input { width: auto; }

.search-row {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.search-row input { flex: 1; }
.search-row button { margin-top: 0; flex-shrink: 0; }

code {
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 0.1rem 0.4rem;
    font-size: 0.85em;
}

/* ---------- Buttons ---------- */

button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1.1rem;
    padding: 0.55rem 1.15rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 0.88rem;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s ease;
}

button:hover, .btn:hover { background: var(--accent-hover); }

button.secondary, .btn.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

button.secondary:hover, .btn.secondary:hover { background: var(--panel-alt); }

/* Disabled (e.g. a sync in progress): greyed out, no hover, not clickable. */
button:disabled, button:disabled:hover {
    background: var(--panel-alt);
    color: var(--text-muted);
    border: 1px solid var(--border);
    cursor: not-allowed;
    opacity: 0.7;
    pointer-events: none;
}

button.small, .btn.small { margin-top: 0; padding: 0.3rem 0.7rem; font-size: 0.8rem; }

.btn-row { display: flex; gap: 0.6rem; flex-wrap: wrap; }

/* ---------- Tables ---------- */

table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }

th {
    text-align: left;
    padding: 0.55rem 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 0.65rem 0.7rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }

.clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: pre-line;
}
tr:hover td { background: var(--panel-alt); }

/* ---------- Badges & flashes ---------- */

.badge {
    display: inline-block;
    padding: 0.18rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.success { background: var(--success-soft); color: var(--success); }
.badge.retrying, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.neutral { background: var(--panel-alt); color: var(--text-muted); }

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.25rem;
    font-size: 0.88rem;
    font-weight: 500;
}

.flash.error { background: var(--danger-soft); color: var(--danger); }
.flash.success { background: var(--success-soft); color: var(--success); }

/* ---------- Empty states ---------- */

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* ---------- Stat tiles (dashboard) ---------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-tile {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.3rem;
}

.stat-tile .stat-value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-tile .stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* ---------- Login page ---------- */

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    box-sizing: border-box;
    background: var(--bg);
}

.login-card {
    width: min(380px, 100%);
    text-align: center;
    padding: 0;
    overflow: hidden;
}

.login-logo-panel {
    background: var(--sidebar-bg);
    padding: 2rem 1.5rem;
}

.login-logo {
    max-width: 220px;
    width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}

.login-logo-panel + .login-body + .login-logo-panel {
    padding: 1rem 1.5rem;
}

.login-logo--secondary {
    max-width: 130px;
}

.login-body {
    padding: 1.75rem 1.75rem 2rem;
    text-align: left;
}

.login-card button { width: 100%; justify-content: center; }

/* Phones: 16px fields (smaller ones make iOS zoom in on focus) and larger touch targets. */
@media (max-width: 600px) {
    .login-card input, .login-card button { font-size: 1rem; padding-top: 0.7rem; padding-bottom: 0.7rem; }
}

/* ---------- Atlas board ---------- */

.board-scroll { overflow-x: auto; }

.board-table { white-space: nowrap; font-size: 0.8rem; table-layout: fixed; min-width: 100%; }
.board-table .pm-tags, .board-table .pm-tags-ro { max-width: none; }
.board-table th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 0.3rem 0.55rem; font-size: 0.72rem; }
.board-table td { vertical-align: top; padding: 0.28rem 0.55rem; line-height: 1.3; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; }
.board-table tr:hover td { background: var(--panel-alt); }
.board-name { font-weight: 600; }
.board-empty { color: var(--text-muted); }
.board-group > summary { padding: 0.8rem 1.1rem; }
.board-group .card-collapsible-body { padding: 0 1rem 0.9rem; }
.board-group .card-collapsible-body .empty-state { padding: 0.6rem 0; }

.board-group--new_group15164 { border-left: 4px solid #9aa0b4; }
.board-group--new_group29179 { border-left: 4px solid var(--accent); }
.board-group--group_mm77sdy3 { border-left: 4px solid var(--success); }

.board-pill {
    display: inline-block;
    padding: 0.05rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--pill-text);
}
.board-pill--good { background: var(--success); }
.board-pill--bad { background: var(--danger); }
.board-pill--idle { background: var(--pill-idle); }
.board-pill--info { background: var(--pill-info); }

.board-longtext { max-width: 18rem; white-space: normal; }
.board-longtext summary { cursor: pointer; color: var(--text-muted); }
.board-longtext div { margin-top: 0.4rem; font-size: 0.85rem; }

/* ---------- Manual sync progress bar ---------- */

.sync-bar {
    position: relative;
    height: 2rem;
    margin-top: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--panel-alt);
    overflow: hidden;
}
.sync-bar[hidden] { display: none; }
.sync-bar-fill {
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.3s ease;
}
.sync-bar-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.sync-status { margin-top: 0.5rem; font-size: 0.88rem; }
.sync-status:empty { display: none; } /* no reserved space until there is a message */
.sync-status--ok { color: var(--success); }
.sync-status--error { color: var(--danger); }

/* Compact data tables (Browse). */
table.dense { font-size: 0.8rem; }
table.dense th { padding: 0.3rem 0.55rem; font-size: 0.72rem; }
table.dense td { padding: 0.28rem 0.55rem; line-height: 1.3; }
table.dense .cell-clip { max-width: 20rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.dense tr:hover td { background: var(--panel-alt); }

/* Sortable table headers (assets/table_sort.js). */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--text); }
th.sortable::after { content: ' \2195'; opacity: 0.35; font-size: 0.85em; }
th.sortable[aria-sort="ascending"]::after { content: ' \25B2'; opacity: 1; }
th.sortable[aria-sort="descending"]::after { content: ' \25BC'; opacity: 1; }

/* ---------- Board tabs and inline edits ---------- */

.board-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.board-tab {
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 550;
}
.board-tab:hover { color: var(--text); background: var(--panel-alt); }
.board-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.board-tab-count { opacity: 0.8; font-weight: 400; margin-left: 0.25rem; }

.board-table .board-edit {
    font: inherit;
    font-size: 0.78rem;
    padding: 0.15rem 0.3rem;
    margin: 0;
    width: auto;
    min-width: 0;
    background: var(--panel-alt);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 5px;
}
.board-table select.board-edit { max-width: 11rem; }
.board-table input[type="date"].board-edit { width: 8.6rem; }
.board-table .board-edit.edit-saved { border-color: var(--success); }
.board-table .board-edit.edit-error { border-color: var(--danger); }
.board-moves button { margin: 0 0.2rem 0 0; }

/* ---------- Compact board rows with expandable detail ---------- */

.board-tools { margin: 0 0 0.8rem; display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }
.board-sub { color: var(--text-muted); font-size: 0.74rem; }
.board-item { min-width: 14rem; max-width: 24rem; white-space: normal; }
.board-item .board-name { display: block; }
.board-item .board-sub { display: block; }
.board-timeline { white-space: nowrap; }
.board-timeline .board-sub { margin: 0 0.15rem; }

.board-toggle {
    margin: 0;
    padding: 0.2rem;
    background: none;
    border: none;
    border-radius: 5px;
    color: var(--accent-hover);
    line-height: 0;
}
.board-toggle:hover { background: none; color: var(--text); }
.board-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.board-toggle svg {
    width: 1.15rem; height: 1.15rem;
    fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round;
    transform-origin: 50% 50%;
    transition: transform 0.15s ease;
}
.board-row.is-open .board-toggle svg { transform: rotate(90deg); } /* the arrow itself turns in place */
.board-row.is-open td { background: var(--panel-alt); }

.board-detail[hidden] { display: none; }
.board-detail td { background: var(--panel-alt); padding: 0.8rem 1rem 1rem; white-space: normal; max-width: none; }
.board-detail-grid { display: grid; grid-template-columns: minmax(16rem, 22rem) 1fr; gap: 1.4rem; }
.board-detail-grid dl { margin: 0; display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.25rem 0.8rem; font-size: 0.82rem; }
.board-detail-grid dt { color: var(--text-muted); }
.board-detail-grid dd { margin: 0; }
.board-detail-grid h4 { margin: 0 0 0.25rem; font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.board-detail-text { font-size: 0.84rem; max-height: 14rem; overflow-y: auto; margin-bottom: 0.9rem; white-space: normal; }
@media (max-width: 800px) { .board-detail-grid { grid-template-columns: 1fr; } }

/* ---------- Timeline range picker (one calendar, start then end) ---------- */

.board-range {
    margin: 0;
    padding: 0.15rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--panel-alt);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: 5px;
    white-space: nowrap;
}
.board-range.is-set { color: var(--text); }
.board-range:hover { background: var(--panel); color: var(--text); }
.board-range.edit-saved { border-color: var(--success); }
.board-range.edit-error { border-color: var(--danger); }

.range-popover {
    position: absolute;
    z-index: 50;
    width: 17.5rem;
    padding: 0.7rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 0.82rem;
}
.range-popover .rp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.range-popover .rp-title { font-weight: 600; }
.range-popover .rp-nav { margin: 0; padding: 0.1rem 0.6rem; background: transparent; color: var(--text); border: 1px solid var(--border); font-size: 1rem; line-height: 1.2; }
.range-popover .rp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.range-popover .rp-dow { text-align: center; color: var(--text-muted); font-size: 0.7rem; padding: 0.15rem 0; }
.range-popover .rp-day {
    margin: 0; padding: 0.3rem 0; justify-content: center;
    background: transparent; color: var(--text); font-size: 0.8rem; font-weight: 450;
    border: 1px solid transparent; border-radius: 5px;
}
.range-popover .rp-day:hover { background: var(--panel-alt); border-color: var(--border); }
.range-popover .rp-day.is-today { border-color: var(--text-muted); }
.range-popover .rp-day.in-range { background: var(--accent-soft); }
.range-popover .rp-day.is-start, .range-popover .rp-day.is-end { background: var(--accent); color: #fff; }
.range-popover .rp-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-top: 0.5rem; }
.range-popover .rp-hint { color: var(--text-muted); font-size: 0.72rem; }
.range-popover .rp-clear { margin: 0; }

/* ---------- PM tags ---------- */

.pm-tags-ro { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; min-width: 6rem; max-width: 16rem; }
.pm-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; min-width: 6rem; max-width: 16rem; }
.pm-chip {
    display: inline-flex; align-items: center; gap: 0.25rem;
    padding: 0.08rem 0.2rem 0.08rem 0.55rem;
    background: var(--accent-soft); color: var(--text);
    border: 1px solid var(--border); border-radius: 999px;
    font-size: 0.74rem; font-weight: 550; white-space: nowrap;
}
.pm-tags .pm-x, .pm-tags .pm-add {
    margin: 0; padding: 0; width: 1.15rem; height: 1.15rem; justify-content: center;
    background: transparent; color: var(--text-muted); border: none; border-radius: 50%;
    font-size: 0.85rem; line-height: 1;
}
.pm-tags .pm-x:hover { background: var(--danger-soft); color: var(--danger); }
.pm-tags .pm-add { border: 1px dashed var(--border); width: 1.35rem; height: 1.35rem; font-size: 0.95rem; }
.pm-tags .pm-add:hover { background: var(--panel-alt); color: var(--text); }
.pm-tags.edit-saved .pm-chip { border-color: var(--success); }
.pm-tags.edit-error .pm-chip { border-color: var(--danger); }

.pm-popover { width: 15rem; }
.pm-popover .pmp-input { width: 100%; margin: 0 0 0.4rem; padding: 0.35rem 0.5rem; font-size: 0.82rem; }
.pm-popover .pmp-list { display: flex; flex-direction: column; gap: 2px; max-height: 13rem; overflow-y: auto; }
.pm-popover .pmp-person, .pm-popover .pmp-new {
    margin: 0; justify-content: flex-start; text-align: left; width: 100%;
    padding: 0.3rem 0.5rem; background: transparent; color: var(--text);
    border: 1px solid transparent; border-radius: 5px; font-size: 0.82rem; font-weight: 450;
}
.pm-popover .pmp-person:hover, .pm-popover .pmp-new:hover { background: var(--panel-alt); border-color: var(--border); }
.pm-popover .pmp-new { color: var(--accent-hover); }

/* ---------- Manage people (inside the PM popover) ---------- */

.pm-popover--wide { width: 21rem; }
.pm-popover .pmp-manage { margin: 0.5rem 0 0; width: 100%; justify-content: center; }
.pmm-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.4rem; }
.pmm-head .pmm-back { margin: 0; }
.pmm-msg { margin-bottom: 0.4rem; color: var(--danger); font-size: 0.78rem; }
.pmm-list { display: flex; flex-direction: column; gap: 3px; max-height: 16rem; overflow-y: auto; }
.pmm-row { display: flex; align-items: center; gap: 0.35rem; padding: 0.2rem 0.1rem; border-bottom: 1px solid var(--border); }
.pmm-row .pmm-name { flex: 1; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pmm-row .pmm-count { color: var(--text-muted); font-size: 0.72rem; white-space: nowrap; }
.pmm-row button { margin: 0; padding: 0.15rem 0.5rem; }
.pmm-row .pmm-input { flex: 1; min-width: 0; margin: 0; padding: 0.25rem 0.4rem; font-size: 0.8rem; }

.board-expander { cursor: pointer; }
.board-expander:hover { color: var(--accent-hover); }

.board-search { margin-bottom: 0.9rem; }
.board-match { display: block; color: var(--accent-hover); font-size: 0.7rem; font-style: italic; }

/* ---------- Integration sections inside the Integrations card ---------- */

.sub-collapsible { border-top: 1px solid var(--border); padding: 0.2rem 0; }
.sub-collapsible:first-child { border-top: none; }
.sub-collapsible > summary { list-style: none; cursor: pointer; padding: 0.8rem 0; display: flex; align-items: baseline; gap: 0.6rem; }
.sub-collapsible > summary::-webkit-details-marker { display: none; }
.sub-collapsible > summary::before { content: '\25B8'; color: var(--text-muted); transition: transform 0.12s ease; }
.sub-collapsible[open] > summary::before { transform: rotate(90deg); }
.sub-collapsible > summary h2 { margin: 0; display: inline; }

/* ---------- Financials pill + modal ---------- */

.board-fin {
    margin: 0; padding: 0.12rem 0.65rem;
    font-size: 0.74rem; font-weight: 600; border-radius: 999px;
    border: 1px solid var(--border); background: var(--panel-alt); color: var(--text);
    white-space: nowrap;
}
.board-fin-ro { display: inline-block; padding: 0.12rem 0.65rem; font-size: 0.74rem; font-weight: 600; border-radius: 999px; border: 1px solid var(--border); background: var(--panel-alt); white-space: nowrap; }
.board-fin-ro.fin-good { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.board-fin-ro.fin-idle { color: var(--text-muted); }
.board-fin-ro.fin-bad { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.board-fin-ro.fin-info { background: var(--accent-soft); border-color: var(--accent); }
.board-fin-ro.fin-none { color: var(--text-muted); }
.board-fin:hover { filter: brightness(1.15); }
.board-fin.fin-none { color: var(--text-muted); border-style: dashed; font-weight: 500; }
.board-fin.fin-good, .modal-option.fin-good { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.board-fin.fin-idle, .modal-option.fin-idle { background: var(--panel-alt); color: var(--text-muted); }
.board-fin.fin-bad, .modal-option.fin-bad { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.board-fin.fin-info, .modal-option.fin-info { background: var(--accent-soft); color: var(--text); border-color: var(--accent); }
.board-fin.edit-saved { box-shadow: 0 0 0 2px var(--success); }
.board-fin.edit-error { box-shadow: 0 0 0 2px var(--danger); }

.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: rgba(5, 6, 10, 0.6); padding: 1rem;
}
.modal {
    width: 100%; max-width: 22rem; max-height: 90vh; overflow-y: auto;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.1rem 1.2rem;
}
.modal h3 { margin: 0; font-size: 1rem; }
.modal-sub { margin: 0.15rem 0 0.8rem; color: var(--text-muted); font-size: 0.82rem; }
.modal-options { display: flex; flex-direction: column; gap: 0.35rem; }
.modal-option {
    margin: 0; width: 100%; justify-content: flex-start; text-align: left;
    padding: 0.5rem 0.75rem; font-size: 0.85rem; font-weight: 550;
    border: 1px solid var(--border); border-radius: 7px;
}
.modal-option:hover, .modal-option:focus-visible { filter: brightness(1.2); outline: 2px solid var(--accent); outline-offset: 1px; }
.modal-option.is-current::after { content: 'current'; margin-left: auto; font-size: 0.7rem; font-weight: 500; opacity: 0.8; }
.modal-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 0.9rem; }
.modal-foot button { margin: 0; }

/* ---------- Send-to icon buttons ---------- */

.board-moves .move-icon { padding: 0.28rem 0.4rem; line-height: 0; }
.move-icon svg { width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.move-icon:hover { color: var(--accent-hover); border-color: var(--accent); }

/* Compact Sync card: tighter padding, and the button doesn't carry the global top margin. */
.sync-card { padding: 0.7rem 1.25rem; margin-bottom: 1rem; }
.sync-card .card-row button { margin: 0; }

/* ---------- Always-visible horizontal scrollbar for tables (assets/hscroll.js) ---------- */

.table-scroll, .board-scroll { overflow-x: auto; }
.table-scroll.has-proxy, .board-scroll.has-proxy { scrollbar-width: none; -ms-overflow-style: none; }
.table-scroll.has-proxy::-webkit-scrollbar, .board-scroll.has-proxy::-webkit-scrollbar { display: none; }

.hscroll-proxy {
    position: sticky; bottom: 0; z-index: 5;
    overflow-x: scroll; overflow-y: hidden;
    background: var(--panel);
}
.hscroll-proxy > div { height: 1px; }
/* Firefox has no way to set the bar's height, so it gets the standard (thick) bar; Chrome/Safari use the custom one below.
   (Setting scrollbar-color in Chrome would override the custom sizing, hence the @supports guard.) */
@supports not selector(::-webkit-scrollbar) {
    .hscroll-proxy { scrollbar-width: auto; scrollbar-color: var(--text-muted) var(--panel-alt); }
}
.hscroll-proxy::-webkit-scrollbar { height: 24px; background: var(--panel-alt); }
.hscroll-proxy::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 10px; border: 4px solid var(--panel-alt); }
.hscroll-proxy::-webkit-scrollbar-thumb:hover { background: var(--text); }

/* ---------- Board Sort dialog ---------- */

.sort-modal { max-width: 26rem; }
.sort-modal label { margin-top: 0.8rem; }
.sort-row { display: flex; gap: 0.5rem; }
.sort-row select { flex: 1; min-width: 0; margin: 0; }
.sort-modal .modal-foot { margin-top: 1.2rem; }
.sort-actions { display: flex; gap: 0.5rem; }
.sort-actions button { margin: 0; }

/* ---------- ATLAS wordmark beside the ATC logo in the top bar ---------- */

.brand { display: flex; align-items: center; gap: 0.9rem; min-width: 0; }
.brand-atlas { height: 24px; width: auto; display: block; flex-shrink: 0; padding-left: 0.9rem; border-left: 1px solid var(--border); }

/* ---------- Project page: aligned label/value tables and a card grid ---------- */

.project-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr));
    gap: 1.25rem;
    align-items: start;
}
.project-grid .card { margin-bottom: 0; min-width: 0; }
.project-grid .card.span-all { grid-column: 1 / -1; }

/* label | value tables: one fixed label column everywhere, so labels line up from card to card */
table.kv { table-layout: fixed; }
table.kv th { width: 11rem; white-space: nowrap; }
@media (max-width: 600px) { table.kv th { width: 6.75rem; white-space: normal; } }
table.kv td { overflow-wrap: anywhere; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: none; }

/* line items: the item description takes the room, quantity and price stay tight and right-aligned */
table.items { table-layout: fixed; }
table.items th:nth-child(2), table.items td:nth-child(2) { width: 6rem; text-align: right; }
table.items th:nth-child(3), table.items td:nth-child(3) { width: 9rem; text-align: right; }

/* comments: when / author stay narrow, the comment gets the width */
table.comments-table { table-layout: fixed; }
table.comments-table th:nth-child(1), table.comments-table td:nth-child(1) { width: 12rem; white-space: nowrap; }
table.comments-table th:nth-child(2), table.comments-table td:nth-child(2) { width: 9rem; }
table.comments-table td:nth-child(3) { overflow-wrap: anywhere; }

.project-col { display: flex; flex-direction: column; gap: 1.25rem; min-width: 0; }

/* Project page on phones: keep the item description readable, and let the comments table scroll sideways instead of crushing the text. */
@media (max-width: 600px) {
    table.items th:nth-child(2), table.items td:nth-child(2) { width: 3.2rem; }
    table.items th:nth-child(3), table.items td:nth-child(3) { width: 6rem; }
    table.comments-table { table-layout: auto; min-width: 32rem; }
    table.comments-table th:nth-child(1), table.comments-table td:nth-child(1),
    table.comments-table th:nth-child(2), table.comments-table td:nth-child(2) { width: auto; }
}

.board-days { width: auto; flex-shrink: 0; margin: 0; }

/* ---------- Sort dialog with any number of sub-sorts ---------- */

.sort-levels { max-height: 52vh; overflow-y: auto; padding-right: 0.15rem; }
.sort-level label { margin-top: 0.7rem; }
.sort-row .sort-remove { margin: 0; flex: 0 0 auto; padding: 0.3rem 0.65rem; font-size: 1rem; line-height: 1; }
.sort-row .sort-x-space { flex: 0 0 2.4rem; }
.sort-add { margin: 0.9rem 0 0; }
.sort-add:disabled { opacity: 0.5; cursor: not-allowed; }
.sort-modal { max-width: 28rem; }

.board-activity { cursor: help; }

/* Payload tables on Integrations: long values (URLs, notes) wrap instead of stretching the table. */
table.kv-payload td:last-child { overflow-wrap: anywhere; }
table.kv-payload { table-layout: fixed; }
table.kv-payload th:first-child, table.kv-payload td:first-child { width: 17rem; }

/* ---------- Sync Log page spacing ---------- */

/* Run cards: the same column widths in every card so the headers line up, with the error taking the slack. */
table.log-table { table-layout: fixed; }
table.log-table th:nth-child(1), table.log-table td:nth-child(1) { width: 11.5rem; white-space: nowrap; }
table.log-table th:nth-child(2), table.log-table td:nth-child(2) { width: 8rem; }
table.log-table th:nth-child(3), table.log-table td:nth-child(3) { width: 6.5rem; }
table.log-table th:nth-child(4), table.log-table td:nth-child(4) { width: 7rem; }
table.log-table th:nth-child(5), table.log-table td:nth-child(5) { width: 5.5rem; }
table.log-table th:nth-child(7), table.log-table td:nth-child(7) { width: 6.5rem; text-align: right; }
table.log-table td.log-error { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); }
table.log-table td form { margin: 0; }
table.log-table td .small { margin-top: 0; }

/* Change cards: time and field stay narrow, the old and new values share the rest. */
table.changes-table { table-layout: fixed; }
table.changes-table th:nth-child(1), table.changes-table td:nth-child(1) { width: 11.5rem; white-space: nowrap; }
table.changes-table th:nth-child(2), table.changes-table td:nth-child(2) { width: 12rem; }
table.changes-table td.change-val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* "Changes since a date": a normal-width date box with its button beside it, not a full-width bar. */
.since-form { margin-bottom: 1rem; }
.since-form .search-row { justify-content: flex-start; }
.since-form .search-row input[type="date"] { flex: 0 0 auto; width: 12rem; }
.since-form p { margin: 0.4rem 0 0; }

/* Empty states inside cards shouldn't add a screen of padding. */
.card-collapsible-body .empty-state { padding: 0.9rem 0; }

/* Buttons and links placed in a search row line up with the field (a.btn carries the global top margin that buttons here don't). */
.search-row .btn, .search-row select { margin-top: 0; flex-shrink: 0; }
.search-row .btn { align-self: center; }

/* Narrow screens: keep the Sync Log tables readable by letting them scroll sideways instead of squeezing columns to nothing. */
@media (max-width: 900px) {
    table.log-table { min-width: 58rem; }
    table.changes-table { min-width: 40rem; }
}

/* Every control in a search row (field, days dropdown, Search, Clear) is exactly the same height. */
.search-row > input, .search-row > select, .search-row > button, .search-row > .btn {
    height: 2.5rem;
    box-sizing: border-box;
    padding-top: 0;
    padding-bottom: 0;
    line-height: 1.2;
}
.search-row > .btn { display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Light theme (the saved per-user choice sets data-theme on <html>; dark is the default) ---------- */

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #f3f4f8;
    --panel: #ffffff;
    --panel-alt: #eceef4;
    --text: #1b1e2b;
    --text-muted: #5d6479;
    --border: #d6d9e3;
    --accent: #5457e6;
    --accent-hover: #4144cc;
    --accent-soft: #e4e5fc;
    --success: #12875c;
    --success-soft: #d9f3e8;
    --warn: #a96a07;
    --warn-soft: #faecd0;
    --danger: #c93434;
    --danger-soft: #fae0e0;
    --pill-text: #ffffff;
    --pill-idle: #6b7188;
    --pill-info: #2f6fd6;
    --shadow: 0 1px 2px rgba(20, 24, 40, 0.08), 0 4px 10px rgba(20, 24, 40, 0.08);
}
/* The top bar stays dark in both themes so the white ATC and ATLAS logos remain readable. */

/* ---------- Theme toggle button (beside the menu button) ---------- */

.topbar-actions { display: flex; align-items: center; gap: 0.35rem; flex-shrink: 0; }
.theme-toggle {
    flex-shrink: 0; width: 34px; height: 34px; padding: 0; margin: 0;
    background: transparent; border: none; border-radius: 7px;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--sidebar-text-active); cursor: pointer;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.08); }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-moon { display: none; }                         /* dark mode shows a sun: click for light */
:root[data-theme="light"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: inline; } /* light mode shows a moon: click for dark */

/* ---------- Calendar ---------- */

.cal-card { padding: 1rem 1.1rem; }
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; margin-bottom: 0.9rem; }
.cal-nav { display: flex; gap: 0.35rem; }
.cal-nav button { margin: 0; }
.cal-title { margin: 0; font-size: 1.05rem; flex: 1; min-width: 12rem; }
.cal-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.cal-toggle button { margin: 0; border: 0; border-radius: 0; background: var(--panel-alt); color: var(--text-muted); }
.cal-toggle button + button { border-left: 1px solid var(--border); }
:root .cal-toggle button.secondary.is-active, :root .cal-toggle button.secondary.is-active:hover { background: var(--accent); color: #fff; }
.cal-note { margin: 0.8rem 0 0; font-size: 0.8rem; color: var(--text-muted); }

.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-dow { padding: 0.35rem 0.5rem; font-size: 0.72rem; font-weight: 600; color: var(--text-muted); background: var(--panel-alt); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-cell { min-height: 6.6rem; padding: 0.25rem 0.3rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.15rem; min-width: 0; }
.cal-cell.is-out { background: var(--panel-alt); opacity: 0.6; }
.cal-cell.is-today, .cal-weekcol.is-today { box-shadow: inset 0 0 0 2px var(--accent); }
.is-clickable { cursor: pointer; }
.cal-cell.is-clickable:hover, .cal-weekcol.is-clickable:hover, .cal-slot.is-clickable:hover, .cal-allday-list.is-clickable:hover { background: var(--panel-alt); }
.cal-daynum { font-size: 0.78rem; font-weight: 600; color: var(--text-muted); padding: 0 0.15rem; }
.cal-chip, .cal-more {
    display: block; width: 100%; margin: 0; padding: 0.12rem 0.4rem; text-align: left; justify-content: flex-start; border-radius: 5px; border: 0;
    font-size: 0.72rem; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    background: var(--accent-soft); color: var(--text); cursor: pointer;
}
.cal-chip:hover { filter: brightness(1.2); }
.cal-chip-time { font-weight: 700; }
.cal-chip-tech { font-weight: 700; color: var(--accent-hover); }
.cal-more { background: transparent; color: var(--text-muted); }
.cal-more:hover { background: var(--panel-alt); color: var(--text); }

.cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--border); border-left: 1px solid var(--border); }
.cal-weekcol { min-height: 20rem; padding: 0.3rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.cal-weekhead { margin: 0; padding: 0.2rem 0.3rem; text-align: left; background: transparent; color: var(--text); border: 0; font-size: 0.82rem; }
.cal-weekhead:hover { background: var(--panel-alt); }
.cal-weekhead span { color: var(--text-muted); }
.cal-card-entry, .cal-block {
    display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; gap: 0.05rem; margin: 0; padding: 0.3rem 0.45rem; text-align: left; font-size: 0.74rem; font-weight: 400;
    border-radius: 6px; border: 0; border-left: 3px solid var(--accent); background: var(--accent-soft); color: var(--text); cursor: pointer; overflow: hidden;
}
.cal-card-entry:hover, .cal-block:hover { filter: brightness(1.2); }
.cal-entry-time { font-weight: 700; }
.cal-entry-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-entry-sub { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.cal-day { border: 1px solid var(--border); }
.cal-allday { display: flex; border-bottom: 1px solid var(--border); min-height: 2.2rem; }
.cal-allday-list { flex: 1; padding: 0.25rem 0.4rem; display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.cal-allday-list .cal-chip { width: auto; max-width: 100%; }
.cal-hint { font-size: 0.74rem; color: var(--text-muted); }
.cal-hour-label { width: 5rem; flex: none; padding: 0.25rem 0.5rem; font-size: 0.72rem; color: var(--text-muted); }
.cal-grid { position: relative; }
.cal-row { position: absolute; left: 0; right: 0; display: flex; border-bottom: 1px solid var(--border); }
.cal-row:last-of-type { border-bottom: 0; }
.cal-slot { flex: 1; border-left: 1px solid var(--border); }
.cal-events { position: absolute; top: 0; bottom: 0; left: 5rem; right: 0; pointer-events: none; }
.cal-block { position: absolute; pointer-events: auto; }

.cal-modal { max-width: 26rem; }
.cal-modal input[type=date], .cal-modal input[type=time] {
    width: 100%; padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: 7px; font-size: 0.92rem;
    background: var(--panel-alt); color: var(--text); font-family: inherit;
}
.cal-modal input[readonly] { color: var(--text-muted); }
.cal-times { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }
.cal-times.is-off { opacity: 0.45; }
.cal-error { margin: 0.8rem 0 0; font-size: 0.82rem; color: var(--danger); }
.cal-detail { display: grid; grid-template-columns: 6rem 1fr; gap: 0.35rem 0.8rem; margin: 0.6rem 0 0; font-size: 0.88rem; }
.cal-detail dt { color: var(--text-muted); }
.cal-detail dd { margin: 0; }

@media (max-width: 720px) {
    .cal-cell { min-height: 4.4rem; }
    .cal-week { grid-template-columns: 1fr; }
    .cal-weekcol { min-height: 0; }
    .cal-hour-label { width: 3.6rem; }
    .cal-events { left: 3.6rem; }
}
.cal-form { margin-top: 0.8rem; }

/* ---------- Proposal notes (in the expanded row) ---------- */

.proposal-chat, .proposal-notes { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--border); max-width: 48rem; }
.pn-head { display: flex; align-items: center; gap: 0.8rem; margin-bottom: 0.4rem; }
.pn-head h4 { margin: 0; font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pn-head button { margin: 0; }
.pn-form { margin: 0.4rem 0 0.8rem; }
.pn-form textarea { width: 100%; resize: vertical; font-size: 0.85rem; }
.pn-actions { display: flex; justify-content: flex-end; gap: 0.4rem; margin-top: 0.4rem; }
.pn-actions button { margin: 0; }
.pn-error { margin: 0.4rem 0 0; font-size: 0.8rem; color: var(--danger); }
.pn-empty { margin: 0; font-size: 0.82rem; color: var(--text-muted); }
.pn-note { padding: 0.45rem 0; border-bottom: 1px solid var(--border); }
.pn-note:last-child { border-bottom: 0; }
.pn-meta { font-size: 0.75rem; color: var(--text-muted); }
.pn-meta strong { color: var(--text); }
.pn-text { margin-top: 0.15rem; font-size: 0.85rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.pn-delete { margin: 0 0 0 0.4rem; padding: 0 0.35rem; font-size: 0.72rem; background: transparent; border: 0; color: var(--text-muted); text-decoration: underline; cursor: pointer; }
.pn-delete:hover { background: transparent; color: var(--danger); }

/* ---------- Sort dialog: custom tag order ---------- */
.sort-order { margin: 0.4rem 0 0.2rem; }
.sort-order .sort-mode { width: 100%; }
.sort-dir-fixed { flex: 1; align-self: center; font-size: 0.85rem; color: var(--text-muted); padding: 0 0.4rem; }
.sort-tags { list-style: none; margin: 0.5rem 0 0; padding: 0; max-height: 14rem; overflow-y: auto; border: 1px solid var(--border); border-radius: 7px; counter-reset: tag; }
.sort-tags li { display: flex; align-items: center; gap: 0.35rem; padding: 0.25rem 0.5rem; border-bottom: 1px solid var(--border); counter-increment: tag; font-size: 0.85rem; }
.sort-tags li:last-child { border-bottom: 0; }
.sort-tags li::before { content: counter(tag) "."; width: 1.5rem; color: var(--text-muted); font-size: 0.75rem; }
.sort-tag-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sort-tags button { margin: 0; padding: 0.15rem 0.5rem; font-size: 0.72rem; }
.sort-tags-note { margin: 0.35rem 0 0; font-size: 0.75rem; color: var(--text-muted); }

/* ---------- Sync Log: Errors section ---------- */
.errors-heading { margin: 1rem 0 0.4rem; font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.errors-heading:first-child { margin-top: 0; }
.pn-projectnotes { margin-bottom: 1rem; max-height: 14rem; overflow-y: auto; }
