/* ────────────────────────────────────────────
   DocScan – Premium Dark UI
   ──────────────────────────────────────────── */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Design Tokens ── */
:root {
    --bg:          #080812;
    --bg2:         #0e0e1c;
    --bg3:         #141428;
    --card:        rgba(255,255,255,0.035);
    --card-border: rgba(255,255,255,0.08);
    --teal:        #00d9b1;
    --teal-dim:    rgba(0,217,177,0.15);
    --teal-glow:   0 0 30px rgba(0,217,177,0.3);
    --purple:      #7c3aed;
    --purple-dim:  rgba(124,58,237,0.2);
    --red:         #ef4444;
    --text:        #eeeef5;
    --text2:       #8888aa;
    --text3:       #4444664;
    --grad:        linear-gradient(135deg, #00d9b1, #7c3aed);
    --shadow:      0 24px 64px rgba(0,0,0,0.6);
    --radius:      16px;
    --radius-sm:   10px;
    --transition:  0.25s cubic-bezier(0.4,0,0.2,1);
}

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

html {
    scroll-behavior: smooth;
    /* Prevent iOS double-tap zoom */
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Subtle grid background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(rgba(0,217,177,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,217,177,0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
    z-index: 0;
}

/* ── Loading Overlay ── */
.loading-overlay {
    position: fixed; inset: 0;
    background: rgba(8,8,18,0.95);
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(8px);
    transition: opacity var(--transition);
}
.loading-overlay.hidden { display: none; }
.loading-content { text-align: center; }
.loading-content h2 { font-size: 1.4rem; font-weight: 700; margin-bottom: 8px; }
.loading-content p  { color: var(--text2); font-size: 0.9rem; }

.spinner {
    width: 56px; height: 56px;
    border: 3px solid rgba(0,217,177,0.2);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
    margin: 0 auto 24px;
    box-shadow: var(--teal-glow);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast Notifications ── */
.toast-container {
    position: fixed; top: 24px; right: 24px;
    z-index: 10000;
    display: flex; flex-direction: column; gap: 10px;
}
.toast {
    background: var(--bg3);
    border: 1px solid var(--card-border);
    border-left: 3px solid var(--teal);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
    animation: toastIn 0.3s ease forwards;
    max-width: 320px;
}
.toast.error { border-left-color: var(--red); }
.toast.warning { border-left-color: #f59e0b; }
@keyframes toastIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ── App Layout ── */
.app-wrapper {
    position: relative; z-index: 1;
    min-height: 100vh;
    display: flex; flex-direction: column;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Header ── */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 0;
    gap: 20px;
    flex-wrap: wrap;
}

.logo {
    display: flex; align-items: center; gap: 10px;
    text-decoration: none;
}
.logo-icon { font-size: 1.8rem; }
.logo-text {
    font-size: 1.4rem; font-weight: 800;
    background: var(--grad); -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

/* Step Indicator */
.steps {
    display: flex; align-items: center; gap: 6px;
}
.step {
    display: flex; align-items: center; gap: 6px;
    opacity: 0.35;
    transition: opacity var(--transition);
}
.step.active { opacity: 1; }
.step.done   { opacity: 0.7; }
.step-icon  { font-size: 1rem; }
.step-label { font-size: 0.8rem; font-weight: 600; color: var(--text2); }
.step.active .step-label { color: var(--teal); }
.step-line {
    width: 28px; height: 1px;
    background: var(--card-border);
}

/* ── Main Content ── */
.app-main { flex: 1; padding-bottom: 40px; }

.section { animation: fadeUp 0.35s ease forwards; }
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Cards ── */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    overflow: hidden;
}

/* ── Upload Card ── */
.upload-card { padding: 0; }

.upload-area {
    padding: 64px 32px;
    text-align: center;
    cursor: pointer;
    position: relative;
    transition: background var(--transition);
    /* Animated dashed border */
    border-radius: var(--radius);
}
.upload-area::before {
    content: '';
    position: absolute; inset: 12px;
    border: 2px dashed rgba(0,217,177,0.25);
    border-radius: calc(var(--radius) - 4px);
    transition: border-color var(--transition);
    background: transparent;
    pointer-events: none;
}
.upload-area:hover::before,
.upload-area.drag-over::before {
    border-color: var(--teal);
    animation: borderDash 15s linear infinite;
}
@keyframes borderDash {
    to { stroke-dashoffset: -1000; }
}
.upload-area.drag-over { background: var(--teal-dim); }

.upload-icon-wrap {
    width: 80px; height: 80px;
    background: var(--teal-dim);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 24px;
    color: var(--teal);
    transition: transform var(--transition), box-shadow var(--transition);
}
.upload-area:hover .upload-icon-wrap {
    transform: translateY(-4px) scale(1.05);
    box-shadow: var(--teal-glow);
}

.upload-area h2 {
    font-size: 1.4rem; font-weight: 700;
    margin-bottom: 8px;
}
.upload-area p {
    color: var(--text2); font-size: 0.9rem;
    margin-bottom: 28px;
}

.upload-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ── Buttons ── */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 24px;
    border: none; border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.9rem; font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}
.btn-primary {
    background: var(--grad);
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,217,177,0.25);
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,217,177,0.4);
}
.btn-ghost {
    background: rgba(255,255,255,0.06);
    color: var(--text);
    border: 1px solid var(--card-border);
}
.btn-ghost:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.15);
}
.btn-danger {
    background: rgba(239,68,68,0.15);
    color: #fca5a5;
    border: 1px solid rgba(239,68,68,0.25);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-lg { padding: 14px 36px; font-size: 1rem; }
.btn-sm { padding: 7px 14px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ── Collection Mini ── */
.collection-mini {
    border-top: 1px solid var(--card-border);
    padding: 24px;
}
.collection-mini-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px;
    margin-bottom: 20px;
    font-weight: 600; font-size: 0.95rem;
}
.collection-mini-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Document Grid ── */
.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
}
.document-item {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--card-border);
    background: var(--bg3);
    transition: transform var(--transition), box-shadow var(--transition);
    cursor: pointer;
}
.document-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0,0,0,0.4);
}
.document-item img {
    width: 100%; height: 180px; object-fit: cover;
    display: block;
}
.document-item .item-label {
    padding: 6px 10px;
    font-size: 0.75rem; font-weight: 600; color: var(--text2);
    text-align: center;
}
.document-item .delete-btn {
    position: absolute; top: 6px; right: 6px;
    background: rgba(239,68,68,0.85);
    color: #fff; border: none;
    width: 26px; height: 26px; border-radius: 50%;
    font-size: 0.75rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
}
.document-item:hover .delete-btn { opacity: 1; }

