:root {
    --bg: #f5f4f1;
    --card-bg: #ffffff;
    --text: #26241f;
    --muted: #7a7568;
    --accent: #d97757;
    --accent-dark: #b85f42;
    --border: #e5e2db;
    --danger: #c0392b;
    --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--accent-dark); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ok { color: #2e7d32; }

/* --- Auth pages --- */
.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 32px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}

.auth-card h1 { margin-top: 0; }

form label {
    display: block;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.9rem;
}

form input[type="text"],
form input[type="password"],
form input[type="number"] {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: normal;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: normal;
}
.checkbox-row input { width: auto; margin: 0; }

.admin-details {
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.admin-details summary { cursor: pointer; color: var(--muted); }

.btn {
    display: inline-block;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
.btn:hover { background: var(--accent-dark); }
.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #a13324; }

.error-box {
    background: #fdecea;
    border: 1px solid #f5c6c0;
    color: #b02a1e;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* --- App shell --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.3rem; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.hello { font-size: 0.9rem; }

.storage-bar-wrap {
    padding: 10px 24px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}
.storage-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.storage-bar-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}
.storage-label {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}

.dropzone {
    margin: 20px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 28px;
    text-align: center;
    background: var(--card-bg);
    transition: border-color 0.2s, background 0.2s;
}
.dropzone.dragover {
    border-color: var(--accent);
    background: #fdf3ee;
}
.dropzone p { margin: 6px 0; }

.upload-list {
    margin: 0 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.upload-row {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.85rem;
}
.upload-row-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 12px;
}
.upload-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease;
}
.upload-row.error .upload-progress-fill { background: var(--danger); }
.upload-row.done .upload-progress-fill { background: #2e7d32; }
.upload-row-status { color: var(--muted); font-size: 0.8rem; }

.toolbar {
    margin: 20px 24px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}
.filters { display: flex; gap: 8px; }
.filter-btn {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 6px 14px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
}
.filter-btn.active { background: var(--text); color: white; border-color: var(--text); }
.selection-tools { display: flex; gap: 8px; align-items: center; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
    margin: 12px 24px 32px;
}

.tile {
    margin: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}
.tile-select {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 2;
    display: none;
}
.selecting .tile-select { display: block; }
.tile-select input { width: 20px; height: 20px; }

.tile-media {
    display: block;
    aspect-ratio: 1 / 1;
    background: #eee;
    overflow: hidden;
}
.tile-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.video-tile {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #2b2b2b, #4a4a4a);
}
.video-icon { font-size: 2rem; color: white; }

.tile figcaption {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.tile-name { font-size: 0.8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-meta { font-size: 0.72rem; color: var(--muted); }

.tile-actions {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
}
.icon-btn {
    background: rgba(0,0,0,0.55);
    color: white;
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;
}
.icon-btn.danger { background: rgba(192,57,43,0.85); }

.empty-state { text-align: center; margin: 40px 0; }

.load-more { text-align: center; margin: 0 0 40px; }

@media (max-width: 640px) {
    .topbar, .storage-bar-wrap, .dropzone, .upload-list, .toolbar, .grid { margin-left: 12px; margin-right: 12px; }
    .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1c1b19;
        --card-bg: #262521;
        --text: #ece9e2;
        --muted: #9b9689;
        --border: #38362f;
    }
    .video-tile { background: linear-gradient(135deg, #111, #333); }
}
