/* =============================================================================
   APP SHELL
   Sidebar layout and the compact, flat component styling that sits on top of
   style.css and editorial.css. Loaded last (inc/head-contents.php).
   Colors and fonts still come from brand.css.
   ============================================================================= */

html {
    font-size: 15px;
}

body {
    background: var(--color-bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* Thin line icons everywhere (Font Awesome light weight). */
.fas {
    font-weight: 300;
}

/* -----------------------------------------------------------------------------
   Sidebar
   ----------------------------------------------------------------------------- */

body:has(.app-sidebar) {
    padding-left: 244px;
}

.app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 244px;
    display: flex;
    flex-direction: column;
    padding: 14px 10px 10px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    z-index: 200;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 4px 8px 14px;
    text-decoration: none;
    color: var(--color-text-primary);
}

.app-brand-mark {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.app-brand-mark-line {
    stroke: var(--sidebar-text-strong);
}

.app-brand-mark-fill {
    fill: var(--logo-accent);
}

.app-brand-name {
    font-size: 0.93rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--color-text-primary);
}

.app-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    flex: 1;
}

.app-nav-group {
    margin: 1.1rem 0 0.3rem;
    padding: 0 8px;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.38rem 8px;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 450;
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: background 0.12s ease, color 0.12s ease;
}

.app-nav-link i {
    width: 16px;
    text-align: center;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.app-nav-link:hover {
    background: color-mix(in srgb, var(--color-text-primary) 5%, transparent);
    color: var(--color-text-primary);
}

.app-nav-link.active {
    background: color-mix(in srgb, var(--color-text-primary) 8%, transparent);
    color: var(--color-text-primary);
    font-weight: 550;
}

.app-nav-link.active i {
    color: var(--color-accent-primary);
}

.app-nav-link .nav-unread-badge {
    margin-left: auto;
}

.app-user {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 1rem;
    padding-top: 10px;
    border-top: 1px solid var(--color-divider-alpha);
}

.app-user-link {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    min-width: 0;
    padding: 0.35rem 8px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--color-text-primary);
    font-size: 0.85rem;
    font-weight: 500;
}

.app-user-link:hover,
.app-user-logout:hover {
    background: color-mix(in srgb, var(--color-text-primary) 5%, transparent);
}

.app-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-tertiary);
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.app-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.app-user-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    color: var(--color-text-muted);
    text-decoration: none;
}

.app-scrim {
    display: none;
}

/* -----------------------------------------------------------------------------
   Page frame and headers
   ----------------------------------------------------------------------------- */

body:has(.app-sidebar) .main-container {
    max-width: 1440px;
    margin: 0;
    padding: 1.75rem 2.25rem 4rem;
}

h1,
.hero h1,
.page-title,
.login-title,
.logout-title,
.page-header-row h1 {
    background: none;
    -webkit-text-fill-color: currentColor;
    color: var(--color-text-primary);
}

body:has(.app-sidebar) h1,
body:has(.app-sidebar) .hero h1,
body:has(.app-sidebar) .page-title,
body:has(.app-sidebar) .page-header-row h1 {
    font-size: 1.5rem;
    line-height: 1.25;
    text-align: left;
    margin: 0 0 0.2rem;
}

body:has(.app-sidebar) .page-header {
    text-align: left;
    margin-bottom: 1.5rem;
    padding-bottom: 1.1rem;
    border-bottom: 1px solid var(--color-divider-alpha);
}

.page-header-split {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
}

body:has(.app-sidebar) .page-description {
    max-width: none;
    margin: 0;
    font-size: 0.93rem;
    color: var(--color-text-secondary);
}

body:has(.app-sidebar) .last-updated {
    justify-content: flex-start;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

/* Section labels (home page) */
body:has(.app-sidebar) .section {
    margin-bottom: 2rem;
}

body:has(.app-sidebar) .section-header {
    justify-content: flex-start;
    margin-bottom: 0.65rem;
}

body:has(.app-sidebar) .section-icon {
    display: none;
}

body:has(.app-sidebar) .section-title {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--color-text-secondary);
}

/* -----------------------------------------------------------------------------
   Sub-navigation
   The sidebar lists Radar and Trends pages, so their pill menus are not needed.
   Articles and Headlines keep theirs as plain underline tabs.
   ----------------------------------------------------------------------------- */

body:has(.app-sidebar) .radar-nav {
    display: none;
}

.editorial-nav,
.category-nav {
    background: none;
    border: 0;
    border-bottom: 1px solid var(--color-divider-alpha);
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
}

