/* ============================================================
   Photo Scanner — Stylesheet
   ============================================================ */

/* ---- Reset & base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #1a1b1e;
    --bg-surface: #25262b;
    --bg-surface-hover: #2c2d33;
    --bg-elevated: #2e2f35;
    --border: #3a3b41;
    --border-light: #4a4b52;
    --text: #e4e4e7;
    --text-muted: #9495a0;
    --text-dim: #6b6c78;
    --primary: #4a9eff;
    --primary-hover: #3b8ee8;
    --primary-bg: rgba(74, 158, 255, 0.12);
    --success: #3dd68c;
    --success-bg: rgba(61, 214, 140, 0.12);
    --warning: #f5a623;
    --danger: #e5534b;
    --danger-bg: rgba(229, 83, 75, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
    --transition: 0.15s ease;
}

html { font-size: 15px; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ---- Header ---- */
#app-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto auto;
    align-items: center;
    padding: 8px 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 0 16px;
}
.header-brand {
    grid-row: 1 / 3;
    display: flex;
    align-items: center;
    gap: 12px;
}
.header-brand h1 {
    font-size: 1.2rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.logo-icon {
    width: 64px;
    height: 64px;
    border-radius: 8px;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}
.scanner-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px rgba(61,214,140,0.5); }
.status-dot.error { background: var(--danger); }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn:hover { background: var(--bg-surface-hover); border-color: var(--border-light); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }

.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border-light);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-muted);
}
.btn-ghost:hover { background: var(--bg-surface-hover); color: var(--text); }

.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

.btn-toggle {
    background: transparent;
    border-color: var(--border);
}
.btn-toggle.active {
    background: var(--primary-bg);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-group { display: flex; gap: 4px; }

.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

/* ---- Step navigation ---- */
.steps-nav {
    grid-column: 2;
    display: flex;
    gap: 4px;
    justify-content: center;
}
.step-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: var(--text-dim);
    font-family: var(--font);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}
.step-tab:hover { color: var(--text-muted); background: var(--bg-surface-hover); }
.step-tab.active {
    color: var(--primary);
    background: var(--primary-bg);
    border-color: rgba(74,158,255,0.2);
}
.step-tab.completed .step-num {
    background: var(--success);
    color: #fff;
}
.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-elevated);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ---- Main panels ---- */
#app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.step-panel {
    display: none;
    flex: 1;
    overflow: hidden;
}
.step-panel.active { display: flex; }

.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px 24px;
    gap: 16px;
    overflow: auto;
    min-height: 0;
}
.panel-split {
    flex-direction: row;
    overflow: hidden;
}
.panel-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    padding-top: 8px;
}

/* ---- Preview area ---- */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 300px;
}
.placeholder {
    text-align: center;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.placeholder p { max-width: 300px; }

#preview-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* ---- Crop area ---- */
.crop-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    min-height: 300px;
}
#crop-canvas {
    max-width: 100%;
    max-height: 100%;
    cursor: crosshair;
}

/* ---- Config sidebar ---- */
.config-sidebar {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow-y: auto;
}
.config-sidebar h3 {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

/* ---- Forms ---- */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-group > label {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-group > label span {
    color: var(--text-dim);
    font-family: var(--mono);
    font-size: 0.75rem;
}
.form-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.form-control {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.9rem;
    transition: border-color var(--transition);
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(74,158,255,0.15);
}
select.form-control { cursor: pointer; }

/* Slider */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}
.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-surface);
}
.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-surface);
}

/* ---- Output info ---- */
.output-info, .scan-info {
    padding: 12px;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 0.85rem;
    color: var(--text-muted);
}
.output-info p, .scan-info p { margin-bottom: 4px; }
.output-info strong, .scan-info strong { color: var(--text); }

/* ---- Transform buttons ---- */
.transform-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

/* ---- Adjust preview ---- */
.adjust-preview-area, .review-preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    min-height: 0;
    /* Hard cap: viewport minus header(~52px) + steps(~52px) + padding(~56px) */
    max-height: calc(100vh - 160px);
}
.adjust-preview-area img, .review-preview-area img {
    max-width: 100%;
    max-height: calc(100vh - 180px);
    object-fit: contain;
    border-radius: 4px;
}

/* ---- Directory browser ---- */
.dir-browser {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.dir-current {
    padding: 8px 10px;
    font-family: var(--mono);
    font-size: 0.8rem;
    color: var(--primary);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    word-break: break-all;
}
.dir-list {
    max-height: 200px;
    overflow-y: auto;
}
.dir-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background var(--transition);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.dir-entry:hover { background: var(--bg-surface-hover); }
.dir-entry-icon { color: var(--text-dim); font-size: 0.9rem; }
.dir-input-row {
    display: flex;
    gap: 4px;
    padding: 6px;
    border-top: 1px solid var(--border);
}
.dir-input-row .form-control {
    font-size: 0.8rem;
    padding: 6px 8px;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-body {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

/* ---- History items ---- */
.history-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.history-item:last-child { border-bottom: none; }
.history-thumb {
    width: 60px;
    height: 60px;
    border-radius: var(--radius);
    object-fit: cover;
    background: var(--bg);
    flex-shrink: 0;
}
.history-details {
    flex: 1;
    min-width: 0;
}
.history-details .filename {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-details .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}
.history-details .path {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-family: var(--mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.history-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 20px;
}

/* ---- Preset list ---- */
.preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.preset-item .preset-info {
    font-size: 0.9rem;
}
.preset-item .preset-dims {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ---- Loading overlay ---- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(6px);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
}
.loading-raspberry {
    width: 64px;
    height: 64px;
    animation: raspberry-bounce 1s ease-in-out infinite;
    filter: drop-shadow(0 0 12px rgba(255,255,255,0.3));
}
@keyframes raspberry-bounce {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-12px) rotate(-8deg); }
    50% { transform: translateY(0) rotate(0deg); }
    75% { transform: translateY(-8px) rotate(8deg); }
}
.loading-text {
    color: var(--text-muted);
    font-size: 1rem;
}

/* ---- Success toast ---- */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    box-shadow: var(--shadow-lg);
    z-index: 3000;
    animation: slideUp 0.3s ease;
}
.toast.error { border-color: var(--danger); }
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }
