/* ==========================================================================
   Site-wide polish (October 2026 audit). Last file in the bundle, so it settles
   conflicts between the older layers: shared button sizing, light-mode colours
   for components that only ever had a dark palette, and phone layouts.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Buttons: the label is centred and the height includes the padding.
   They were content-box blocks, so a 44px minimum height plus padding made
   ~66px tall buttons with the label stuck to the top on phones.
   [hidden] is excluded because the portfolio wizard hides steps that way.
   Single-class specificity on purpose: any more specific rule that hides a
   button (e.g. the mobile-only "new portfolio" button on desktop) still wins.
   -------------------------------------------------------------------------- */

:is(.btn-primary, .btn-secondary, .btn-outline, .btn-save, .btn-delete, .btn-export):where(:not([hidden])) {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45em;
    max-width: 100%;
    text-align: center;
    text-decoration: none;
}

/* --------------------------------------------------------------------------
   Page headers: intro text lines up with the heading. A global
   ".subtitle { margin: auto }" centred the paragraph box under a
   left-aligned h1 (companies, market, model portfolios, AI reports).
   -------------------------------------------------------------------------- */

.directory-header :is(.subtitle, .dir-intro) {
    margin-left: 0;
    margin-right: 0;
}

/* --------------------------------------------------------------------------
   Dialogs: title on the left, close button top right. The flex header only
   applied inside the portfolio page, and the create-portfolio dialog sits
   outside it, so its close button dropped under the title.
   -------------------------------------------------------------------------- */

.modal .modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.modal .modal-head > .modal-close-btn {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--ak-border);
    border-radius: 999px;
    background: transparent;
    box-shadow: none;
    color: var(--ak-text-soft);
    font-size: 1.25rem;
    line-height: 1;
}

.modal .modal-head > .modal-close-btn:hover,
.modal .modal-head > .modal-close-btn:focus-visible {
    border-color: var(--ak-border-strong);
    color: var(--ak-text);
}

/* Create-portfolio wizard: a full-width name field, and a step 1 "Back"
   button that reads as unavailable. */
#createModal .portfolio-wizard-name-field input {
    box-sizing: border-box;
    width: 100%;
    min-height: 48px;
    box-shadow: none;
}

#createModal [data-create-back]:disabled {
    opacity: 0.45;
    cursor: default;
}

/* --------------------------------------------------------------------------
   Form fields: the height includes the padding (content-box made 46px fields
   ~67px tall), and ledger/tax form fields fill their column.
   -------------------------------------------------------------------------- */

.public-site :is(input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]):not([type="file"]):not([type="color"]), select, textarea) {
    box-sizing: border-box;
}

:is(.accounting-entry-form, .accounting-filter-form) :is(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) {
    width: 100%;
    max-width: 100%;
}

/* --------------------------------------------------------------------------
   Footer: column headings stay small labels on phones (a global mobile h2
   size made them 20px headlines).
   -------------------------------------------------------------------------- */

.sf-col h2 {
    font-size: 0.75rem !important;
    line-height: 1.4;
    letter-spacing: 0.06em;
}

/* --------------------------------------------------------------------------
   Numbers: the UI font with aligned digits instead of Courier, which the
   "font-mono" helper fell back to on Windows.
   -------------------------------------------------------------------------- */

.font-mono,
.ai-tpl-ticker {
    font-family: inherit !important;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0 !important;
}

/* --------------------------------------------------------------------------
   Notices: readable titles on the light theme.
   -------------------------------------------------------------------------- */

:root[data-theme="light"] .fx-data-quality-notice strong,
:root[data-theme="light"] .stock-data-warning strong {
    color: #92400e !important;
}

:root[data-theme="light"] .fx-data-quality-notice {
    background: #fffbeb !important;
    border-color: #fcd34d !important;
}

/* --------------------------------------------------------------------------
   Light theme: components that kept their dark-theme surfaces.
   -------------------------------------------------------------------------- */

:root[data-theme="light"] .market-board-context-note {
    background: var(--ak-surface-muted) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text-soft) !important;
}

/* Small "kicker" labels above headings. */
:root[data-theme="light"] .public-social-rail-kicker,
:root[data-theme="light"] .portfolio-page .portfolio-empty-kicker {
    background: #eaf5fb !important;
    border-color: #bfdcec !important;
    color: var(--ak-brand-strong) !important;
}

:root[data-theme="light"] .social-page .social-hero-spotlight-rank {
    background: var(--ak-surface-soft) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text) !important;
}

/* New-user empty portfolio: the three cards had white titles. */
:root[data-theme="light"] .portfolio-page .portfolio-empty-card strong {
    color: var(--ak-text) !important;
}

:root[data-theme="light"] .portfolio-page .export-format-group {
    background: var(--ak-surface-muted) !important;
    border-color: var(--ak-border) !important;
}

