:root {
    /* Coastal Professional palette */
    --primary-color: #0891b2;
    --primary-hover: #0e7490;

    /* Accent */
    --accent-color: #fb923c;

    /* Ocean tones */
    --ocean-light: #e0f7fa;
    --ocean-subtle: rgba(8, 145, 178, 0.08);
    --navy: #0f172a;
    --shadow-ocean: 0 4px 16px rgba(8, 145, 178, 0.2);

    /* Warm grays */
    --gray-50: #fafaf9;
    --gray-100: #f5f5f4;
    --gray-200: #e7e5e4;
    --gray-400: #78716c;
    --gray-600: #57534e;
    --gray-900: #0f172a;

    /* Semantic */
    --background: #fffbf5;
    --surface: #ffffff;
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-400);
    --border-color: var(--gray-200);

    /* Warm-tinted shadows */
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-md: 0 4px 16px rgba(28, 25, 23, 0.08), 0 2px 4px rgba(28, 25, 23, 0.04);
    --shadow-lg: 0 12px 40px rgba(28, 25, 23, 0.12);

    /* Transitions */
    --transition-fast: 200ms ease-out;
    --transition-medium: 300ms ease-out;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Hide Alpine x-cloak elements before Alpine initializes */
[x-cloak] {
    display: none !important;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 17px;
    line-height: 1.47;
    letter-spacing: -0.022em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--background);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    padding-bottom: 0;
}

/* Header - frosted glass effect */
.header {
    background: rgba(255, 251, 245, 0.72);
    backdrop-filter: saturate(120%) blur(16px);
    -webkit-backdrop-filter: saturate(120%) blur(16px);
    border-bottom: none;
    padding: 0 22px;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: 100%;
}

.logo {
    font-size: 21px;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    transition: opacity var(--transition-fast);
}

.logo:hover {
    opacity: 0.7;
}

.nav {
    display: flex;
    gap: 0.25rem;
}

.nav-link {
    padding: 6px 12px;
    color: var(--text-primary);
    text-decoration: none;
    border-radius: 980px;
    font-size: 14px;
    font-weight: 400;
    transition: all var(--transition-fast);
}

.nav-link:hover {
    background: var(--gray-100);
}

.nav-link.active {
    background: var(--gray-900);
    color: #ffffff;
}

/* User menu */
.user-menu {
    position: relative;
}
.user-menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
}
.user-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
}
.user-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    padding: 6px 0;
    z-index: 1001;
}
.user-dropdown-email {
    padding: 10px 16px 8px;
    font-size: 13px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--gray-100);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 16px;
    font-size: 14px;
    color: var(--text-primary);
    text-decoration: none;
    background: none;
    border: none;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    transition: background var(--transition-fast);
}
.user-dropdown-item:hover {
    background: var(--gray-100);
}
.user-dropdown-logout {
    color: #dc2626;
}
.user-dropdown-form {
    margin: 0;
}
.signin-btn {
    font-weight: 500;
    color: var(--primary-color) !important;
}

/* Hamburger menu button - hidden on desktop */
.mobile-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background var(--transition-fast);
}

.mobile-menu-btn:hover {
    background: var(--gray-100);
}

.hamburger-line {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 1px;
    transition: all var(--transition-fast);
}

/* Desktop: nav group is just a flex row */
.header-nav-group {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Mobile header */
@media (max-width: 768px) {
    .header {
        height: auto;
        min-height: 48px;
    }

    .header-content {
        flex-wrap: wrap;
        padding: 0;
        gap: 0;
    }

    .logo {
        font-size: 18px;
        padding: 12px 0;
    }

    .mobile-menu-btn {
        display: flex;
        margin-left: auto;
    }

    .header-nav-group {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        padding-bottom: 8px;
        border-top: 1px solid var(--gray-200);
    }

    .header-nav-group.is-open {
        display: flex;
    }

    .nav {
        flex-direction: column;
        gap: 2px;
        padding: 8px 0 4px;
    }

    .nav-link {
        padding: 10px 12px;
        font-size: 15px;
        border-radius: 8px;
    }

    .user-menu {
        padding: 4px 0 0;
        border-top: 1px solid var(--gray-100);
    }

    .signin-btn {
        display: block;
        padding: 10px 12px !important;
        font-size: 15px !important;
    }
}

/* App sub-navigation bar */
.app-subnav {
    background: rgba(255, 251, 245, 0.72);
    backdrop-filter: saturate(120%) blur(16px);
    -webkit-backdrop-filter: saturate(120%) blur(16px);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 52px;
    z-index: 999;
    overflow-x: auto;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.app-subnav::-webkit-scrollbar {
    display: none;
}
.app-subnav-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 40px;
    padding: 0 22px;
    gap: 4px;
}
.app-subnav-link {
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color var(--transition-fast), border-color var(--transition-fast);
}
.app-subnav-link:hover {
    color: var(--text-primary);
}
.app-subnav-link.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* DM child page breadcrumbs */
.dm-breadcrumbs {
    padding: 10px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.dm-breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}
.dm-breadcrumbs a:hover {
    color: var(--primary-color);
}
.dm-breadcrumbs .sep {
    margin: 0 6px;
}
.dm-breadcrumbs .current {
    color: var(--text-primary);
}

/* Breadcrumbs */
.breadcrumbs {
    max-width: 960px;
    margin: 0 auto;
    padding: 10px 22px 0;
    font-size: 13px;
    color: var(--text-secondary);
}
.breadcrumbs a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}
.breadcrumbs a:hover {
    color: var(--primary-color);
}
.breadcrumbs .sep {
    margin: 0 6px;
}
.breadcrumbs .current {
    color: var(--text-primary);
}

