:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface-hover: #1f2630;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #2f81f7;
    --green: #3fb950;
    --orange: #d29922;
    --red: #f85149;
    --purple: #a371f7;
    --pink: #db61a2;
}

* { box-sizing: border-box; }

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

.container {
    max-width: 1500px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 2rem;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
}

h1 .repo {
    color: var(--text-muted);
    font-weight: 400;
}

.controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

button {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
}

button:hover { background: var(--surface-hover); }

/* Buttons that pair a leading icon with their label. */
.icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.icon-btn svg { width: 14px; height: 14px; display: block; }

/* Vertical rule separating the filter toggles from the action buttons. */
.controls-divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 0.4rem;
}

/* Filter toggles — accent-highlighted when active. */
.filter-btn.active {
    background: rgba(47, 129, 247, 0.15);
    color: var(--accent);
    border-color: var(--accent);
}

input[type="password"], input[type="text"], input[type="number"] {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

input:focus { outline: none; border-color: var(--accent); }

.config-body { padding: 0.5rem 0; }

.config-section {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.config-section:last-child { border-bottom: none; }

.config-section label {
    display: block;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.45rem;
    font-size: 0.85rem;
}

.config-section input[type="password"],
.config-section input[type="number"] {
    width: 100%;
    box-sizing: border-box;
}

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

.config-row input[type="number"] { width: 110px; }
.config-suffix { color: var(--text-muted); font-size: 0.85rem; }

.config-help {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0.55rem 0 0;
    line-height: 1.45;
}

.config-help a { color: var(--accent); }

.config-dialog-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.config-saved {
    color: var(--green);
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.config-saved.show { opacity: 1; }

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    padding: 0.45rem 1.1rem;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.85rem;
}

.btn-primary:hover { filter: brightness(1.1); }

.token-status {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin: 0.55rem 0 0;
}

.token-status.ok { color: var(--green); }

dialog#config-dialog {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0;
    max-width: 640px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

dialog#config-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.config-dialog-form { margin: 0; }

.config-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.config-dialog-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

#config-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 0.4rem;
    cursor: pointer;
}

#config-close:hover { color: var(--text); background: var(--surface-hover); border-radius: 4px; }

.group {
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    /* Keep overflow visible so the pipeline hover popover can escape sideways. */
    background: var(--surface);
}

.group-header { border-radius: 7px 7px 0 0; }

.group-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: var(--surface-hover);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
}

