:root {
    --bg-color: #050505;
    --surface-color: #121212;
    --primary-color: #ff3b30;
    /* Neon Red */
    --secondary-color: #ffffff;
    --text-color: #e0e0e0;
    --dim-text: #666;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --focus-guide-color: rgba(255, 59, 48, 0.15);
    --reader-bg: #000000;
    --modal-bg: #0a0a0a;
    --tooltip-bg: rgba(15, 15, 15, 0.95);
    --tooltip-shadow: 0 15px 40px rgba(0, 0, 0, 0.6);
    --font-heading: 'Outfit', sans-serif;
    --font-mono: 'Space Mono', monospace;
    --transition-speed: 0.3s;

    /* Reader dynamic properties (JS updates; defaults = lighter & slightly smaller) */
    --reader-font-size: 0.85;
    --reader-font-family: var(--font-heading);
    --reader-text-upper: none;
    --reader-word-weight: 500;
    --reader-orp-weight: 620;
    /* Set from JS per token so long words shrink instead of clipping the viewport */
    --reader-word-len: 10;
}

:root[data-theme="light"] {
    --bg-color: #f5f5f7;
    --surface-color: #ffffff;
    --primary-color: #ff3b30;
    --secondary-color: #1d1d1f;
    --text-color: #1d1d1f;
    --dim-text: #86868b;
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(0, 0, 0, 0.1);
    --reader-bg: #ffffff;
    --modal-bg: #ffffff;
    --tooltip-bg: rgba(255, 255, 255, 0.98);
    --tooltip-shadow: 0 15px 40px rgba(0, 0, 0, 0.1);
    --reader-font-size: 0.85;
    --reader-font-family: var(--font-heading);
    --reader-text-upper: none;
    --reader-word-weight: 500;
    --reader-orp-weight: 620;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-heading);
    height: 100vh;
    display: flex;
    overflow: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
    /* App-like feel */
}

.app-container {
    width: 100%;
    max-width: 100%;
    height: 100vh;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -1px;
}

.logo .highlight {
    color: var(--primary-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    position: relative;
    z-index: 50;
    /* Ensure buttons are above other content */
}

/* Main Layout */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 0;
    /* Flexbox scrolling fix */
}

/* Reader Display - The Core */
.reader-display {
    flex: 1.5;
    background: var(--reader-bg);
    border-radius: 24px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: relative;
    border: 1px solid var(--glass-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    margin-bottom: 0;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

/* Hide the vertical guide line - we'll use underline instead */
.focus-line {
    display: none;
}

/* 
   We use CSS Grid to perfectly align the ORP (Optimal Recognition Point)
   to the center of the screen.
   Columns: 1fr (Right Aligned Text) | auto (The Red Letter) | 1fr (Left Aligned Text)
*/

.word-container {
    font-family: var(--reader-font-family);
    /* Desktop / tablet landscape: stable size from viewport only (no per-word jumps) */
    font-size: calc(clamp(3rem, 10vw, 6rem) * var(--reader-font-size));
    font-weight: var(--reader-word-weight);
    color: var(--secondary-color);
    white-space: nowrap;
    z-index: 10;
    line-height: 1;
    position: relative;
    top: -4px;
    width: 100%;
    max-width: min(90%, calc(100vw - max(1.25rem, env(safe-area-inset-left, 0px)) - max(1.25rem, env(safe-area-inset-right, 0px))));
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: baseline;
    gap: 0;
    margin: 0 auto;
    padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    min-width: 0;
}


.word-left,
.word-orp,
.word-right {
    text-transform: var(--reader-text-upper);
}

.word-left,
.word-right {
    min-width: 0;
}

.word-left {
    text-align: right;
}

.word-orp {
    color: var(--primary-color);
    font-weight: var(--reader-orp-weight);
    text-align: center;
    text-decoration: underline;
    text-decoration-color: var(--primary-color);
    text-decoration-thickness: 3px;
    text-underline-offset: 8px;
}

.word-right {
    text-align: left;
}

/* Highlight the Optimal Recognition Point (ORP) - Legacy support removed */

/* Controls */
.controls-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
    height: auto;
    padding: 1.5rem;
    position: relative;
    min-height: 140px;
}

.glass-panel {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    backdrop-filter: blur(10px);
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

.main-controls-row {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    position: relative;
    padding: 0 1rem;
}

.controls-spacer {
    width: 120px;
    flex-shrink: 0;
}

@media (max-width: 1100px) {
    .controls-spacer {
        display: none;
    }
}

.playback-controls {
    display: flex;
    gap: 1.5rem;
    align-items: center;
    z-index: 20;
}

.playback-controls.playback-primary {
    position: relative;
    left: auto;
    transform: none;
    flex: 0 1 auto;
    justify-content: center;
    min-width: 0;
}

.main-controls-row.reader-dock-row {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
}

/* Transport + WPM: one column, centered (replaces <details> "More") */
.reader-dock-stack {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    max-width: min(520px, 100%);
    margin: 0 auto;
    flex-shrink: 0;
}

.reader-dock-transport-row {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: clamp(0.5rem, 3vw, 1.1rem);
    width: 100%;
}

.reader-dock-transport-row .playback-controls.playback-primary {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    justify-content: center;
}

.reader-dock-transport-row .focus-settings-btn {
    flex-shrink: 0;
}

.reader-dock-wpm-row {
    display: flex;
    width: 100%;
    justify-content: center;
}

.reader-dock-wpm-row .wpm-control-container {
    /* Reset global .wpm-control-container { margin-left: auto } so the pill stays centered */
    margin-left: 0;
    margin-right: 0;
    width: 100%;
    max-width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.reader-dock-wpm-row .wpm-control-group {
    width: auto;
    max-width: min(340px, 92vw);
    margin-left: auto;
    margin-right: auto;
}

@media (min-width: 1024px) {
    .main-controls-row.reader-dock-row {
        padding: 0.35rem 1rem 0;
    }

    .main-controls-row.reader-dock-row .controls-spacer {
        display: none !important;
    }

    .reader-dock-stack {
        max-width: min(520px, 94vw);
    }
}

.control-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    /* overflow: hidden; REMOVED to allow tooltips */
}

/* Ensure icon/text text sits above the shine */
.control-btn>* {
    position: relative;
    z-index: 2;
}

/* Subtle glass highlight on hover - Moved to ::after to free ::before for tooltips */
.control-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent);
    opacity: 0;
    border-radius: 50%;
    /* Match button shape manually since overflow is visible */
    transition: opacity 0.3s ease;
    z-index: 1;
    pointer-events: none;
}

.control-btn:hover::after {
    opacity: 1;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px) scale(1.05);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.control-btn:active {
    transform: translateY(0) scale(0.95);
}

.control-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.35);
}

/* Big Play Button - The Star of the Show */
.control-btn.big-play {
    width: 72px;
    height: 72px;
    background: var(--secondary-color);
    color: var(--reader-bg);
    border: none;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
    animation: neon-pulse 3s infinite;
}

@keyframes neon-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.4);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(255, 59, 48, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 59, 48, 0);
    }
}

.control-btn.big-play:hover {
    transform: translateY(-3px) scale(1.1);
    box-shadow: 0 10px 30px rgba(255, 59, 48, 0.4);
    /* Stronger glow on hover */
    animation: none;
    /* Stop pulsing on hover so it feels solid */
}

.control-btn.big-play:active {
    transform: translateY(0) scale(0.95);
    box-shadow: 0 2px 10px rgba(255, 59, 48, 0.3);
}

/* Directional Animations */
#rewindBtn svg {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#rewindBtn:hover svg {
    transform: translateX(-3px);
}

#forwardBtn svg {
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#forwardBtn:hover svg {
    transform: translateX(3px);
}

.settings-group {
    display: flex;
    flex: 1;
    gap: 2rem;
    align-items: center;
}

.wpm-control-container {
    margin-left: auto;
}

.wpm-control-group {
    display: grid;
    grid-template-columns: auto auto auto auto;
    align-items: center;
    gap: 0.6rem;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02));
    padding: 0.45rem 0.65rem;
    border-radius: 14px;
    border: 1px solid var(--glass-border);
}

.wpm-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--dim-text);
    letter-spacing: 0.08em;
    padding: 0 0.25rem;
}

.wpm-step-btn {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-color);
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.wpm-step-btn:hover {
    transform: translateY(-1px);
    border-color: rgba(255, 59, 48, 0.45);
    background: rgba(255, 59, 48, 0.12);
}

#wpmDisplay {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--secondary-color);
    min-width: 3.2ch;
    text-align: center;
}


.progress-control-wrap {
    position: relative;
    width: 100%;
}

.progress-hover-preview {
    position: absolute;
    bottom: calc(100% + 0.55rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    width: min(420px, 94vw);
    pointer-events: none;
    text-align: left;
}

.progress-hover-preview-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
    font-size: 0.68rem;
    letter-spacing: 0.02em;
    margin-bottom: 0.35rem;
    padding: 0 0.15rem;
}

.progress-hover-muted {
    color: var(--dim-text);
    font-family: var(--font-mono);
}

.progress-hover-preview-card {
    background: rgba(12, 12, 12, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
    padding: 0.65rem 0.75rem 0.7rem;
}

:root[data-theme="light"] .progress-hover-preview-card {
    background: rgba(255, 255, 255, 0.98);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.12);
}

.progress-hover-preview-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.45rem;
}

.progress-hover-preview-head #progressHoverMeta {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--dim-text);
}

.progress-hover-preview-head #progressHoverMeta .progress-hover-pct,
.progress-hover-preview-top .progress-hover-pct {
    color: var(--primary-color);
    font-weight: 700;
}

.progress-hover-snippet {
    font-size: 0.78rem;
    line-height: 1.48;
    color: var(--text-color);
    max-height: 4.65em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    word-break: break-word;
}

.preview-fade {
    color: var(--dim-text);
    opacity: 0.85;
}

.preview-token {
    color: var(--dim-text);
}

.preview-focus {
    font-weight: 600;
    color: var(--secondary-color);
}

.preview-focus-orp {
    color: var(--primary-color);
    font-weight: 700;
}

.progress-control {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--secondary-color);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

#progressBar {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    border: 0;
    outline: none;
    background:
        linear-gradient(90deg, var(--primary-color), var(--primary-color)) 0 0 / 0% 100% no-repeat,
        rgba(255, 255, 255, 0.14);
}

#progressBar::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: transparent;
}

#progressBar::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    margin-top: -6px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: #ffffff;
    box-shadow: 0 0 0 5px rgba(255, 59, 48, 0.12), 0 2px 12px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

#progressBar::-moz-range-track {
    height: 6px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.14);
}

#progressBar::-moz-range-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--primary-color);
}

#progressBar::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    background: #ffffff;
    box-shadow: 0 0 0 5px rgba(255, 59, 48, 0.12), 0 2px 12px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.progress-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.8rem;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--dim-text);
}

.stat-item {
    display: flex;
    gap: 0.3rem;
}

.highlight-stat {
    color: var(--primary-color);
    font-weight: 700;
}

.time-stat {
    color: var(--text-color);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.time-divider {
    opacity: 0.3;
    font-weight: 300;
}

.time-icon {
    opacity: 0.7;
    font-size: 0.95em;
}


/* Input Section */
.input-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.tabs {
    display: flex;
    gap: 1rem;
    border-bottom: 1px solid var(--glass-border);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--dim-text);
    font-family: var(--font-heading);
    font-weight: 600;
    cursor: pointer;
    padding: 0.5rem 1.2rem;
    transition: 0.3s;
    outline: none;
    /* Remove blue outline */
}

.tab-btn.active {
    color: var(--secondary-color);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 100px;
    box-shadow: 0 0 0 1px var(--glass-border);
}

.tab-content {
    display: none;
    height: 100%;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 100%;
}

#contentArea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-heading);
    line-height: 1.6;
    resize: none;
    font-size: 1rem;
    outline: none;
}

.btn-primary,
.btn-secondary {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    font-family: var(--font-heading);
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-primary {
    background: #ffffff;
    color: #000000;
    width: fit-content;
    align-self: center;
    box-shadow: 0 4px 15px rgba(255, 255, 255, 0.1);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 255, 255, 0.2);
    background: #f0f0f0;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.file-drop-zone {
    flex: 1;
    border: 2px dashed var(--glass-border);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--dim-text);
    cursor: pointer;
    transition: 0.3s;
}

.kofi-link,
.kofi-link:visited {
    color: var(--secondary-color);
    text-decoration: none;
    font-size: 0.85rem;
    opacity: 0.5;
    transition: opacity 0.3s ease;
    display: inline-block;
}

.kofi-link:hover {
    opacity: 1;
    color: var(--primary-color);
}

/* FAQ Button */
.btn-icon {
    background: transparent;
    border: none;
    color: var(--dim-text);
    cursor: pointer;
    padding: 0.5rem;
    transition: all 0.2s;
    border-radius: 50%;
}

.btn-icon:hover {
    color: var(--primary-color);
    background: rgba(255, 255, 255, 0.05);
}

/* Custom Instant Tooltip */
[data-tooltip] {
    position: relative;
    cursor: pointer;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--tooltip-bg);
    color: var(--text-color);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-family: var(--font-heading);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
    border: 1px solid var(--glass-border);
    box-shadow: var(--tooltip-shadow);
    z-index: 1000;
}

[data-tooltip]:hover::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Modal Styling */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    justify-content: center;
    align-items: center;
}

.modal-content {
    margin: auto;
    width: 90%;
    max-width: 600px;
    padding: 2.5rem;
    position: relative;
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    background: var(--modal-bg);
    /* Enhance glass panel for modal */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: modalSlideIn 0.3s ease;
    transition: background-color var(--transition-speed), border-color var(--transition-speed);
}

