/* ==========================================================================
   base.css - Design tokens, reset and application shell.
   Loaded by every page (app and public). Components live in components.css.

   1. Tokens          2. Reset & accessibility   3. Typography
   4. App shell       5. Header & menus          6. Mobile nav
   7. Page layout     8. Utilities
   ========================================================================== */

/* ==========================================================================
   1. TOKENS
   ========================================================================== */
:root {
    /* ---- Design system: single source of truth for the app and the public pages ---- */

    /* Brand */
    --ds-brand: #FCD34D;
    --ds-brand-hover: #F5C400;
    --ds-brand-soft: #FFF4C2;

    /* Surfaces */
    --ds-bg: #FFFDF7;
    --ds-surface: #FFFFFF;
    --ds-surface-alt: #F5F2E9;

    /* Text and lines */
    --ds-text: #1F2937;
    --ds-text-strong: #111827;
    --ds-muted: #4B5563;
    --ds-border: #E8E4D8;
    --ds-border-strong: #8A8478;
    --ds-focus: #1F2937;

    /* Feedback tones: soft background / border / text / solid (dots, accents) */
    --ds-success-soft: #ECFDF5;
    --ds-success-border: #6EE7B7;
    --ds-success-text: #065F46;
    --ds-success-solid: #10B981;
    --ds-info-soft: #EFF6FF;
    --ds-info-border: #BFDBFE;
    --ds-info-text: #1E40AF;
    --ds-info-solid: #3B82F6;
    --ds-warning-soft: #FFFBEB;
    --ds-warning-border: #FCD34D;
    --ds-warning-text: #92400E;
    --ds-warning-solid: #F59E0B;
    --ds-danger-soft: #FDE4E2;
    --ds-danger-border: #F5B5AF;
    --ds-danger-text: #991B1B;
    --ds-danger-solid: #EF4444;
    --ds-danger-strong: #DC2626; /* solid danger background carrying white text (AA contrast) */
    --ds-danger-strong-hover: #B91C1C;
    --ds-accent-soft: #F5F3FF;
    --ds-accent-border: #DDD6FE;
    --ds-accent-text: #5B21B6;
    --ds-accent-solid: #8B5CF6;

    /* Shape */
    --ds-radius-sm: 8px;
    --ds-radius-input: 10px;
    --ds-radius: 12px;
    --ds-radius-lg: 16px;
    --ds-radius-pill: 999px;

    /* Elevation: flat by default, soft shadows only for floating layers */
    --ds-shadow-card: 0 1px 2px rgba(31, 41, 55, 0.04);
    --ds-shadow-card-hover: 0 6px 18px rgba(31, 41, 55, 0.08);
    --ds-shadow-pop: 0 12px 32px rgba(31, 41, 55, 0.14);
    --ds-shadow-modal: 0 16px 40px rgba(31, 41, 55, 0.18);
    --ds-shadow-toast: 0 8px 24px rgba(31, 41, 55, 0.14);

    /* Typography */
    --font-display: 'Bricolage Grotesque', 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    /* ---- Legacy tokens: still read by pages that are not migrated yet.
           Brand, text and background follow the design system; borders stay brutalist. ---- */
    --primary-color: var(--ds-brand);
    --secondary-color: #FEF3C7;
    --orange: #EA580C;

    --text-color: var(--ds-text);
    --text-muted: var(--ds-muted);
    --text-warning: #F59E0B;
    --text-success: #10B981;

    --bg-color: var(--ds-bg);
    --border-color: #000000;
    --white: #FFFFFF;
    --border-bottom: #E5E7EB;

    --red-alert: #EF4444;
    --red-alert-text: #FFFFFF;

    --status-success: #22C55E; /* Green - Verified, Active, Completed */
    --status-warning: #FACC15; /* Yellow - Restricted, Pending review */
    --status-info: #3B82F6; /* Blue - Pending activation, In progress */
    --status-neutral: #9CA3AF; /* Gray - Inactive, Unknown */
}

