/* Side by Side — the whole stylesheet.
 *
 * It lives here rather than in a <style> block because the app is served under
 * a `style-src 'self'` CSP (server.py): an inline stylesheet is refused, and so
 * is an inline `style="..."` attribute — which is why the few the markup used
 * to carry are classes now (.grow, .push-down).
 */

:root {
    /* One token source for every colour, radius and timing below. */
    --bg: #fafafa;
    --surface: #fff;
    --line: #e5e5e5;
    --ink: #1a1a1a;
    --ink-dim: #666;
    --ink-faint: #888;
    --accent: #007AFF;
    --accent-strong: #0066DD;
    --danger: #FF3B30;
    --ok: #34C759;
    --radius: 8px;
    --radius-small: 6px;
    --tap: 0.15s;

    /* iOS zooms the page when a control below 16px takes focus and leaves it
     * zoomed. ONE token, raised for coarse pointers, so a later rule on a
     * specific control class cannot silently reopen the hole. */
    --control-font-size: 0.85rem;
}

@media (pointer: coarse) {
    :root { --control-font-size: 16px; }
}

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

/* Any element toggled through the `hidden` property needs this: an author
 * `display:` rule beats the UA hidden rule, making the toggle a no-op. */
[hidden] { display: none !important; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    min-height: 100dvh;
}

.container {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--line);
}

.sidebar-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.panel {
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ink-faint);
    margin-bottom: 12px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 12px;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    margin-bottom: 4px;
    color: #444;
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.grow { flex: 1; }
.push-down { margin-top: auto; }

input[type="number"],
input[type="text"],
select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg);
    border: 1px solid #ddd;
    border-radius: var(--radius-small);
    color: var(--ink);
    font-size: var(--control-font-size);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

input[type="color"] {
    width: 36px;
    height: 32px;
    padding: 2px;
    background: var(--surface);
    border: 1px solid #ddd;
    border-radius: var(--radius-small);
    cursor: pointer;
}

input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: var(--control-font-size);
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: var(--control-font-size);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--tap);
    touch-action: manipulation;
}

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}

.btn-primary:hover {
    background: var(--accent-strong);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: var(--line);
}

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

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

/* Engine panel */
.engine-note {
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--ink-dim);
    margin-bottom: 10px;
}

.engine-note strong { color: var(--ink); font-weight: 600; }
.engine-note.is-error { color: var(--danger); }
.engine-note.is-ready { color: #1f8a3b; }

.engine-storage {
    font-size: 0.7rem;
    color: var(--ink-faint);
    margin-top: 10px;
    line-height: 1.4;
}

.engine-bar {
    height: 6px;
    background: var(--line);
    border-radius: 3px;
    overflow: hidden;
    margin: 10px 0 8px;
}

.engine-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.2s;
}

.engine-actions {
    display: flex;
    gap: 8px;
}

.engine-actions .btn { flex: 1; }

/* Main content */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.toolbar {
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: var(--control-font-size);
}

.toolbar-info {
    color: var(--ink-dim);
}

.toolbar-info strong {
    color: var(--ink);
}

/* Drop zone */
.drop-zone {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    margin: 20px;
    border: 2px dashed #ddd;
    border-radius: 12px;
    transition: all 0.2s;
    background: var(--surface);
}

.drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(0, 122, 255, 0.05);
}

.drop-zone.has-videos {
    justify-content: flex-start;
    padding: 16px;
}

.drop-zone-prompt {
    text-align: center;
    color: var(--ink-faint);
}

.drop-zone-prompt svg {
    width: 48px;
    height: 48px;
    stroke: #bbb;
    margin-bottom: 12px;
}

.drop-zone-prompt h2 {
    font-size: 1rem;
    font-weight: 500;
    color: #555;
    margin-bottom: 4px;
}

.drop-zone-prompt p {
    font-size: var(--control-font-size);
}

/* Video Grid */
.video-grid {
    display: grid;
    gap: 4px;
    width: 100%;
    height: 100%;
    align-content: center;
}

.video-item {
    position: relative;
    background: #f0f0f0;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 16/9;
    transition: transform var(--tap), box-shadow var(--tap);
}

.video-item.dragging {
    opacity: 0.5;
}

.video-item.drag-over {
    outline: 2px solid var(--accent);
}

.video-item video {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #000;
}

.video-preview {
    position: absolute;
    inset: 0;
}

.video-item-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 25%, transparent 75%, rgba(0,0,0,0.5) 100%);
    transition: opacity var(--tap);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 8px;
}

/* Reveal-on-hover ONLY where hovering exists. On a touch screen `:hover` is a
 * hiding place, not an affordance: the remove button and the label editor live
 * in this overlay, so hiding it by default would make them unreachable on a
 * phone. Same gate on the lift, which a touch browser would otherwise leave
 * stuck on the last tile tapped. */
@media (hover: hover) {
    .video-item-overlay { opacity: 0; }
    .video-item:hover .video-item-overlay { opacity: 1; }
    .video-item:hover {
        transform: scale(1.01);
        box-shadow: 0 2px 12px rgba(0,0,0,0.1);
    }
}

.video-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.video-item-actions {
    display: flex;
    gap: 6px;
}

.video-item-index {
    background: var(--accent);
    color: white;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
}

.video-item-remove,
.video-item-move,
.video-item-drag {
    background: var(--danger);
    color: white;
    border: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    touch-action: manipulation;
}