@keyframes modalSlideIn {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.close-modal {
    color: var(--dim-text);
    float: right;
    font-size: 2rem;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
}

.close-modal:hover,
.close-modal:focus {
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
}

.modal h2 {
    margin-bottom: 2rem;
    font-size: 1.8rem;
    color: var(--secondary-color);
}

.faq-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

.faq-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.faq-section h3 {
    margin-bottom: 0.8rem;
    color: var(--text-color);
    font-size: 1.2rem;
}

.faq-section p,
.faq-section li {
    line-height: 1.6;
    color: var(--dim-text);
    font-size: 0.95rem;
}

.faq-section ul {
    padding-left: 1.2rem;
    margin-top: 0.5rem;
}

/* Focus Guides: Vertical Lines above/below */
.reader-display {
    position: relative;
    /* Ensure absolute children position relative to this */
}

/* Top Vertical Guide - Lengthened */
.reader-display::before {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: calc(50% - 132px);
    height: 24px;
    width: 2px;
    background-color: var(--primary-color);
    opacity: 0.82;
    pointer-events: none;
}

/* Bottom Vertical Guide - Lengthened */
.reader-display::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(50% - 132px);
    height: 24px;
    width: 2px;
    background-color: var(--primary-color);
    opacity: 0.82;
    pointer-events: none;
}

/* Cleanup ORP */
.word-orp {
    color: var(--part-primary-color, #ff3b30);
    font-weight: 700;
    margin: 0;
    text-decoration: none !important;
    /* Remove any default underline */
    position: relative;
    display: inline-block;
}

/* Horizontal Bracket removed as requested */
.word-orp::after {
    display: none;
}

/* Fluid Alignment: Force ORP to be dead center */
.word-chunk {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    line-height: normal;
    /* prevent vertical jumping */
}

.word-left {
    flex: 1;
    min-width: 0;
    text-align: right;
    display: inline-block;
    white-space: pre;
}

.word-orp {
    color: var(--part-primary-color, #ff3b30);
    /* fallback or variable */
    font-weight: 700;
    margin: 0;
}

.word-right {
    flex: 1;
    min-width: 0;
    text-align: left;
    display: inline-block;
    white-space: pre;
}

/* Responsive Design (Aggressive Mobile-First Overhaul) */

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

@media (max-width: 768px) {
    body {
        height: auto;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .app-container {
        padding: 1rem 1rem 4rem 1rem;
        gap: 1.5rem;
        height: auto;
        min-height: 100vh;
        display: block;
    }

    main {
        display: block;
        height: auto;
    }

    .sidebar-section {
        width: 100%;
        height: auto;
        margin-bottom: 2rem;
        padding: 1.2rem;
    }

    .workspace-main {
        width: 100%;
        height: auto;
        gap: 1.5rem;
    }

    .reader-display {
        height: 250px;
        min-height: 200px;
        margin-bottom: 1.5rem;
    }

    /* Mobile: stable --reader-word-len from JS (~88th pct, capped); higher floor + coef so short words stay readable */
    .word-container {
        font-size: calc(
            clamp(
                2.15rem,
                min(
                    5.5rem,
                    calc(
                        (100vw - max(0.65rem, env(safe-area-inset-left, 0px) + env(safe-area-inset-right, 0px)))
                        / max(var(--reader-word-len, 10), 3)
                        * 0.92
                    )
                ),
                5.75rem
            ) * var(--reader-font-size)
        );
        max-width: 100%;
        box-sizing: border-box;
        padding-left: max(0.2rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.2rem, env(safe-area-inset-right, 0px));
    }

    .logo {
        font-size: 1.5rem;
    }

    .controls-container {
        padding: 1rem;
        gap: 1.2rem;
        min-height: auto;
    }

    .main-controls-row {
        flex-direction: column;
        gap: 1.5rem;
    }

    .playback-controls.playback-primary {
        position: static;
        transform: none;
        justify-content: center;
        width: auto;
        gap: 1.2rem;
    }

    .reader-dock-row .reader-dock-stack {
        max-width: 100%;
    }

    .reader-dock-wpm-row .wpm-control-group {
        width: auto;
        justify-content: center;
        padding: 0.65rem 0.8rem;
        margin: 0 auto;
    }

    .progress-stats {
        justify-content: space-around;
        gap: 1rem;
    }

    .tabs {
        padding-bottom: 0.5rem;
        margin-bottom: 0.8rem;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .tab-btn {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    /* URL Import Redesign for Mobile */
    .url-input-group {
        flex-direction: column;
        height: auto;
        gap: 1rem;
        margin: 0.5rem 0 2rem 0;
    }

    .url-field {
        width: 100%;
        height: 54px;
        font-size: 0.95rem;
    }

    .url-actions {
        display: flex;
        width: 100%;
        gap: 0.8rem;
        align-items: center;
    }

    #extractUrlBtn {
        flex: 1;
        height: 54px;
        order: 1;
    }

    .tooltip-container {
        order: 2;
        margin: 0;
    }

    .info-icon {
        width: 44px;
        height: 44px;
    }

    .smart-tooltip {
        width: calc(100vw - 3rem);
        right: 0;
        left: auto;
        bottom: 120%;
        transform: translateY(10px);
    }

    .tooltip-container:hover .smart-tooltip {
        transform: translateY(0);
    }

    .smart-tooltip::after {
        right: 14px;
    }

    .footer-links-container {
        margin-top: 2rem;
        padding-bottom: 2rem;
    }
}

@media (max-width: 480px) {
    .reader-display {
        border-radius: 16px;
    }

    .app-container {
        padding: 0.8rem;
    }

    /* Slightly smaller play than tablet, still above 44px minimum */
    .playback-controls.playback-primary .control-btn.big-play {
        width: 70px;
        height: 70px;
    }

    body.document-reading-mode .playback-controls.playback-primary .control-btn.big-play {
        width: 78px;
        height: 78px;
    }
}

/* Reader: progress + transport — phones & tablets (real devices, fat thumbs) */
@media (max-width: 1024px) {
    .controls-container .progress-control {
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    .controls-container {
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
    }

    /* Extra-slim bar (~half prior mobile thickness); thumb still grabbable */
    #progressBar {
        height: 2px;
        padding-block: 4px;
        box-sizing: content-box;
        cursor: pointer;
        touch-action: none;
        -webkit-tap-highlight-color: transparent;
    }

    #progressBar::-webkit-slider-runnable-track {
        height: 2px;
    }

    #progressBar::-webkit-slider-thumb {
        width: 12px;
        height: 12px;
        margin-top: -5px;
        border-width: 2px;
    }

    #progressBar::-moz-range-track {
        height: 2px;
    }

    #progressBar::-moz-range-thumb {
        width: 12px;
        height: 12px;
    }

    .progress-stats {
        flex-wrap: wrap;
        row-gap: 0.45rem;
        column-gap: 0.65rem;
        margin-top: 0.55rem;
        font-size: 0.78rem;
        align-items: center;
    }

    .time-stat {
        gap: 0.35rem 0.5rem;
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .playback-controls.playback-primary {
        max-width: 100%;
        box-sizing: border-box;
        padding-left: max(0.35rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.35rem, env(safe-area-inset-right, 0px));
        gap: clamp(0.65rem, 3.5vw, 1.35rem);
    }

    .playback-controls.playback-primary .control-btn:not(.big-play) {
        width: 52px;
        height: 52px;
        flex-shrink: 0;
    }

    .playback-controls.playback-primary .control-btn.big-play {
        width: 76px;
        height: 76px;
        flex-shrink: 0;
    }

    .main-controls-row {
        padding-left: max(0.35rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.35rem, env(safe-area-inset-right, 0px));
    }

    body.document-reading-mode .controls-container {
        padding-left: max(0.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.5rem, env(safe-area-inset-right, 0px));
    }

    body.document-reading-mode .playback-controls.playback-primary {
        gap: clamp(0.55rem, 3vw, 1rem);
    }

    body.document-reading-mode .playback-controls.playback-primary .control-btn:not(.big-play) {
        width: 56px;
        height: 56px;
    }

    body.document-reading-mode .playback-controls.playback-primary .control-btn.big-play {
        width: 84px;
        height: 84px;
    }
}

@media (max-width: 380px) {
    .progress-stats {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .progress-stats .stat-item,
    .progress-stats .time-stat {
        justify-content: center;
        width: 100%;
    }
}



/* Appearance & Header Controls */
.appearance-wrapper {
    position: relative;
    display: inline-block;
}

.appearance-panel {
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 1000;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--glass-border);
}

.appearance-row {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.appearance-row label {
    font-size: 0.8rem;
    color: var(--dim-text);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.segmented-control {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    padding: 2px;
    border: 1px solid var(--glass-border);
    align-items: center;
    /* Center items vertically */
}

.segmented-control.three-way {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 2px;
}

.segment-btn {
    background: transparent;
    border: none;
    color: var(--dim-text);
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-align: center;
}

.segment-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.segment-btn.active {
    background: var(--secondary-color);
    color: var(--bg-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.segment-display {
    flex: 1;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

@media (max-width: 480px) {
    .appearance-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        width: 100%;
        transform: none;
        border-radius: 20px 20px 0 0;
        padding-bottom: 2rem;
        background: var(--surface-color);
        /* More solid background for mobile sheet */
    }
}

/* Language Selector */
.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.lang-select {
    background: transparent;
    color: var(--dim-text);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    padding: 0.3rem 0.6rem;
    font-family: var(--font-heading);
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.lang-select:hover {
    color: var(--secondary-color);
    border-color: var(--text-color);
}

.lang-select option {
    background: var(--surface-color);
    color: var(--text-color);
}

/* Ultra Focus - Autohide UI */
.autohide-ui {
    transition: opacity 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        visibility 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 1;
    visibility: visible;
}

.ui-hidden .autohide-ui {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(20px);
}

/* Cinematic Centering for Reader */
.reader-display {
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1),
        background-color var(--transition-speed),
        border-color var(--transition-speed),
        box-shadow 0.8s ease;
    z-index: 10;
}

.ui-hidden .reader-display {
    transform: translateY(20vh);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.15);
}

@media (max-width: 768px) {
    .ui-hidden .reader-display {
        transform: translateY(10vh);
    }
}

/* Report Modal Specifics */
.report-content {
    text-align: center;
}

.report-stat-card {
    transition: transform 0.3s ease;
}

.report-stat-card:hover {
    transform: translateY(-5px);
}

.report-value {
    display: block;
    line-height: 1.2;
}

@keyframes reportPop {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Full Screen Focus Mode Enhancements */
:fullscreen .app-container {
    max-width: 100vw;
    padding: 5vh 5vw;
}

:fullscreen .reader-display {
    border-radius: 40px;
    box-shadow: 0 50px 120px rgba(0, 0, 0, 0.5);
    background-color: var(--reader-bg);
}

:fullscreen .word-container {
    font-size: calc(
        clamp(
            1.25rem,
            min(12rem, calc((100vw - 3rem) / max(var(--reader-word-len), 3) * 0.82)),
            14rem
        ) * var(--reader-font-size)
    );
}

:fullscreen .app-footer,
:fullscreen .kofi-link {
    display: none !important;
}

:fullscreen .modal-content {
    max-width: 600px;
}

.report-content {
    animation: reportPop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* URL Extraction Layout */
.url-input-group {
    display: flex;
    gap: 1rem;
    margin: 1.5rem auto;
    height: 50px;
    align-items: center;
    max-width: 800px;
    width: 100%;
}

.url-field {
    flex: 1;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0 1.2rem;
    color: var(--text-color);
    font-family: var(--font-heading);
    font-size: 1rem;
    height: 100%;
    transition: all 0.3s;
}

.url-field:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.1);
}

#extractUrlBtn {
    white-space: nowrap;
    height: 100%;
    padding: 0 1.5rem;
    border-radius: 12px;
}

/* Header Icon Buttons */
.header-control-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--dim-text);
    width: 48px;
    /* Slight increase */
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin: 0;
    padding: 0;
    /* SVG has own viewbox */
}

.header-control-btn:hover {
    color: var(--secondary-color);
    background: var(--glass-bg);
    border-color: var(--glass-border);
}

.header-control-btn svg {
    pointer-events: none;
    display: block;
}

.btn-icon {
    /* Legacy / other usage */
    background: transparent;
    border: 1px solid transparent;
    color: var(--dim-text);
    width: 44px;
    height: 44px;
    border-radius: 50%;
    /* Circle */
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.btn-icon svg {
    pointer-events: none;
    /* Prevent clicks on SVG from bubbling weirdly */
}

/* Smart Tooltip Section */
.tooltip-container {
    position: relative;
    display: flex;
    align-items: center;
    cursor: help;
}

.info-icon {
    font-size: 1.2rem;
    color: var(--dim-text);
    opacity: 0.7;
    transition: all 0.3s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.03);
}

.tooltip-container:hover .info-icon {
    opacity: 1;
    color: #ffd60a;
    background: rgba(255, 214, 10, 0.1);
    border-color: rgba(255, 214, 10, 0.3);
    transform: scale(1.1);
}

.smart-tooltip {
    position: absolute;
    bottom: calc(100% + 15px);
    right: -10px;
    width: 280px;
    background: var(--tooltip-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    padding: 1.2rem;
    border-radius: 16px;
    box-shadow: var(--tooltip-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    pointer-events: none;
}

.tooltip-container:hover .smart-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.smart-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 20px;
    border-width: 8px;
    border-style: solid;
    border-color: var(--tooltip-bg) transparent transparent transparent;
}

.smart-tooltip .warning-title {
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #ffd60a;
    font-size: 0.95rem;
}

.smart-tooltip p {
    font-size: 0.85rem;
    color: var(--text-color);
    line-height: 1.5;
    margin: 0;
}

.footer-links-container {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    text-align: center;
}

.kofi-link-alt {
    opacity: 0.5;
    font-size: 0.8rem;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.3s;
}

.kofi-link-alt:hover {
    opacity: 1;
    color: var(--primary-color);
}

/* Settings Modal Styles */
.settings-content {
    max-width: 500px;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.02);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--secondary-color);
}

