/* ==========================================
   FOUNDER OS - GLOBAL DESIGN SYSTEM
   Inspiration: Linear.app & Mercury.com
========================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Roboto+Mono:wght@400;500&display=swap');

/* Balgin (Studio Sun) — add licensed .woff2 files in assets/fonts/ (extra-light for wordmark; bold optional) */
@font-face {
    font-family: 'Balgin';
    src: local('Balgin Display Extra Light'),
        local('Balgin Display Light'),
        local('Balgin Extra Light'),
        local('Balgin Light'),
        url('assets/fonts/balgin-extra-light.woff2') format('woff2');
    font-weight: 200;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Balgin';
    src: local('Balgin Display Bold'),
        local('Balgin Bold'),
        url('assets/fonts/balgin-display.woff2') format('woff2');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

:root,
[data-theme="dark"] {
    /* --- 1. Color Palette --- */
    --bg-dark: #0A0A0A;
    --bg-surface: #1A1A1A;
    --border-subtle: #2A2A2A;
    --surface-hover: #242424;
    --border-hover: #3A3A3A;
    --bg-elevated: #141414;
    --row-hover: #222222;
    --bg-row-muted: #111111;

    /* Text */
    --text-primary: #EDEDED;
    --text-muted: #888888;
    
    /* The 'Traffic Lights' & Quentl brand (logo palette) */
    --runway-green: #2ECC71;
    --warning-yellow: #F1C40F;
    --death-red: #E74C3C;
    --brand-brown: #3B1908;
    --accent-orange: #A14B14; /* Burnt orange — primary buttons & accents */
    --accent-orange-hover: #C46328; /* Lighter on hover */
    --accent-indigo: #A14B14; /* Alias: charts & tab accents match brand orange */
    /* Readable on #0A0A0A — #140004 alone is effectively invisible on this background */
    --logo-wordmark-color: #A14004;
    --logo-wordmark-color-hover: #E8A05D;

    --text-runway-answer: 3.75rem; /* text-6xl — #runway-text */
    --logo-wordmark-size: clamp(2.35rem, 6.25vw, 3.75rem);
    --logo-wordmark-weight: 200;
    --logo-wordmark-tracking: -0.087em; /* tracking -87 (thousandths of em) */
    --logo-wordmark-stretch: expanded;

    /* Semantic surfaces (tables, status chips) */
    --status-good-bg: #1a2b22;
    --status-good-hover: #20362b;
    --status-bad-bg: #3a1c1c;

    /* Charts (read via getComputedStyle in analytics) */
    --chart-muted: #888888;
    --chart-grid: #2A2A2A;
    --chart-text: #EDEDED;

    /* --- 2. Typography --- */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    --font-brand: 'Balgin', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

[data-theme="light"] {
    --bg-dark: #FAFAFA;
    --bg-surface: #FFFFFF;
    --border-subtle: #E4E4E7;
    --surface-hover: #F4F4F5;
    --border-hover: #D4D4D8;
    --bg-elevated: #F4F4F5;
    --row-hover: #F0F0F0;
    --bg-row-muted: #E8E8E8;

    --text-primary: #18181B;
    --text-muted: #71717A;

    --logo-wordmark-color: #8B3A0E;
    --logo-wordmark-color-hover: #C46328;

    --status-good-bg: #DCFCE7;
    --status-good-hover: #BBF7D0;
    --status-bad-bg: #FEE2E2;

    --chart-muted: #71717A;
    --chart-grid: #E4E4E7;
    --chart-text: #18181B;
}

/* ==========================================
   THEME TOGGLE (header)
========================================== */
.site-header-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
}

.theme-toggle {
    flex-shrink: 0;
    width: 44px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border-subtle);
    border-radius: 999px;
    background: var(--bg-surface);
    cursor: pointer;
    position: relative;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

.theme-toggle:hover {
    border-color: var(--border-hover);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
}

.theme-toggle__thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-orange);
    transition: transform 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .theme-toggle__thumb {
    transform: translateX(18px);
}

/* Saved / muted table rows (project builder) */
.maker-row-saved {
    background-color: var(--bg-row-muted);
    opacity: 0.7;
}

/* ==========================================
   BASE RESETS & TYPOGRAPHY
========================================== */
body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    margin: 0;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    letter-spacing: -0.02em; /* Linear-style tight tracking */
}

/* Tabular Numbers for all financial figures */
.metric, .currency, td, input[type="number"] {
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

/* ==========================================
   SURFACES & CARDS
========================================== */
.surface-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    box-shadow: none; /* Flat and modern */
}

