/* Topbar & Strip Design System
   Extracted from base.html for reuse across standalone templates (e.g. dashboard) */

:root {
    /* Typography */
    --font-display: 'Sora', sans-serif;
    --font-body: 'DM Sans', sans-serif;

    /* Accent Colors (purple theme) */
    --tb-accent-primary: #754ffe;
    --tb-accent-primary-light: rgba(117, 79, 254, 0.1);
    --tb-accent-secondary: #8b5cf6;
    --tb-accent-success: #10b981;
    --tb-accent-warning: #f59e0b;
    --tb-accent-danger: #ef4444;
    --tb-accent-info: #0ea5e9;

    /* Background Colors */
    --tb-bg-primary: #ffffff;
    --tb-bg-tertiary: #f1f3f5;
    --tb-bg-hover: #f1f3f5;

    /* Text Colors */
    --tb-text-primary: #1a1a2e;
    --tb-text-secondary: #4a5568;
    --tb-text-muted: #718096;

    /* Borders */
    --tb-border-color: #e2e8f0;
    --tb-border-hover: #cbd5e1;
    --tb-shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);

    /* Layout */
    --topbar-height: 72px;
    --strip-height: 0px;
    --tb-container-padding: 3rem;

    /* Transitions */
    --tb-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-bs-theme="dark"] {
    --tb-bg-primary: #0f172a;
    --tb-bg-tertiary: #1e293b;
    --tb-bg-hover: #1f2937;
    --tb-text-primary: #f8fafc;
    --tb-text-secondary: #cbd5e1;
    --tb-text-muted: #94a3b8;
    --tb-border-color: #334155;
    --tb-border-hover: #475569;
    --tb-accent-primary-light: rgba(117, 79, 254, 0.22);
    --tb-shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.55);
}

/* Topbar */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-height);
    background: linear-gradient(180deg, #ffffff 0%, #f6f9ff 100%);
    border-bottom: 1px solid var(--tb-border-color);
    z-index: 1030;
    display: flex;
    align-items: center;
    padding: 0 var(--tb-container-padding);
    font-family: var(--font-display);
}

html[data-bs-theme="dark"] .topbar {
    background: var(--tb-bg-primary);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--tb-text-primary);
    font-weight: 600;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.topbar-brand:hover {
    color: var(--tb-accent-primary);
    text-decoration: none;
}

.topbar-brand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tb-accent-primary);
    font-size: 1.35rem;
    line-height: 1;
}

.topbar-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 2rem;
    flex: 1;
    min-width: 0;
}

.topbar-nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    color: var(--tb-text-secondary);
    text-decoration: none;
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.9rem;
    transition: all var(--tb-transition-fast);
    white-space: nowrap;
}

.topbar-nav-link:hover {
    background: var(--tb-bg-hover);
    color: var(--tb-text-primary);
    text-decoration: none;
}

.topbar-nav-link.active {
    background: var(--tb-accent-primary-light);
    color: var(--tb-accent-primary);
}

.topbar-end {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-shrink: 0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    background: var(--tb-bg-tertiary);
    color: var(--tb-text-primary);
    font-family: var(--font-display);
    font-weight: 500;
    font-size: 0.9rem;
}

.topbar-user-avatar {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--tb-accent-primary), var(--tb-accent-secondary));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.8rem;
    overflow: hidden;
}

.topbar-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0.5rem;
    color: var(--tb-text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

.theme-toggle-btn {
    border: none;
    background: transparent;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 10px;
    color: var(--tb-text-secondary);
    transition: all var(--tb-transition-fast);
}

.theme-toggle-btn:hover {
    background: var(--tb-bg-hover);
    color: var(--tb-text-primary);
}

/* Navigation Dropdown (hover-based) */
.nav-dropdown {
    position: relative;
}

.nav-dropdown .nav-chevron {
    font-size: 0.7rem;
    transition: transform var(--tb-transition-fast);
}

.nav-dropdown:hover .nav-chevron {
    transform: rotate(180deg);
}

.nav-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 200px;
    background: var(--tb-bg-primary);
    border: 1px solid var(--tb-border-color);
    border-radius: 12px;
    box-shadow: var(--tb-shadow-lg);
    padding: 0.5rem;
    margin-top: 0.25rem;
    list-style: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all var(--tb-transition-fast);
    z-index: 1050;
}

.nav-dropdown:hover .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-dropdown:focus-within .nav-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.nav-dropdown-menu .dropdown-item {
    display: flex;
    align-items: center;
    font-family: var(--font-display);
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    color: var(--tb-text-secondary);
    text-decoration: none;
    transition: all var(--tb-transition-fast);
}