/* ── Camera ── */
.camera-card { padding: 24px; text-align: center; }
.camera-card video {
    width: 100%; max-width: 720px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    border: 1px solid var(--card-border);
}
.camera-controls { display: flex; gap: 12px; justify-content: center; }

/* ── Preview / Crop ── */
.preview-card { padding: 24px; }
.section-title { margin-bottom: 20px; }
.section-title h3 { font-size: 1.2rem; font-weight: 700; margin-bottom: 4px; }
.section-title p  { color: var(--text2); font-size: 0.875rem; }

.canvas-wrapper {
    position: relative;
    display: inline-block;
    max-width: 100%;
    margin: 0 auto;
    display: flex; justify-content: center;
    margin-bottom: 24px;
}

#previewCanvas, #canvas {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: var(--radius-sm);
    border: 1px solid var(--card-border);
}

.corner-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    pointer-events: none;
    border-radius: var(--radius-sm);
    overflow: visible;
}

.corner-line {
    stroke: var(--teal);
    stroke-width: 2;
    stroke-dasharray: 6 4;
    animation: dashMove 20s linear infinite;
}
@keyframes dashMove { to { stroke-dashoffset: -500; } }

.corner-point { pointer-events: all; cursor: grab; }
.corner-point:active { cursor: grabbing; }
/* Larger touch target on mobile (at least 44px×44px) */
.corner-outer {
    fill: rgba(0,217,177,0.15);
    stroke: var(--teal);
    stroke-width: 2;
    filter: url(#glow);
    transition: r 0.2s;
}
.corner-inner { fill: var(--teal); }
.corner-point:hover .corner-outer,
.corner-point:active .corner-outer { r: 22; }

.preview-actions {
    display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
}

/* ── Editor ── */
.editor-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
    align-items: start;
}

.editor-canvas-card {
    padding: 16px;
    display: flex; align-items: center; justify-content: center;
}

.editor-panel {
    padding: 24px;
    display: flex; flex-direction: column; gap: 20px;
}
.panel-title {
    font-size: 1.1rem; font-weight: 700;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--card-border);
}

.control-group { display: flex; flex-direction: column; gap: 10px; }
.control-group label {
    font-size: 0.8rem; font-weight: 600; color: var(--text2);
    text-transform: uppercase; letter-spacing: 0.05em;
    display: flex; justify-content: space-between; align-items: center;
}
.value-badge {
    background: var(--teal-dim); color: var(--teal);
    padding: 2px 8px; border-radius: 20px;
    font-size: 0.75rem; font-weight: 700;
    font-family: 'Inter', monospace;
}