/* ==========================================
   TABLES (Data-Forward & Breathable)
========================================== */
table {
    width: 100%;
    border-collapse: collapse;
}

th {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-size: 0.875rem;
}

/* Remove border from the last row */
tr:last-child td {
    border-bottom: none;
}

/* ==========================================
   BUTTONS (Minimalist)
========================================== */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    padding: 0.625rem 1.125rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.2;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.btn-primary:hover {
    background-color: var(--surface-hover);
    border-color: var(--border-hover);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.btn-primary:focus-visible {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
}

.btn-accent {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none !important;
    background-color: var(--accent-orange);
    color: var(--brand-brown);
    border: none;
    padding: 0.625rem 1.125rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    line-height: 1.2;
    transition: background-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
    box-shadow:
        0 1px 2px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.btn-accent:hover {
    background-color: var(--accent-orange-hover);
    color: var(--brand-brown);
    box-shadow:
        0 4px 14px rgba(161, 75, 20, 0.28),
        inset 0 1px 0 rgba(255, 255, 255, 0.14);
    transform: translateY(-1px);
}

.btn-accent:focus-visible {
    outline: 2px solid var(--accent-orange-hover);
    outline-offset: 2px;
}

.btn-primary:active,
.btn-accent:active {
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .btn-accent:hover {
        transform: none;
    }
}

/* Top app nav — unique class names so Tailwind CDN cannot override .btn-primary / .btn-accent */
.site-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.site-nav-link {
    display: inline-block;
    text-decoration: none;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.site-nav-link:hover {
    background-color: var(--surface-hover);
    border-color: var(--border-hover);
}

.site-nav-link--active {
    background-color: var(--accent-orange);
    color: var(--brand-brown);
    border-color: transparent;
}

.site-nav-link--active:hover {
    background-color: var(--accent-orange-hover);
    color: var(--brand-brown);
}

/* Financial model — secondary tabs (Tailwind-safe BEM) */
.fm-subnav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-subtle);
}

.fm-subnav-link {
    display: inline-block;
    text-decoration: none;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8125rem;
    font-weight: 500;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.fm-subnav-link:hover {
    background-color: var(--surface-hover);
    border-color: var(--border-hover);
}

.fm-subnav-link--active {
    background-color: var(--surface-hover);
    border-color: var(--accent-orange);
    color: var(--text-primary);
    box-shadow: inset 0 -2px 0 var(--accent-orange);
}

.fm-matrix-wrap {
    overflow-x: auto;
    max-width: 100%;
}

.fm-matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.fm-matrix th,
.fm-matrix td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

.fm-matrix th {
    text-align: right;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.fm-matrix th.fm-matrix__label {
    text-align: left;
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    z-index: 1;
    box-shadow: 1px 0 0 var(--border-subtle);
}

.fm-matrix td.fm-matrix__label {
    text-align: left;
    font-weight: 500;
    color: var(--text-primary);
    position: sticky;
    left: 0;
    background: var(--bg-surface);
    z-index: 1;
    box-shadow: 1px 0 0 var(--border-subtle);
}

.fm-matrix td {
    text-align: right;
    font-family: ui-monospace, monospace;
    color: var(--text-primary);
}

body[data-nav="financial"] > div:first-child {
    max-width: 80rem;
    margin-left: auto;
    margin-right: auto;
}

/* Costs: override stale cached Tailwind shell/padding (loads after CDN). */
body[data-nav="costs"] > div:first-child {
    max-width: 72rem;
    margin-left: auto;
    margin-right: auto;
}

body[data-nav="costs"] .surface-card {
    padding: 1.5rem;
}

/* App shell — one header style for every page (avoids Tailwind class drift between tabs) */
.site-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Header wordmark — parent column must use shrink-0 in HTML so flex doesn’t crush the brand */
.site-brand {
    display: inline-flex;
    align-items: flex-start;
    flex-shrink: 0;
    min-width: 0;
}

/*
 * Wordmark link — scoped so Tailwind CDNs can’t flatten Balgin styling.
 * Same treatment on app shell (.site-header), marketing bar (.marketing-header), landing footer.
 */
.site-header .site-brand-logoLink,
.marketing-header .site-brand-logoLink,
.marketing-landing footer .site-brand-logoLink {
    display: inline-block;
    line-height: 1;
    outline: none;
    flex-shrink: 0;
    text-decoration: none !important;
    color: var(--logo-wordmark-color) !important;
    transition: color 0.2s ease, opacity 0.2s ease;
}

.site-header .site-brand-logoLink:visited,
.marketing-header .site-brand-logoLink:visited,
.marketing-landing footer .site-brand-logoLink:visited {
    color: var(--logo-wordmark-color) !important;
}

.site-header .site-brand-logoLink:hover,
.site-header .site-brand-logoLink:hover .site-logo-text,
.marketing-header .site-brand-logoLink:hover,
.marketing-header .site-brand-logoLink:hover .site-logo-text,
.marketing-landing footer .site-brand-logoLink:hover,
.marketing-landing footer .site-brand-logoLink:hover .site-logo-text {
    color: var(--logo-wordmark-color-hover) !important;
}

.site-header .site-brand-logoLink:focus-visible,
.marketing-header .site-brand-logoLink:focus-visible,
.marketing-landing footer .site-brand-logoLink:focus-visible {
    outline: 2px solid var(--accent-orange);
    outline-offset: 3px;
    border-radius: 4px;
}

.site-header .site-brand .site-logo-text,
.marketing-header .site-brand .site-logo-text,
.marketing-landing footer .site-brand .site-logo-text {
    font-family: var(--font-brand) !important;
    font-size: var(--logo-wordmark-size) !important;
    font-weight: var(--logo-wordmark-weight) !important;
    font-stretch: var(--logo-wordmark-stretch);
    letter-spacing: var(--logo-wordmark-tracking) !important;
    line-height: 1 !important;
    display: block;
    color: var(--logo-wordmark-color) !important;
}

/* Marketing footer: same wordmark, smaller optical size than app chrome */
.marketing-landing footer .site-brand .site-logo-text {
    font-size: clamp(1.125rem, 2.5vw, 1.5rem) !important;
}

/* ==========================================
   MODALS (Glass/Sleek Overlay)
========================================== */
.modal-backdrop {
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px); /* Sleek glass effect */
}

[data-theme="light"] .modal-backdrop {
    background-color: rgba(24, 24, 27, 0.35);
}

.modal-surface {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); /* Deep, soft shadow for depth */
}

/* ==========================================
   INPUTS
========================================== */
input, select {
    background-color: var(--bg-dark);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s ease;
}

input:focus, select:focus {
    border-color: var(--text-muted);
}

/* Settings page — in-page tabs (moved from inline HTML for consistency) */
.settings-tab.tab-active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-orange);
}