.group-header:hover { background: #232a35; }

.group-prefix {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.85rem;
}


.section-ready-for-merge .group-prefix { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.section-ready-for-review .group-prefix { background: rgba(47, 129, 247, 0.15); color: var(--accent); }
.section-running .group-prefix { background: rgba(210, 153, 34, 0.15); color: var(--orange); }
.section-stuck .group-prefix { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.section-conflicts .group-prefix { background: rgba(219, 97, 162, 0.15); color: var(--pink); }
.section-in-development .group-prefix { background: rgba(139, 148, 158, 0.15); color: var(--text-muted); }
.section-stale .group-prefix { background: rgba(163, 113, 247, 0.15); color: var(--purple); }

.repo-tag {
    display: inline-block;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.7rem;
    padding: 0.05rem 0;
    border-radius: 3px;
    margin-right: 0.5rem;
    vertical-align: 1px;
    width: 44px;
    text-align: center;
}

.repo-accent { background: rgba(47, 129, 247, 0.15); color: var(--accent); }
.repo-purple { background: rgba(163, 113, 247, 0.15); color: var(--purple); }
.repo-green { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.repo-orange { background: rgba(210, 153, 34, 0.15); color: var(--orange); }
.repo-pink { background: rgba(219, 97, 162, 0.15); color: var(--pink); }

.group-count {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-left: auto;
}

.chevron {
    transition: transform 0.15s ease;
    color: var(--text-muted);
}

.group.collapsed .chevron { transform: rotate(-90deg); }
.group.collapsed .pr-table { display: none; }

.pr-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.875rem;
}

/* All tables share the same column widths so the Title column starts and ends at the
   same x-coordinate in every group. */
col.w-number { width: 50px; }
col.w-author { width: 200px; }
col.w-approvals { width: 120px; }
col.w-pipeline { width: 110px; }
col.w-actions { width: 90px; }

.pr-table thead th {
    background: var(--surface);
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.pr-table tbody tr {
    border-bottom: 1px solid var(--border);
}

.pr-table tbody tr:last-child { border-bottom: none; }
.pr-table tbody tr:hover { background: var(--surface-hover); }

/* PRs that include a commit by the authenticated viewer get a green left accent so you can
   spot your own work at a glance. */
.pr-table tbody tr.pr-mine td:first-child {
    box-shadow: inset 3px 0 0 var(--green);
}

.pr-table td {
    padding: 0.6rem 0.75rem;
    vertical-align: middle;
    white-space: nowrap;
}

.col-number {
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
}

.col-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-title .pr-title { vertical-align: baseline; }

.pr-title {
    color: var(--text);
    text-decoration: none;
    font-weight: 500;
    word-break: break-word;
}

.pr-title:hover { color: var(--accent); text-decoration: underline; }

.pr-age {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

.col-author-cell {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.col-ci { text-align: center; }
.empty-cell { color: var(--text-muted); font-size: 0.85rem; }


/* Pipeline summary: dot + "X/Y" counter, color from rollup state. */
.pipeline-summary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.pipeline-summary .ci-dot { width: 10px; height: 10px; flex-shrink: 0; }

/* Pipeline hover popover — lists each check with its dot, name, and duration. */
.pipeline-cell {
    position: relative;
    display: inline-block;
    cursor: default;
}
.pipeline-popover {
    position: absolute;
    right: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    background: #0b0f15;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    z-index: 50;
    min-width: 320px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease;
}
.pipeline-cell:hover .pipeline-popover { opacity: 1; }

.popover-row {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: 0.6rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
}
.popover-row .ci-dot { width: 9px; height: 9px; box-shadow: none; }
.popover-row .check-name {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.popover-row .check-time {
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
}

/* Actions cell — two compact buttons that always appear in the same place. */
.col-actions {
    display: flex;
    gap: 0.3rem;
    justify-content: flex-end;
}
.row-btn {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.row-btn svg { width: 14px; height: 14px; display: block; }
.row-btn:hover { background: var(--surface-hover); color: var(--text); }
.row-btn.copied { background: rgba(63, 185, 80, 0.15); color: var(--green); border-color: var(--green); }

.badge {
    padding: 0.1rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-draft { background: rgba(139, 148, 158, 0.2); color: var(--text-muted); }

.author-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    vertical-align: middle;
}

.approvals {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--green);
}

.approvals-avatars {
    display: inline-flex;
}

.approval-avatar {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--green);
    margin-left: -6px;
    background: var(--surface);
}

.approval-avatar:first-child { margin-left: 0; }

.approvals-check {
    font-size: 0.85rem;
    line-height: 1;
}

.approvals-incomplete {
    color: var(--text-muted);
}

.approvals-incomplete .approval-avatar {
    border-color: var(--text-muted);
}

.comment-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    color: var(--text-muted);
    margin-left: 0.4rem;
    font-size: 0.7rem;
    vertical-align: middle;
}

.comment-badge svg {
    vertical-align: middle;
}

.comment-count {
    font-weight: 600;
    line-height: 1;
}

.ci-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    vertical-align: middle;
}

.ci-success { background: var(--green); box-shadow: 0 0 0 2px rgba(63, 185, 80, 0.2); }
.ci-failure { background: var(--red); box-shadow: 0 0 0 2px rgba(248, 81, 73, 0.2); }
.ci-pending { background: var(--orange); box-shadow: 0 0 0 2px rgba(210, 153, 34, 0.2); }
.ci-none, .ci-skipped { background: var(--border); }

.ci-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.merge-button {
    display: inline-block;
    background: var(--green);
    color: #0d1117;
    font-weight: 600;
    padding: 0.15rem 0.6rem;
    border-radius: 4px;
    text-decoration: none;
    font-size: 0.75rem;
    white-space: nowrap;
}

.merge-button:hover { filter: brightness(1.1); }

.state {
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
}

.state.error {
    color: var(--red);
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    border-radius: 8px;
}

.footer {
    margin-top: 2rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
}