.settings-grid {
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.settings-section h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: 0.9;
}

.setting-item {
    margin-bottom: 1.5rem;
}

.setting-item:last-child {
    margin-bottom: 0;
}

.setting-item label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--dim-text);
    font-size: 0.9rem;
    font-weight: 600;
}

.segmented-control {
    display: flex;
    background: var(--glass-bg);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    gap: 4px;
}

.segmented-control.three-way .segment-btn {
    flex: 1;
}

.segment-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--dim-text);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: var(--font-heading);
    font-weight: 600;
    transition: all 0.2s ease;
}

.segment-btn:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.segment-btn.active {
    background: var(--secondary-color);
    color: var(--reader-bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.segment-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--text-color);
    font-size: 0.9rem;
}

.settings-select {
    width: 100%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    font-family: var(--font-heading);
    font-size: 1rem;
    cursor: pointer;
    appearance: none;

    /* Using a simple encoded SVG chevron for the select arrow */
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23666%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 0.65em auto;
}

.full-width {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Premium Animations */
.btn-animate {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.btn-animate:active {
    transform: scale(0.95);
}

/* Hover Glow Effect */
.btn-animate::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 59, 48, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.4s ease, height 0.4s ease;
    z-index: 0;
    pointer-events: none;
}

.btn-animate:hover::after {
    width: 150%;
    height: 150%;
}

/* Ensure content is above the glow */
.btn-animate span,
.btn-animate svg,
.btn-animate path {
    position: relative;
    z-index: 1;
}

/* Improved Toggle Button inside Modal */
#themeToggle .icon-wrapper svg {
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

#themeToggle:hover .icon-wrapper svg {
    transform: rotate(15deg);
}

/* Stats Dashboard Styles */
.stats-content {
    max-width: 650px;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.stats-dashboard {
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Stats Cards */
.stats-cards-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    text-align: center;
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
}

.stat-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--secondary-color);
    font-family: var(--font-heading);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--dim-text);
    margin-top: 0.2rem;
}

/* Achievements */
.achievements-scroll {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 1rem;
    scrollbar-width: thin;
}

.achievement-badge {
    min-width: 140px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    opacity: 0.5;
    filter: grayscale(1);
    transition: all 0.3s;
}

.achievement-badge.unlocked {
    opacity: 1;
    filter: none;
    border-color: var(--primary-color);
    background: rgba(255, 59, 48, 0.05);
}

.badge-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    display: block;
}

.badge-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--secondary-color);
    display: block;
    margin-bottom: 0.2rem;
}

.badge-desc {
    font-size: 0.75rem;
    color: var(--dim-text);
}

/* History List */
.history-section {
    flex: 1;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.small-select {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-color);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    cursor: pointer;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    max-height: 250px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.8rem 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    font-size: 0.9rem;
}

.history-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.history-date {
    font-size: 0.75rem;
    color: var(--dim-text);
}

.history-source {
    font-weight: 600;
    color: var(--secondary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.history-source-tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    font-weight: 700;
}

.tag-pdf {
    background: rgba(255, 59, 48, 0.2);
    color: #ff3b30;
}

.tag-url {
    background: rgba(0, 122, 255, 0.2);
    color: #007aff;
}

.tag-text {
    background: rgba(52, 199, 89, 0.2);
    color: #34c759;
}

.history-stat {
    font-family: var(--font-mono);
    color: var(--dim-text);
    text-align: right;
}

/* Warning Footer */
.warning-footer {
    background: rgba(255, 214, 10, 0.1);
    /* Yellow tint */
    padding: 1rem 2rem;
    text-align: center;
    font-size: 0.8rem;
    color: #ffd60a;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-top: 1px solid rgba(255, 214, 10, 0.2);
}

/* Header right group */
.header-right {
    display: flex;
    gap: 0.5rem;
}

@media (max-width: 600px) {
    .stats-cards-row {
        grid-template-columns: 1fr;
    }
}

/* Collapsible Stats Section */
.collapsible-section {
    margin-top: 1.5rem;
    overflow: hidden;
    transition: all 0.3s ease;
    border-radius: 16px;
    /* Smooth corners */
}

.collapsible-header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: transparent;
    border: none;
    color: var(--text-color);
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}

.collapsible-header:hover {
    background: rgba(255, 255, 255, 0.03);
}

.collapsible-content {
    padding: 0 1.5rem 1.5rem 1.5rem;
    border-top: 1px solid var(--glass-border);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stats-grid-dashboard {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    margin-top: 1rem;
}

.stats-summary-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: 1px solid var(--glass-border);
}

@media (max-width: 600px) {
    .stats-summary-row {
        grid-template-columns: 1fr;
    }
}

/* --- Auth & Library Styles --- */

/* Auth Page Specifics */
/* --- Auth & Library Styles --- */

/* Auth Page Specifics */
body.auth-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-color);
    margin: 0;
    font-family: 'Outfit', sans-serif;
    position: relative;
    overflow: hidden;
}

.auth-bg-glow {
    position: fixed;
    top: -30%;
    left: 50%;
    transform: translateX(-50%);
    width: 800px;
    height: 800px;
    background: radial-gradient(circle, rgba(255, 59, 48, 0.12) 0%, rgba(255, 59, 48, 0.02) 40%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* Keyframes for Authentication Animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.auth-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    padding: 4rem;
    background: rgba(12, 12, 12, 0.85);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 24px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
    animation: fadeInUp 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
    text-align: center;
}

.auth-header {
    text-align: center;
    margin-bottom: 2.5rem;
}

.brand img {
    border-radius: 24px;
    /* Rounded logo container if square, or just smooth edges */
    box-shadow: 0 0 20px rgba(255, 59, 48, 0.2);
    /* Subtle glow matching brand */
    margin-bottom: 1.5rem !important;
    transition: transform 0.5s ease;
}

.brand img.auth-brand-logo {
    border-radius: 50%;
}

.auth-brand-logo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    height: 72px;
    width: 72px;
}

.brand img:hover {
    transform: scale(1.05) rotate(5deg);
}

.auth-title {
    font-size: 2rem;
    color: white;
    font-weight: 700;
    margin-top: 0.5rem;
    letter-spacing: -0.03em;
}

.auth-tagline {
    color: var(--dim-text);
    font-size: 0.95rem;
    margin-bottom: 2rem;
    line-height: 1.5;
}

/* Google Sign-in Button - Premium Style */
.btn-google-pro {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
    padding: 1.1rem 1.75rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s ease;
}

.btn-google-pro:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(255, 59, 48, 0.35);
    transform: translateY(-2px);
}

.btn-google-pro .btn-google-icon {
    flex-shrink: 0;
}

.auth-oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 360px;
    margin: 0 auto;
}

.auth-oauth-buttons .btn-google-pro,
.auth-oauth-buttons .btn-x-pro,
.auth-oauth-buttons .btn-azure-pro,
.auth-oauth-buttons .btn-discord-pro {
    margin: 0;
    max-width: none;
    justify-content: center;
    padding: 1.1rem 1.75rem;
}

/* Icon + label centered as one unit inside the full-width button */
.auth-oauth-buttons .btn-oauth-inner {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
}

.auth-oauth-buttons .btn-google-icon,
.auth-oauth-buttons .btn-x-icon,
.auth-oauth-buttons .btn-azure-icon,
.auth-oauth-buttons .btn-discord-icon {
    display: block;
    flex-shrink: 0;
}

/* X (Twitter) sign-in — matches auth card width */
.btn-x-pro {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1.1rem 1.75rem;
    background: #000;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s ease;
}

.btn-x-pro:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(255, 59, 48, 0.35);
    transform: translateY(-2px);
}

.btn-x-pro .btn-x-icon {
    flex-shrink: 0;
}

/* Microsoft (Azure / Entra) sign-in */
.btn-azure-pro {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1.1rem 1.75rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s ease;
}

.btn-azure-pro:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(255, 59, 48, 0.35);
    transform: translateY(-2px);
}

.btn-azure-pro .btn-azure-icon {
    flex-shrink: 0;
}

/* Discord sign-in */
.btn-discord-pro {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    width: 100%;
    padding: 1.1rem 1.75rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s ease;
}

.btn-discord-pro:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 8px 24px rgba(255, 59, 48, 0.35);
    transform: translateY(-2px);
}

.btn-discord-pro .btn-discord-icon {
    flex-shrink: 0;
}

.flashes {
    list-style: none;
    padding: 0;
    margin-bottom: 1.5rem;
}

.flash {
    padding: 1rem;
    border-radius: 16px;
    margin-bottom: 0.8rem;
    font-size: 0.9rem;
    text-align: center;
    animation: fadeInUp 0.4s ease forwards;
}

.flash.error {
    background: rgba(255, 59, 48, 0.1);
    color: #ff453a;
    border: 1px solid rgba(255, 59, 48, 0.2);
}

.flash.success {
    background: rgba(50, 215, 75, 0.1);
    color: #32d74b;
    border: 1px solid rgba(50, 215, 75, 0.2);
}

/* Form Styles */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    text-align: left;
    /* Keep inputs left-aligned for readability */
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    color: #888;
    font-weight: 500;
    margin-left: 0.5rem;
    /* Align with rounded input */
}

.form-group input {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem 1.2rem;
    border-radius: 50px;
    /* Fully rounded inputs */
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

.form-group input:focus {
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.1);
}

.btn-primary.full-width {
    width: 100%;
    border-radius: 50px;
    /* Fully rounded button */
    padding: 1rem;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: var(--primary-color);
    border: none;
    color: white;
    box-shadow: 0 10px 20px rgba(255, 59, 48, 0.3);
    /* Glow effect */
    transition: all 0.3s ease;
}

.btn-primary.full-width:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px rgba(255, 59, 48, 0.4);
}

.auth-footer {
    text-align: center;
    margin-top: 2rem;
    font-size: 0.9rem;
    color: #666;
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

.auth-footer a:hover {
    color: white;
    text-decoration: underline;
}

/* User Profile in Header */
.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    background: transparent;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50px;
    transition: 0.2s;
}

.user-profile-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    color: white;
}

.user-avatar-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

/* Library Grid */
.library-content {
    max-width: 900px;
    height: 80vh;
    display: flex;
    flex-direction: column;
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-top: 1.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.library-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.2rem;
    transition: 0.3s;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 180px;
    position: relative;
    overflow: hidden;
}

.library-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.08);
}

.lib-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.8;
}

.lib-title {
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.lib-meta {
    font-size: 0.8rem;
    color: var(--dim-text);
}

.lib-progress-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    margin-top: auto;
    overflow: hidden;
}

.lib-progress-fill {
    height: 100%;
    background: var(--primary-color);
}


.full-width {
    width: 100%;
}

/* Sidebar Layout */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    background-color: var(--bg-color);
    overflow: hidden;
}

.sidebar {
    width: 320px;
    background: linear-gradient(180deg, #09090d 0%, #10070a 45%, #1a0507 100%);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    padding: 1.8rem 1.2rem;
    height: 100%;
    z-index: 10;
    flex-shrink: 0;
    transition: width 0.3s ease;
}

.sidebar.collapsed {
    width: 92px;
    padding-left: 0.8rem;
    padding-right: 0.8rem;
}

.sidebar-header {
    margin-bottom: 1.8rem;
    padding: 0 0.5rem 1.2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-header-top {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.55rem;
}

.sidebar-header .logo {
    font-size: 1.5rem;
    text-decoration: none;
    color: var(--text-color);
    display: inline-block;
}

.sidebar-header .logo .logo-short {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: transparent;
    box-shadow: none;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

.sidebar-header .logo .logo-short img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.sidebar-toggle {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.04);
    color: #d8e0ed;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.2s ease, background-color 0.2s ease;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.32);
}

.sidebar-toggle:hover {
    border-color: rgba(255, 59, 48, 0.45);
    background: rgba(255, 59, 48, 0.12);
}

.sidebar-toggle i,
.sidebar-toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.22s ease;
}

.sidebar-toggle:hover .sidebar-toggle-open,
.sidebar-toggle:hover .sidebar-toggle-open svg {
    transform: translateX(-1px) scale(1.08);
}

.sidebar-toggle:hover .sidebar-toggle-closed,
.sidebar-toggle:hover .sidebar-toggle-closed svg {
    transform: translateX(1px) scale(1.08);
}

.sidebar-toggle .sidebar-toggle-closed {
    display: none;
}

.sidebar-tile-grid {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    flex: 0 0 auto;
    overflow-y: auto;
    padding-top: 0.3rem;
}

.sidebar-nav-secondary {
    padding-top: 0.35rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem 1.05rem;
    border-radius: 12px;
    color: var(--dim-text);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    font-size: 1rem;
    border: 1px solid transparent;
    transform: translateX(0);
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    transform: translateX(3px);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(255, 59, 48, 0.22) 0%, rgba(255, 59, 48, 0.08) 100%);
    color: #ffffff;
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: inset 4px 0 0 var(--primary-color);
}

.nav-item i,
.nav-item svg {
    width: 19px;
    height: 19px;
    transition: transform 0.24s ease, color 0.24s ease, filter 0.24s ease;
    transform-origin: center;
}

.nav-item:hover i,
.nav-item:hover svg {
    transform: translateX(2px) scale(1.08);
    color: #f3f7ff;
    filter: drop-shadow(0 0 8px rgba(255, 89, 80, 0.28));
}

.nav-item.active i,
.nav-item.active svg {
    transform: scale(1.06);
    color: #ffffff;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-top: 1.05rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: auto;
    position: relative;
}

