:root {
    --bg: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --border: #30363d;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --yellow: #d29922;
    --radius: 6px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

header h1 {
    font-size: 20px;
    font-weight: 600;
}

header .subtitle {
    font-size: 14px;
    color: var(--text-muted);
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

/* Form */
#input-section {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
}

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group-wide {
    flex: 1;
}

label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
}

label .hint {
    font-weight: 400;
    color: var(--text-muted);
}

input, select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 12px;
    font-size: 14px;
    outline: none;
}

input:focus, select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.15);
}

.form-actions {
    display: flex;
    gap: 12px;
}

button {
    padding: 8px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

#view-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

#view-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

#share-btn {
    background: var(--bg-tertiary);
    color: var(--text);
}

#share-btn:hover {
    border-color: var(--text-muted);
}

/* Loading */
#loading {
    text-align: center;
    padding: 48px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error */
.error-box {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    padding: 12px 16px;
    color: var(--red);
    font-size: 14px;
}

/* Stack navigation */
#stack-nav {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 8px 0;
    margin-bottom: 16px;
}

.stack-tab {
    flex-shrink: 0;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.stack-tab:hover {
    border-color: var(--text-muted);
    color: var(--text);
}

.stack-tab.active {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    color: var(--text);
}

.stack-tab .tab-title {
    font-weight: 500;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stack-tab .tab-badge {
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 500;
}

.badge-approved { background: rgba(63, 185, 80, 0.2); color: var(--green); }
.badge-changes { background: rgba(248, 81, 73, 0.2); color: var(--red); }
.badge-pending { background: rgba(210, 153, 34, 0.2); color: var(--yellow); }
.badge-open { background: rgba(63, 185, 80, 0.15); color: var(--green); }
.badge-merged { background: rgba(163, 113, 247, 0.2); color: #a371f7; }
.badge-closed { background: rgba(248, 81, 73, 0.15); color: var(--red); }

/* PR header */
#pr-header {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 12px;
}

#pr-header h2 {
    font-size: 18px;
    margin-bottom: 4px;
}

#pr-header a {
    color: var(--accent);
    text-decoration: none;
}

#pr-header a:hover {
    text-decoration: underline;
}

.pr-meta {
    font-size: 13px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 8px;
}

.pr-meta .stat-add { color: var(--green); }
.pr-meta .stat-del { color: var(--red); }

.incremental-label {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
    margin-top: 8px;
    display: inline-block;
}

/* Diff controls */
.diff-controls {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}

.diff-mode {
    padding: 4px 12px;
    font-size: 12px;
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.diff-mode.active {
    background: var(--bg-tertiary);
    color: var(--text);
    border-color: var(--accent);
}

/* Reviews */
#reviews-section {
    margin-bottom: 12px;
}

.review-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    margin-right: 8px;
    margin-bottom: 4px;
}

.review-author { font-weight: 500; }

/* Checks */
#checks-section {
    margin-bottom: 12px;
}

.check-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 8px;
}

.check-icon { font-size: 14px; }
.check-pass .check-icon { color: var(--green); }
.check-fail .check-icon { color: var(--red); }
.check-pending .check-icon { color: var(--yellow); }

/* Diff container overrides for dark theme */
#diff-container {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Override diff2html for dark mode */
.d2h-wrapper {
    background: var(--bg-secondary) !important;
}

.d2h-file-header {
    background: var(--bg-tertiary) !important;
    border-bottom: 1px solid var(--border) !important;
}

.d2h-file-name {
    color: var(--text) !important;
}

.d2h-tag {
    background: var(--bg) !important;
    border-color: var(--border) !important;
    color: var(--text-muted) !important;
}

/* Inline commenting */
.commentable {
    cursor: pointer;
    position: relative;
}

.commentable:hover {
    background: rgba(88, 166, 255, 0.1) !important;
}

.commentable:hover::before {
    content: "+";
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent);
    font-weight: 700;
    font-size: 14px;
}

.comment-form-cell {
    padding: 0 !important;
}

.comment-form {
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    margin: 4px 8px;
    padding: 12px;
}

.comment-form-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 12px;
}

.comment-file {
    color: var(--text-muted);
    font-family: monospace;
}

.comment-warning {
    color: var(--yellow);
    font-size: 11px;
}

.comment-textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.comment-textarea:focus {
    border-color: var(--accent);
}

.comment-form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.comment-cancel {
    padding: 4px 12px;
    font-size: 12px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.comment-submit {
    padding: 4px 12px;
    font-size: 12px;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.comment-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.comment-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 6px;
}

.posted-comment-cell {
    padding: 0 !important;
}

.posted-comment {
    background: var(--bg-secondary);
    border-left: 3px solid var(--accent);
    margin: 4px 8px;
    padding: 8px 12px;
    font-size: 13px;
}

.comment-author {
    font-weight: 600;
    color: var(--accent);
}

.comment-body {
    color: var(--text);
}

/* Review actions */
.review-actions {
    margin-top: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.review-body-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 8px;
}

.review-body-input:focus {
    border-color: var(--accent);
}

.review-action-buttons {
    display: flex;
    gap: 8px;
}

.review-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: opacity 0.15s;
}