.category-nav-list {
    justify-content: flex-start;
    gap: 0.25rem;
}

.editorial-nav-link,
.category-nav-link {
    height: auto;
    padding: 0.55rem 0.7rem;
    margin-bottom: -1px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    font-size: 0.875rem;
    font-weight: 500;
}

.editorial-nav-link.active,
.category-nav-link.active,
.category-nav-link.active:hover {
    background: none !important;
    color: var(--color-text-primary) !important;
    border: 0;
    border-bottom: 2px solid var(--color-accent-primary);
    box-shadow: none;
}

/* -----------------------------------------------------------------------------
   Tool tiles
   ----------------------------------------------------------------------------- */

.tool-grid,
.tool-grid[data-columns] {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 0.75rem;
    justify-content: stretch;
}

.tool-card {
    align-items: flex-start;
    gap: 0.8rem;
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px solid var(--color-divider-alpha);
    border-radius: var(--radius);
    box-shadow: none;
    transition: border-color 0.12s ease, background 0.12s ease;
}

.tool-card::before {
    display: none;
}

.tool-card:hover {
    transform: none;
    box-shadow: none;
    background: var(--color-bg-secondary);
    border-color: color-mix(in srgb, var(--color-text-primary) 28%, transparent);
}

.tool-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: var(--color-bg-secondary);
    font-size: 0.95rem;
    color: var(--color-text-primary);
}

.tool-card:hover .tool-icon {
    background: var(--surface);
    color: var(--color-accent-primary);
    transform: none;
}

.tool-name {
    font-size: 0.93rem;
    margin-bottom: 0.1rem;
}

.tool-description {
    font-size: 0.83rem;
}

/* -----------------------------------------------------------------------------
   Panels, stats, lists
   ----------------------------------------------------------------------------- */

.radar-source,
.generator-card,
.result-card,
.history-card,
.info-card,
.stat-card,
.traffic-kpi,
.article-card {
    background: var(--surface);
    border: 1px solid var(--color-divider-alpha);
    border-radius: var(--radius);
    box-shadow: none;
}

.radar-source:hover,
.generator-card:hover,
.stat-card:hover {
    transform: none;
    box-shadow: none;
}

.source-header {
    justify-content: flex-start;
    padding: 0.8rem 1rem;
    background: none;
    border-bottom: 1px solid var(--color-divider-alpha);
}

.source-icon {
    display: none;
}

.source-title {
    font-size: 0.93rem;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

/* On the home page the section already supplies the space below. */
.section .stats-grid {
    margin-bottom: 0;
}

.stat-card {
    padding: 0.85rem 1rem;
    text-align: left;
}

.stat-card:hover {
    background: var(--color-bg-secondary);
}

.stat-number,
.traffic-kpi-value {
    font-size: 1.55rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: 0.8rem;
}

.traffic-kpi {
    padding: 0.9rem 1rem;
}

.chart-item {
    padding: 0.55rem 1rem;
    border-bottom-color: var(--color-divider-alpha);
}

.chart-rank,
.chart-rank.rank-gold,
.chart-rank.rank-silver,
.chart-rank.rank-bronze {
    width: 22px;
    height: 22px;
    border-radius: 5px;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    font-size: 0.72rem;
    font-weight: 600;
}

.radar-grid {
    gap: 1rem;
    margin-top: 1rem;
}

/* -----------------------------------------------------------------------------
   Buttons and forms
   ----------------------------------------------------------------------------- */

.btn {
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 550;
    box-shadow: none;
}

.btn:hover {
    transform: none;
    box-shadow: none;
}

.btn-primary:hover {
    filter: brightness(1.08);
}

.form-input,
.form-select,
.form-textarea {
    padding: 0.55rem 0.75rem;
    border-width: 1px;
    border-color: color-mix(in srgb, var(--color-text-primary) 18%, transparent);
    font-size: 0.9rem;
}

/* Unread count in the sidebar (defined here so it works on every page) */
.app-nav-link .nav-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--color-accent-primary);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
}

/* -----------------------------------------------------------------------------
   Top bar
   ----------------------------------------------------------------------------- */

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 150;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    height: 48px;
    padding: 0 2.25rem;
    background: color-mix(in srgb, var(--color-bg-primary) 82%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(10px);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--color-divider-alpha);
}

.app-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 6px;
    background: none;
    font-size: 1rem;
    color: var(--color-text-primary);
    cursor: pointer;
}