/* Filter icon grid – CamScanner style */
.filter-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}
.btn-filter {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 6px;
    padding: 12px 6px 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text2);
    font-family: inherit; font-size: 0.72rem; font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 68px;
}
.btn-filter:hover {
    border-color: rgba(0,217,177,0.5);
    color: var(--text);
    background: rgba(255,255,255,0.07);
    transform: translateY(-1px);
}
.btn-filter.active {
    background: var(--teal-dim);
    border-color: var(--teal);
    color: var(--teal);
    box-shadow: 0 0 12px rgba(0,217,177,0.2);
}
.fi-icon {
    font-size: 1.4rem;
    line-height: 1;
    display: block;
}
/* Magic Pro gets special gradient icon */
.btn-filter.active .fi-magic { filter: drop-shadow(0 0 6px rgba(0,217,177,0.8)); }
.fi-bw  { font-size: 1.3rem; color: #ccc; }
.fi-bw2 { font-size: 1.3rem; color: #999; }
/* Keep backwards compat with old filter-buttons class */
.filter-buttons { display: flex; flex-wrap: wrap; gap: 8px; }


/* Custom Range Slider */
.slider {
    -webkit-appearance: none;
    width: 100%; height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    outline: none;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px; height: 18px;
    background: var(--teal);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 8px rgba(0,217,177,0.5);
    transition: transform 0.2s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider::-moz-range-thumb {
    width: 18px; height: 18px;
    background: var(--teal); border: none;
    border-radius: 50%; cursor: pointer;
}

.panel-actions {
    display: flex; flex-direction: column; gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--card-border);
}
.panel-actions .btn { justify-content: center; }

/* ── Footer ── */
.app-footer {
    text-align: center; padding: 20px 0;
    color: var(--text2); font-size: 0.8rem;
    border-top: 1px solid var(--card-border);
}

/* ── Features Grid ── */
.features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    border-top: 1px solid var(--card-border);
}
.feature-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 20px 24px;
    border-right: 1px solid var(--card-border);
    transition: background var(--transition);
}
.feature-item:last-child { border-right: none; }
.feature-item:hover { background: rgba(255,255,255,0.03); }
.feature-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
    margin-top: 2px;
}
.feature-item h4 {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}
.feature-item p {
    font-size: 0.75rem;
    color: var(--text2);
    line-height: 1.5;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .app-header {
        justify-content: center;
        flex-direction: column;
        padding: 16px 0 12px;
        gap: 12px;
    }
    .steps { flex-wrap: wrap; justify-content: center; }
    .step-line { display: none; }
    .step-label { font-size: 0.7rem; }

    /* Full-width card, no padding waste */
    .app-wrapper { padding: 0 12px; }
    .upload-area { padding: 36px 16px; }
    .features-grid { grid-template-columns: 1fr 1fr; }
    .feature-item { padding: 14px 16px; }

    .editor-layout { grid-template-columns: 1fr; }
    .editor-panel { order: 2; }
    .editor-canvas-card { order: 1; }

    /* Sticky bottom action bar for preview & editor */
    .preview-actions,
    .panel-actions {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: var(--bg2);
        border-top: 1px solid var(--card-border);
        padding: 12px 16px;
        z-index: 100;
        display: flex;
        gap: 10px;
        justify-content: stretch;
        backdrop-filter: blur(12px);
    }
    .preview-actions .btn,
    .panel-actions .btn { flex: 1; justify-content: center; }

    /* Extra bottom padding so content isn't hidden by sticky bar */
    .preview-card { padding-bottom: 80px; }
    .editor-panel  { padding-bottom: 80px; }

    /* Make corner handles bigger for fat fingers */
    .corner-outer { r: 20; }
    .corner-inner { r: 8; }

    /* Full-screen camera on mobile */
    .camera-card {
        position: fixed; inset: 0;
        border-radius: 0;
        z-index: 200;
        background: #000;
        display: flex; flex-direction: column;
        justify-content: space-between;
    }
    .camera-card video {
        width: 100%; flex: 1;
        object-fit: cover;
        border-radius: 0;
        margin-bottom: 0;
        max-width: none;
    }
    .camera-controls {
        padding: 20px;
        background: rgba(0,0,0,0.8);
    }

    /* Bigger document thumbnails */
    .document-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
    .document-item img { height: 150px; }

    .toast-container { left: 12px; right: 12px; top: 12px; }
    .toast { max-width: 100%; }
}

/* Very small screens */
@media (max-width: 400px) {
    .logo-text { font-size: 1.2rem; }
    .upload-area h2 { font-size: 1.1rem; }
    .features-grid { grid-template-columns: 1fr; }
    .btn-lg { padding: 12px 24px; font-size: 0.95rem; }
}
