/* =========================================================
   Main App Layout / Dashboard
   ========================================================= */

/* ---------------------------------------------------------
     Global page shell
     --------------------------------------------------------- */

html,
body {
    overflow-x: hidden;
}

body.companies-page {
    background: transparent;
}

.companies-page {
    position: relative;
    min-height: 100vh;
    overflow-x: hidden;
    padding-bottom: 28px;
}

/* ---------------------------------------------------------
     Main width control
     THIS is the big fix for "full width" pages
     --------------------------------------------------------- */

.companies-page .wrap {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: min(var(--appPageMaxWidth, 1120px), 100%);
    margin-left: var(--appMainMarginLeft, 30px);
    margin-right: auto;
    box-sizing: border-box;
}

.companies-page .wrap.wrap-wide {
    width: 100%;
    max-width: min(var(--appPageWideMaxWidth, 1360px), 100%);
    margin-left: var(--appMainMarginLeft, 30px);
    margin-right: auto;
}

/* Gives top-level pages breathing room without needing inline spacing */
.page-shell {
    padding-top: var(--appPagePaddingTop, 20px);
    padding-bottom: var(--appPagePaddingBottom, 32px);
}

.eyebrow {
    margin: 0 0 4px;
    font-size: var(--font-scale-eyebrow, 0.6875rem);
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ---------------------------------------------------------
     Search / toolbar input (Companies hub + shared)
     --------------------------------------------------------- */

.search-input {
    min-width: 220px;
    height: var(--appInputHeight, 40px);
    padding: 0 12px;
    border-radius: var(--radius-input, 8px);
    border: 1px solid var(--control-border, rgba(15, 23, 42, 0.12));
    background: var(--control-bg, #fff);
    color: var(--control-text, var(--text));
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.search-input:focus:not(:focus-visible) {
    outline: none;
}

.search-input:focus {
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.search-input:focus-visible {
    outline: 2px solid var(--accent, #2563eb);
    outline-offset: 2px;
}

/* ---------------------------------------------------------
     Company grid (workspace cards styled in companyWorkspaceCards.css)
     --------------------------------------------------------- */

.company-grid {
    display: grid;
    /* Hub: at most 4 cards per row on wide viewports; cards expand to fill each track. */
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--appGridGap, 16px);
    justify-content: stretch;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
}

@media (max-width: 1200px) {
    .company-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ---------------------------------------------------------
     Empty states / text helpers
     --------------------------------------------------------- */

.empty-state {
    margin-top: 12px;
    color: var(--muted);
    text-align: center;
    padding: 40px 0;
}

.muted {
    color: var(--muted);
}

/* ---------------------------------------------------------
     Responsive
     --------------------------------------------------------- */

@media (max-width: 900px) {
    .search-input {
        width: 100%;
        min-width: 0;
    }

    .company-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .companies-page .wrap {
        padding-left: var(--page-gutter-mobile);
        padding-right: var(--page-gutter-mobile);
    }

    .card .inside,
    .stat-card .inside,
    .companyWorkspaceBody {
        padding: 16px;
    }
}

/* =========================================================
     Companies hub — compact control center (scoped)
     ========================================================= */

body.companies-page .app-main {
    flex: 1;
    min-height: 0;
}

body.companies-page .app-main__inner.page-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding-top: 16px;
    padding-bottom: 20px;
}

body.companies-page .companies-page {
    padding-bottom: 16px;
}

body.companies-page #appArea.companiesWorkspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 14px;
}

body.companies-page .companiesHubPanel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    margin-bottom: 0;
    padding: clamp(14px, 2vw, 20px) clamp(16px, 2vw, 22px) clamp(14px, 2vw, 18px);
    border-radius: var(--radius-card, 8px);
    border: 1px solid var(--panel-border, rgba(15, 23, 42, 0.08));
    background: var(--surface, #ffffff);
    box-shadow: var(--shadow-card, 0 8px 24px rgba(15, 23, 42, 0.07));
}

body.companies-page .companiesHubPanel .companiesToolbar {
    flex-shrink: 0;
    padding: 0 0 14px;
    margin: 0 0 12px;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--line, #e2e8f0);
    background: transparent;
    box-shadow: none;
}

body.companies-page .companiesHubPanel .companiesGridShell {
    flex: 1;
    min-height: 0;
    padding: 4px 2px 8px 0;
    margin: 0;
    border: none;
}

body.companies-page .company-stats--companiesHub {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.companies-page .stat-card__value--role {
    font-size: clamp(0.82rem, 1.15vw, 0.95rem);
    font-weight: 700;
    max-width: 16rem;
    margin-left: auto;
    margin-right: auto;
    white-space: normal;
    line-height: 1.3;
    letter-spacing: -0.02em;
}

body.companies-page .companiesToolbar {
    flex-shrink: 0;
    padding: 14px 18px;
    border-radius: var(--radius-card, 8px);
    border: 1px solid var(--panel-border, rgba(15, 23, 42, 0.08));
    background: var(--surface, #ffffff);
    box-shadow: var(--shadow-soft, 0 1px 3px rgba(15, 23, 42, 0.06));
}

body.companies-page .companiesToolbar__inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px 20px;
}

body.companies-page .companiesToolbar__lead {
    flex: 1;
    min-width: min(100%, 200px);
}

body.companies-page .companiesToolbar__title {
    margin: 0 0 4px;
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--ink, #0f172a);
    letter-spacing: -0.02em;
}

body.companies-page .companiesToolbar__hint {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.4;
}

body.companies-page .companiesToolbar__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex: 1;
    min-width: min(100%, 320px);
}

body.companies-page .companiesToolbar__search {
    flex: 1;
    min-width: min(100%, 220px);
    max-width: 320px;
}

body.companies-page .companiesToolbar__createWrap.hidden {
    display: none !important;
}

body.companies-page .companiesToolbar__createWrap:not(.hidden) {
    display: inline-flex;
}

body.companies-page .companiesToolbar__err {
    margin: 10px 0 0;
    padding-top: 2px;
}

body.companies-page .companiesGridShell {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 4px 6px 12px 2px;
    margin: 0 -4px 0 -2px;
    border-radius: var(--radius-card, 8px);
    border: 1px solid transparent;
}

body.companies-page .companiesGridShell__loadErr:not(.hidden) {
    flex-shrink: 0;
    margin-bottom: 10px;
}

body.companies-page .companiesGridShell__grid {
    flex-shrink: 0;
}

body.companies-page .companiesGridShell .empty-state {
    flex-shrink: 0;
    margin-top: 8px;
    padding: 24px 16px 16px;
}

@media (max-width: 900px) {
    body.companies-page .companiesToolbar__actions {
        width: 100%;
        justify-content: stretch;
    }

    body.companies-page .companiesToolbar__search {
        max-width: none;
        width: 100%;
    }

    body.companies-page .companiesToolbar__createWrap:not(.hidden) .btn {
        width: 100%;
        justify-content: center;
    }
}