/* ==========================================================================
   2. RESET & ACCESSIBILITY
   ========================================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

/* Visible keyboard focus everywhere; components can refine it (zero specificity). */
:where(a, button, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--ds-focus);
    outline-offset: 3px;
}

/* Skip navigation (WCAG 2.4.1) */
.skip-navigation {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    border-radius: var(--ds-radius);
    background: var(--ds-brand);
    color: var(--ds-text);
    box-shadow: var(--ds-shadow-pop);
    font-weight: 600;
    text-decoration: none;
    z-index: 9999;
    transition: top 0.2s ease;
}

.skip-navigation:focus {
    top: 1rem;
    outline: 3px solid var(--ds-focus);
    outline-offset: 2px;
}

/* ==========================================================================
   3. TYPOGRAPHY
   ========================================================================== */
body {
    font-family: var(--font-body);
    background-color: var(--ds-bg);
    color: var(--ds-text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
    font-family: var(--font-display);
    color: var(--ds-text);
}

/* ==========================================================================
   4. APP SHELL: brand mark and main area
   ========================================================================== */

/* Brand mark (also used by the landing header as .app-icon-small) */
.app-icon,
.app-icon-small {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-sm);
    color: var(--ds-text);
}

.app-icon {
    width: 40px;
    height: 40px;
    background-color: var(--ds-brand);
    border-color: var(--ds-brand);
}

.app-icon-small {
    width: 36px;
    height: 36px;
}

.app-icon svg,
.app-icon-small svg {
    width: 20px;
    height: 20px;
}

.app-icon-small.yellow {
    background-color: var(--ds-brand);
    border-color: var(--ds-brand);
}

/* Main content area */
.app-main {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background-color: var(--ds-bg);
}

@media (min-width: 901px) {
    .app-main {
        max-width: 1200px;
        margin: 0 auto;
        padding: 2rem;
        width: 100%;
        overflow-y: auto;
    }
}

/* ==========================================================================
   5. HEADER & MENUS
   ========================================================================== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
    z-index: 40;
    padding: 0.625rem 1rem;
    background-color: var(--ds-surface);
    border-bottom: 1px solid var(--ds-border);
}

@media (min-width: 901px) {
    .app-header {
        padding: 0.625rem 1.5rem;
    }
}

.header-group-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    min-width: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.header-title {
    overflow: hidden;
    color: var(--ds-text);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 1.0625rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--ds-muted);
}

/* Desktop navigation: pills */
.nav-highlight {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 0.875rem;
    border-radius: var(--ds-radius-pill);
    color: var(--ds-text);
    font-weight: 600;
    font-size: 0.9375rem;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.nav-highlight:hover {
    background-color: var(--ds-surface-alt);
}

.nav-highlight.active {
    background-color: var(--ds-brand-soft);
    font-weight: 700;
}

@media (max-width: 900px) {
    .nav-highlight {
        display: none;
    }
}

.desktop-header-content {
    display: none;
}

@media (min-width: 901px) {
    .desktop-header-content {
        display: flex;
        gap: 1rem;
        align-items: center;
    }
}

/* Always-visible header actions (mobile + desktop) */
.header-actions-always {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
}

.header-action-btn,
.header-user-btn {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background: var(--ds-surface);
    color: var(--ds-text);
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.header-action-btn:hover,
.header-user-btn:hover,
details[open] > .header-action-btn,
details[open] > .header-user-btn {
    border-color: var(--ds-border-strong);
    background: var(--ds-surface-alt);
}

.notification-badge-count {
    position: absolute;
    top: -6px;
    right: -6px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 2px solid var(--ds-surface);
    border-radius: var(--ds-radius-pill);
    background: var(--ds-danger-solid);
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
}

/* No unread notification: no badge */
.notification-badge-count.is-empty {
    display: none;
}

/* Floating menus (create, notifications, user, community) */
.dropdown-menu,
.notification-popover,
.user-dropdown-menu,
.community-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 50;
    display: flex;
    flex-direction: column;
    margin-top: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background-color: var(--ds-surface);
    box-shadow: var(--ds-shadow-pop);
}

.header-create-dropdown,
.header-notification-dropdown,
.header-user-dropdown,
.header-community-dropdown {
    position: relative;
}

.header-create-dropdown summary,
.header-notification-dropdown summary,
.header-user-dropdown summary,
.header-community-dropdown summary {
    list-style: none;
    cursor: pointer;
}

.header-create-dropdown summary::-webkit-details-marker,
.header-notification-dropdown summary::-webkit-details-marker,
.header-user-dropdown summary::-webkit-details-marker,
.header-community-dropdown summary::-webkit-details-marker {
    display: none;
}

/* Create dropdown */
.dropdown-menu {
    list-style: none;
    min-width: 170px;
}

.dropdown-menu li + li,
.user-actions li + li {
    border-top: 1px solid var(--ds-border);
}

.dropdown-menu a,
.user-actions a,
.community-switch-btn {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--ds-text);
    font-size: 0.9375rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.dropdown-menu a:hover,
.user-actions a:hover,
.community-switch-btn:hover {
    background-color: var(--ds-surface-alt);
}

/* Notification popover */
.notification-popover {
    right: -80px;
    width: 320px;
}

@media (min-width: 901px) {
    .notification-popover {
        right: 0;
    }
}

.popover-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--ds-border);
}

