/* =========================================
   Feather Scan — Refined Minimalist Dashboard
   Strict Claude-Style Interaction
   ========================================= */

:root {
    --bg-main: #F3EFE7;
    --bg-sidebar: #F3EFE7;
    --bg-msg-user: #EAE5DB;
    --bg-input: #FAFAF8;
    --text-primary: #1A1A1A;
    --text-muted: #736F68;
    --border: #D6D1C7;
    --accent: #1A1A1A;
    --accent-hover: #333333;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    --font-body: 'Inter', sans-serif;
    --font-serif: 'Newsreader', serif;
}

[data-theme="dark"] {
    --bg-main: #262624;
    --bg-sidebar: #262624;
    --bg-msg-user: #2C2C2C;
    --bg-input: #1A1A1A;
    --text-primary: #F3EFE7;
    --text-muted: #8C877E;
    --border: #333333;
    --accent: #F3EFE7;
    --accent-hover: #FFFFFF;
}

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

body {
    height: 100vh;
    font-family: var(--font-body);
    font-size: 0.95rem;
    background: var(--bg-main);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.serif {
    font-family: var(--font-serif);
}

.mt-auto {
    margin-top: auto;
}

.mt-2 {
    margin-top: 8px;
}

/* ─── Scrollbar (Ultra-Thin 4px) ────────────── */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ─── Dashboard Shell ────────────────────────── */
.dashboard-shell {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ─── Sidebar Dashboard ──────────────────────── */
.sidebar {
    width: 268px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), width var(--transition);
    flex-shrink: 0;
    overflow: hidden;
    z-index: 2000;
}

body.sidebar-closed .sidebar {
    width: 0;
    transform: translateX(-100%);
    border-right-color: transparent;
}

.sidebar-header {
    padding: 20px 20px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.brand .serif {
    font-size: 1.3rem;
    font-weight: 500;
}

.logo-svg {
    color: var(--accent);
}

.header-tools {
    display: flex;
    gap: 8px;
}

/* Refinement: Square Rounded Action Buttons */
.sq-action-btn {
    width: 32px;
    height: 32px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.sq-action-btn:hover {
    background: var(--border);
    color: var(--text-primary);
    border-color: transparent;
}

.sq-action-btn.floating {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 3000;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

body.sidebar-closed .sq-action-btn.floating {
    visibility: visible;
    opacity: 1;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    gap: 24px;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 240px;
}

.section-label {
    font-size: 0.73rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    padding: 6px 8px;
}



.btn-secondary {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    height: 35px;
    padding: 0 16px;
    border-radius: 6px;
    font-weight: 500;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
    color: var(--text-primary);
}

.btn-secondary:disabled,
.btn-primary-focused:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn-primary-focused {
    background: var(--accent);
    color: var(--bg-main);
    border: none;
    height: 35px;
    padding: 0 16px;
    border-radius: 6px;
    font-weight: 500;
    font-family: var(--font-body);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary-focused:hover:not(:disabled) {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.filter-gallery-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    padding: 0;
}

.filter-gallery-item {
    cursor: pointer;
    text-align: center;
    transition: var(--transition);
}

.filter-gallery-item .thumb-wrap {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    aspect-ratio: 3/4;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    padding: 4px;
}

.filter-gallery-item img {
    max-width: 100%;
    max-height: 100%;
    object-fit: cover;
    opacity: 0.85;
}

.filter-gallery-item span {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
}

.filter-gallery-item:hover .thumb-wrap {
    border-color: var(--accent);
}

.filter-gallery-item.active .thumb-wrap {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

.filter-gallery-item.active span {
    color: var(--accent);
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-3 {
    margin-bottom: 1.25rem;
}

.w-full {
    width: 100%;
}


.filter-pill {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 12px 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.75rem;
    font-weight: 500;
}

.filter-pill:hover {
    background: var(--bg-msg-user);
    color: var(--text-primary);
}

.filter-pill.active {
    background: var(--accent);
    color: var(--bg-main);
    border-color: transparent;
}

.toggle-group {
    display: flex;
    gap: 6px;
    padding: 0 8px;
}

.pill-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.pill-btn:hover {
    background: var(--border);
    transform: translateY(-2px);
}

.pill-btn.active {
    background: var(--accent);
    color: var(--bg-main);
    border-color: transparent;
}

.pill-btn.active:hover {
    background: var(--accent-hover);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
}

.dot.ready {
    background: #10b981;
}

/* ─── Main Content (Dynamic Expansion) ────────── */
.main-content {
    flex: 1;
    position: relative;
    background: var(--bg-main);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: flex 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#workspace {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

.stage {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.stage.active {
    opacity: 1;
    pointer-events: all;
}

/* Upload Area (Split: Box + Info) */
.upload-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    text-align: center;
    width: 100%;
    max-width: 350px;
}

.upload-box {
    width: 100%;
    padding: 40px 48px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: 0.2s;
    color: var(--text-muted);
    opacity: 0.5;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.upload-box:hover {
    border-color: var(--accent);
    background: var(--bg-sidebar);
    opacity: 1;
    color: var(--accent);
}


.upload-wrap h3 {
    font-size: 1.4rem;
    font-weight: 500;
}

.upload-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
}

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

.canvas-mount {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    position: relative;
}

#main-canvas {
    display: block;
    max-width: 85vw;
    max-height: 85vh;
    transition: 0.3s ease;
}

/* Interaction Styles (8px dots) */
.handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: move;
    z-index: 500;
}

.lens-glass {
    position: fixed;
    width: 150px;
    height: 150px;
    border: 2px solid var(--accent);
    border-radius: 50%;
    background: #fff;
    pointer-events: none;
    z-index: 1000;
    display: none;
    overflow: hidden;
}

#lens-canvas {
    width: 100%;
    height: 100%;
}

.lens-crosshair {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.lens-crosshair::before,
.lens-crosshair::after {
    content: '';
    position: absolute;
    background: #22c55e;
    /* Bright Green */
}

.lens-crosshair::before {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    margin-top: -1px;
}

.lens-crosshair::after {
    width: 2px;
    height: 100%;
    top: 0;
    left: 50%;
    margin-left: -1px;
}

/* Result View */
.result-surface {
    width: 100%;
    max-width: 900px;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.result-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: var(--radius-md);
}

.result-placeholder {
    flex: 1;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

#result-canvas {
    max-width: 100%;
    max-height: 100%;
    background: #fff;
    border: 1px solid var(--border);
    display: block;
}

.btn-ghost-iconic {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =========================================
   Layout Editor & Universal Utilities
   ========================================= */

:root {
    --a4-width-landscape: 297mm;
    --a4-height-landscape: 210mm;
    --page-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    --slot-bg: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] {
    --page-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    --slot-bg: rgba(255, 255, 255, 0.03);
}

/* Sidebar Nav States */
.tool-link {
    text-decoration: none;
    padding: 12px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    color: var(--text-muted);
}

.tool-link.active {
    color: var(--accent);
    background: var(--border);
}

.tool-link:hover:not(.active) {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-primary);
}

[data-theme="dark"] .tool-link:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

/* Layout Editor Components */
.layout-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    gap: 20px;
    overflow-y: auto;
    flex: 1;
    scroll-behavior: smooth;
    background: var(--bg-main);
}

.workspace-layout {
    display: flex;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.a4-page {
    width: var(--a4-width-landscape);
    height: var(--a4-height-landscape);
    background: white;
    border: 1px solid var(--border);
    display: flex;
    position: relative;
    flex-shrink: 0;
    border-radius: 2px;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.a4-page:hover {
    transform: translateY(-5px) scale(1.01);
}



.page-slot {
    flex: 1;
    height: 100%;
    border-right: 1px dashed var(--border);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--slot-bg);
}

.exporting-pdf .page-slot {
    border-right: none !important;
    background: white !important;
}

.page-slot:last-child {
    border-right: none;
}

.page-slot.active-slot {
    outline: 2px solid #2563eb;
    background: rgba(37, 99, 235, 0.05);
}

.page-slot.empty::after {
    content: 'Drop Scan Here';
    font-family: var(--font-body);
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 600;
    opacity: 0.5;
}

.slot-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    animation: fadeIn 0.5s ease;
}

.exporting-pdf .slot-image {
    padding: 5px;
    /* Small safe margin for PDF */
    animation: none !important;
    opacity: 1 !important;
    image-rendering: -webkit-optimize-contrast;
    /* Sharper images */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.98);
    }

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

.page-controls {
    position: absolute;
    top: 20px;
    right: -50px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    opacity: 0;
    transition: all 0.3s ease;
}

.a4-page:hover .page-controls {
    opacity: 1;
    right: 20px;
}

/* Hide remove button for the first (default) page */
.a4-page:first-of-type .page-controls {
    display: none !important;
}

.control-btn {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.control-btn:hover {
    background: #d94e33;
    transform: scale(1.1);
}

/* Modal / Selection UI */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-sidebar);
    width: 90%;
    max-width: 600px;
    height: 80vh;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--page-shadow);
    animation: slideUp 0.4s cubic-bezier(0.2, 1, 0.2, 1);
}

.modal-header {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.gallery-grid-modal {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
}

.modal-gallery-item {
    aspect-ratio: 1/1.414;
    background: var(--bg-main);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
}

.modal-gallery-item:hover {
    transform: translateY(-4px);
}

.modal-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.toolbar-floating {
    position: fixed;
    bottom: 40px;
    left: calc(268px + (100% - 268px)/2);
    transform: translateX(-50%);
    background: var(--bg-sidebar);
    padding: 8px;
    border-radius: 16px;
    box-shadow: var(--page-shadow);
    display: flex;
    gap: 8px;
    z-index: 1000;
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-closed .toolbar-floating {
    left: 50%;
}

.toolbar-floating .pill-btn {
    border: none;
    height: 35px;
    min-width: 110px;
}

.empty-state {
    text-align: center;
    margin-top: 15vh;
    color: var(--text-muted);
    opacity: 0.6;
}

.btn-pdf {
    background: transparent !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
}

.btn-pdf:hover {
    background: var(--border) !important;
}

.btn-clear {
    background: rgba(217, 78, 51, 0.1) !important;
    color: #d94e33 !important;
    border: 1px solid rgba(217, 78, 51, 0.2) !important;
}

.btn-clear:hover {
    background: #d94e33 !important;
    color: white !important;
}

/* ─── Export Loader Overlay ─────────────────── */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s ease;
}

.loader-card {
    background: var(--bg-sidebar);
    padding: 40px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    box-shadow: var(--page-shadow);
    text-align: center;
    min-width: 320px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#loader-progress {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: -5px;
}

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

@media (max-width: 1500px) {
    .layout-container {
        zoom: 0.6;
    }
}