/* Wrapper so mobile can show a second row of tiles; desktop layout unchanged */
.sidebar-footer-nav {
    display: contents;
}

.sidebar-collapse-row {
    position: absolute;
    top: -18px;
    right: -17px;
    padding: 0;
    display: block;
}

.nav-item-small {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.8rem;
    border-radius: 6px;
    color: var(--dim-text);
    text-decoration: none;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    transform: translateX(0);
}

.nav-item-small:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.03);
    transform: translateX(3px);
}

.nav-item-small i,
.nav-item-small svg {
    width: 16px;
    height: 16px;
    transition: transform 0.24s ease, color 0.24s ease;
}

.nav-item-small:hover i,
.nav-item-small:hover svg {
    transform: translateX(2px) scale(1.08);
    color: #f3f7ff;
}

.sidebar-sign-out-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.35rem 0.2rem 0;
    margin-top: 0.15rem;
}

.sidebar-sign-out {
    display: inline-flex;
    align-items: center;
    gap: 0.42rem;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.01em;
    color: rgba(252, 165, 165, 0.92);
    text-decoration: none;
    padding: 0.28rem 0.5rem;
    border-radius: 8px;
    border: none;
    background: transparent;
    transition: color 0.15s ease, background 0.15s ease;
}

.sidebar-sign-out:hover {
    color: #fecaca;
    background: rgba(255, 59, 48, 0.1);
}

.sidebar-sign-out-icon,
.sidebar-sign-out-icon svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    flex-shrink: 0;
}

.sidebar.collapsed .sidebar-sign-out-label {
    display: none;
}

.sidebar.collapsed .sidebar-sign-out {
    justify-content: center;
    padding: 0.5rem 0.35rem;
}

.sidebar.collapsed .sidebar-sign-out-icon,
.sidebar.collapsed .sidebar-sign-out-icon svg {
    width: 17px;
    height: 17px;
}

.sidebar.collapsed .sidebar-header {
    padding-left: 0;
    padding-right: 0;
}

.sidebar.collapsed .sidebar-header .logo {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    margin: 0 auto;
}

.sidebar.collapsed .sidebar-header .logo .logo-full,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-item-small span {
    display: none;
}

.sidebar.collapsed .sidebar-header .logo .logo-short {
    display: inline-flex;
}

.sidebar.collapsed .sidebar-header-top {
    width: 100%;
    justify-content: center;
}

.sidebar.collapsed .sidebar-toggle .sidebar-toggle-open {
    display: none;
}

.sidebar.collapsed .sidebar-toggle .sidebar-toggle-closed {
    display: inline;
}

.sidebar.collapsed .sidebar-nav {
    align-items: center;
}

.sidebar.collapsed .nav-item {
    width: 100%;
    justify-content: center;
    padding-left: 0.55rem;
    padding-right: 0.55rem;
    transform: none;
}

.sidebar.collapsed .nav-item:hover {
    transform: none;
}

.sidebar.collapsed .nav-item:hover i,
.sidebar.collapsed .nav-item:hover svg {
    transform: translateY(-1px) scale(1.1);
}

.sidebar.collapsed .nav-item.active {
    box-shadow: none;
    border-color: rgba(255, 59, 48, 0.55);
}

.sidebar.collapsed .sidebar-footer {
    align-items: center;
    margin-top: auto;
}

.sidebar.collapsed .nav-item-small {
    width: 100%;
    justify-content: center;
    transform: none;
}

.sidebar.collapsed .nav-item-small:hover {
    transform: none;
}

.sidebar.collapsed .sidebar-collapse-row {
    right: -17px;
}

.main-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2.2rem 2.4rem;
    position: relative;
    max-width: 100%;
    margin: 0;
    width: 100%;
    transition: padding 0.3s ease;
}

.app-layout.sidebar-collapsed .main-content {
    padding-left: 2rem;
    padding-right: 2rem;
}

/* App shell: phones & tablets — top bar, centered brand & nav */
@media (max-width: 900px) {
    /* Whole shell scrolls (not only main); keeps “WPM Reader” sticky while nav tiles scroll away */
    body:has(.app-layout) {
        min-height: 100vh;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .app-layout {
        flex-direction: column;
        min-height: 100vh;
        height: auto;
        overflow: visible;
    }

    .app-layout > .sidebar {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        margin-inline: 0;
        align-self: stretch;
    }

    .sidebar {
        width: 100%;
        max-width: 100%;
        height: auto;
        /* Space for title bar: fixed below removes it from flex flow */
        padding: calc(3.25rem + env(safe-area-inset-top, 0px)) 0.5rem 1rem;
        border-right: none;
        border-bottom: 1px solid var(--glass-border);
        align-items: stretch;
        box-sizing: border-box;
        overflow: visible;
    }

    .sidebar-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 40;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: calc(env(safe-area-inset-top, 0px) + 0.35rem) 0.5rem 0.85rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        background: linear-gradient(180deg, #09090d 0%, #0c080a 55%, #09090d 100%);
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
        box-sizing: border-box;
    }

    .sidebar-header-top {
        justify-content: center;
        width: 100%;
    }

    .sidebar-header .logo {
        display: block;
        width: 100%;
        max-width: none;
        font-size: clamp(1.35rem, 4.2vw, 1.65rem);
        letter-spacing: -0.02em;
        text-align: center;
        margin: 0 auto;
    }

    .sidebar-toggle {
        display: none;
    }

    .nav-item-billing-desktop-only {
        display: none !important;
    }

    .sidebar-tile-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 0.4rem;
        flex: 0 0 auto;
        width: 100%;
        min-height: 0;
        align-items: stretch;
    }

    .sidebar-nav-primary,
    .sidebar-nav-secondary {
        display: contents;
    }

    .sidebar-nav {
        flex: 0 0 auto;
        overflow: visible;
        overflow-y: visible;
        padding: 0;
        margin: 0;
        gap: 0;
        width: auto;
        max-width: none;
        box-sizing: border-box;
    }

    .nav-item {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.28rem;
        padding: 0.55rem 0.35rem 0.48rem;
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.04);
        font-size: clamp(0.62rem, 2.8vw, 0.72rem);
        font-weight: 600;
        transform: none;
        text-align: center;
        box-sizing: border-box;
    }

    .nav-item span {
        display: block;
        line-height: 1.15;
        text-align: center;
    }

    .nav-item i,
    .nav-item svg {
        width: 18px;
        height: 18px;
    }

    .nav-item:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.16);
    }

    .nav-item:hover i,
    .nav-item:hover svg {
        transform: none;
    }

    .sidebar .nav-item.active {
        background: linear-gradient(180deg, rgba(255, 59, 48, 0.22) 0%, rgba(255, 59, 48, 0.08) 100%);
        border-color: rgba(255, 59, 48, 0.55);
        color: #fff;
        box-shadow: 0 0 0 1px rgba(255, 59, 48, 0.35), 0 8px 22px rgba(255, 59, 48, 0.12);
    }

    .sidebar .nav-item.active i,
    .sidebar .nav-item.active svg {
        color: #fff;
    }

    .sidebar-footer {
        display: contents;
        margin-top: 0;
        padding-top: 0;
        margin-bottom: 0;
        border-top: none;
        gap: 0;
    }

    .sidebar-footer .sidebar-collapse-row {
        display: none;
    }

    .sidebar-footer-faqs-desktop {
        display: none;
    }

    .sidebar-footer-nav {
        display: contents;
    }

    /* Match primary .nav-item mobile “tile” look */
    .sidebar-footer-nav .nav-item-small {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.28rem;
        padding: 0.55rem 0.3rem 0.48rem;
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        background: rgba(255, 255, 255, 0.04);
        font-size: clamp(0.55rem, 2.2vw, 0.68rem);
        font-weight: 600;
        transform: none;
        text-align: center;
        box-sizing: border-box;
        color: var(--dim-text);
    }

    .sidebar-footer-nav .nav-item-small span {
        display: block;
        line-height: 1.12;
        text-align: center;
        hyphens: auto;
        overflow-wrap: anywhere;
    }

    .sidebar-footer-nav .nav-item-small i,
    .sidebar-footer-nav .nav-item-small svg {
        width: 18px;
        height: 18px;
    }

    .sidebar-footer-nav .nav-item-small:hover {
        transform: none;
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.16);
        color: var(--text-color);
    }

    .sidebar-footer-nav .nav-item-small:hover i,
    .sidebar-footer-nav .nav-item-small:hover svg {
        transform: none;
    }

    .sidebar-sign-out-wrap {
        grid-column: 3;
        grid-row: 3;
        display: flex;
        justify-content: center;
        align-items: flex-start;
        width: 100%;
        margin: 0;
        padding: 0.1rem 0 0;
        justify-self: stretch;
    }

    .sidebar-sign-out {
        font-size: clamp(0.62rem, 2.3vw, 0.74rem);
        font-weight: 500;
        color: rgba(252, 129, 129, 0.95);
        padding: 0.22rem 0.35rem;
    }

    .sidebar-sign-out:hover {
        color: #fecaca;
        background: rgba(255, 59, 48, 0.07);
    }

    .sidebar-sign-out-icon {
        display: none;
    }

    .main-content {
        flex: 1 0 auto;
        padding: 0.95rem 0.9rem 1.2rem;
        overflow-x: clip;
        overflow-y: visible;
    }
}

/* Library Page */
.library-container {
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding-right: 0;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.45rem;
}

.header-content h1 {
    font-size: clamp(2.2rem, 3vw, 3.4rem);
    letter-spacing: -0.03em;
    line-height: 0.98;
    margin-bottom: 0.45rem;
}

.header-content .text-dim {
    font-size: 1.05rem;
}