.video-item-drag {
    background: rgba(255,255,255,0.95);
    color: var(--ink);
    cursor: grab;
    touch-action: none;
}

.video-item-drag:active { cursor: grabbing; }

.video-item-move {
    background: rgba(255,255,255,0.95);
    color: var(--ink);
}

.video-item-move:disabled {
    opacity: 0.4;
    cursor: default;
}

.video-item-footer {
    text-align: center;
}

.video-item-name {
    font-size: 0.7rem;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-label-editor {
    position: absolute;
    bottom: 64px;
    left: 8px;
    right: 8px;
    display: flex;
    gap: 4px;
}

.video-time-editor {
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 32px;
    display: grid;
    grid-template-columns: auto minmax(40px, 1fr) 58px auto;
    align-items: center;
    gap: 5px;
    color: white;
    font-size: 0.7rem;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}

.video-time-editor input[type="range"] {
    min-width: 0;
    accent-color: var(--accent);
    touch-action: pan-x;
}

.video-time-editor input[type="number"] {
    padding: 4px 5px;
    text-align: right;
}

.video-label-editor input {
    flex: 1;
    padding: 5px 8px;
    font-size: var(--control-font-size);
    background: rgba(255,255,255,0.95);
    border: 1px solid #ddd;
    border-radius: 4px;
    color: var(--ink);
}

.video-label-editor select {
    padding: 5px;
    font-size: var(--control-font-size);
    background: rgba(255,255,255,0.95);
    border: 1px solid #ddd;
    border-radius: 4px;
    color: var(--ink);
    width: auto;
}

.video-text-overlay {
    position: absolute;
    padding: 3px 6px;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 0.75rem;
    font-weight: 500;
    pointer-events: none;
}

.video-text-overlay.top-left { top: 6px; left: 6px; }
.video-text-overlay.top-center { top: 6px; left: 50%; transform: translateX(-50%); }
.video-text-overlay.top-right { top: 6px; right: 6px; }
.video-text-overlay.bottom-left { bottom: 6px; left: 6px; }
.video-text-overlay.bottom-center { bottom: 6px; left: 50%; transform: translateX(-50%); }
.video-text-overlay.bottom-right { bottom: 6px; right: 6px; }

/* Progress */
.progress-container {
    padding: 16px 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.progress-bar {
    height: 6px;
    background: var(--line);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

.progress-text {
    font-size: 0.8rem;
    color: var(--ink-dim);
    display: flex;
    justify-content: space-between;
}

/* Status bar */
.status-bar {
    padding: 8px 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    font-size: 0.75rem;
    color: var(--ink-faint);
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.status-ready { color: var(--ok); }
.status-loading { color: var(--accent); }
.status-error { color: var(--danger); }

#fileInput { display: none; }

/* fleet_pwa.js publishes connectivity as a class on <html>. */
.pwa-offline .status-bar::before {
    content: "Offline";
    color: var(--danger);
    font-weight: 600;
}

@media (max-width: 760px) {
    body { min-width: 0; }

    .container {
        height: auto;
        min-height: 100dvh;
        flex-direction: column;
    }

    .main {
        order: -1;
        flex: none;
        overflow: visible;
    }

    .sidebar {
        width: 100%;
        overflow: visible;
        border-right: 0;
        border-top: 1px solid var(--line);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .sidebar-header { display: none; }

    .toolbar {
        padding: 10px 12px;
        gap: 8px;
        flex-wrap: wrap;
        padding-top: max(10px, env(safe-area-inset-top, 0px));
    }

    .toolbar .grow { display: none; }
    .toolbar-info { flex: 1 1 auto; }
    .toolbar .btn { min-height: 44px; }

    .drop-zone {
        min-height: 260px;
        margin: 12px;
        padding: 20px;
    }

    .drop-zone.has-videos { padding: 8px; }

    .video-grid {
        height: auto;
        grid-template-columns: 1fr !important;
        align-content: start;
    }

    .video-item {
        aspect-ratio: auto;
        cursor: default;
        overflow: visible;
        border: 1px solid var(--line);
        background: var(--surface);
    }

    .video-preview {
        position: relative;
        inset: auto;
        aspect-ratio: var(--video-aspect-ratio, 16 / 9);
        overflow: hidden;
        border-radius: var(--radius) var(--radius) 0 0;
        background: #f0f0f0;
    }

    .video-item-overlay {
        position: relative;
        inset: auto;
        gap: 10px;
        padding: 10px;
        background: var(--surface);
        color: var(--ink);
    }

    .video-item-index { align-self: center; }

    .video-item-remove,
    .video-item-move,
    .video-item-drag {
        width: 44px;
        height: 44px;
        font-size: 1.1rem;
    }

    .video-item-drag { display: none; }

    .video-label-editor,
    .video-time-editor {
        position: static;
    }

    .video-time-editor {
        color: var(--ink-dim);
        text-shadow: none;
        grid-template-columns: auto minmax(60px, 1fr) 70px auto;
        font-size: var(--control-font-size);
    }

    .video-item-footer { text-align: left; }
    .video-item-name { color: var(--ink-dim); text-shadow: none; }

    .status-bar {
        padding: 8px 12px;
        flex-direction: column;
        gap: 4px;
    }

    .panel { padding-left: 16px; padding-right: 16px; }
    .push-down { margin-top: 0; }
}
