/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161922;
    --bg-tertiary: #1e2130;
    --bg-hover: #252836;
    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #2a2d37;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-on-accent: #ffffff;
    --navbar-height: 48px;
    --navbar-control-height: 36px;
    --navbar-control-radius: 8px;
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 64px;
    /* Shared frame for the New Chat composer and its upgrade notice. */
    --design-home-content-width: min(760px, 100%);
    --design-home-content-gutter: 24px;
    --transition-speed: 200ms;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f4f4f5;
    --bg-tertiary: #e4e4e7;
    --bg-hover: #d4d4d8;
    --text-primary: #18181b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --border: #d4d4d8;
    --success: #16a34a;
    --warning: #d97706;
    --danger: #dc2626;
    --text-on-accent: #ffffff;
}

[data-theme="light"] .project-card,
[data-theme="light"] .stat-card,
[data-theme="light"] .channel-card,
[data-theme="light"] .wizard-step-content,
[data-theme="light"] .deliverable-card {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .dropup-menu {
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .chat-bubble.ai {
    background: var(--bg-secondary);
}

[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: var(--border);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Light-mode chip/badge/tag/state contrast.
   The status colours throughout the app are bright pastels tuned for a dark
   translucent chip; on the near-white light card the same text on a faint tint
   falls below WCAG. Override every tinted-background label to a deeper 700-level
   shade of the same hue (grouped by colour). Plain links / menu items / borders
   are intentionally excluded - those are a separate concern, not tinted chips.
 */
[data-theme="light"] .status-dev,
[data-theme="light"] .status-released,
[data-theme="light"] .issue-status.done,
[data-theme="light"] .role-badge-tag.owner,
[data-theme="light"] .plan-badge.growth,
[data-theme="light"] .docs-cat-tag.getting-started,
[data-theme="light"] .chat-badge.active,
[data-theme="light"] .btn-deploy.ready,
[data-theme="light"] .usage-range-chip.active,
[data-theme="light"] .plan-card-status.current {
    color: #1d4ed8; /* blue-700 */
}

[data-theme="light"] .issue-status.open,
[data-theme="light"] .role-badge-tag.member,
[data-theme="light"] .docs-cat-tag.team,
[data-theme="light"] .chat-badge.success,
[data-theme="light"] .project-status-bar.completed,
[data-theme="light"] .domain-state.ready,
[data-theme="light"] .invite-feedback.success,
[data-theme="light"] .credit-status.ok,
[data-theme="light"] .upgrade-plan-badge.active,
[data-theme="light"] .invoice-status.paid,
[data-theme="light"] .doc-stage.done,
[data-theme="light"] .settings-sec-status.enabled,
[data-theme="light"] .settings-gh-status.connected,
[data-theme="light"] .playground-preview-pill.public {
    color: #15803d; /* green-700 */
}

[data-theme="light"] .status-analyzing,
[data-theme="light"] .docs-cat-tag.billing,
[data-theme="light"] .credit-status.low,
[data-theme="light"] .invoice-status.due,
[data-theme="light"] .spend-alert,
[data-theme="light"] .new-repo-banner,
[data-theme="light"] .new-repo-banner-link {
    color: #b45309; /* amber-700 */
}

/* Every non-terminal issue stage uses the same calm green treatment. */
[data-theme="light"] .issue-status.working,
[data-theme="light"] .issue-status.open,
[data-theme="light"] .issue-status.todo,
[data-theme="light"] .status-dev,
[data-theme="light"] .status-todo {
    color: #15803d; /* green-700 */
}

[data-theme="light"] .issue-status.queued {
    color: #475569; /* slate-700 */
}

[data-theme="light"] .new-repo-banner-link:hover {
    color: #92400e; /* amber-800 */
}

[data-theme="light"] .role-badge-tag.admin,
[data-theme="light"] .plan-badge.enterprise,
[data-theme="light"] .docs-cat-tag.projects {
    color: #7e22ce; /* purple-700 */
}

[data-theme="light"] .credit-status.critical {
    color: #c2410c; /* orange-700 */
}

[data-theme="light"] .domain-state.failed,
[data-theme="light"] .invite-feedback.error,
[data-theme="light"] .credit-status.empty,
[data-theme="light"] .issue-status.failed {
    color: #b91c1c; /* red-700 */
}

[data-theme="light"] .domain-state.pending {
    color: #854d0e; /* yellow-800 -> yellow-700 #a16207 was only 4.48:1, just under 4.5 */
}

[data-theme="light"] .docs-cat-tag.api {
    color: #be185d; /* pink-700 */
}

[data-theme="light"] .docs-cat-tag.integrations {
    color: #0e7490; /* cyan-700 */
}

[data-theme="light"] .status-todo {
    color: #52525b; /* zinc-600 */
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font-family: inherit;
    font-size: 14px;
}

button {
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
}

small {
    font-size: 14px;
}

.pwa-install-banner {
    position: fixed;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    bottom: max(78px, calc(70px + env(safe-area-inset-bottom)));
    z-index: 500;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.3);
}

.pwa-install-copy {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.pwa-install-copy strong {
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.2;
}

.pwa-install-copy span {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.35;
}

.pwa-install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.pwa-install-primary {
    min-height: 34px;
    padding: 0 12px;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
}

.pwa-install-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: var(--text-muted);
}

.pwa-install-close:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .pwa-install-banner {
        display: flex;
    }
}

@media (display-mode: standalone) {
    .pwa-install-banner {
        display: none;
    }
}

/* --- App Shell --- */
/* Row chrome: full-height sidebar + content column (topbar is not full-bleed). */
.app {
    display: flex;
    flex-direction: row;
    height: 100vh;
    overflow: hidden;
}

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

/* --- Main Content --- */
.main-content {
    position: relative;
    flex: 1;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 24px 32px;
    background: var(--bg-primary);
}

@media (max-width: 768px) {
    html,
    body,
    .app {
        min-height: 100dvh;
    }

    .app {
        height: 100dvh;
    }

    .app {
        flex-direction: column;
    }

    .navbar {
        padding: 0 max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
        gap: 8px;
    }

    .navbar-logo,
    .navbar-logo-mobile {
        display: flex;
    }

    .navbar-mode-switcher {
        display: none;
    }

    .navbar-mode-compact {
        display: inline-flex;
    }

    .navbar-cmd {
        width: var(--navbar-control-height);
        height: var(--navbar-control-height);
        padding: 0;
        justify-content: center;
    }

    .navbar-cmd-label,
    .navbar-cmd .navbar-cmd-kbd {
        display: none;
    }

    .credit-navbar-badge span {
        display: none;
    }

    .credit-summary-popover {
        position: fixed;
        top: auto;
        right: max(10px, env(safe-area-inset-right));
        bottom: calc(74px + env(safe-area-inset-bottom));
        left: max(10px, env(safe-area-inset-left));
        width: auto;
        max-height: min(72dvh, 560px);
        overflow-y: auto;
        border-radius: 14px;
        z-index: 190;
    }

    .credit-popover-backdrop {
        z-index: 180;
        background: rgba(0, 0, 0, 0.42);
    }

    .navbar-avatar .role-badge {
        display: none;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        padding: 16px max(14px, env(safe-area-inset-right)) calc(82px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
    }

    .mobile-bottom-nav {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 120;
        display: flex;
        min-height: calc(64px + env(safe-area-inset-bottom));
        padding: 6px max(8px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
    }

    /* mobile notification sheet */
    .notif-backdrop {
        z-index: 180;
        background: rgba(0, 0, 0, 0.42);
    }

    .notif-dropdown {
        position: fixed;
        left: max(10px, env(safe-area-inset-left));
        right: max(10px, env(safe-area-inset-right));
        bottom: calc(74px + env(safe-area-inset-bottom));
        top: auto;
        width: auto;
        max-height: min(72dvh, 560px);
        border-radius: 14px;
        z-index: 190;
    }

    .notif-header {
        padding: 13px 14px;
    }

    .notif-item {
        padding: 13px 14px;
    }

    .mobile-project-detail {
        height: calc(100dvh - var(--navbar-height) - 82px);
        min-height: 0;
        padding-bottom: 0;
    }

    .mobile-project-header {
        margin-bottom: 10px;
        padding-bottom: 12px;
    }

    .mobile-project-tabs {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        gap: 4px;
        padding: 3px;
        margin-bottom: 10px;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: 10px;
        flex-shrink: 0;
    }

    .mobile-project-tab {
        min-height: 36px;
        border-radius: 8px;
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 700;
    }

    .mobile-project-tab.active {
        background: var(--bg-tertiary);
        color: var(--text-primary);
    }

    .mobile-project-body {
        display: flex;
        flex: 1;
        min-height: 0;
        flex-direction: column;
    }

    .mobile-project-body .right-panel {
        flex: 1;
        min-height: 0;
        min-width: 0;
    }

    /* Keep chat composer inside the panel above the bottom nav (panel height
       already accounts for nav; do not pin input over fixed chrome). */
    .mobile-project-body .project-chat-panel {
        display: flex;
        flex-direction: column;
        min-width: 0;
        min-height: 0;
    }

    .mobile-project-body .project-chat-panel .chat-input-area {
        margin-bottom: 10px;
        flex-shrink: 0;
    }

    .mobile-project-panel {
        flex: 1;
        min-height: 0;
        min-width: 0;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }

    .mobile-work-panel,
    .mobile-lite-work-panel,
    .mobile-info-panel {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .mobile-lite-work-panel {
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: 8px;
    }

    .mobile-work-card {
        display: flex;
        flex-shrink: 0;
        flex-direction: column;
        gap: 8px;
        padding: 12px;
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: 10px;
    }

    .mobile-deployment-action {
        width: 100%;
        justify-content: center;
    }

    .mobile-work-label {
        color: var(--text-muted);
        font-size: 14px;
        font-weight: 800;
        text-transform: uppercase;
        letter-spacing: 0;
    }

    .mobile-work-value {
        color: var(--text-primary);
        font-size: 14px;
        font-weight: 700;
        text-transform: capitalize;
    }

    .mobile-work-list {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .mobile-work-list.long {
        max-height: min(42dvh, 360px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-right: 2px;
    }

    .mobile-work-load-more {
        justify-content: center;
        width: 100%;
    }

    .mobile-work-row {
        display: flex;
        justify-content: space-between;
        gap: 10px;
        color: var(--text-secondary);
        font-size: 14px;
        min-width: 0;
    }

    .mobile-work-row span:first-child {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-work-muted {
        color: var(--text-muted);
        flex-shrink: 0;
    }

    .mobile-danger-zone {
        margin-top: 8px;
        border-color: rgba(239, 68, 68, 0.35);
    }
}

/* --- Page Stubs --- */
.page-header {
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.page-header p {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 14px;
}

.page-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 14px;
}

/* --- Buttons (shared) --- */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    transition: background var(--transition-speed);
}

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

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-primary.btn-sm {
    height: 30px;
    padding: 0 12px;
    font-size: 14px;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    white-space: nowrap;
    transition: background var(--transition-speed), border-color var(--transition-speed);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-success {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 16px;
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
}

/* Shared deployment action button. */
.btn-deploy {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    background: rgba(113, 113, 122, 0.15);
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    transition: background var(--transition-speed), color var(--transition-speed);
}

.btn-deploy:hover {
    background: rgba(113, 113, 122, 0.25);
}

.btn-deploy:disabled {
    cursor: not-allowed;
    opacity: 1;
}

.btn-deploy.ready {
    background: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

.btn-deploy.ready:hover {
    background: rgba(59, 130, 246, 0.25);
}

.btn-deploy.released {
    cursor: default;
    opacity: 1;
    background: rgba(34, 197, 94, 0.15);
    border-color: rgba(34, 197, 94, 0.3);
    color: var(--success);
}

.deploy-pending-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--warning, #f59e0b);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.18);
}

.deploy-action-error {
    max-width: 260px;
}

.btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 36px;
    padding: 0 16px;
    color: var(--text-muted);
    border-radius: 8px;
    font-weight: 500;
    font-size: 14px;
    transition: background var(--transition-speed), color var(--transition-speed);
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* --- Progress Bar --- */
.progress-bar {
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    flex: 1;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* --- Invite Modal --- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 440px;
    max-width: 92vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}


.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 0;
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.modal-body {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}


.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

.subscription-upgrade-notice {
    position: absolute;
    top: 24px;
    left: 50%;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    width: calc(var(--design-home-content-width) - var(--design-home-content-gutter) - var(--design-home-content-gutter));
    margin: 0;
    padding: 12px 14px;
    transform: translateX(-50%);
    background: color-mix(in srgb, var(--warning) 10%, var(--bg-secondary));
    border: 1px solid color-mix(in srgb, var(--warning) 30%, transparent);
    border-radius: 10px;
}

.subscription-upgrade-notice-copy,
.subscription-upgrade-notice-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.subscription-upgrade-notice-copy > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.subscription-upgrade-notice-copy strong {
    color: var(--text-primary);
    font-size: 14px;
}

.subscription-upgrade-notice-copy span:not(.subscription-upgrade-notice-icon) {
    color: var(--text-muted);
    font-size: 14px;
}

.subscription-upgrade-notice .btn-sm,
.subscription-upgrade-notice-close {
    font-size: 14px;
}

.subscription-upgrade-notice-icon {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 14%, transparent);
    border-radius: 8px;
    font-weight: 800;
}

.subscription-upgrade-notice-close {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    color: var(--text-muted);
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

.subscription-upgrade-notice-close:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.credited-free-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 16px;
    padding: 12px 14px;
    background: color-mix(in srgb, var(--accent) 10%, var(--bg-secondary));
    border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
    border-radius: 10px;
}

.credited-free-notice > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.credited-free-notice strong {
    color: var(--text-primary);
    font-size: 14px;
}

.credited-free-notice span {
    color: var(--text-muted);
    font-size: 14px;
}

.design-workspace > .credited-free-notice {
    margin: 12px 16px 0;
}

@media (max-width: 700px) {
    .subscription-upgrade-notice {
        top: 12px;
        align-items: flex-start;
    }

    .subscription-upgrade-notice-copy span:not(.subscription-upgrade-notice-icon) {
        display: none;
    }

    .credited-free-notice {
        align-items: flex-start;
        flex-direction: column;
    }
    .credited-free-notice .btn-sm {
        align-self: flex-end;
    }
}

/* --- Form Controls --- */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
}

.form-input {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-input::placeholder {
    color: var(--text-muted);
}

.form-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Secondary Button --- */

.btn-secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