:root[data-theme="light"] body.page-portfolio .portfolio-page .portfolio-health-primary.tone-warn .portfolio-health-summary {
    background: #fef3c7 !important;
    border-color: #fcd34d !important;
    color: #92400e !important;
}

/* Import: broker picker and file summary. */
:root[data-theme="light"] .portfolio-import-page .broker-card {
    background: var(--ak-surface-solid) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text-soft) !important;
}

:root[data-theme="light"] .portfolio-import-page .broker-card.is-active {
    background: #eaf5fb !important;
    border-color: var(--ak-brand) !important;
    color: var(--ak-brand-strong) !important;
}

:root[data-theme="light"] .portfolio-import-page .broker-import-summary {
    background: var(--ak-surface-muted) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text) !important;
}

:root[data-theme="light"] .portfolio-import-page .broker-import-summary-row span {
    color: var(--ak-brand) !important;
}

:root[data-theme="light"] .portfolio-import-page .broker-delete-toggle {
    background: var(--ak-surface-solid) !important;
    border-color: var(--ak-border) !important;
}

/* Portfolio settings: form sections and the sticky save bar. */
:root[data-theme="light"] .portfolio-page .portfolio-settings-section {
    background: var(--ak-surface-solid) !important;
    border-color: var(--ak-border) !important;
}

:root[data-theme="light"] .portfolio-settings-page .portfolio-settings-savebar {
    background: rgba(255, 255, 255, 0.96) !important;
    border-color: var(--ak-border) !important;
    box-shadow: 0 -6px 24px rgba(15, 35, 55, 0.08) !important;
}

/* AI stock report: section shortcuts. */
:root[data-theme="light"] .stock-ai-report-nav a {
    background: var(--ak-surface-solid) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text-soft) !important;
}

:root[data-theme="light"] .stock-ai-report-nav a:hover,
:root[data-theme="light"] .stock-ai-report-nav a:focus-visible {
    border-color: var(--ak-brand) !important;
    color: var(--ak-brand-strong) !important;
}

/* Labels and notes that kept pale dark-theme text colours. */
:root[data-theme="light"] :is(.stock-setup-item span, .stock-why-eyebrow, .public-social-rail-stat-label) {
    color: var(--ak-text-muted) !important;
}

:root[data-theme="light"] .market-board-context-note strong {
    color: var(--ak-text) !important;
}

:root[data-theme="light"] body.page-model-portfolio-detail .model-portfolio-page .model-portfolio-seo-intro-kicker {
    color: var(--ak-brand) !important;
}

:root[data-theme="light"] .accounting-export-panel summary {
    background: var(--ak-surface-solid) !important;
    border-color: var(--ak-border) !important;
    color: var(--ak-text) !important;
}

:root[data-theme="light"] .ai-tpl .ai-tpl-priority-badge em {
    color: inherit !important;
}

/* AI stock report page: small labels set in the page's own dark-only styles. */
:root[data-theme="light"] :is(
    .stock-ai-report-overview-card span,
    .stock-ai-report-overview-card em,
    .stock-ai-library-summary span,
    .stock-ai-current-meta span,
    .stock-ai-rail-meta div span,
    .stock-ai-history-stat span,
    .ai-stock-report__summary-card span,
    .ai-stock-report__metric span,
    .ai-stock-report__closing-callout em,
    .stock-peer-table-head span
) {
    color: var(--ak-text-muted) !important;
}

:root[data-theme="light"] :is(.ai-stock-report__closing-callout span, .blog-index-principles strong) {
    color: var(--ak-brand) !important;
}

/* Tables: the social board header kept a pale dark-theme text colour. */
:root[data-theme="light"] .social-page .social-table thead th {
    color: var(--ak-text-muted) !important;
}

/* Gains and losses in ledgers and summaries. */
:root[data-theme="light"] :is(.col-positive, .col-credit) {
    color: var(--ak-positive) !important;
}

:root[data-theme="light"] :is(.col-negative, .col-debit) {
    color: var(--ak-negative) !important;
}

:root[data-theme="light"] .portfolio-transactions-page .active-holdings-summary-card .pos {
    color: var(--ak-positive) !important;
}

:root[data-theme="light"] .portfolio-transactions-page .active-holdings-summary-card .neg {
    color: var(--ak-negative) !important;
}

/* Articles: kicker and meta text. */
:root[data-theme="light"] :is(.blog-kicker, .blog-section-heading > span, .blog-rail-label, .blog-card-meta) {
    color: var(--ak-brand) !important;
}

/* AI report templates: the stock report page gets the same light palette as
   the portfolio report page, and status colours dark enough for white. */
:root[data-theme="light"] .ai-tpl {
    --tpl-text: #10253b !important;
    --tpl-muted: #5a6c7e !important;
    --tpl-card-bg: #f7f9fb !important;
    --tpl-border: #dce4eb !important;
    --tpl-row-hover: #eef3f7 !important;
}