.review-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.review-approve {
    background: rgba(63, 185, 80, 0.15);
    color: var(--green);
    border-color: var(--green);
}

.review-approve:hover:not(:disabled) {
    background: rgba(63, 185, 80, 0.25);
}

.review-request-changes {
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
    border-color: var(--red);
}

.review-request-changes:hover:not(:disabled) {
    background: rgba(248, 81, 73, 0.25);
}

.review-comment-only {
    background: var(--bg-secondary);
    color: var(--text);
}

.review-comment-only:hover:not(:disabled) {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

.review-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 6px;
}

/* Merge PR */
.merge-actions {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.merge-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.merge-method-select {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px 10px;
    font-size: 13px;
    outline: none;
}

.merge-method-select:focus {
    border-color: var(--accent);
}

.merge-btn {
    padding: 6px 20px;
    font-size: 13px;
    font-weight: 500;
    border-radius: var(--radius);
    border: 1px solid #a371f7;
    background: rgba(163, 113, 247, 0.15);
    color: #a371f7;
    cursor: pointer;
    transition: background 0.15s;
}

.merge-btn:hover:not(:disabled) {
    background: rgba(163, 113, 247, 0.25);
}

.merge-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.merge-success {
    color: var(--green);
    font-size: 13px;
    font-weight: 500;
}

.merge-error {
    margin-top: 8px;
    padding: 10px 12px;
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid var(--red);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
}

.merge-error strong {
    color: var(--red);
}

.merge-error a {
    color: var(--accent);
    text-decoration: none;
    margin-top: 4px;
    display: inline-block;
}

.merge-error a:hover {
    text-decoration: underline;
}

.merge-stack-btn {
    background: transparent;
    border-style: dashed;
}

.merge-stack-btn:hover:not(:disabled) {
    background: rgba(163, 113, 247, 0.1);
}

.merge-closed {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.delete-branch-btn {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--red);
    border-radius: var(--radius);
    background: rgba(248, 81, 73, 0.15);
    color: var(--red);
    cursor: pointer;
    transition: background 0.15s;
}

.delete-branch-btn:hover:not(:disabled) {
    background: rgba(248, 81, 73, 0.25);
}

.delete-branch-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.delete-branches-btn {
    background: transparent;
    border-style: dashed;
}

.delete-branches-btn:hover:not(:disabled) {
    background: rgba(248, 81, 73, 0.1);
}

.delete-success {
    color: var(--green);
    font-size: 13px;
    font-weight: 500;
}

/* PR body / description */
.pr-body {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.pr-body-text {
    font-size: 14px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;
}

.edit-pr-btn {
    padding: 4px 10px;
    font-size: 12px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    margin-bottom: 8px;
}

.edit-pr-btn:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.pr-edit-textarea {
    width: 100%;
    min-height: 120px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 8px;
}

.pr-edit-textarea:focus {
    border-color: var(--accent);
}

.pr-edit-actions {
    display: flex;
    gap: 8px;
}

.pr-edit-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 6px;
}

/* Issue comments / PR-level discussion */
#issue-comments-section {
    margin-bottom: 12px;
}

.issue-comments {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

.issue-comment {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 10px 12px;
    margin-bottom: 8px;
}

.issue-comment:last-of-type {
    margin-bottom: 12px;
}

.issue-comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 13px;
}

.issue-comment-header .comment-author {
    font-weight: 600;
    color: var(--accent);
}

.comment-time {
    color: var(--text-muted);
    font-size: 12px;
}

.issue-comment-body {
    font-size: 13px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.no-comments {
    color: var(--text-muted);
    font-size: 13px;
    font-style: italic;
    margin-bottom: 12px;
}

.issue-comment-form {
    border-top: 1px solid var(--border);
    padding-top: 12px;
}

.issue-comment-form textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 8px;
}

.issue-comment-form textarea:focus {
    border-color: var(--accent);
}

.issue-comment-form button {
    padding: 6px 16px;
    font-size: 13px;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    border-radius: var(--radius);
}

.issue-comment-form button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.issue-comment-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 6px;
}

/* Inline comment threads */
.comment-thread-cell {
    padding: 0 !important;
    background: var(--bg-secondary) !important;
}

.comment-thread {
    margin: 4px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.comment-entry {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.comment-entry:last-of-type {
    border-bottom: none;
}

.comment-entry-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.comment-entry-body {
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
}

.comment-reply-form {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-tertiary);
}

.comment-reply-form textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 6px 8px;
    font-size: 12px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 6px;
}

.comment-reply-form textarea:focus {
    border-color: var(--accent);
}

.reply-submit {
    padding: 4px 12px;
    font-size: 12px;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    border-radius: var(--radius);
}

.reply-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.reply-error {
    color: var(--red);
    font-size: 12px;
    margin-top: 4px;
}

/* Orphaned comments */
.orphaned-comments {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-bottom: 8px;
}

.orphaned-label {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    margin-bottom: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    main {
        padding: 12px;
    }

    .form-row {
        flex-direction: column;
    }

    #stack-nav {
        flex-wrap: nowrap;
    }

    .stack-tab .tab-title {
        max-width: 120px;
    }
}
