:root {
    /* Color Palette - Premium Dark Theme with vibrant accents */
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #8b5cf6;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.05);
    --success: #10b981;
    --error: #ef4444;

    /* Fonts */
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;

    /* Shadows & Transitions */
    --shadow-glass: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Animated Background Orbs */
.bg-orb {
    position: fixed;
    border-radius: 50%;
    filter: blur(100px);
    z-index: -1;
    animation: float 20s infinite ease-in-out alternate;
}

.orb-1 {
    width: 400px;
    height: 400px;
    background: rgba(59, 130, 246, 0.15);
    top: -100px;
    left: -100px;
}

.orb-2 {
    width: 300px;
    height: 300px;
    background: rgba(139, 92, 246, 0.15);
    bottom: 10%;
    right: -50px;
    animation-delay: -5s;
}

.orb-3 {
    width: 250px;
    height: 250px;
    background: rgba(16, 185, 129, 0.1);
    top: 40%;
    left: 30%;
    animation-duration: 25s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(50px, 50px) scale(1.1); }
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    padding: 1.5rem;
    gap: 1.5rem;
    max-width: 1600px;
    margin: 0 auto;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--shadow-glass);
}

/* Sidebar */
.sidebar {
    width: 350px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 2rem;
    flex-shrink: 0;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo i {
    font-size: 2rem;
    color: var(--primary);
    background: -webkit-linear-gradient(45deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo h2 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Forms & Inputs */
.api-key-section {
    background: rgba(0,0,0,0.2);
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 2rem;
    border: 1px dashed var(--border-color);
}

.form-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group i {
    position: absolute;
    left: 1rem;
    color: var(--text-muted);
}

.input-group input {
    padding-left: 2.5rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="tel"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="date"],
textarea,
select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}

input::placeholder,
textarea::placeholder {
    color: rgba(148, 163, 184, 0.55);
}

/* Kill the browser's yellow autofill background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-main);
    -webkit-box-shadow: 0 0 0 1000px rgba(15, 23, 42, 0.95) inset;
    caret-color: var(--text-main);
    transition: background-color 5000s ease-in-out 0s;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.select-wrapper {
    position: relative;
}

.select-wrapper i {
    position: absolute;
    right: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

select {
    appearance: none;
    cursor: pointer;
}

select option {
    background: var(--bg-dark);
    color: var(--text-main);
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    font-weight: 400;
    font-size: 0.95rem;
}

.radio-label input[type="radio"] {
    display: none;
}

.custom-radio {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    position: relative;
    transition: var(--transition);
}

.radio-label input[type="radio"]:checked + .custom-radio {
    border-color: var(--primary);
}

.radio-label input[type="radio"]:checked + .custom-radio::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 10px;
    height: 10px;
    background: var(--primary);
    border-radius: 50%;
}

small {
    display: block;
    margin-top: 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Button */
.settings-btn {
    width: 100%;
    padding: 0.75rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-main);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.settings-btn:hover {
    background: rgba(255,255,255,0.1);
}

.secondary-btn {
    padding: 0.5rem 1rem;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

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

.file-input {
    background: rgba(15, 23, 42, 0.6);
    padding: 0.5rem;
    border-radius: 10px;
    width: 100%;
    color: var(--text-main);
    border: 1px dashed var(--border-color);
}

.primary-btn {
    width: 100%;
    padding: 1rem;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1.05rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
    margin-top: 2rem;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.primary-btn:active {
    transform: translateY(1px);
}

.primary-btn.generating {
    opacity: 0.8;
    pointer-events: none;
}

.primary-btn.generating i {
    animation: spin 2s linear infinite;
}

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

.sidebar-footer {
    margin-top: auto;
    padding-top: 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0; /* Prevents overflow in flex child */
}

.main-header {
    padding: 1.25rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-title h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
}

.badge {
    padding: 0.25rem 0.75rem;
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.generating {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.page-size-selector select {
    padding: 0.5rem 2rem 0.5rem 1rem;
    height: 40px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.2rem;
}

.icon-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Tooltip implementation */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    pointer-events: none;
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Output Area */
.output-container {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

.output-container::-webkit-scrollbar {
    width: 8px;
}
.output-container::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 10px;
}

.empty-state, .loading-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-muted);
}

.floating-icon {
    font-size: 4rem;
    color: rgba(255,255,255,0.1);
    margin-bottom: 1.5rem;
    animation: float 4s infinite ease-in-out alternate;
}

.empty-state h3, .loading-state h3 {
    font-family: var(--font-heading);
    color: var(--text-main);
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.empty-state p {
    max-width: 400px;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Loading Animation */
.spinner {
    width: 60px;
    height: 60px;
    position: relative;
    margin-bottom: 2rem;
}

.double-bounce1, .double-bounce2 {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--primary);
    opacity: 0.6;
    position: absolute;
    top: 0;
    left: 0;
    animation: sk-bounce 2.0s infinite ease-in-out;
}

.double-bounce2 {
    animation-delay: -1.0s;
}

@keyframes sk-bounce {
    0%, 100% { transform: scale(0.0) }
    50% { transform: scale(1.0) }
}

.loading-text {
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

/* Generated Content Formatting inside Paper */
.document-paper {
    background: #ffffff;
    color: #1e293b;
    margin: 0 auto;
    padding: 2.2rem 2.9rem;
    border-radius: 4px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transition: width 0.3s ease;
    min-height: 420px;
    position: relative;
    z-index: 1;
}

.document-paper::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: var(--watermark-url);
    background-size: 60%;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.08; /* Very light watermark */
    z-index: -1;
    pointer-events: none;
}

.document-header {
    margin-bottom: 0.9rem;
    border-bottom: 2px solid #000;
    padding-bottom: 0.55rem;
}

.custom-letterhead {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.lh-logo {
    width: 90px;
    height: 90px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.lh-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.lh-logo.left {
    border: 1px solid #000;
    border-radius: 8px;
    padding: 3px;
}

.lh-logo.right {
    border: 1px solid #000;
    border-radius: 8px;
    padding: 3px;
}

.lh-center-text {
    flex: 1;
    text-align: center;
    padding: 0 0.5rem;
    color: #000;
    line-height: 1.3;
    min-width: 0;
    overflow: hidden; /* Prevent text from painting over logos */
}

.lh-subtitle {
    font-size: 0.8em;
    font-weight: 600;
    margin-bottom: 0.1rem;
}

.lh-title {
    font-size: 1.35em;
    font-weight: 800;
    margin-bottom: 0.2rem;
    white-space: nowrap;
    letter-spacing: -0.5px;
}

.lh-address {
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 0.1rem;
    white-space: nowrap;
}

.lh-contact {
    font-size: 0.9em;
    font-weight: 800;
    margin-bottom: 0.1rem;
}

.lh-website {
    font-size: 0.75em;
    font-weight: 500;
    word-break: break-word;
}

/* Page Sizes */
.document-paper.a4 { width: 794px; }
.document-paper.letter { width: 816px; }
.document-paper.legal { width: 816px; }

.result-content {
    animation: fadeIn 0.5s ease-out forwards;
    line-height: 1.55;
    font-size: 0.98rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-content h1, .result-content h2, .result-content h3 {
    font-family: var(--font-heading);
    color: #0f172a;
    margin-top: 1.05rem;
    margin-bottom: 0.45rem;
    line-height: 1.25;
}

.result-content h1 { font-size: 1.55rem; border-bottom: 2px solid #cbd5e1; padding-bottom: 0.35rem; margin-top: 0.2rem; }
.result-content h2 { font-size: 1.2rem; color: #1d4ed8; }
.result-content h3 { font-size: 1.02rem; }

.result-content > *:first-child { margin-top: 0; }
.result-content h1 + *, .result-content h2 + *, .result-content h3 + * { margin-top: 0.25rem; }

.result-content p {
    margin: 0.4rem 0;
    color: #334155;
}

.result-content ul, .result-content ol {
    margin: 0.35rem 0 0.7rem;
    padding-left: 1.4rem;
    color: #334155;
}

.result-content li {
    margin-bottom: 0.2rem;
}

.result-content li > ul, .result-content li > ol { margin: 0.2rem 0; }

.result-content strong {
    color: #0f172a;
    font-weight: 600;
}

.result-content code {
    background: #f1f5f9;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: monospace;
    color: #be185d;
    border: 1px solid #e2e8f0;
}

.result-content pre {
    background: #f8fafc;
    padding: 0.8rem 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0 0.85rem;
    border: 1px solid #e2e8f0;
    color: #334155;
    font-size: 0.82rem;
    line-height: 1.45;
}

.result-content blockquote {
    border-left: 4px solid var(--primary);
    margin: 0.5rem 0 0.85rem;
    color: #475569;
    background: #eff6ff;
    padding: 0.6rem 0.9rem;
    border-radius: 0 8px 8px 0;
}

/* Responsive */
@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        height: auto;
    }
    
    .sidebar {
        width: 100%;
        max-height: none;
    }
    
    .output-container {
        min-height: 500px;
    }
    
    .document-paper {
        width: 100% !important;
        padding: 2rem;
    }
}

/* Print Media Queries */
@media print {
    body {
        background: #ffffff;
        color: #000000;
    }

    .bg-orb, .sidebar, .main-header, .api-key-section {
        display: none !important;
    }

    .app-container, .main-content, .output-container {
        display: block;
        padding: 0;
        margin: 0;
        height: auto;
        overflow: visible;
        background: none;
        border: none;
        box-shadow: none;
    }

    .document-paper {
        width: 100% !important;
        margin: 0;
        padding: 0;
        box-shadow: none;
        min-height: auto;
    }

    /* Keep the flow tight; let big tables split across pages so we don't
       get blank pages, but never split a row or orphan a heading. */
    .document-header, .doc-meta { break-inside: avoid; }
    .result-content h1,
    .result-content h2,
    .result-content h3 { break-after: avoid; page-break-after: avoid; break-inside: avoid; }
    .result-content table { break-inside: auto; page-break-inside: auto; }
    .result-content tr { break-inside: avoid; page-break-inside: avoid; }
    .result-content thead { display: table-header-group; }
    .result-content pre,
    .result-content blockquote { break-inside: avoid; page-break-inside: avoid; }
    .result-content p, .result-content li { orphans: 2; widows: 2; }
    .result-content img { max-width: 100%; }
    .lp-signs { break-inside: avoid; margin-top: 1rem !important; }

    @page {
        margin: 1.1cm 1.2cm;
    }
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
    display: flex !important; /* Keep flex to allow transition, rely on opacity/pointer-events */
}

.modal-content {
    width: 90%;
    max-width: 500px;
    background: var(--bg-dark);
    padding: 0;
    overflow: hidden;
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
    transform: translateY(-50px);
}

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

.modal-header h2 {
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.close-btn:hover {
    color: var(--error);
    transform: scale(1.1);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: rgba(255,255,255,0.02);
}

/* ============================================================
   Laravel app additions — top nav, auth, history, flash
   ============================================================ */

a { color: inherit; text-decoration: none; }

.topbar {
    max-width: 1600px;
    margin: 1.5rem auto 0;
    padding: 0.7rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    position: relative;
    z-index: 100;           /* lift the whole bar so the Create dropdown sits above page content */
}
.topbar .brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.15rem;
}
.topbar .brand i {
    font-size: 1.5rem;
    background: -webkit-linear-gradient(45deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.topnav {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.topnav > a,
.topnav .nav-trigger,
.topnav .logout-btn {
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.topnav > a:hover,
.topnav .nav-trigger:hover,
.topnav .logout-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
}
.topnav > a.active,
.topnav .nav-trigger.active {
    color: var(--text-main);
    background: rgba(59,130,246,0.15);
    border-color: rgba(59,130,246,0.3);
}
.topnav .nav-spacer { flex: 1; }
.topnav .user-chip {
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

/* "Create" dropdown */
.nav-group { position: relative; }
.nav-trigger .caret { font-size: 1rem; transition: transform 0.2s; }
.nav-group.open .nav-trigger .caret { transform: rotate(180deg); }
.nav-menu {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    min-width: 230px;
    padding: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
    background: #131a2b;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: var(--shadow-glass);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    z-index: 200;
}
.nav-group:hover .nav-menu,
.nav-group:focus-within .nav-menu,
.nav-group.open .nav-menu {
    opacity: 1;
    visibility: visible;
    transform: none;
}
.nav-menu a {
    padding: 0.6rem 0.8rem;
    border-radius: 9px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.55rem;
    white-space: nowrap;
    transition: var(--transition);
}
.nav-menu a i { font-size: 1.05rem; opacity: 0.8; }
.nav-menu a:hover { background: rgba(255,255,255,0.06); color: var(--text-main); }
.nav-menu a.active { background: rgba(59,130,246,0.16); color: var(--text-main); }

@media (max-width: 720px) {
    .topbar { flex-wrap: wrap; gap: 0.6rem 1rem; }
    .topnav { flex-wrap: wrap; }
    .topnav .nav-spacer { display: none; }
    .nav-menu { left: auto; right: 0; }
}

/* Flash + alerts */
.flash {
    max-width: 1600px;
    margin: 1rem auto 0;
    padding: 0.85rem 1.25rem;
    border-radius: 12px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}
.flash.success { background: rgba(16,185,129,0.15); color: var(--success); border: 1px solid rgba(16,185,129,0.3); }
.flash.error   { background: rgba(239,68,68,0.15); color: var(--error); border: 1px solid rgba(239,68,68,0.3); }

.field-error {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 0.35rem;
    display: block;
}

/* ============================================================
   Auth pages — polished login / register
   ============================================================ */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2.5rem 1.5rem;
    position: relative;
}
/* Soft aurora glow behind the card */
.auth-wrap::before {
    content: "";
    position: absolute;
    width: 620px;
    height: 620px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background:
        radial-gradient(circle at 30% 30%, rgba(59, 130, 246, 0.25), transparent 60%),
        radial-gradient(circle at 70% 70%, rgba(139, 92, 246, 0.22), transparent 60%);
    filter: blur(50px);
    z-index: -1;
    pointer-events: none;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    padding: 2.75rem 2.75rem 2.5rem;
    position: relative;
    border-radius: 24px;
    animation: authIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}
/* Gradient hairline border */
.auth-card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 24px;
    padding: 1px;
    background: linear-gradient(150deg, rgba(59, 130, 246, 0.6), rgba(139, 92, 246, 0.35) 40%, rgba(255, 255, 255, 0.04) 70%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
            mask-composite: exclude;
    pointer-events: none;
}

@keyframes authIn {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.auth-brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    margin-bottom: 1.75rem;
}
.auth-brand .brand-badge {
    width: 58px;
    height: 58px;
    border-radius: 16px;
    display: grid;
    place-items: center;
    font-size: 1.8rem;
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 10px 28px rgba(59, 130, 246, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.auth-brand .brand-name {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.35rem;
    letter-spacing: -0.5px;
}
.auth-brand .brand-tag {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: -0.35rem;
}

.auth-card h1 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 0.35rem;
}
.auth-hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 1.75rem;
}

.auth-card .form-group { margin-bottom: 1.15rem; }
.auth-card label {
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: var(--text-muted);
    text-transform: uppercase;
}
.auth-card .input-group i {
    font-size: 1.05rem;
    transition: var(--transition);
}
.auth-card .input-group input {
    height: 48px;
    background: rgba(15, 23, 42, 0.75);
}
.auth-card .input-group input:focus + i,
.auth-card .input-group:focus-within i { color: var(--primary); }

.auth-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.35rem 0 0.25rem;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.86rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.checkbox-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkbox-row .box {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    border: 1.5px solid var(--border-color);
    background: rgba(15, 23, 42, 0.6);
    display: grid;
    place-items: center;
    transition: var(--transition);
    flex-shrink: 0;
}
.checkbox-row .box::after {
    content: "\2713";
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    opacity: 0;
    transform: scale(0.5);
    transition: var(--transition);
}
.checkbox-row input:checked + .box {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
}
.checkbox-row input:checked + .box::after { opacity: 1; transform: scale(1); }
.checkbox-row input:focus-visible + .box { box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25); }

.auth-card .primary-btn {
    margin-top: 1.25rem;
    height: 50px;
    padding: 0;
}

.auth-switch {
    text-align: center;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
}
.auth-switch a {
    color: var(--primary);
    font-weight: 600;
    transition: var(--transition);
}
.auth-switch a:hover { color: var(--accent); }

@media (max-width: 480px) {
    .auth-card { padding: 2rem 1.5rem 1.75rem; }
}

/* Content page wrapper */
.page {
    max-width: 1600px;
    margin: 1.5rem auto;
    padding: 0 1.5rem 3rem;
}
.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.page-head h1 { font-family: var(--font-heading); font-size: 1.6rem; }

/* History grid */
.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}
.history-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    transition: var(--transition);
}
.history-card:hover { transform: translateY(-3px); border-color: rgba(59,130,246,0.3); }
.history-card .tags { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.tag {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    background: rgba(255,255,255,0.06);
    color: var(--text-muted);
}
.tag.lang { background: rgba(139,92,246,0.15); color: #c4b5fd; }
.tag.sim  { background: rgba(245,158,11,0.15); color: #fbbf24; }
.history-card h3 { font-family: var(--font-heading); font-size: 1.1rem; color: var(--text-main); }
.history-card p.excerpt { color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; flex: 1; }
.history-card .card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
}
.link-btn {
    color: var(--primary);
    font-weight: 600;
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
}
.danger-link {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.82rem;
    transition: var(--transition);
}
.danger-link:hover { color: var(--error); }

.empty-box {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-box i { font-size: 3rem; opacity: 0.3; display: block; margin-bottom: 1rem; }

/* Settings form width */
.settings-page .glass-panel { padding: 2rem; }
.settings-page .two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}
@media (max-width: 640px) { .settings-page .two-col { grid-template-columns: 1fr; } }

.pagination-wrap { margin-top: 2rem; }
.pagination-wrap nav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.pagination-wrap a, .pagination-wrap span {
    padding: 0.4rem 0.75rem;
    border-radius: 8px;
    background: rgba(255,255,255,0.05);
    font-size: 0.85rem;
}
.pagination-wrap span[aria-current] { background: var(--primary); color: #fff; }

.dashboard-body { display: block; }
.sim-note {
    background: rgba(245,158,11,0.12);
    border: 1px solid rgba(245,158,11,0.3);
    color: #fbbf24;
    font-size: 0.82rem;
    padding: 0.6rem 0.85rem;
    border-radius: 10px;
    margin-bottom: 1rem;
}

@media print {
    .topbar, .flash { display: none !important; }
}

/* ============================================================
   History multi-select + Combine
   ============================================================ */
.page-sub {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.35rem;
}

/* Reusable small buttons */
.ghost-btn {
    padding: 0.55rem 1rem;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.ghost-btn:hover { background: rgba(255, 255, 255, 0.09); }
.ghost-btn.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); }
.ghost-btn.danger:hover { background: rgba(239, 68, 68, 0.15); color: #fecaca; }

.pill-btn {
    padding: 0.6rem 1.25rem;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: #fff;
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}
.pill-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(59, 130, 246, 0.4); }
.pill-btn.disabled {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(0.4);
    box-shadow: none;
}

/* Sticky selection toolbar */
.select-bar {
    position: sticky;
    top: 1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    animation: authIn 0.25s ease both;
}
.select-bar .checkbox-row { font-size: 0.9rem; color: var(--text-main); }
.select-bar #sel-count { font-weight: 700; color: var(--primary); }
.select-bar-actions { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }

/* Per-card picker */
.history-card { position: relative; }
.history-card .pick {
    position: absolute;
    top: 1rem;
    right: 1rem;
    cursor: pointer;
    z-index: 2;
}
.history-card .pick input { position: absolute; opacity: 0; width: 0; height: 0; }
.history-card .pick .box {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    border: 1.5px solid var(--border-color);
    background: rgba(15, 23, 42, 0.75);
    display: grid;
    place-items: center;
    transition: var(--transition);
}
.history-card .pick .box::after {
    content: "\2713";
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    opacity: 0;
    transform: scale(0.4);
    transition: var(--transition);
}
.history-card .pick input:checked + .box {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
}
.history-card .pick input:checked + .box::after { opacity: 1; transform: scale(1); }
.history-card.is-picked {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35), var(--shadow-glass);
}
.history-card .tags { padding-right: 2rem; }
.foot-actions { display: flex; gap: 0.75rem; align-items: center; }
.card-foot span i { margin-right: 0.25rem; opacity: 0.7; }

/* Combine screen */
.combine-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.combine-save {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    flex: 1;
}
.combine-save input[type="text"] { flex: 1; min-width: 200px; }
.combine-save .page-size-selector select { height: 42px; }

.combine-section + .combine-section { margin-top: 1.5rem; }
.combine-section-meta {
    font-size: 0.8rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px dashed #cbd5e1;
}
.combine-section:not(:first-of-type) {
    border-top: 3px double #cbd5e1;
    padding-top: 1rem;
}

@media print {
    .combine-toolbar, .select-bar, .page-head, .pagination-wrap { display: none !important; }
    .page { margin: 0; padding: 0; }
    .output-container { padding: 0 !important; background: none !important; border: none !important; box-shadow: none !important; }
    .page-break { page-break-before: always; break-before: page; }
    .combine-section:not(:first-of-type) { border-top: none; padding-top: 0; }
}

@media (max-width: 640px) {
    .select-bar { flex-direction: column; align-items: stretch; }
    .select-bar-actions { justify-content: space-between; }
}

/* ============================================================
   History — LIST layout (overrides the earlier card grid)
   ============================================================ */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.history-list-head {
    display: grid;
    grid-template-columns: 34px minmax(0, 2.2fr) minmax(0, 1.6fr) 150px 130px;
    align-items: center;
    gap: 1rem;
    padding: 0.35rem 1.25rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.history-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 2.2fr) minmax(0, 1.6fr) 150px 130px;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    border-radius: 14px;
    transition: var(--transition);
}
.history-row:hover {
    border-color: rgba(59, 130, 246, 0.3);
    transform: translateX(2px);
}
.history-row.is-picked {
    border-color: rgba(59, 130, 246, 0.55);
    box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.35), var(--shadow-glass);
}

/* Checkbox */
.history-list .pick { cursor: pointer; display: inline-flex; }
.history-list .pick input { position: absolute; opacity: 0; width: 0; height: 0; }
.history-list .pick .box {
    width: 20px;
    height: 20px;
    border-radius: 6px;
    border: 1.5px solid var(--border-color);
    background: rgba(15, 23, 42, 0.75);
    display: grid;
    place-items: center;
    transition: var(--transition);
    flex-shrink: 0;
}
.history-list .pick .box::after {
    content: "\2713";
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    opacity: 0;
    transform: scale(0.4);
    transition: var(--transition);
}
.history-list .pick input:checked + .box {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
}
.history-list .pick input:checked + .box::after { opacity: 1; transform: scale(1); }

/* Topic column */
.col-topic { min-width: 0; }
.row-topic {
    display: block;
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: var(--transition);
}
.row-topic:hover { color: var(--primary); }
.row-excerpt {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.15rem;
}

/* Meta column */
.col-meta { display: flex; flex-wrap: wrap; gap: 0.35rem; }

/* Date column */
.col-date {
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}
.col-date i { opacity: 0.7; margin-right: 0.25rem; }

/* Actions column */
.col-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.85rem;
}

/* Responsive: collapse to stacked cards */
@media (max-width: 860px) {
    .history-list-head { display: none; }
    .history-row {
        grid-template-columns: 24px 1fr auto;
        grid-template-areas:
            "pick topic   topic"
            "meta meta     meta"
            "date date     actions";
        gap: 0.55rem 0.85rem;
        padding: 1rem 1.25rem;
    }
    .history-row .pick { grid-area: pick; margin-top: 0.15rem; }
    .col-topic  { grid-area: topic; }
    .col-meta   { grid-area: meta; }
    .col-date   { grid-area: date; display: inline-flex; align-items: center; }
    .col-actions { grid-area: actions; justify-content: flex-end; }
    .row-topic, .row-excerpt { white-space: normal; }
}

/* ============================================================
   Document metadata strip (under the letterhead)
   ============================================================ */
.doc-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 1.75rem;
    padding-bottom: 0.5rem;
    margin: 0.5rem 0 0.95rem;
    border-bottom: 2px solid #0f172a;
    color: #1e293b;
    font-family: var(--font-body);
    font-size: 0.86rem;
    line-height: 1.55;
}
.doc-meta span {
    display: flex;
    gap: 0.4rem;
    min-width: 0;
    white-space: normal;
    padding: 0.18rem 0;
    border-top: 1px solid #e2e8f0;
}
.doc-meta span:nth-child(1),
.doc-meta span:nth-child(2) { border-top: 0; }
/* Topic / lesson name gets its own full-width row (values are long) */
.doc-meta span:nth-of-type(3) { grid-column: 1 / -1; }
.doc-meta strong {
    font-weight: 700;
    color: #0f172a;
    flex-shrink: 0;
}
.doc-meta span > :not(strong) { min-width: 0; overflow-wrap: anywhere; }

@media (max-width: 640px) {
    .doc-meta { grid-template-columns: 1fr; }
    .doc-meta span:nth-child(2) { border-top: 1px solid #e2e8f0; }
}

/* When there is no letterhead, keep a little breathing room on top */
.document-header[style*="display:none"] + .doc-meta,
.document-header[style*="display: none"] + .doc-meta {
    margin-top: 0.5rem;
}

/* Combined document: the meta strip repeats per section */
.combine-section .doc-meta {
    border-bottom-width: 1px;
    border-bottom-style: dashed;
    border-bottom-color: #94a3b8;
    font-size: 0.84rem;
    margin: 0.3rem 0 0.9rem;
}

@media print {
    .doc-meta { border-bottom-color: #000; }
}

/* Source-URL bits */
.tag.src { background: rgba(56, 189, 248, 0.15); color: #7dd3fc; }
.doc-meta a { color: #1d4ed8; word-break: break-all; text-decoration: underline; }
#source-url { direction: ltr; }

/* ============================================================
   Inline document editor (doc-editor.js)
   ============================================================ */
.icon-btn.is-active {
    background: rgba(59, 130, 246, 0.25);
    color: var(--primary);
    border-color: rgba(59, 130, 246, 0.4);
}

.md-edit-panel {
    margin-top: 1.25rem;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    overflow: hidden;
    background: #f8fafc;
}
.md-edit-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.75rem;
    background: #eef2f6;
    border-bottom: 1px solid #cbd5e1;
}
.md-edit-hint {
    font-size: 0.78rem;
    color: #475569;
    margin-right: auto;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}
.md-edit-hint code {
    background: #e2e8f0;
    padding: 0.05em 0.35em;
    border-radius: 4px;
    font-size: 0.92em;
}
.md-edit-status { font-size: 0.8rem; color: #475569; }
.md-edit-status.ok { color: #15803d; font-weight: 600; }
.md-edit-status.err { color: #b91c1c; font-weight: 600; }

.md-edit-panel .ghost-btn {
    background: #fff;
    border: 1px solid #cbd5e1;
    color: #334155;
    padding: 0.45rem 0.8rem;
}
.md-edit-panel .ghost-btn:hover { background: #f1f5f9; }
.md-edit-panel .pill-btn {
    box-shadow: none;
    padding: 0.45rem 1rem;
}

.md-edit-area {
    width: 100%;
    min-height: 62vh;
    resize: vertical;
    border: 0;
    border-radius: 0;
    padding: 1.25rem 1.5rem;
    font-family: "IBM Plex Mono", ui-monospace, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.7;
    color: #1e293b;
    background: #fff;
    outline: none;
    display: block;
}
.md-edit-area:focus {
    box-shadow: inset 0 0 0 2px rgba(67, 56, 202, 0.25);
    border-color: transparent;
}

@media print {
    .md-edit-panel { display: none !important; }
}

/* ============================================================
   History — segmented filter + data table (H4)
   ============================================================ */
.hist-seg {
    display: flex;
    gap: 0.25rem;
    padding: 0.3rem;
    margin-bottom: 1rem;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow-x: auto;
    scrollbar-width: thin;
}
.hist-seg a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.8rem;
    border-radius: 9px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    transition: var(--transition);
}
.hist-seg a i { font-size: 1rem; opacity: 0.7; }
.hist-seg a:hover { color: var(--text-main); background: rgba(148, 163, 184, 0.12); }
.hist-seg a.on {
    color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--accent));
}
.hist-seg a .n {
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.02rem 0.4rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
}
.hist-seg a:not(.on) .n { background: rgba(148, 163, 184, 0.16); color: var(--text-muted); }

.tbl-wrap { overflow-x: auto; padding: 0; }
.hist-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.86rem;
    min-width: 720px;
}
.hist-tbl thead th {
    text-align: left;
    padding: 0.65rem 0.85rem;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.hist-tbl tbody td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
.hist-tbl tbody tr:last-child td { border-bottom: 0; }
.hist-tbl tbody tr:nth-child(even) td { background: rgba(148, 163, 184, 0.045); }
.hist-tbl tbody tr:hover td { background: rgba(59, 130, 246, 0.07); }
.hist-tbl tbody tr.is-picked td { background: rgba(59, 130, 246, 0.14); }

.hist-tbl .c-pick { width: 40px; text-align: center; }
.hist-tbl .c-topic { min-width: 240px; }
.hist-tbl .c-topic a {
    font-weight: 600;
    color: var(--text-main);
}
.hist-tbl .c-topic a:hover { color: var(--primary); }
.hist-tbl .cdot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 0.5rem;
    vertical-align: 1px;
}
.hist-tbl .c-type, .hist-tbl .c-src { color: var(--text-muted); white-space: nowrap; }
.hist-tbl .c-date { color: var(--text-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.hist-tbl .c-act { white-space: nowrap; text-align: right; }
.hist-tbl .c-act .link-btn { margin-right: 0.6rem; }
.hist-tbl .tbl-empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}
.hist-tbl .tbl-empty i { display: block; font-size: 2rem; opacity: 0.3; margin-bottom: 0.6rem; }

/* checkbox reused from the old list */
.hist-tbl .pick { cursor: pointer; display: inline-flex; }
.hist-tbl .pick input { position: absolute; opacity: 0; width: 0; height: 0; }
.hist-tbl .pick .box {
    width: 18px; height: 18px;
    border-radius: 5px;
    border: 1.5px solid var(--border-color);
    background: rgba(15, 23, 42, 0.06);
    display: grid; place-items: center;
    transition: var(--transition);
}
html[data-theme="light"] .hist-tbl .pick .box { background: rgba(15, 23, 42, 0.04); }
.hist-tbl .pick .box::after {
    content: "\2713";
    font-size: 11px; font-weight: 700; color: #fff;
    opacity: 0; transform: scale(0.4);
    transition: var(--transition);
}
.hist-tbl .pick input:checked + .box {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-color: transparent;
}
.hist-tbl .pick input:checked + .box::after { opacity: 1; transform: scale(1); }

/* ============================================================
   THEME TOGGLE + LIGHT (DAY) MODE
   ============================================================ */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 1.15rem;
    flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text-main); background: rgba(148, 163, 184, 0.14); }
.theme-toggle-float {
    position: fixed;
    top: 1.1rem;
    right: 1.1rem;
    z-index: 50;
    background: var(--bg-card);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* ---- light palette ---- */
:root[data-theme="light"] {
    --bg-dark: #ffffff;                        /* page background — fully white */
    --bg-card: #ffffff;                        /* panels: white, separated by border + shadow */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --accent: #7c3aed;
    --text-main: #1f2937;
    --text-muted: #5b6675;
    --border-color: rgba(15, 23, 42, 0.13);
    --glass-border: rgba(15, 23, 42, 0.09);
    --shadow-glass: 0 6px 22px rgba(15, 23, 42, 0.08);
}
html[data-theme="light"] body { background-color: #ffffff; color: var(--text-main); }

/* no coloured tint blobs on a white page */
html[data-theme="light"] .bg-orb { display: none; }

/* panels need a crisper edge on pure white */
html[data-theme="light"] .glass-panel { border-color: rgba(15, 23, 42, 0.10); }
html[data-theme="light"] .topbar { box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06); }

/* the white "paper" needs a soft edge against the white page */
html[data-theme="light"] .document-paper {
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
    border: 1px solid rgba(15, 23, 42, 0.10);
}

/* white-overlay surfaces → dark-overlay */
html[data-theme="light"] .topnav > a:hover,
html[data-theme="light"] .topnav .nav-trigger:hover,
html[data-theme="light"] .topnav .logout-btn:hover,
html[data-theme="light"] .nav-menu a:hover,
html[data-theme="light"] .icon-btn:hover:not(:disabled),
html[data-theme="light"] .settings-btn:hover,
html[data-theme="light"] .ghost-btn:hover,
html[data-theme="light"] .hf-tab:hover,
html[data-theme="light"] .history-row:hover { background: rgba(15, 23, 42, 0.055); }

html[data-theme="light"] .nav-menu { background: #ffffff; }
html[data-theme="light"] .icon-btn,
html[data-theme="light"] .settings-btn,
html[data-theme="light"] .ghost-btn,
html[data-theme="light"] .hf-tab,
html[data-theme="light"] .file-input,
html[data-theme="light"] .api-key-section { background: rgba(15, 23, 42, 0.04); }
html[data-theme="light"] .hf-count { background: rgba(15, 23, 42, 0.09); }
html[data-theme="light"] .hf-tab:not(.active) .hf-count { background: rgba(15, 23, 42, 0.06); }
html[data-theme="light"] .tag { background: rgba(15, 23, 42, 0.06); }
html[data-theme="light"] .badge:not(.generating) { background: rgba(16, 185, 129, 0.16); }

/* form fields */
html[data-theme="light"] input[type="text"],
html[data-theme="light"] input[type="password"],
html[data-theme="light"] input[type="email"],
html[data-theme="light"] input[type="tel"],
html[data-theme="light"] input[type="url"],
html[data-theme="light"] input[type="number"],
html[data-theme="light"] input[type="search"],
html[data-theme="light"] input[type="date"],
html[data-theme="light"] input[type="month"],
html[data-theme="light"] textarea,
html[data-theme="light"] select { background: rgba(255, 255, 255, 0.92); }
html[data-theme="light"] select option { background: #ffffff; color: var(--text-main); }
html[data-theme="light"] input::placeholder,
html[data-theme="light"] textarea::placeholder { color: rgba(30, 41, 59, 0.45); }
html[data-theme="light"] input:-webkit-autofill,
html[data-theme="light"] input:-webkit-autofill:hover,
html[data-theme="light"] input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #ffffff inset;
    -webkit-text-fill-color: var(--text-main);
}

/* scrollbars */
html[data-theme="light"] .sidebar::-webkit-scrollbar-thumb,
html[data-theme="light"] .output-container::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.18); }

/* auth (login) card aurora a bit softer on light */
html[data-theme="light"] .auth-wrap::before { opacity: 0.55; }

/* ============================================================
   HOME / Overview dashboard (D1)
   ============================================================ */
.home { display: flex; flex-direction: column; gap: 1.4rem; }
.home-greet h1 {
    font-family: var(--font-heading);
    font-size: 1.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.home-greet .wave { display: inline-block; animation: wave 2.2s ease-in-out 1; transform-origin: 70% 70%; }
@keyframes wave { 0%,60%,100%{transform:rotate(0)} 15%{transform:rotate(16deg)} 30%{transform:rotate(-10deg)} 45%{transform:rotate(12deg)} }

.home-kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.9rem;
}
.home-kpi { padding: 1rem 1.15rem; }
.home-kpi .k-lab {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}
.home-kpi .k-val {
    font-family: var(--font-heading);
    font-size: 1.9rem;
    font-weight: 700;
    margin-top: 0.15rem;
    color: var(--text-main);
}
.home-kpi .k-val small { font-size: 0.85rem; font-weight: 500; color: var(--text-muted); }

.home-h2 {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-top: 0.2rem;
}

.home-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.9rem;
}
.home-act {
    position: relative;
    padding: 1.1rem 1.15rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    overflow: hidden;
    transition: var(--transition);
}
.home-act::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--ac, var(--primary));
}
.home-act:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--ac) 45%, transparent); }
.home-act .a-ic {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    color: #fff;
    background: var(--ac, var(--primary));
    margin-bottom: 0.35rem;
}
.home-act .a-nm { font-weight: 600; font-size: 1rem; color: var(--text-main); }
.home-act .a-sub { font-size: 0.8rem; color: var(--text-muted); line-height: 1.4; }
.home-act .a-foot {
    margin-top: 0.5rem;
    font-size: 0.76rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
}
.home-act .a-foot i { color: var(--ac, var(--primary)); }

.home-grid {
    display: grid;
    grid-template-columns: 1.6fr 1fr;
    gap: 1.1rem;
    align-items: start;
}
.home-panel { padding: 1.1rem 1.2rem; }
.home-panel h3 {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    margin-bottom: 0.7rem;
}
.home-panel h3 .more { margin-left: auto; font-size: 0.78rem; font-weight: 500; color: var(--primary); }

.home-rlist { display: flex; flex-direction: column; }
.home-rrow {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.55rem 0.3rem;
    border-top: 1px solid var(--border-color);
    border-radius: 8px;
    transition: var(--transition);
}
.home-rrow:first-child { border-top: 0; }
.home-rrow:hover { background: rgba(148, 163, 184, 0.08); }
.home-rrow .r-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.home-rrow .r-t {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    font-size: 0.88rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.home-rrow .r-d { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }

.home-status { display: flex; flex-direction: column; }
.home-status .s-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.83rem;
    padding: 0.45rem 0;
    border-top: 1px solid var(--border-color);
}
.home-status .s-row:first-child { border-top: 0; }
.home-status .s-row i { font-size: 1rem; color: var(--text-muted); }
.home-status .s-row i.ok { color: var(--success); }
.home-status .s-row i.warn { color: #f59e0b; }
.home-status .s-row .k { color: var(--text-muted); }
.home-status .s-row .v { margin-left: auto; color: var(--text-main); font-weight: 500; }
.home-status .s-row .v.link { color: var(--primary); }

@media (max-width: 1000px) {
    .home-kpis { grid-template-columns: repeat(2, 1fr); }
    .home-actions { grid-template-columns: repeat(2, 1fr); }
    .home-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
    .home-actions { grid-template-columns: 1fr; }
}