.nav-dropdown-menu .dropdown-item:hover {
    background: var(--tb-accent-primary-light);
    color: var(--tb-accent-primary);
}

/* User Dropdown */
.user-dropdown .topbar-user {
    transition: all var(--tb-transition-fast);
    cursor: pointer;
}

.user-dropdown:hover .topbar-user {
    background: var(--tb-bg-hover);
}

.user-dropdown .nav-dropdown-menu {
    min-width: 220px;
}

/* Stats Strip */
.has-strip { --strip-height: 42px; }

.stats-strip {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    right: 0;
    height: var(--strip-height);
    z-index: 1029;
    display: flex;
    align-items: center;
    background: linear-gradient(180deg, #131b2d 0%, #0a1020 100%);
    border-bottom: 1px solid #27334a;
    padding: 0 var(--tb-container-padding);
    color: #dbe7ff;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 10px 24px rgba(2, 6, 23, 0.3);
    font-family: var(--font-display);
}

.strip-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0 1rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.strip-item i { font-size: 0.95rem; }
.strip-value {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 0.95rem;
    color: #f8fbff;
}
.strip-label {
    font-size: 0.7rem;
    color: #9fb1cf;
    font-weight: 500;
}
.strip-sep {
    width: 1px;
    height: 24px;
    background: #334155;
    flex-shrink: 0;
}

/* Main Content Area */
.main-content {
    margin-top: calc(var(--topbar-height) + var(--strip-height));
    padding-top: 2rem;
    flex: 1;
}

/* Mobile Menu */
.mobile-menu {
    display: none;
}

/* Responsive */
@media (max-width: 991.98px) {
    :root {
        --topbar-height: 64px;
        --tb-container-padding: 1rem;
    }
    .has-strip { --strip-height: 36px; }
    .stats-strip {
        height: 36px;
        padding: 0 var(--tb-container-padding);
    }
    .strip-item { padding: 0 0.6rem; gap: 0.3rem; }
    .strip-value { font-size: 0.85rem; }
    .strip-label { display: none; }

    .topbar {
        padding: 0 var(--tb-container-padding);
    }

    .topbar-nav {
        display: none;
    }

    .topbar-end {
        display: none;
    }

    .topbar-toggle {
        display: block;
        margin-left: auto;
    }

    .topbar-brand span {
        display: none;
    }

    /* Mobile Menu */
    .mobile-menu {
        position: fixed;
        top: calc(var(--topbar-height) + var(--strip-height));
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--tb-bg-primary);
        padding: 1rem;
        z-index: 1020;
        display: none;
        flex-direction: column;
        gap: 0.25rem;
        overflow-y: auto;
    }

    .mobile-menu.show {
        display: flex;
    }

    .mobile-menu .topbar-nav-link {
        padding: 0.85rem 1rem;
        font-size: 1rem;
        border-radius: 10px;
    }
}

@media (max-width: 767.98px) {
    .topbar-user span {
        display: none;
    }
}

/* ── Search Bar ── */
.topbar-search-wrapper {
    width: 640px;
    flex-shrink: 0;
    margin-right: 0.5rem;
}

.search-bar {
    width: 100%;
    max-width: 100%;
    position: relative;
}

.search-form {
    width: 100%;
    position: relative;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--tb-bg-tertiary);
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 0.5rem 0.875rem;
    transition: all var(--tb-transition-fast);
    cursor: text;
}

.search-input-wrapper:hover {
    background: var(--tb-bg-hover);
}

.search-input-wrapper:focus-within {
    background: var(--tb-bg-primary);
    border-color: var(--tb-accent-primary);
    box-shadow: 0 0 0 3px var(--tb-accent-primary-light);
}

.search-bar.dropdown-open .search-input-wrapper {
    border-radius: 10px 10px 0 0;
    border-bottom-color: var(--tb-border-color);
}

.search-icon {
    width: 1rem;
    height: 1rem;
    color: var(--tb-text-muted);
    margin-right: 0.5rem;
    flex-shrink: 0;
    transition: color var(--tb-transition-fast);
}

.search-input-wrapper:focus-within .search-icon {
    color: var(--tb-accent-primary);
}

.search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--tb-text-primary);
    font-weight: 400;
    padding: 0;
    min-width: 0;
}

.search-input::placeholder {
    color: var(--tb-text-muted);
}