.popover-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9375rem;
}

.mark-read-btn {
    color: var(--ds-muted);
    font-size: 0.75rem;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.mark-read-btn:hover {
    color: var(--ds-text);
    text-decoration: underline;
}

.notification-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.notification-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--ds-border);
    transition: background-color 0.15s ease;
}

.notification-item:hover {
    background-color: var(--ds-surface-alt);
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item.unread {
    background-color: var(--ds-warning-soft);
}

.notification-item.unread:hover {
    background-color: var(--ds-brand-soft);
}

.notification-icon {
    font-size: 1.2rem;
    line-height: 1;
}

.notification-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.notification-text {
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.35;
}

.notification-time {
    font-size: 0.75rem;
    color: var(--ds-muted);
}

.notification-status {
    display: none;
    width: 8px;
    height: 8px;
    margin-top: 0.4rem;
    border-radius: 50%;
    background-color: var(--ds-warning-solid);
}

.notification-item.unread .notification-status {
    display: block;
}

.popover-footer {
    padding: 0.75rem;
    border-top: 1px solid var(--ds-border);
    background-color: var(--ds-surface-alt);
    text-align: center;
}

.popover-footer a {
    color: var(--ds-text);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.popover-footer a:hover {
    text-decoration: underline;
}

/* User menu */
.user-dropdown-menu {
    width: 240px;
}

.user-header {
    padding: 1rem;
    border-bottom: 1px solid var(--ds-border);
    background-color: var(--ds-surface-alt);
}

.user-name {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.9375rem;
}

.user-role {
    margin-top: 0.125rem;
    font-size: 0.75rem;
    color: var(--ds-muted);
}

.user-actions {
    list-style: none;
}

.user-footer {
    border-top: 1px solid var(--ds-border);
}

.logout-btn {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    color: var(--ds-danger-text);
    font-family: inherit;
    font-weight: 600;
    font-size: 0.9375rem;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.logout-btn:hover {
    background-color: var(--ds-danger-soft);
}

/* Community selector */
.header-community-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.875rem;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius);
    background: var(--ds-surface);
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.header-community-btn:hover,
.header-community-dropdown[open] > .header-community-btn {
    border-color: var(--ds-border-strong);
    background: var(--ds-surface-alt);
}

.header-community-btn svg {
    width: 16px;
    height: 16px;
}

.community-current-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.community-dropdown-menu {
    width: 280px;
}

.community-dropdown-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--ds-border);
    background-color: var(--ds-surface-alt);
    font-weight: 700;
    font-size: 0.8125rem;
}

.community-list {
    list-style: none;
    max-height: 300px;
    overflow-y: auto;
}

.community-item {
    border-bottom: 1px solid var(--ds-border);
}

.community-item:last-child {
    border-bottom: none;
}

.community-item.active {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background-color: var(--ds-brand-soft);
}