.settings-tab.tab-inactive {
    color: var(--text-muted);
    border-bottom-color: transparent;
}

.settings-tab.tab-inactive:hover {
    color: var(--text-primary);
}

/* Dashboard — drag-and-drop tiles */
.dashboard-tile--drop-target {
    outline: 2px dashed var(--accent-orange);
    outline-offset: 3px;
    border-radius: 6px;
}

/* Ask Quentl — floating Q&A */
.ask-quentl-root {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 60;
    font-family: var(--font-sans);
}

.ask-quentl-fab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.65rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.ask-quentl-fab:hover {
    border-color: var(--accent-orange);
    background: var(--surface-hover);
}

.ask-quentl-fab-label {
    letter-spacing: -0.02em;
}

.ask-quentl-panel {
    position: absolute;
    right: 0;
    bottom: calc(100% + 0.75rem);
    width: min(22rem, calc(100vw - 2.5rem));
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    max-height: min(28rem, 70vh);
}

.ask-quentl-panel.hidden {
    display: none;
}

.ask-quentl-panel__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border-subtle);
}

.ask-quentl-panel__title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.ask-quentl-panel__sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0.15rem 0 0;
}

.ask-quentl-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.35rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.15rem;
}

.ask-quentl-close:hover {
    color: var(--text-primary);
}

.ask-quentl-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.ask-quentl-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.45;
}

.ask-quentl-bubble {
    max-width: 95%;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    font-size: 0.85rem;
    line-height: 1.45;
}

.ask-quentl-bubble p {
    margin: 0;
}

.ask-quentl-bubble--user {
    align-self: flex-end;
    background: var(--accent-orange);
    color: #fff;
}

.ask-quentl-bubble--assistant {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.ask-quentl-bubble--loading {
    color: var(--text-muted);
    font-style: italic;
}

.ask-quentl-meta {
    margin-top: 0.35rem !important;
    font-size: 0.7rem !important;
    color: var(--text-muted) !important;
}

.ask-quentl-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem 1rem;
    border-top: 1px solid var(--border-subtle);
}

.ask-quentl-input {
    flex: 1;
    min-width: 0;
    font-size: 0.85rem;
}

.ask-quentl-send {
    flex-shrink: 0;
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
}

.dashboard-tile--dragging {
    opacity: 0.65;
}