.app-crumbs {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.app-crumbs i {
    font-size: 0.75rem;
}

.app-crumbs a {
    color: var(--color-text-muted);
    text-decoration: none;
    border-radius: 4px;
}

.app-crumbs a:hover {
    color: var(--color-text-primary);
}

.app-crumbs a.current,
.app-crumbs strong {
    font-weight: 550;
    color: var(--color-text-primary);
}

.app-topbar-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.btn-compact {
    padding: 0.32rem 0.65rem;
    font-size: 0.8rem;
}

/* -----------------------------------------------------------------------------
   Finish: type, depth, focus, motion
   ----------------------------------------------------------------------------- */

:root {
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --ring: 0 0 0 3px color-mix(in srgb, var(--color-accent-primary) 22%, transparent);
}

body {
    font-feature-settings: 'cv11', 'ss01', 'calt';
    text-rendering: optimizeLegibility;
}

::selection {
    background: color-mix(in srgb, var(--color-accent-primary) 22%, transparent);
}

.stat-number,
.traffic-kpi-value,
.chart-meta,
.chart-rank,
.nav-unread-badge {
    font-variant-numeric: tabular-nums;
}

a:focus-visible,
button:focus-visible,
.btn:focus-visible,
.tool-card:focus-visible,
.app-nav-link:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--color-accent-primary);
    box-shadow: var(--ring);
}

.app-sidebar {
    scrollbar-width: thin;
}

/* Cards sit just above the page */
.tool-card,
.radar-source,
.generator-card,
.result-card,
.history-card,
.info-card,
.stat-card,
.traffic-kpi,
.article-card {
    box-shadow: var(--shadow-xs);
}

.tool-card:hover,
.stat-card:hover {
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.07);
}

/* Tool tiles: an arrow slides in on hover */
.tool-card::after {
    content: '\2192';
    margin-left: auto;
    align-self: center;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.tool-card:hover::after {
    opacity: 1;
    transform: none;
}

/* Stat tiles: label above the number */
.stat-card {
    display: flex;
    flex-direction: column-reverse;
    gap: 0.3rem;
}

.stat-label {
    color: var(--color-text-muted);
}

.stat-number {
    margin: 0;
}

/* Buttons */
.btn {
    transition: background 0.12s ease, border-color 0.12s ease, filter 0.12s ease;
}

.btn-primary,
.btn-ai {
    background: var(--color-accent-primary);
    border: 1px solid color-mix(in srgb, var(--color-accent-primary) 82%, #000);
    color: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 1px 2px rgba(15, 23, 42, 0.14);
}

.btn-secondary {
    background: var(--surface);
    border: 1px solid color-mix(in srgb, var(--color-text-primary) 16%, transparent);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-xs);
}

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

.btn:active {
    transform: translateY(0.5px);
}

@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
    }
}

/* -----------------------------------------------------------------------------
   Small screens: sidebar slides in over the page
   ----------------------------------------------------------------------------- */

@media (max-width: 760px) {
    body:has(.app-sidebar) {
        padding-left: 0;
    }

    .app-menu-toggle {
        display: inline-flex;
    }

    .app-topbar {
        padding: 0 12px;
    }

    .app-crumbs > :not(:last-child) {
        display: none;
    }

    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-xl);
    }

    body.nav-open .app-sidebar {
        transform: none;
    }

    body.nav-open .app-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 190;
        background: rgba(0, 0, 0, 0.35);
    }

    body:has(.app-sidebar) .main-container {
        padding: 1.25rem 1rem 3rem;
    }

    .page-header-split {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* -----------------------------------------------------------------------------
   Sidebar colors (tokens in brand.css)
   ----------------------------------------------------------------------------- */

.app-sidebar .app-brand,
.app-sidebar .app-brand-name,
.app-sidebar .app-user-link {
    color: var(--sidebar-text-strong);
}

.app-sidebar .app-nav-group,
.app-sidebar .app-nav-link i,
.app-sidebar .app-user-logout {
    color: var(--sidebar-muted);
}

.app-sidebar .app-nav-link {
    color: var(--sidebar-text);
}

.app-sidebar .app-nav-link:hover,
.app-sidebar .app-user-link:hover,
.app-sidebar .app-user-logout:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-strong);
}

.app-sidebar .app-nav-link.active {
    background: var(--sidebar-active);
    color: var(--sidebar-text-strong);
}

.app-sidebar .app-nav-link.active i {
    color: var(--sidebar-text-strong);
}

.app-sidebar .app-user {
    border-top-color: var(--sidebar-border);
}

.app-sidebar .app-user-avatar {
    background: var(--sidebar-active);
    color: var(--sidebar-text);
}