.community-item .community-name {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.community-item .community-role {
    font-size: 0.75rem;
    color: var(--ds-muted);
    font-weight: 400;
}

.community-check {
    color: var(--ds-success-text);
    font-weight: 700;
}

.community-switch-btn {
    width: 100%;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
}

/* ==========================================================================
   6. MOBILE NAVIGATION (bottom bar)
   ========================================================================== */
.app-nav {
    display: flex;
    justify-content: space-around;
    flex-shrink: 0;
    z-index: 40;
    padding: 0.375rem 0.5rem env(safe-area-inset-bottom, 0.5rem);
    background-color: var(--ds-surface);
    border-top: 1px solid var(--ds-border);
}

@media (min-width: 901px) {
    .app-nav {
        display: none;
    }
}

.nav-item {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.125rem;
    padding: 0.25rem 0;
    color: var(--ds-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    text-decoration: none;
}

.nav-item.active {
    color: var(--ds-text-strong);
}

.nav-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 28px;
    border-radius: var(--ds-radius-pill);
    transition: background-color 0.15s ease;
}

.nav-item.active .nav-icon {
    background-color: var(--ds-brand-soft);
}

.nav-icon svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

/* ==========================================================================
   7. PAGE LAYOUT
   ========================================================================== */
.page-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.page-header .text-muted {
    color: var(--ds-muted);
    font-size: 0.9rem;
}

/* Right side of a page header row */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
    scrollbar-width: none;
    overflow-x: auto;
    width: 700px;
    padding: 1rem 2rem;
}

/* Content is pushed to the right when it fits, but scrolls from the left when it overflows */
.header-actions > :first-child {
    margin-left: auto;
}

/* Type switcher (filter pills) */
.type-filter {
    display: flex;
    gap: 0.5rem;
    padding: 0;
    background-color: transparent;
    border: none;
    box-shadow: none;
    width: fit-content;
    border-radius: 0;
}

.type-filter-btn {
    padding: 0.2rem 0.6rem;
    font-weight: 600;
    text-transform: uppercase;
    cursor: pointer;
    border: 1.5px solid var(--border-color);
    border-radius: 4px;
    background: var(--white);
    color: var(--text-muted);
    font-size: 0.7rem;
    text-decoration: none;
    transition: all 0.15s ease;
    box-shadow: none;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.type-filter-btn:hover {
    color: var(--text-color);
    background-color: #F3F4F6;
    border-color: black;
}

.type-filter-btn.active {
    background-color: var(--primary-color);
    color: black;
    border-color: black;
    font-weight: 700;
    cursor: default;
}

.type-filter-btn.active:hover {
    transform: none;
}

/* Section header row (title + actions) */
.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 0;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 800;
    margin: 0;
}

.section-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.section-title-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.dashboard-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
}

.notification-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.feed-list {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.last-button {
    margin-top: 1rem;
    display: flex;
    justify-content: flex-end;
}

/* Error pages */
.error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    gap: 2rem;
    padding: 2rem;
}

.error-message {
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 500;
    background-color: var(--white);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-around;
    padding: 0.5rem 0;
    padding-bottom: env(safe-area-inset-bottom, 0.5rem);
    flex-shrink: 0;
}

body.error-page {
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    height: auto;
    overflow: auto;
    padding: 1rem;
}

.error-page-card {
    background-color: var(--ds-surface);
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-lg);
    padding: 3rem 2rem;
    text-align: center;
    max-width: 480px;
    width: 100%;
}

.error-page-emoji {
    font-size: 4rem;
    line-height: 1;
    margin-bottom: 1.5rem;
}

.error-page-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ds-text);
    margin-bottom: 0.75rem;
}

.error-page-message {
    font-size: 1rem;
    color: var(--ds-muted);
    line-height: 1.6;
    margin-bottom: 2rem;
}

/* ==========================================================================
   8. UTILITIES
   ========================================================================== */
.text-sm {
    font-size: 0.85rem;
}

.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

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

.text-success {
    color: var(--ds-success-text);
}

.font-bold {
    font-weight: 700;
}

.full-width {
    width: 100%;
}

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