.search-spinner {
    color: var(--tb-text-muted);
    margin-right: 0.25rem;
}

.search-spinner svg {
    animation: search-spin 1s linear infinite;
}

@keyframes search-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.search-clear {
    background: none;
    border: none;
    padding: 0.125rem;
    cursor: pointer;
    color: var(--tb-text-muted);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--tb-transition-fast);
    flex-shrink: 0;
    border-radius: 4px;
}

.search-clear svg {
    width: 1rem;
    height: 1rem;
}

.search-clear:hover {
    color: var(--tb-accent-danger);
    background: rgba(239, 68, 68, 0.1);
}

.search-shortcut {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    flex-shrink: 0;
}

.search-shortcut kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.25rem;
    font-family: var(--font-display);
    font-size: 0.625rem;
    font-weight: 500;
    color: var(--tb-text-muted);
    background: var(--tb-bg-primary);
    border: 1px solid var(--tb-border-color);
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
}

.search-input-wrapper:focus-within .search-shortcut {
    display: none;
}

/* Search Dropdown */
.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--tb-bg-primary);
    border: 1px solid var(--tb-accent-primary);
    border-top: none;
    border-radius: 0 0 12px 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    z-index: 1050;
    max-height: 520px;
    overflow: hidden;
}

.search-dropdown-results {
    max-height: 460px;
    overflow-y: auto;
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--tb-text-primary);
    transition: background var(--tb-transition-fast);
    border-bottom: 1px solid var(--tb-border-color);
}

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

.search-result-item:hover,
.search-result-item.active {
    background: var(--tb-bg-hover);
    text-decoration: none;
    color: var(--tb-text-primary);
}

.search-result-cover {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--tb-bg-tertiary);
}

.search-result-cover-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    flex-shrink: 0;
    background: var(--tb-bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--tb-text-muted);
}

.search-result-cover-placeholder svg {
    width: 20px;
    height: 20px;
}

.search-result-info {
    flex: 1;
    min-width: 0;
}

.search-result-title {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--tb-text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.125rem;
}

.search-result-subtitle {
    font-size: 0.75rem;
    color: var(--tb-text-muted);
    margin-top: 0.125rem;
}

.search-result-score {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 6px;
    padding: 0.125rem 0.5rem;
}

.search-result-score.score-good {
    background: rgba(16, 185, 129, 0.12);
    color: #10b981;
}

.search-result-score.score-mixed {
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
}

.search-result-score.score-bad {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.search-result-score-value {
    font-variant-numeric: tabular-nums;
}

.search-result-score-label {
    font-weight: 500;
}

.search-dropdown-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: var(--tb-bg-tertiary);
    color: var(--tb-accent-primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    transition: background var(--tb-transition-fast);
    border-top: 1px solid var(--tb-border-color);
}

.search-dropdown-footer:hover {
    background: var(--tb-bg-hover);
    color: var(--tb-accent-primary);
    text-decoration: none;
}

.search-dropdown-footer svg {
    width: 1.125rem;
    height: 1.125rem;
}

.search-no-results {
    padding: 2rem;
    text-align: center;
    color: var(--tb-text-muted);
    font-size: 0.9375rem;
}

.search-no-results svg {
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto 0.75rem;
    opacity: 0.5;
}

/* Grouped Results */
.search-result-group {
    border-bottom: 1px solid var(--tb-border-color);
}

.search-result-group:last-child {
    border-bottom: none;
}

.search-result-group-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: var(--tb-bg-tertiary);
    border-bottom: 1px solid var(--tb-border-color);
}

.search-result-group-icon {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
}

.search-result-group-icon.statement { color: var(--tb-accent-primary); }
.search-result-group-icon.argument { color: var(--tb-accent-info); }
.search-result-group-icon.source { color: var(--tb-accent-success); }
.search-result-group-icon.author { color: var(--tb-accent-warning); }

.search-result-group-label {
    font-family: var(--font-display);
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--tb-text-muted);
}

.search-result-group-count {
    margin-left: auto;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--tb-text-muted);
    background: var(--tb-bg-primary);
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    border: 1px solid var(--tb-border-color);
}

.search-result-group-items .search-result-item {
    border-bottom: 1px solid var(--tb-bg-tertiary);
}

.search-result-group-items .search-result-item:last-child {
    border-bottom: none;
}

/* Search Bar Responsive */
@media (max-width: 1200px) {
    .search-shortcut {
        display: none;
    }
}

@media (max-width: 991.98px) {
    .topbar-search-wrapper {
        display: none;
    }
}