/* Mobile: app sub-nav & breadcrumbs */
@media (max-width: 768px) {
    .app-subnav {
        position: relative;
        top: auto;
    }
    .app-subnav-inner {
        padding: 0 16px;
    }
    .app-subnav-link {
        font-size: 12px;
        padding: 8px 10px;
    }
    .breadcrumbs {
        padding: 8px 16px 0;
    }
}

/* Page content wrapper - grows to fill space */
.page-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Flash messages */
.messages-container {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
    padding: 0.75rem 1rem 0;
}

.message {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.message-success {
    background: #e8f5e9;
    color: #2e7d32;
}

.message-error {
    background: #fbe9e7;
    color: #c62828;
}

.message-warning {
    background: #fff8e1;
    color: #f57f17;
}

.message-info {
    background: #e0f7fa;
    color: #0891b2;
}

/* Main content */
.main {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px 22px;
}

.main.full-width {
    max-width: 100%;
    padding: 0;
}

/* Filter bar */
.filter-bar {
    background: rgba(255, 251, 245, 0.72);
    backdrop-filter: saturate(120%) blur(16px);
    -webkit-backdrop-filter: saturate(120%) blur(16px);
    padding: 12px 22px;
    border-bottom: none;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* iOS-style segmented control */
.filter-group {
    display: inline-flex;
    background: var(--gray-100);
    border-radius: 8px;
    padding: 2px;
}

.filter-btn {
    padding: 6px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.filter-btn:hover {
    color: var(--gray-600);
}

.filter-btn.active {
    background: var(--surface);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

/* Map page layout - flex column to fill viewport */
.map-page-layout {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px - 26px); /* viewport minus header and disclaimer */
}

/* Map container */
#map {
    height: 100%;
    width: 100%;
    min-height: 300px;
    background: #e5e7eb;
}

/* Stats card */
.stats-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: none;
    transition: all var(--transition-fast);
}

.stats-card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

.stats-title {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.stats-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.03em;
}

/* Word cloud container */
.wordcloud-container {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: none;
    min-height: 400px;
    transition: all var(--transition-fast);
}

.wordcloud-container:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

/* Section headers */
.section-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    letter-spacing: -0.022em;
}

.section-subtitle {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Loading indicator */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-200);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Footer - normal document flow */
.footer {
    border-top: 1px solid var(--gray-100);
    padding: 12px 22px;
}

.footer-content {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.footer-links {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
}

.footer-links a {
    font-size: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.footer-links a:hover {
    color: var(--primary-color);
}

.footer-divider {
    color: var(--gray-200);
    font-size: 12px;
}

/* Sticky disclaimer - sticks to viewport bottom, settles above footer on scroll */
.footer-disclaimer {
    position: sticky;
    bottom: 0;
    background: var(--background);
    border-top: 1px solid var(--gray-100);
    text-align: center;
    font-size: 10px;
    color: var(--gray-400);
    padding: 6px 22px;
    margin: 0;
    line-height: 1.3;
    z-index: 10;
}

/* Keyword rows */
.keyword-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
}

.keyword-row:not(:last-child) {
    border-bottom: 1px solid var(--gray-100);
}

.keyword-word {
    font-weight: 500;
    text-transform: capitalize;
    font-size: 15px;
}

.keyword-count {
    color: var(--text-secondary);
    font-size: 15px;
}

/* Filing type rows */
.filing-type-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    font-size: 15px;
}

.filing-type-row:not(:last-child) {
    border-bottom: 1px solid var(--gray-100);
}

.filing-type-name {
    color: var(--text-primary);
}

.filing-type-count {
    font-weight: 600;
    color: var(--text-primary);
}

/* Screen-reader only (visually hidden) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: 0;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Global focus-visible indicator for interactive elements */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Reset fieldset styling for semantic grouping without visual chrome */
.fieldset-plain {
    border: 0;
    padding: 0;
    margin: 0;
    min-width: 0;
}

/* Utility classes */
.grid {
    display: grid;
    gap: 1rem;
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 768px) {
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.p-4 { padding: 1rem; }

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    border: none;
}

.leaflet-popup-content {
    margin: 14px 16px;
    font-size: 14px;
}

.popup-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.popup-count {
    color: var(--primary-color);
    font-weight: 600;
}

.popup-divider {
    margin: 10px 0;
    border: none;
    border-top: 1px solid var(--gray-100);
}

.popup-filing {
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--text-primary);
}

.popup-more {
    font-size: 12px;
    color: var(--text-secondary);
}

/* =============================================
   Global Modal
   ============================================= */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.modal {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    margin: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal h4 {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.modal p {
    margin: 0 0 16px 0;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.modal-btn {
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.modal-btn.secondary {
    background: var(--gray-100);
    color: var(--text-primary);
}

.modal-btn.secondary:hover {
    background: var(--gray-200);
}

.modal-btn.primary {
    background: var(--primary-color);
    color: white;
}

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

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

.modal-btn.danger {
    background: #ff3b30;
    color: white;
}

.modal-btn.danger:hover {
    background: #d63028;
}

/* =============================================
   Shared Date Inputs
   ============================================= */

.date-input {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    background: var(--surface);
    color: var(--text-primary);
}

.date-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(8, 145, 178, 0.2);
}

.date-separator {
    font-size: 13px;
    color: var(--text-secondary);
}

.apply-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Beta banner */
.beta-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.4rem 1rem;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 500;
    text-align: center;
}
.beta-banner button {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
    opacity: 0.7;
}
.beta-banner button:hover {
    opacity: 1;
}

/* Feedback widget */
.feedback-widget {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}
.feedback-widget button {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}
.feedback-widget button:hover {
    background: var(--bg-secondary, #f5f5f5);
}