:root[data-theme="light"] .ai-tpl :is(.tpl-sig--bull, .tpl-badge--bull, .tpl-assess--bull .ai-tpl-assess-value) {
    color: #047857 !important;
}

:root[data-theme="light"] .ai-tpl :is(.tpl-sig--bear, .tpl-priority--high, .tpl-assess--bear .ai-tpl-assess-value) {
    color: #be123c !important;
}

:root[data-theme="light"] .ai-tpl :is(.tpl-sig--warn, .tpl-badge--warn, .tpl-priority--med) {
    color: #b45309 !important;
}

:root[data-theme="light"] .ai-tpl :is(.tpl-sig--neutral, .tpl-badge--muted, .tpl-priority--low, .tpl-assess--neutral .ai-tpl-assess-value) {
    color: #475569 !important;
}

:root[data-theme="light"] .ai-tpl :is(.tpl-badge--ok, .ai-tpl-ticker) {
    color: var(--ak-brand) !important;
}

/* Dark theme: evaluator group labels were 65% grey on navy. */
:root:not([data-theme="light"]) .delta-group-label {
    color: var(--ak-text-muted);
}

/* Dark theme: secondary text in AI reports was below readable contrast. */
:root:not([data-theme="light"]) .ai-tpl {
    --tpl-muted: #94a3b8;
}

/* --------------------------------------------------------------------------
   Phones and small tablets
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
    /* Light theme: stacked table rows and collapsible panels were dark. */
    :root[data-theme="light"] .market-table tbody tr {
        background: var(--ak-surface-solid) !important;
        border-color: var(--ak-border) !important;
    }

    :root[data-theme="light"] .mobile-collapse-details {
        background: var(--ak-surface-solid) !important;
        border-color: var(--ak-border) !important;
    }

    :root[data-theme="light"] .portfolio-page .portfolio-switcher-kicker,
    :root[data-theme="light"] .portfolio-page .portfolio-switcher-meta {
        color: var(--ak-text-muted) !important;
    }

    /* Key figures side by side instead of one tall column. */
    .market-hero-stats,
    .social-overview-strip,
    .public-portfolio-hero-facts {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    /* Decorative artwork adds a screen of scrolling on phones. */
    .market-spotlight-visual,
    .social-hero-spotlight-surface {
        display: none !important;
    }

    /* Model portfolio filters: wrap instead of a sideways scroller that
       clipped the group label. */
    .model-portfolio-filter-group {
        flex-wrap: wrap !important;
        overflow: visible !important;
    }

    .model-portfolio-filter-label {
        flex: 0 0 100%;
    }

    /* Portfolio header: one row of actions instead of three stacked
       full-width buttons on every portfolio tab. "New portfolio" is also in
       the portfolio switcher right below, so the header copy is dropped. */
    html body .portfolio-page .portfolio-toolbar .toolbar-actions {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) minmax(0, 7.5rem) !important;
        align-items: stretch;
        gap: 0.5rem !important;
    }

    .portfolio-toolbar .toolbar-actions .portfolio-create-mobile-btn {
        display: none !important;
    }

    .portfolio-toolbar .toolbar-actions :is(.btn-secondary, .currency-form, select) {
        width: 100% !important;
        margin: 0 !important;
    }

    /* "Read more" style links: a finger-sized touch area without changing
       how they look. */
    :is(.blog-card-link, .hp-more, .acct-link) {
        display: inline-flex;
        align-items: center;
        min-height: 40px;
    }

    /* Short tags stay tags instead of full-width bars. */
    .public-portfolio-header-meta {
        display: flex !important;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .public-portfolio-header-chip {
        width: auto !important;
    }
}

/* Stock page: short AI-report teaser shown to visitors without an account. */
.stock-ai-guest-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.9rem 1.5rem;
}

.stock-ai-guest-card .stock-ai-guest-copy {
    flex: 1 1 20rem;
    min-width: 0;
}

.stock-ai-guest-card h2 {
    margin: 0 0 0.3rem;
}

.stock-ai-guest-card .insight-meta {
    margin: 0;
}

.stock-ai-guest-card .btn-secondary {
    flex: none;
    width: auto;
    margin: 0;
}

.trust-page .trust-page-contents {
    margin-block: 1.25rem;
    padding: clamp(0.9rem, 2.5vw, 1.4rem);
    border: 1px solid var(--ak-border);
    border-radius: 0.75rem;
    background: var(--ak-surface-muted);
}

.trust-page .trust-page-contents ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
    gap: 0.25rem 1rem;
    padding: 0;
    list-style: none;
}

.trust-page .trust-page-contents li {
    margin: 0;
}

.trust-page .trust-page-contents a {
    display: block;
    padding: 0.35rem 0;
    color: var(--ak-brand);
    text-decoration: underline;
    text-underline-offset: 0.18em;
}