.library-add-btn {
    min-width: 170px;
    padding: 0.85rem 1.2rem;
    border-radius: 12px;
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    border: 1px solid rgba(255, 255, 255, 0.75);
    background: linear-gradient(180deg, #ffffff 0%, #f2f5fa 100%);
    color: #0a0e15;
    font-weight: 700;
    box-shadow:
        0 10px 24px rgba(0, 0, 0, 0.3),
        0 8px 18px rgba(255, 59, 48, 0.14),
        0 0 0 1px rgba(255, 255, 255, 0.45) inset;
    transition: transform 0.24s ease, box-shadow 0.24s ease, border-color 0.24s ease, filter 0.24s ease;
    animation: addDocBtnPulse 3.2s ease-in-out infinite;
}

.library-add-btn::before {
    content: "";
    position: absolute;
    inset: -30% auto -30% -80%;
    width: 48%;
    transform: skewX(-18deg);
    background: linear-gradient(90deg,
            rgba(255, 255, 255, 0) 0%,
            rgba(255, 255, 255, 0.8) 48%,
            rgba(255, 255, 255, 0) 100%);
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}

.library-add-btn::after {
    content: "";
    position: absolute;
    inset: auto -2px -2px -2px;
    height: 42%;
    border-radius: 0 0 12px 12px;
    background: linear-gradient(180deg, rgba(255, 75, 63, 0) 0%, rgba(255, 75, 63, 0.16) 100%);
    z-index: 0;
}

.library-add-btn:hover {
    transform: translateY(-2px);
    background: linear-gradient(180deg, #ffffff 0%, #f6f8fd 100%);
    border-color: rgba(255, 255, 255, 0.95);
    box-shadow:
        0 16px 32px rgba(0, 0, 0, 0.35),
        0 18px 38px rgba(255, 59, 48, 0.46),
        0 0 34px rgba(255, 59, 48, 0.42),
        0 0 0 3px rgba(255, 59, 48, 0.2),
        0 0 0 1px rgba(255, 255, 255, 0.58) inset,
        0 0 28px rgba(255, 90, 80, 0.26);
    filter: saturate(1.03);
    animation-duration: 2.1s;
}

.library-add-btn:hover::before {
    opacity: 1;
    animation: addDocBtnShimmer 0.85s ease;
}

.library-add-btn:active {
    transform: translateY(0);
    box-shadow:
        0 8px 18px rgba(0, 0, 0, 0.26),
        0 0 0 1px rgba(255, 255, 255, 0.45) inset;
}

.library-add-btn:focus-visible {
    outline: none;
    box-shadow:
        0 12px 26px rgba(0, 0, 0, 0.33),
        0 0 0 3px rgba(255, 59, 48, 0.32),
        0 0 0 1px rgba(255, 255, 255, 0.55) inset;
}

.library-add-btn i {
    width: 17px;
    height: 17px;
    position: relative;
    z-index: 2;
    transition: transform 0.24s ease;
}

.library-add-btn:hover i {
    transform: rotate(90deg) scale(1.08);
}

.library-add-btn span,
.library-add-btn {
    position: relative;
    z-index: 2;
}

@keyframes addDocBtnShimmer {
    0% {
        transform: translateX(0) skewX(-18deg);
    }

    100% {
        transform: translateX(340%) skewX(-18deg);
    }
}

@keyframes addDocBtnPulse {
    0%,
    100% {
        box-shadow:
            0 10px 24px rgba(0, 0, 0, 0.3),
            0 0 0 1px rgba(255, 255, 255, 0.45) inset;
    }

    50% {
        box-shadow:
            0 14px 28px rgba(0, 0, 0, 0.34),
            0 0 0 1px rgba(255, 255, 255, 0.54) inset,
            0 0 18px rgba(255, 88, 77, 0.16);
    }
}

@media (prefers-reduced-motion: reduce) {
    .library-add-btn,
    .library-add-btn::before,
    .library-add-btn i {
        animation: none !important;
        transition: none !important;
    }
}

.search-container {
    background: #0b0f15;
    border: 1px solid #1f2732;
    border-radius: 12px;
    padding: 0.95rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1.6rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-container:focus-within {
    border-color: rgba(255, 59, 48, 0.5);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.13);
}

.search-icon {
    color: #747f8f;
    width: 21px;
    height: 21px;
}

.search-input {
    background: transparent;
    border: none;
    color: var(--text-color);
    font-size: 1.05rem;
    flex: 1;
    outline: none;
    font-family: var(--font-heading);
}

.search-input::placeholder {
    color: #7d8390;
}

.library-filter-row {
    margin-bottom: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
}

.library-filter-advanced-btn {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    height: 40px;
    padding: 0 1rem;
    border-radius: 10px;
    border: 1px solid #2f3a4a;
    background: linear-gradient(180deg, #121a26 0%, #0c121c 100%);
    color: #d4dce8;
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.library-filter-advanced-btn:hover {
    border-color: rgba(255, 59, 48, 0.45);
    background: #101826;
}

.library-filter-advanced-btn[aria-expanded="true"] {
    border-color: rgba(255, 59, 48, 0.55);
    box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.12);
}

.library-filter-advanced-btn i,
.library-filter-advanced-btn svg {
    width: 16px;
    height: 16px;
    color: #ff8a80;
}

.library-filters-advanced {
    display: contents;
}

.library-filters-advanced .library-filter-select,
.library-filters-advanced .library-date-custom,
.library-filters-advanced .library-filter-clear {
    flex: 0 0 190px;
    min-width: 170px;
}

.library-filters-advanced .library-date-custom {
    flex: 0 0 250px;
    min-width: 220px;
}

.library-filters-advanced .library-filter-clear {
    flex: 0 0 auto;
    min-width: unset;
}

.library-filter-search {
    flex: 1 1 320px;
    min-width: 220px;
    height: 40px;
    background: #0b0f15;
    border: 1px solid #1f2732;
    border-radius: 10px;
    padding: 0.4rem 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    min-width: 0;
}

.library-filter-select {
    flex: 0 0 190px;
    min-width: 170px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid #2a3341;
    background: #0a1018;
    color: #d7deea;
    font-family: var(--font-heading);
    font-size: 0.92rem;
    padding: 0 0.8rem;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.library-filter-select:focus {
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

.library-filter-clear {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    border-radius: 10px;
    padding: 0 0.95rem;
    text-decoration: none;
    white-space: nowrap;
}

.library-date-custom {
    display: none;
    align-items: center;
    gap: 0.5rem;
    flex: 0 0 250px;
    min-width: 220px;
    position: relative;
}

.library-date-custom.visible {
    display: inline-flex;
}

.library-date-picker-btn {
    width: 100%;
    height: 40px;
    border-radius: 10px;
    border: 1px solid #2a3341;
    background: #0a1018;
    color: #d7deea;
    font-family: var(--font-heading);
    font-size: 0.92rem;
    padding: 0 0.8rem;
    outline: none;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.library-date-picker-btn:hover {
    border-color: #3b4758;
    background: #0e1520;
}

.library-date-picker-btn:focus,
.library-date-picker-btn.is-open {
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

.library-date-picker-proxy {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
    border: 0;
    padding: 0;
}

.flatpickr-calendar.library-calendar-theme {
    background: linear-gradient(180deg, #0b1018 0%, #070b11 100%);
    border: 1px solid #2b3443;
    border-radius: 14px;
    box-shadow: 0 20px 55px rgba(0, 0, 0, 0.52);
    padding: 0.4rem;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-months {
    margin-bottom: 0.2rem;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-month {
    color: #eaf0fa;
    fill: #eaf0fa;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-weekday {
    color: #8f9db3;
    font-weight: 600;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-day {
    color: #d8e0ec;
    border-radius: 9px;
    border-color: transparent;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-day:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: transparent;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-day.today {
    border-color: rgba(255, 59, 48, 0.62);
    color: #ff7c75;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-day.inRange {
    background: rgba(255, 59, 48, 0.2);
    border-color: transparent;
    box-shadow: none;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-day.startRange,
.flatpickr-calendar.library-calendar-theme .flatpickr-day.endRange,
.flatpickr-calendar.library-calendar-theme .flatpickr-day.selected {
    background: linear-gradient(180deg, #ff4a40 0%, #ff3328 100%);
    border-color: #ff3b30;
    color: #ffffff;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-prev-month,
.flatpickr-calendar.library-calendar-theme .flatpickr-next-month {
    fill: #9aa7ba;
}

.flatpickr-calendar.library-calendar-theme .flatpickr-prev-month:hover,
.flatpickr-calendar.library-calendar-theme .flatpickr-next-month:hover {
    fill: #ffffff;
}

.flatpickr-calendar.library-calendar-theme .numInputWrapper span {
    border-color: rgba(255, 255, 255, 0.12);
}

.flatpickr-calendar.library-calendar-theme .numInputWrapper span:hover {
    background: rgba(255, 255, 255, 0.12);
}

.library-date-input {
    height: 40px;
    border-radius: 10px;
    border: 1px solid #2a3341;
    background: #0a1018;
    color: #d7deea;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    padding: 0 0.7rem;
    outline: none;
}

.library-date-input:focus {
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

.library-date-sep {
    color: #8b93a2;
    font-size: 0.88rem;
}

.documents-shell {
    background: #080c12;
    border: 1px solid #222933;
    border-radius: 18px;
    min-height: 250px;
    padding: 1rem;
}

/* Document Grid - Switched to List/Horizontal Layout */
.document-grid {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
}

.doc-card {
    background: #05080f;
    border: 1px solid #252d39;
    border-radius: 14px;
    overflow: hidden;
    transition: border-color 0.2s ease, background 0.2s ease;
    text-decoration: none;
    color: inherit;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    column-gap: 0.85rem;
    row-gap: 0.5rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
}

.doc-card:hover {
    border-color: rgba(255, 255, 255, 0.18);
    background: #080d15;
}

.doc-card--text:hover,
.doc-card--url:hover,
.doc-card--file:hover {
    border-color: rgba(255, 59, 48, 0.22);
}

.doc-preview {
    grid-column: 1;
    grid-row: 1;
    height: 76px;
    width: 76px;
    background:
        radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.02) 48%, rgba(0, 0, 0, 0.5) 72%),
        linear-gradient(145deg, #151a22 0%, #0f141c 65%, #131923 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid #2b3443;
    flex-shrink: 0;
    align-self: center;
}

.doc-icon i,
.doc-icon svg {
    width: 22px;
    height: 22px;
    color: rgba(255, 255, 255, 0.5);
}

/* Source-type tiles: one family (primary red) so library matches sidebar accent */
.doc-card--text .doc-preview {
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 120, 100, 0.14), transparent 58%),
        linear-gradient(145deg, #141110 0%, #0e0c0c 62%, #121010 100%);
    border-color: rgba(255, 59, 48, 0.3);
}

.doc-card--text .doc-icon i,
.doc-card--text .doc-icon svg {
    color: #ff9f94;
    stroke: #ff9f94;
}

.doc-card--url .doc-preview {
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 59, 48, 0.2), transparent 58%),
        linear-gradient(145deg, #151011 0%, #0d0a0b 62%, #121010 100%);
    border-color: rgba(255, 59, 48, 0.38);
}

.doc-card--url .doc-icon i,
.doc-card--url .doc-icon svg {
    color: #ff6b60;
    stroke: #ff6b60;
}

.doc-card--file .doc-preview {
    background:
        radial-gradient(circle at 32% 28%, rgba(255, 90, 78, 0.12), transparent 58%),
        linear-gradient(145deg, #131011 0%, #0c0b0b 62%, #111010 100%);
    border-color: rgba(255, 59, 48, 0.26);
}

.doc-card--file .doc-icon i,
.doc-card--file .doc-icon svg {
    color: #ffb0a8;
    stroke: #ffb0a8;
}

.doc-card--no-delete {
    grid-template-columns: auto minmax(0, 1fr) auto;
}

.doc-demo-badge {
    display: inline-block;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #111;
    background: #e8d96a;
    padding: 0.12rem 0.45rem;
    border-radius: 4px;
    margin-right: 0.45rem;
    vertical-align: middle;
    line-height: 1.2;
}

.doc-info {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.28rem;
}

.doc-title {
    font-size: 0.97rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 100%;
    color: #f0f3f7;
    margin: 0;
}

.doc-badges {
    grid-column: 3;
    grid-row: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 0.35rem;
    flex-wrap: wrap;
    max-width: min(100%, 220px);
    align-self: center;
    justify-self: end;
}

.doc-delete-btn {
    grid-column: 4;
    grid-row: 1;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: transparent;
    color: #525d6e;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.18s ease;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
}

.doc-delete-btn i {
    width: 13px;
    height: 13px;
}

.doc-delete-btn:hover {
    border-color: rgba(255, 59, 48, 0.5);
    color: #ff6b63;
    background: rgba(255, 59, 48, 0.1);
}

.doc-delete-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.doc-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.22rem 0.58rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
}

.doc-status-badge.completed {
    color: #073b1f;
    background: #24d97b;
}

.doc-status-badge.in-progress {
    color: #ffd6a8;
    background: linear-gradient(180deg, rgba(255, 159, 67, 0.28) 0%, rgba(255, 123, 47, 0.2) 100%);
    border: 1px solid rgba(255, 153, 74, 0.5);
    box-shadow: inset 0 0 0 1px rgba(255, 194, 128, 0.15);
}

.doc-type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.32rem;
    padding: 0.22rem 0.52rem 0.22rem 0.45rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    white-space: nowrap;
    border: 1px solid rgba(106, 125, 153, 0.45);
    color: #b8c6dd;
    background: rgba(89, 102, 121, 0.2);
}

.doc-type-badge > svg,
.doc-type-badge .doc-type-badge-label {
    display: inline-block;
    vertical-align: middle;
}

.doc-type-badge > svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

.doc-type-badge.url {
    border-color: rgba(255, 59, 48, 0.42);
    color: #ff9a91;
    background: rgba(255, 59, 48, 0.12);
}

.doc-type-badge.file {
    border-color: rgba(255, 59, 48, 0.32);
    color: #ffc4be;
    background: rgba(255, 59, 48, 0.08);
}

.doc-type-badge.text {
    border-color: rgba(255, 59, 48, 0.36);
    color: #ffb8b0;
    background: rgba(255, 59, 48, 0.1);
}

.doc-meta {
    font-size: 0.82rem;
    color: #6b7585;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    row-gap: 0.2rem;
}

.doc-meta-extra,
.doc-meta-tail {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.doc-dot {
    opacity: 0.4;
}

.empty-state {
    width: 100%;
    text-align: center;
    min-height: 210px;
    padding: 3.5rem 1.8rem;
    background: #0b1018;
    border-radius: 14px;
    border: 1px dashed #2a3340;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.empty-icon {
    width: 48px;
    height: 48px;
    color: #727b89;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.empty-state h3 {
    font-size: clamp(1.4rem, 1.8vw, 1.9rem);
    color: #e8ecf2;
}

.empty-state p {
    margin-top: 0.35rem;
    color: #8791a0;
    font-size: 1.05rem;
}

.library-pagination {
    margin-top: 1rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.55rem;
}

.page-btn,
.page-number {
    min-width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid #2a3443;
    background: #0a1018;
    color: #d2d9e5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0 0.8rem;
    transition: all 0.2s ease;
}

.page-btn:hover,
.page-number:hover {
    border-color: rgba(255, 59, 48, 0.55);
    color: #fff;
    background: rgba(255, 59, 48, 0.12);
}

.page-number.active {
    border-color: rgba(255, 59, 48, 0.55);
    background: rgba(255, 59, 48, 0.18);
    color: #fff;
}

.page-btn.disabled {
    opacity: 0.45;
    cursor: default;
    pointer-events: none;
}

.page-size-control {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    margin-left: 0.25rem;
    padding: 0.2rem 0.25rem 0.2rem 0.5rem;
    border-radius: 10px;
    border: 1px solid #2a3443;
    background: #0a1018;
}

.page-size-control label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #9aa8bd;
    white-space: nowrap;
}

.page-size-select {
    height: 32px;
    border-radius: 8px;
    border: 1px solid #313b4b;
    background: #101825;
    color: #d7deea;
    font-family: var(--font-heading);
    font-size: 0.84rem;
    font-weight: 600;
    padding: 0 0.55rem;
    outline: none;
    cursor: pointer;
}

.page-size-select:focus {
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

/* Tablet-only: do not apply narrow sidebar width on phones (would leave empty space). */
@media (min-width: 901px) and (max-width: 1100px) {
    .sidebar {
        width: 280px;
    }

    .main-content {
        padding: 1.8rem;
    }
}

@media (max-width: 900px) {
    .library-header {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
        gap: 1rem;
    }

    .library-header .header-content {
        width: 100%;
        text-align: left;
    }

    .library-header .header-content h1,
    .library-header .header-content .text-dim {
        text-align: left;
    }

    .library-add-btn {
        width: 100%;
    }

    .library-filter-row {
        flex-direction: column;
        align-items: stretch;
        gap: 0.7rem;
    }

    .library-filter-search {
        flex: 1 1 auto;
        min-width: 0;
        width: 100%;
    }

    .library-filter-advanced-btn {
        display: flex;
        width: 100%;
        min-height: 44px;
        justify-content: center;
    }

    .library-filters-advanced {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0.85rem;
        padding: 1rem 1.05rem 1.05rem;
        border-radius: 14px;
        border: 1px solid #2a3342;
        background: linear-gradient(180deg, #0a1018 0%, #070b12 100%);
        box-sizing: border-box;
    }

    .library-filters-advanced.is-open {
        display: flex;
    }

    .library-filters-advanced .library-filter-select,
    .library-filters-advanced .library-date-custom,
    .library-filters-advanced .library-filter-clear {
        width: 100%;
        min-width: 0;
        flex: 0 0 auto;
    }

    .library-filters-advanced .library-filter-select {
        min-height: 44px;
        height: auto;
        padding-top: 0.15rem;
        padding-bottom: 0.15rem;
    }

    .library-filters-advanced .library-date-picker-btn {
        min-height: 44px;
    }

    .library-filters-advanced .library-filter-clear {
        justify-content: center;
        margin-top: 0.35rem;
        min-height: 44px;
        padding: 0 1rem;
    }

    .stats-v2-controls {
        flex-direction: column;
        align-items: stretch;
        gap: 0.7rem;
    }

    .stats-v2-controls .stats-filters-form {
        width: 100%;
    }

    .stats-v2-controls .stats-v2-export-btn {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }

    .doc-card {
        padding: 0.62rem 0.75rem;
        grid-template-columns: 2.85rem minmax(0, 1fr) auto;
        grid-template-rows: auto;
        column-gap: 0.55rem;
        row-gap: 0;
        align-items: center;
    }

    .doc-preview {
        width: 46px;
        height: 46px;
        align-self: center;
    }

    .doc-info {
        grid-column: 2;
        grid-row: 1;
        max-width: none;
        min-width: 0;
        gap: 0.15rem;
    }

    /* Una sola línea: menos altura; el % en .doc-meta indica avance */
    .doc-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.88rem;
        line-height: 1.25;
        -webkit-line-clamp: unset;
        -webkit-box-orient: unset;
        display: block;
    }

    .doc-meta {
        font-size: 0.76rem;
        color: #8b95a8;
        flex-wrap: nowrap;
        row-gap: 0;
        gap: 0.28rem;
    }

    /* Móvil: sin fecha; sin pastillas — icono + % bastan */
    .doc-meta-extra {
        display: none;
    }

    .doc-badges {
        display: none;
    }

    .doc-delete-btn {
        grid-column: 3;
        grid-row: 1;
        align-self: center;
        justify-self: end;
    }

    .library-pagination {
        justify-content: center;
        flex-wrap: wrap;
        gap: 0.35rem;
    }

    .page-size-control {
        width: 100%;
        justify-content: center;
        margin-left: 0;
    }

    .page-size-select {
        flex: 0 1 auto;
        max-width: 120px;
    }

    .library-date-input {
        flex: 1;
        min-width: 0;
    }
}

/* Modal specific overrides/additions */
.add-doc-modal-content {
    width: min(92vw, 920px);
    max-width: 920px;
    padding: 2.2rem;
    border-radius: 28px;
    background: linear-gradient(180deg, #090b10 0%, #05070c 100%);
    border: 1px solid rgba(255, 255, 255, 0.09);
}

.add-doc-modal-content h2 {
    font-size: clamp(2rem, 2.6vw, 3rem);
    margin-bottom: 1.4rem;
    letter-spacing: -0.02em;
}

.add-doc-modal-content .close-modal {
    top: 1.2rem;
    right: 1.3rem;
    font-size: 2.2rem;
}

.add-doc-tabs {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.35rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    margin-bottom: 1.3rem;
}

/* Custom delete confirmation modal */
.delete-confirm-content {
    width: min(92vw, 460px);
    max-width: 460px;
    padding: 1.65rem 1.5rem 1.35rem;
    border-radius: 20px;
    background: linear-gradient(180deg, #0c0f15 0%, #090c11 100%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    position: relative;
}

.delete-confirm-close {
    position: absolute;
    top: 0.65rem;
    right: 0.85rem;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.03);
    color: #d2d8e2;
    font-size: 1.45rem;
    line-height: 1;
    cursor: pointer;
}

.delete-confirm-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1px solid rgba(255, 59, 48, 0.35);
    background: rgba(255, 59, 48, 0.15);
    color: #ff7a73;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.95rem;
}

.delete-confirm-icon i {
    width: 19px;
    height: 19px;
}

.delete-confirm-content h3 {
    font-size: 1.25rem;
    letter-spacing: -0.015em;
    margin-bottom: 0.5rem;
}

.delete-confirm-content p {
    color: #9aa5b8;
    line-height: 1.55;
}

.delete-confirm-actions {
    margin-top: 1.2rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
}

.delete-confirm-actions .btn-secondary {
    min-width: 95px;
}

.delete-danger-btn {
    min-width: 165px;
    background: linear-gradient(180deg, #ff4f47 0%, #f33027 100%);
    color: #ffffff;
    box-shadow: 0 12px 24px rgba(255, 59, 48, 0.25);
}

.delete-danger-btn:hover {
    background: linear-gradient(180deg, #ff6159 0%, #ff3b30 100%);
}

.add-doc-tab-btn {
    border: none;
    background: transparent;
    color: #8b93a2;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    padding: 0.72rem 1.35rem;
    border-radius: 999px;
    cursor: pointer;
    transition: all 0.22s ease;
}

.add-doc-tab-btn:hover {
    color: #d9deea;
    background: rgba(255, 255, 255, 0.06);
}

.add-doc-tab-btn.active {
    color: #ffffff;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0.07) 100%);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
}

.add-doc-tab-content {
    display: none;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding-top: 1.25rem;
}

.add-doc-tab-content.active {
    display: block;
}

.add-doc-form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.source-pills {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.pill {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--dim-text);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.pill i {
    width: 14px;
    height: 14px;
}

.add-doc-form .input-field,
.add-doc-form .textarea-field {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.09);
    padding: 1.05rem 1.1rem;
    border-radius: 14px;
    color: var(--text-color);
    font-family: inherit;
    font-size: 1rem;
    transition: 0.2s;
}

.add-doc-form .input-field:focus,
.add-doc-form .textarea-field:focus {
    border-color: var(--primary-color);
    outline: none;
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 0 4px rgba(255, 59, 48, 0.12);
}

.add-doc-form .textarea-field {
    min-height: 220px;
    resize: vertical;
}

.add-doc-link-hint {
    margin: 0 0 0.35rem;
}

.add-doc-quota-summary {
    margin: 0.35rem 0 0.85rem;
    line-height: 1.45;
}

.add-doc-quota-summary strong {
    color: var(--text-color);
    font-weight: 600;
}

.add-doc-char-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.add-doc-char-row .add-doc-limit-hint {
    margin: 0;
    flex: 1 1 12rem;
}

.add-doc-char-count {
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    font-weight: 600;
}

.add-doc-char-count.is-near-limit {
    color: #e8b84a;
}

.add-doc-char-count.is-at-limit {
    color: var(--primary-color);
}

.add-doc-submit-btn,
.add-doc-save-btn {
    margin-top: 0.5rem;
}

.add-doc-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

.input-group {
    display: flex;
    gap: 0.7rem;
    align-items: center;
}

.input-icon {
    width: 18px;
    height: 18px;
    color: #8b93a2;
    margin-left: 0.2rem;
}

.input-group .input-field {
    flex: 1;
}

.add-doc-extraction-preview {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    margin-top: 0.55rem;
}

.add-doc-inline-status {
    margin-top: 0.7rem;
    border-radius: 11px;
    padding: 0.65rem 0.85rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid transparent;
}

.add-doc-inline-status.is-error {
    color: #ffc7c4;
    background: rgba(255, 59, 48, 0.12);
    border-color: rgba(255, 59, 48, 0.38);
}

.add-doc-inline-status.is-success {
    color: #c2f6da;
    background: rgba(36, 217, 123, 0.1);
    border-color: rgba(36, 217, 123, 0.34);
}

.add-doc-inline-status.is-info {
    color: #d0dcff;
    background: rgba(79, 129, 255, 0.12);
    border-color: rgba(79, 129, 255, 0.36);
}

.spinner {
    width: 17px;
    height: 17px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ffffff;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* Used by index.html flash toasts (inline animation: fadeOut …) */
@keyframes fadeOut {
    0%, 70% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        visibility: hidden;
    }
}

.add-doc-upload-status {
    margin-top: 0.75rem;
    text-align: center;
    line-height: 1.45;
}

.add-doc-upload-actions {
    margin-top: 0.85rem;
}

.add-doc-source-pills {
    margin-top: 0.45rem;
}

.preview-text-box {
    background: rgba(255, 255, 255, 0.02);
    padding: 1rem;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    max-height: 100px;
    overflow-y: auto;
}

.add-doc-upload-zone {
    min-height: 250px;
    border-radius: 16px;
    border-color: rgba(255, 255, 255, 0.14);
}

@media (max-width: 760px) {
    .add-doc-modal-content {
        padding: 1.25rem;
        border-radius: 22px;
    }

    .add-doc-tabs {
        width: 100%;
        justify-content: space-between;
    }

    .add-doc-tab-btn {
        flex: 1;
        padding: 0.66rem 0.8rem;
        font-size: 0.95rem;
        text-align: center;
    }

    .add-doc-form .textarea-field {
        min-height: 170px;
    }

    .add-doc-actions {
        grid-template-columns: 1fr;
    }
}

/* Reader focus mode for /read/<doc_id> sessions */
body.document-reading-mode .input-section {
    display: none;
}

.exit-reading-btn {
    position: fixed;
    top: max(0.85rem, calc(env(safe-area-inset-top, 0px) + 0.45rem));
    right: max(0.85rem, calc(env(safe-area-inset-right, 0px) + 0.45rem));
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(10, 10, 10, 0.72);
    color: #f2f2f2;
    text-decoration: none;
    font-size: 1.7rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
}

.exit-reading-btn:hover {
    background: rgba(255, 59, 48, 0.16);
    border-color: rgba(255, 59, 48, 0.6);
    color: #ffffff;
}

body.document-reading-mode header {
    display: none;
}

body.document-reading-mode {
    overflow-x: hidden;
}

body.document-reading-mode .app-container {
    width: 100%;
    max-width: 100%;
}

@media (max-width: 768px) {
    body.document-reading-mode .app-container {
        padding: 0;
        min-height: 100dvh;
        min-height: 100vh;
    }
}

body.document-reading-mode main {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    justify-content: center;
    align-items: center;
    gap: 2.1rem;
    padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
}

body.document-reading-mode .reader-display {
    flex: 0 0 auto;
    width: min(980px, calc(100vw - max(1.5rem, env(safe-area-inset-left, 0px)) - max(1.5rem, env(safe-area-inset-right, 0px))));
    height: min(56vh, 620px);
    min-height: 320px;
    border: none;
    box-shadow: none;
    background:
        radial-gradient(120% 90% at 50% 50%, rgba(255, 255, 255, 0.03), rgba(0, 0, 0, 0) 60%),
        transparent;
}

body.document-reading-mode .reader-display::before {
    top: calc(50% - 92px);
    height: 30px;
    opacity: 0.9;
}

body.document-reading-mode .reader-display::after {
    bottom: calc(50% - 92px);
    height: 30px;
    opacity: 0.9;
}

body.document-reading-mode .word-container {
    max-width: min(900px, calc(100vw - max(1.5rem, env(safe-area-inset-left, 0px)) - max(1.5rem, env(safe-area-inset-right, 0px))));
    position: relative;
}

@media (max-width: 768px) {
    body.document-reading-mode .word-container {
        max-width: calc(100vw - max(0.35rem, env(safe-area-inset-left, 0px)) - max(0.35rem, env(safe-area-inset-right, 0px)));
    }
}

body.document-reading-mode .word-container::before,
body.document-reading-mode .word-container::after {
    display: none;
}

body.document-reading-mode .word-container::before {
    display: none;
}

body.document-reading-mode .word-container::after {
    display: none;
}

body.document-reading-mode .controls-container {
    width: min(660px, 100%);
    min-height: auto;
    padding: 0.2rem 0;
    background: transparent;
    border: none;
    backdrop-filter: none;
}

body.document-reading-mode .settings-group.full-width {
    width: 100%;
    justify-content: center;
}

body.document-reading-mode .main-controls-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: min(620px, 100%);
    margin: 0 auto;
    gap: 0.72rem;
    padding: 0;
    transition: opacity 0.42s ease, transform 0.42s ease, filter 0.42s ease;
}

body.document-reading-mode .main-controls-row>div:first-child {
    display: none;
}

body.document-reading-mode .playback-controls.playback-primary {
    position: static;
    transform: none;
    min-width: 0;
    justify-content: center;
    gap: 0.88rem;
}

body.document-reading-mode .playback-controls.playback-primary .control-btn {
    width: 54px;
    height: 54px;
    background: radial-gradient(120% 120% at 30% 20%, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #f3f6ff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 26px rgba(0, 0, 0, 0.28);
}

body.document-reading-mode .playback-controls.playback-primary .control-btn:hover {
    transform: translateY(-2px) scale(1.02);
    border-color: rgba(255, 255, 255, 0.24);
    background: radial-gradient(120% 120% at 30% 20%, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.03));
}

body.document-reading-mode .playback-controls.playback-primary .control-btn.big-play {
    width: 82px;
    height: 82px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    background: rgba(7, 9, 13, 0.7);
    color: #ffffff;
    animation: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 14px 36px rgba(0, 0, 0, 0.45);
}

body.document-reading-mode .playback-controls.playback-primary .control-btn.big-play:hover {
    border-color: rgba(255, 59, 48, 0.72);
    box-shadow: 0 14px 36px rgba(255, 59, 48, 0.2);
    transform: translateY(-2px) scale(1.04);
}

body.document-reading-mode .focus-settings-btn svg {
    transition: transform 0.35s ease;
}

body.document-reading-mode .focus-settings-btn:hover svg {
    transform: rotate(30deg);
}

body.document-reading-mode .reader-dock-stack {
    width: 100%;
    max-width: min(620px, 100%);
    margin-left: auto;
    margin-right: auto;
    text-align: center;
}

body.document-reading-mode .reader-dock-wpm-row .wpm-control-container {
    margin-left: 0;
    margin-right: 0;
    justify-content: center;
}

body.document-reading-mode .reader-dock-wpm-row .wpm-control-group {
    min-width: 0;
    width: auto;
    max-width: min(340px, 92vw);
    margin-left: auto;
    margin-right: auto;
    justify-content: center;
    padding: 0.66rem 0.95rem;
    border-radius: 16px;
    border-color: rgba(255, 255, 255, 0.16);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02)),
        rgba(9, 11, 16, 0.6);
}

body.document-reading-mode .reader-dock-transport-row > .focus-settings-btn,
body.document-reading-mode .reader-dock-transport-row > .bookmarks-toolbar-btn {
    width: 48px;
    height: 48px;
    background: radial-gradient(120% 120% at 30% 20%, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #f3f6ff;
    flex-shrink: 0;
}

.bookmarks-modal .bookmarks-modal-content {
    max-width: min(440px, 94vw);
    max-height: min(78vh, 560px);
    display: flex;
    flex-direction: column;
    text-align: left;
}

.bookmarks-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.35rem;
}

.bookmarks-modal-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.bookmarks-modal-hint {
    font-size: 0.82rem;
    margin: 0 0 0.85rem;
    line-height: 1.4;
}

.bookmarks-add-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}

.bookmark-label-input {
    flex: 1 1 160px;
    min-width: 0;
    padding: 0.55rem 0.65rem;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: var(--glass-bg);
    color: var(--text-color);
    font-size: 0.88rem;
}

.bookmark-add-btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.bookmarks-list {
    flex: 1 1 auto;
    min-height: 120px;
    max-height: 42vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding-right: 0.15rem;
}

.bookmark-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.65rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
}

:root[data-theme="light"] .bookmark-row {
    border-color: rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.03);
}

.bookmark-row-main {
    flex: 1 1 auto;
    min-width: 0;
    cursor: pointer;
    text-align: left;
    background: none;
    border: 0;
    padding: 0;
    color: inherit;
    font: inherit;
}

.bookmark-row-title {
    font-weight: 600;
    font-size: 0.88rem;
    margin-bottom: 0.2rem;
    color: var(--secondary-color);
}

.bookmark-row-meta {
    font-size: 0.72rem;
    color: var(--dim-text);
    font-family: var(--font-mono);
}

.bookmark-row-snippet {
    font-size: 0.78rem;
    color: var(--dim-text);
    margin-top: 0.25rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.bookmark-delete-btn {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid rgba(255, 59, 48, 0.35);
    background: rgba(255, 59, 48, 0.08);
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bookmarks-empty,
.bookmarks-error {
    font-size: 0.82rem;
    margin: 0.5rem 0 0;
}

.bookmarks-error {
    color: var(--primary-color);
}

.bookmarks-modal .text-dim {
    color: var(--dim-text);
}

.bookmarks-filter-form {
    margin: 0 0 1rem;
    max-width: min(420px, 100%);
}

.bookmarks-filter-search {
    width: 100%;
    flex: 1 1 auto;
    min-width: 0;
}

.bookmarks-global-list {
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
    margin-top: 0.25rem;
}

.bookmark-global-label {
    margin: 0.2rem 0 0;
    font-size: 0.84rem;
    font-weight: 600;
    color: rgba(240, 243, 247, 0.92);
}

.bookmark-global-snippet {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.4;
    color: rgba(180, 190, 208, 0.82);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

:root[data-theme="light"] .bookmark-global-label {
    color: #1a1d24;
}

:root[data-theme="light"] .bookmark-global-snippet {
    color: rgba(70, 75, 85, 0.88);
}

body.document-reading-mode .wpm-step-btn {
    width: 34px;
    height: 34px;
    border-color: rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: #f3f6ff;
}

body.document-reading-mode .wpm-label {
    min-width: 42px;
    color: rgba(228, 233, 245, 0.54);
    letter-spacing: 0.1em;
}

body.document-reading-mode #wpmDisplay {
    min-width: 3.8ch;
    color: #ffffff;
    font-size: 1.12rem;
}

body.document-reading-mode.reading-active .main-controls-row {
    opacity: 0.26;
    transform: translateY(10px) scale(0.98);
    filter: saturate(0.82);
}

body.document-reading-mode.reading-active .main-controls-row:hover {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: none;
}

body.document-reading-mode .progress-control-wrap {
    width: min(620px, 100%);
    margin: 0 auto;
}

body.document-reading-mode .progress-control {
    width: 100%;
    margin: 0 auto;
    gap: 0.35rem;
    padding-bottom: 0.38rem;
}

body.document-reading-mode .progress-control input[type="range"] {
    order: 2;
}

body.document-reading-mode .progress-stats {
    order: 1;
    margin-top: 0;
    margin-bottom: 0.28rem;
    font-size: 1.03rem;
    color: rgba(231, 236, 248, 0.72);
}

body.document-reading-mode .progress-stats .stat-item:first-child {
    color: rgba(231, 236, 248, 0.6);
}

body.document-reading-mode .time-stat {
    font-weight: 600;
}

@media (min-width: 900px) {
    body.document-reading-mode .controls-container {
        width: min(920px, 100%);
    }

    /* Escritorio: misma jerarquía que el lector principal — play arriba, utilidades abajo */
    body.document-reading-mode .main-controls-row.reader-dock-row {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 0.95rem;
        width: min(880px, 100%);
        max-width: 100%;
        padding: 0.15rem 0 0.35rem;
    }

    body.document-reading-mode .reader-dock-transport-row .playback-controls.playback-primary {
        width: auto;
        max-width: min(420px, 100%);
        flex: none;
        justify-content: center;
        min-width: 0;
    }

    body.document-reading-mode .reader-dock-stack {
        width: 100%;
        max-width: min(520px, 100%);
        margin: 0 auto;
        text-align: center;
        flex: none;
    }

    body.document-reading-mode .reader-dock-wpm-row .wpm-control-container {
        width: auto;
        flex: 0 1 auto;
        margin-left: 0;
        margin-right: 0;
        justify-content: center;
    }

    body.document-reading-mode .reader-dock-wpm-row .wpm-control-group {
        width: auto;
        max-width: none;
        min-width: 0;
        justify-content: center;
    }
}

@media (max-width: 899px) {
    body.document-reading-mode .progress-stats {
        font-size: 0.78rem;
        gap: 0.45rem 0.65rem;
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 0.35rem;
    }

    body.document-reading-mode .progress-stats .stat-item {
        flex-wrap: wrap;
        justify-content: center;
    }

    body.document-reading-mode .time-stat .time-divider {
        display: none;
    }
}

@media (max-width: 700px) {
    .reader-display::before {
        top: calc(50% - 96px);
    }

    .reader-display::after {
        bottom: calc(50% - 96px);
    }

    body.document-reading-mode .reader-display {
        min-height: 250px;
    }

    body.document-reading-mode .controls-container {
        width: 100%;
    }

    body.document-reading-mode .word-container::before,
    body.document-reading-mode .word-container::after {
        display: none;
    }

    body.document-reading-mode .word-container::before {
        display: none;
    }

    body.document-reading-mode .word-container::after {
        display: none;
    }
}

/* Billing Page */
.billing-container {
    max-width: 900px;
    margin: 0 auto;
}

.billing-header {
    margin-bottom: 2rem;
}

.billing-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.billing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.billing-card {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 2rem;
    position: relative;
    overflow: hidden;
}

.current-plan {
    border-top: 4px solid var(--dim-text);
}

.badge {
    padding: 0.4rem 0.8rem;
    border-radius: 100px;
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-block;
    margin-bottom: 1rem;
}

.badge-free {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
}

.badge-premium {
    background: rgba(255, 59, 48, 0.15);
    color: var(--primary-color);
}

.upgrade-card {
    border-color: rgba(255, 59, 48, 0.3);
    background: linear-gradient(180deg, rgba(255, 59, 48, 0.05) 0%, rgba(20, 20, 20, 0) 100%);
}

.upgrade-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.price {
    display: flex;
    align-items: baseline;
}

.currency {
    font-size: 1.2rem;
    font-weight: 600;
}

.amount {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
}

.period {
    color: var(--dim-text);
    margin-left: 0.2rem;
}

.feature-list {
    list-style: none;
    margin-bottom: 2rem;
}

.feature-list li {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
    color: var(--text-color);
}

.feature-list li i {
    color: var(--primary-color);
    width: 18px;
    height: 18px;
}

.billing-history h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.history-list {
    background: var(--surface-color);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
}

/* FAQ Page */
.faq-page {
    width: min(1220px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.app-layout.sidebar-collapsed .faq-page {
    width: 100%;
    max-width: none;
}

.faq-hero-card {
    background:
        radial-gradient(circle at 86% -20%, rgba(255, 59, 48, 0.14), rgba(255, 59, 48, 0) 42%),
        linear-gradient(180deg, #0d1118 0%, #080c12 100%);
    border: 1px solid #273140;
    border-radius: 18px;
    padding: 1.28rem 1.32rem 1.2rem;
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.24);
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(260px, 0.9fr);
    align-items: end;
    gap: 1rem;
}

.faq-hero-card h1 {
    font-size: clamp(1.8rem, 3vw, 2.55rem);
    letter-spacing: -0.02em;
    margin-bottom: 0.45rem;
}

.faq-pill-row {
    margin-top: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: flex-end;
    align-content: flex-start;
}

.faq-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.13);
    background: rgba(255, 255, 255, 0.04);
    padding: 0.35rem 0.7rem;
    color: #d8e1ee;
    font-size: 0.82rem;
    font-weight: 600;
}

.faq-pill i {
    width: 14px;
    height: 14px;
    color: #ff6b62;
}

.faq-insight-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.95rem;
}

.faq-insight-card {
    background: linear-gradient(180deg, #09101a 0%, #070d16 100%);
    border: 1px solid #243041;
    border-radius: 14px;
    padding: 1rem 1rem 1.08rem;
    min-height: 182px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.faq-insight-card:hover {
    transform: translateY(-1px);
    border-color: #34465f;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.26);
}

.faq-insight-card h3 {
    font-size: 1rem;
    margin-bottom: 0.45rem;
    letter-spacing: -0.01em;
}

.faq-insight-card p {
    color: #9ea9bc;
    line-height: 1.55;
    font-size: 0.92rem;
}

.faq-accordion-panel {
    background: linear-gradient(180deg, #080c13 0%, #060b11 100%);
    border: 1px solid #222e3c;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

.faq-item {
    border-bottom: 1px solid #1d2530;
}

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

.faq-item summary {
    list-style: none;
    cursor: pointer;
    padding: 1rem 1.1rem;
    color: #edf2fb;
    font-weight: 600;
    font-size: 0.98rem;
    position: relative;
    padding-right: 2.3rem;
}

.faq-item summary::-webkit-details-marker {
    display: none;
}

.faq-item summary::after {
    content: "+";
    position: absolute;
    right: 1.05rem;
    top: 50%;
    transform: translateY(-50%);
    color: #ff7f77;
    font-size: 1.15rem;
    line-height: 1;
}

.faq-item[open] summary {
    background: rgba(255, 59, 48, 0.08);
}

.faq-item[open] summary::after {
    content: "−";
}

.faq-answer {
    padding: 0.05rem 1.1rem 1rem;
}

.faq-answer p,
.faq-answer li {
    color: #a0acbe;
    line-height: 1.6;
    font-size: 0.93rem;
}

.faq-answer ul {
    padding-left: 1rem;
}

.faq-note-card {
    border-radius: 14px;
    border: 1px solid #2f2832;
    background: linear-gradient(180deg, rgba(255, 59, 48, 0.08) 0%, rgba(255, 59, 48, 0.03) 100%);
    padding: 1rem 1.1rem;
}

.faq-note-card h3 {
    margin-bottom: 0.35rem;
    letter-spacing: -0.01em;
}

@media (max-width: 950px) {
    .faq-hero-card {
        grid-template-columns: 1fr;
        gap: 0.85rem;
    }

    .faq-pill-row {
        justify-content: flex-start;
    }

    .faq-insight-grid {
        grid-template-columns: 1fr;
    }

    .faq-insight-card {
        min-height: 0;
    }
}

/* Profile — centered column (avatar block, then danger zone below) */
.profile-page {
    width: 100%;
    max-width: min(1180px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: min(calc(100vh - 9rem), 640px);
    padding: clamp(1.5rem, 4vw, 3rem) 1rem;
    box-sizing: border-box;
}

.app-layout.sidebar-collapsed .profile-page {
    max-width: none;
}

.profile-page__column {
    width: 100%;
    max-width: 28rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.profile-page__shell {
    width: 100%;
    text-align: center;
}

.profile-page__eyebrow {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: var(--dim-text);
    margin-bottom: 1.35rem;
}

.profile-page__avatar {
    width: 5.5rem;
    height: 5.5rem;
    margin: 0 auto;
    border-radius: 50%;
    border: 1px solid rgba(255, 59, 48, 0.38);
    background: radial-gradient(circle at 32% 22%, rgba(255, 59, 48, 0.22), transparent 58%),
        radial-gradient(circle at 70% 80%, rgba(255, 59, 48, 0.08), transparent 45%);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.06) inset,
        0 20px 48px rgba(0, 0, 0, 0.45),
        0 12px 32px rgba(255, 59, 48, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.profile-page__avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.profile-page__avatar-initial {
    font-size: 1.85rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.profile-page__name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.35rem 0.5rem;
    margin: 1.5rem 0 0;
    width: 100%;
}

.profile-page__name {
    margin: 0;
    font-size: clamp(1.65rem, 4.2vw, 2.15rem);
    font-weight: 600;
    letter-spacing: -0.035em;
    line-height: 1.15;
    color: var(--text-color);
}

.profile-page__copy-id {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: rgba(255, 255, 255, 0.38);
    cursor: pointer;
    transition:
        color 0.18s ease,
        background 0.18s ease,
        border-color 0.18s ease,
        transform 0.15s ease;
}

.profile-page__copy-id:hover {
    color: rgba(255, 255, 255, 0.72);
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}

.profile-page__copy-id:focus-visible {
    outline: none;
    color: #fff;
    border-color: rgba(255, 59, 48, 0.45);
    box-shadow: 0 0 0 2px rgba(255, 59, 48, 0.25);
}

.profile-page__copy-id:active {
    transform: scale(0.94);
}

.profile-page__copy-id svg {
    width: 15px;
    height: 15px;
}

:root[data-theme="light"] .profile-page__copy-id {
    color: rgba(0, 0, 0, 0.32);
}

:root[data-theme="light"] .profile-page__copy-id:hover {
    color: rgba(0, 0, 0, 0.72);
    background: rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.08);
}

:root[data-theme="light"] .profile-page__copy-id:focus-visible {
    color: var(--text-color);
}

.profile-page__since {
    margin: 0.55rem 0 0;
    font-size: 0.98rem;
    font-weight: 400;
    color: var(--dim-text);
    line-height: 1.45;
}

.profile-page__email {
    margin: 0.45rem 0 0;
    width: 100%;
    font-size: 0.95rem;
    font-weight: 400;
    line-height: 1.45;
    text-align: center;
}

.profile-page__email-inner {
    display: inline-block;
    max-width: 100%;
    color: var(--dim-text);
    text-align: center;
    word-break: break-word;
}

.profile-danger {
    margin-top: 2.5rem;
    width: 100%;
    text-align: left;
}

.profile-danger__details {
    border-radius: 16px;
    border: 1px solid rgba(255, 59, 48, 0.35);
    background: linear-gradient(165deg, rgba(255, 59, 48, 0.1) 0%, rgba(0, 0, 0, 0.35) 55%);
    overflow: hidden;
}

.profile-danger__summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.18s ease;
}

.profile-danger__summary::-webkit-details-marker {
    display: none;
}

.profile-danger__summary::marker {
    content: '';
}

.profile-danger__summary:hover {
    background: rgba(255, 255, 255, 0.04);
}

.profile-danger__summary-text {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffb4ae;
    letter-spacing: -0.02em;
}

.profile-danger__summary-meta {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

.profile-danger__chevron {
    display: inline-block;
    width: 0.55rem;
    height: 0.55rem;
    border-right: 2px solid rgba(255, 180, 174, 0.8);
    border-bottom: 2px solid rgba(255, 180, 174, 0.8);
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -0.2rem;
}

.profile-danger__details[open] .profile-danger__chevron {
    transform: rotate(-135deg);
    margin-top: 0.12rem;
}

.profile-danger__body {
    padding: 1rem 1.35rem 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.profile-danger__lead {
    margin: 0 0 1.15rem;
    font-size: 0.9rem;
    line-height: 1.6;
    color: rgba(255, 255, 255, 0.72);
}

.profile-danger__lead a {
    color: var(--primary-color, #ff3b30);
    text-decoration: underline;
    text-underline-offset: 0.12em;
}

.profile-danger__form {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.profile-danger__check {
    display: flex;
    align-items: flex-start;
    gap: 0.55rem;
    font-size: 0.88rem;
    line-height: 1.45;
    color: rgba(255, 255, 255, 0.82);
    cursor: pointer;
}

.profile-danger__check input {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.profile-danger__check a {
    color: var(--primary-color, #ff3b30);
}

.profile-danger__phrase-label {
    margin: 0.35rem 0 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.88);
}

.profile-danger__phrase-input {
    width: 100%;
    max-width: 16rem;
    box-sizing: border-box;
    padding: 0.55rem 0.75rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-size: 0.95rem;
}

.profile-danger__hint {
    margin: -0.35rem 0 0;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.45);
}

.profile-danger__phrase-error {
    margin: 0.35rem 0 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: #ff8a82;
    line-height: 1.4;
}

.profile-danger__submit {
    margin-top: 0.5rem;
    width: 100%;
    padding: 0.7rem 1.15rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 59, 48, 0.55);
    background: rgba(255, 59, 48, 0.18);
    color: #fff;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.profile-danger__submit:hover:not(:disabled) {
    background: rgba(255, 59, 48, 0.32);
    border-color: rgba(255, 59, 48, 0.85);
}

.profile-danger__submit:disabled {
    opacity: 0.42;
    cursor: not-allowed;
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
}

/* Native <dialog> — final delete confirmation
   Never set display:flex on the bare selector: it overrides the UA `dialog { display:none }`
   and paints the panel on every page load without a real modal (buttons feel “dead”). */
.profile-delete-dialog {
    padding: 0;
    border: none;
    margin: 0;
    background: transparent;
}

.profile-delete-dialog[open] {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    padding: max(1rem, env(safe-area-inset-top, 0px)) max(1.25rem, env(safe-area-inset-right, 0px))
        max(1rem, env(safe-area-inset-bottom, 0px)) max(1.25rem, env(safe-area-inset-left, 0px));
    border: none;
    background: transparent;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10050;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.profile-delete-dialog::backdrop {
    background: rgba(0, 0, 0, 0.78);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .profile-delete-dialog::backdrop {
        -webkit-backdrop-filter: blur(6px);
        backdrop-filter: blur(6px);
    }
}

.profile-delete-dialog__panel {
    width: min(22rem, calc(100vw - 2rem));
    flex-shrink: 0;
    margin-block: auto;
    padding: 1.35rem 1.35rem 1.4rem;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: linear-gradient(165deg, #1a1a1c 0%, #101012 100%);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
    text-align: center;
}

.profile-delete-dialog__title {
    margin: 0 0 0.65rem;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.02em;
}

.profile-delete-dialog__text {
    margin: 0 auto 1.25rem;
    max-width: 34ch;
    font-size: 0.9rem;
    line-height: 1.55;
    color: rgba(255, 255, 255, 0.72);
    text-align: center;
}

.profile-delete-dialog__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: center;
    align-items: center;
}

.profile-delete-dialog__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    border-radius: 10px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
    min-height: 44px;
    box-sizing: border-box;
}

@media (max-width: 420px) {
    .profile-delete-dialog__actions {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-delete-dialog__btn {
        width: 100%;
        justify-content: center;
    }
}

.profile-delete-dialog__btn--secondary {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.88);
}

.profile-delete-dialog__btn--secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.profile-delete-dialog__btn--danger {
    background: rgba(255, 59, 48, 0.22);
    border-color: rgba(255, 59, 48, 0.55);
    color: #fff;
}

.profile-delete-dialog__btn--danger:hover {
    background: rgba(255, 59, 48, 0.38);
    border-color: rgba(255, 59, 48, 0.85);
}

/* Stats V2 */
.stats-v2-page {
    width: min(1320px, 100%);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.95rem;
    min-width: 0;
    overflow-x: clip;
}

.app-layout.sidebar-collapsed .stats-v2-page {
    width: 100%;
    max-width: none;
}

.stats-v2-header {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.stats-v2-header h1 {
    font-size: clamp(2rem, 3vw, 3.2rem);
    line-height: 0.98;
    letter-spacing: -0.03em;
    margin-bottom: 0;
}

.stats-v2-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: center;
    min-width: 0;
}

.stats-v2-controls .stats-filters-form {
    flex: 1 1 auto;
    min-width: 0;
}

.stats-filters-form {
    min-width: 0;
}

.stats-v2-custom-dates {
    display: none;
    align-items: center;
    gap: 0.45rem;
}

.stats-v2-custom-dates.visible {
    display: inline-flex;
}

.stats-v2-custom-dates span {
    color: #8c98aa;
    font-size: 0.9rem;
}

.stats-v2-compare-note {
    font-size: 0.9rem;
    color: #8e9cb1;
    margin-left: 0.15rem;
}

.stats-v2-kpi-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.85rem;
    min-width: 0;
    align-items: stretch;
}

.stats-v2-kpi-card {
    background: linear-gradient(180deg, #0a1019 0%, #070d16 100%);
    border: 1px solid #233041;
    border-radius: 14px;
    padding: 1rem 1.05rem;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
    min-height: 118px;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.stats-v2-kpi-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    color: #95a2b8;
    font-size: 0.78rem;
    font-weight: 600;
    min-height: 20px;
}

.stats-v2-kpi-head span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stats-v2-kpi-head i {
    width: 15px;
    height: 15px;
    color: #ff7f77;
}

.stats-v2-kpi-value {
    margin-top: 0.55rem;
    font-size: clamp(1.22rem, 1.8vw, 1.56rem);
    line-height: 1;
    font-weight: 700;
    color: #f2f6fd;
    display: flex;
    align-items: flex-end;
    min-height: 44px;
}

.stats-v2-kpi-delta {
    margin-top: 0.55rem;
    font-size: 0.78rem;
    font-weight: 700;
}

.stats-v2-kpi-delta.up {
    color: #3fe087;
}

.stats-v2-kpi-delta.down {
    color: #ff7b73;
}

.stats-v2-kpi-delta.neutral {
    color: #95a2b8;
}

.stats-v2-chart-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr);
    gap: 0.7rem;
    min-width: 0;
}

.stats-v2-panel {
    background: linear-gradient(180deg, #0a1019 0%, #070d16 100%);
    border: 1px solid #223042;
    border-radius: 16px;
    padding: 0.95rem;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.stats-v2-panel-head {
    margin-bottom: 0.75rem;
}

.stats-v2-panel-head h3 {
    font-size: 1.08rem;
    letter-spacing: -0.01em;
    margin-bottom: 0.2rem;
}

.stats-v2-chart-wrap {
    position: relative;
    width: 100%;
    min-width: 0;
    overflow: hidden;
}

.stats-v2-chart-wrap-lg {
    height: 300px;
}

.stats-v2-chart-wrap-md {
    height: 260px;
}

.stats-v2-chart-wrap canvas {
    width: 100%;
    height: 100%;
    max-width: 100%;
    display: block;
}

.stats-v2-chart-empty {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: #93a2b6;
    font-size: 0.9rem;
    background: radial-gradient(circle at center, rgba(8, 16, 26, 0.55) 0%, rgba(8, 16, 26, 0.9) 72%);
    border: 1px dashed #2a3748;
    border-radius: 12px;
    padding: 0.9rem;
}

.stats-v2-top-list {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.stats-v2-top-item {
    border: 1px solid #202c3a;
    border-radius: 12px;
    background: #070d15;
    padding: 0.75rem;
}

.stats-v2-top-main h4 {
    color: #f1f5fc;
    font-size: 0.98rem;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stats-v2-top-meta {
    margin-top: 0.3rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
    color: #93a1b6;
    font-size: 0.82rem;
}

.stats-v2-top-meta .source {
    border-radius: 999px;
    padding: 0.14rem 0.46rem;
    border: 1px solid rgba(122, 138, 160, 0.45);
    background: rgba(108, 124, 147, 0.18);
    font-size: 0.68rem;
    letter-spacing: 0.02em;
    font-weight: 700;
}

.stats-v2-top-meta .source.text {
    border-color: rgba(255, 173, 72, 0.42);
    color: #ffc98b;
    background: rgba(167, 103, 28, 0.24);
}

.stats-v2-top-meta .source.url {
    border-color: rgba(68, 156, 255, 0.45);
    color: #87c8ff;
    background: rgba(40, 114, 194, 0.2);
}

.stats-v2-top-meta .source.file {
    border-color: rgba(167, 126, 255, 0.48);
    color: #c2a8ff;
    background: rgba(99, 69, 173, 0.24);
}

.stats-v2-mini-progress {
    margin-top: 0.5rem;
    width: 100%;
    height: 5px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.stats-v2-mini-progress span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, #ff3b30 0%, #ff726b 100%);
}

.stats-v2-empty {
    min-height: 230px;
    border-radius: 12px;
    border: 1px dashed #293648;
    background: #080f17;
    color: #91a0b5;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
}

.stats-v2-export-btn {
    height: 40px;
    border-radius: 10px;
    border: 1px solid #343f50;
    color: #dde4f0;
    background: #151d2a;
    padding: 0 0.9rem;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
}

.stats-v2-controls .stats-v2-export-btn {
    margin-left: auto;
}

.stats-v2-export-btn {
    border-color: rgba(255, 95, 86, 0.42);
    background: linear-gradient(180deg, rgba(255, 90, 80, 0.2) 0%, rgba(255, 70, 60, 0.12) 100%);
}

.stats-v2-export-btn:hover {
    border-color: rgba(255, 95, 86, 0.64);
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.12);
}

@media (max-width: 1280px) {
    .stats-v2-chart-wrap-lg {
        height: 270px;
    }

    .stats-v2-chart-wrap-md {
        height: 235px;
    }
}

@media (max-width: 980px) {
    .stats-v2-chart-grid {
        grid-template-columns: 1fr;
    }

    .stats-v2-chart-wrap-lg,
    .stats-v2-chart-wrap-md {
        height: 240px;
    }
}

@media (max-width: 720px) {
    .stats-v2-kpi-grid {
        grid-template-columns: 1fr;
    }

    .stats-v2-controls .library-filter-row {
        align-items: stretch;
    }

    .stats-v2-controls .library-filter-select,
    .stats-v2-custom-dates,
    .stats-v2-export-btn,
    .stats-v2-controls .library-filter-clear {
        width: 100%;
    }

    .stats-v2-custom-dates {
        flex-wrap: wrap;
    }

    .stats-v2-date-input {
        flex: 1;
        min-width: 150px;
    }

    .stats-v2-controls .library-filter-clear {
        justify-content: center;
        margin-left: 0;
    }

    .stats-v2-export-btn {
        justify-content: center;
        margin-left: 0;
    }

    .stats-v2-chart-wrap-lg,
    .stats-v2-chart-wrap-md {
        height: 220px;
    }
}

@media (max-width: 520px) {
    .stats-v2-kpi-card {
        min-height: 108px;
    }
}

