:root {
    --bg: #f6f8fa;
    --bg-2: #eef1f4;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --text: #24292f;
    --muted: #57606a;
    --accent: #0969da;
    --accent-2: #0856b8;
    --good: #1a7f37;
    --bad: #cf222e;
    --border: #d0d7de;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.page {
    max-width: 1280px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

/* Keep the upload UI focused — only the file grid breaks out wider. */
.brand-header,
.gate-card,
.dropzone,
.upload-list,
.row-bar.pill-row {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
}

.brand-header {
    text-align: center;
    margin-bottom: 24px;
}
.brand-header .logo {
    max-height: 96px;
    max-width: 240px;
    margin-bottom: 12px;
}
.brand-header h1 { margin: 0; font-size: 1.8rem; font-weight: 600; }
.brand-header .subtitle { margin: 4px 0 0; color: var(--muted); font-size: 0.95rem; }

.dropzone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 48px 16px;
    background: var(--panel);
    transition: all 0.15s;
    text-align: center;
    cursor: pointer;
}
.dropzone.drag {
    border-color: var(--accent);
    background: var(--panel-2);
    transform: scale(1.01);
}
.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.dz-icon { font-size: 40px; color: var(--accent); }
.dz-title { font-size: 1.15rem; font-weight: 500; margin: 0; }
.dz-or { color: var(--muted); margin: 0; font-size: 0.9rem; }
.dz-hint { color: var(--muted); margin: 8px 0 0; font-size: 0.85rem; }

.btn {
    display: inline-block;
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    font-size: 1rem;
    text-decoration: none;
}
.btn:hover { background: var(--accent-2); text-decoration: none; color: white; }
.btn.btn-secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn.btn-secondary:hover { background: var(--bg-2); color: var(--text); }
.btn.btn-danger { background: var(--bad); }
.btn.btn-ghost { background: transparent; color: var(--accent); padding: 6px 10px; }
.btn.btn-ghost:hover { background: rgba(9, 105, 218, 0.08); }

.upload-list {
    margin-top: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.upload-row {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.78rem;
    transition: opacity 0.35s ease, max-height 0.35s ease, padding 0.35s ease, margin 0.35s ease, border-color 0.2s;
    max-height: 60px;
    overflow: hidden;
}
.upload-row.done { border-color: var(--good); }
.upload-row.error { border-color: var(--bad); }
.upload-row.fading {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: -4px; /* counteract gap */
    border-color: transparent;
}

.upload-row-line {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    line-height: 1.3;
}
.upload-row .filename {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.upload-row .status {
    color: var(--muted);
    font-size: 0.72rem;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
}
.upload-row.done .status { color: var(--good); }
.upload-row.error .status { color: var(--bad); }

.progress {
    height: 3px;
    background: var(--bg-2);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 4px;
}
.progress .bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.2s ease-out;
}
.upload-row.done .progress .bar { background: var(--good); }
.upload-row.error .progress .bar { background: var(--bad); }
.upload-row.finalizing .progress .bar {
    background: var(--accent-2);
    background-image: linear-gradient(45deg,
        rgba(255, 255, 255, 0.25) 25%, transparent 25%,
        transparent 50%, rgba(255, 255, 255, 0.25) 50%,
        rgba(255, 255, 255, 0.25) 75%, transparent 75%, transparent);
    background-size: 16px 16px;
    animation: wfs-finalize-stripes 0.8s linear infinite;
}
@keyframes wfs-finalize-stripes {
    from { background-position: 0 0; }
    to   { background-position: 16px 0; }
}

.admin-footer {
    margin-top: 48px;
    text-align: center;
    color: var(--muted);
    font-size: 0.85rem;
}

.upload-section, .download-section { margin-top: 24px; }

.gate-card { padding: 20px; }
.gate-card h2 { margin: 0 0 8px; font-size: 1.1rem; }
.gate-card form { margin-top: 12px; }
.gate-card .field { margin-bottom: 12px; }

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.date-group-header {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.date-group-header:first-child { margin-top: 4px; }
.date-group-header .muted {
    font-size: 0.85rem;
    font-weight: 400;
    margin-left: 6px;
}
.file-grid + .date-group-header { margin-top: 24px; }

.tile {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.12s ease-out, border-color 0.12s ease-out;
    display: flex;
    flex-direction: column;
    position: relative;
}
.tile:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.thumb-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--bg);
    overflow: hidden;
}
.thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.thumb.file-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: 0.05em;
    background: var(--bg-2);
}
.thumb.file-icon span {
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
}
.play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 2.4rem;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
    pointer-events: none;
    transition: opacity 0.12s;
}
.tile:hover .play-overlay { opacity: 0.6; }

.tile-meta {
    padding: 8px 10px 4px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.tile-name {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tile-size {
    color: var(--muted);
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tile-actions {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    padding: 0 6px 6px;
}
.tile-actions .btn {
    padding: 2px 8px;
    font-size: 0.95rem;
    line-height: 1;
}
.tile-actions .btn-danger-link { color: var(--bad); }
.tile-actions .btn-danger-link:hover { background: rgba(248, 81, 73, 0.12); }
.tile-actions a:hover { background: rgba(78, 161, 243, 0.12); }

/* Lightbox */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
    gap: 12px;
}
.lightbox.hidden { display: none; }
.lightbox-content {
    max-width: 100%;
    max-height: calc(100vh - 80px);
    display: flex;
    align-items: center;
    justify-content: center;
}
.lightbox-content img,
.lightbox-content video {
    max-width: 100%;
    max-height: calc(100vh - 80px);
    display: block;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-name {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.9rem;
    text-align: center;
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    color: white;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.22); }

/* ---------- Photo map ---------- */
.map-section { padding: 16px; }
.photo-map {
    width: 100%;
    height: 380px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--bg-2);
}
.photo-marker {
    background: transparent;
    border: 0;
}
.photo-marker img {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    transition: transform 0.12s ease-out;
}
.photo-marker img:hover { transform: scale(1.12); }
.photo-marker .no-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    font-size: 1rem;
}
.geo-pill { font-size: 0.85em; margin-left: 4px; }

.map-section .map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.map-section button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Info modal */
.info-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1100;
    padding: 24px;
}
.info-modal.hidden { display: none; }
.info-card {
    position: relative;
    width: min(520px, 100%);
    max-height: 85vh;
    overflow-y: auto;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.25);
}
.info-card .info-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
.info-card .info-close:hover { background: var(--bg-2); color: var(--text); }
.info-card .info-title {
    margin: 0 32px 16px 0;
    font-size: 1rem;
    word-break: break-all;
}
.info-card .info-list {
    margin: 0;
    display: grid;
    grid-template-columns: minmax(110px, max-content) 1fr;
    gap: 6px 14px;
    font-size: 0.88rem;
}
.info-card .info-list dt {
    color: var(--muted);
    font-weight: 500;
}
.info-card .info-list dd {
    margin: 0;
    word-break: break-word;
    font-variant-numeric: tabular-nums;
}

.tile-actions .info-btn {
    color: var(--accent);
    font-weight: 600;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.filter-tabs .tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    background: var(--bg-2);
    border: 1px solid var(--border);
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.filter-tabs .tab:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.filter-tabs .tab.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}
.filter-tabs .tab .count {
    background: rgba(0, 0, 0, 0.08);
    border-radius: 999px;
    padding: 1px 8px;
    font-variant-numeric: tabular-nums;
    font-size: 0.75rem;
}
.filter-tabs .tab.active .count { background: rgba(255, 255, 255, 0.25); }

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.pagination .muted { font-size: 0.85rem; }
.pagination .btn.disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: default;
}

@media (max-width: 600px) {
    .file-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
    .tile-name { font-size: 0.8rem; }
}

@media (max-width: 600px) {
    .file-row { flex-direction: column; align-items: flex-start; gap: 4px; }
    .file-row .file-meta { font-size: 0.75rem; }
}

/* ---------- Admin ---------- */
body.admin { background: var(--bg-2); }
.admin-header {
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.admin-header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}
.admin-header .brand {
    font-weight: 600;
    color: var(--text);
}
.admin-header nav { display: flex; gap: 16px; flex-wrap: wrap; flex: 1; }
.admin-header nav a { color: var(--muted); }
.admin-header nav a:hover { color: var(--text); }
.admin-userbar { display: flex; align-items: center; gap: 10px; }
.admin-userbar a { color: var(--muted); font-size: 0.85rem; }
.admin-userbar a:hover { color: var(--text); }

.auth-shell {
    max-width: 420px;
    margin: 64px auto;
    padding: 0 16px;
}
.auth-card { padding: 28px; }
.auth-card h1 { margin: 0 0 18px; font-size: 1.35rem; }
.auth-or {
    text-align: center;
    color: var(--muted);
    font-size: 0.8rem;
    margin: 18px 0 14px;
    position: relative;
}
.auth-or::before, .auth-or::after {
    content: "";
    position: absolute;
    top: 50%;
    width: calc(50% - 24px);
    height: 1px;
    background: var(--border);
}
.auth-or::before { left: 0; }
.auth-or::after  { right: 0; }
.auth-sso { display: flex; flex-direction: column; gap: 8px; }

.admin-main {
    max-width: 1100px;
    margin: 24px auto;
    padding: 0 20px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.tile {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}
.tile .label { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.tile .value { font-size: 1.4rem; font-weight: 600; margin-top: 6px; }

.row-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

table.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}
table.table th, table.table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}
table.table th { color: var(--muted); font-weight: 500; }
table.table tr:last-child td { border-bottom: none; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.actions form { display: inline; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.field input[type=text],
.field input[type=email],
.field input[type=password],
.field input[type=number],
.field input[type=datetime-local],
.field select,
.field textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
}
.field input:focus, .field select:focus { outline: 1px solid var(--accent); }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert.alert-error { background: rgba(207, 34, 46, 0.08); border: 1px solid var(--bad); color: var(--bad); }
.alert.alert-info  { background: rgba(9, 105, 218, 0.08);  border: 1px solid var(--accent); color: var(--accent); }

.pill {
    display: inline-block;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--panel-2);
    color: var(--muted);
    border: 1px solid var(--border);
}
.pill.ok { color: var(--good); border-color: var(--good); }
.pill.bad { color: var(--bad); border-color: var(--bad); }
.pill.default { color: var(--accent); border-color: var(--accent); }

pre.snippet {
    background: #1f2328;
    color: #e6edf3;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    overflow-x: auto;
    font-size: 0.85rem;
    line-height: 1.45;
    white-space: pre;
}

.checkbox { display: inline-flex; align-items: center; gap: 8px; }
.checkbox input { width: 18px; height: 18px; }

.muted { color: var(--muted); }

@media (max-width: 600px) {
    .page { padding: 16px 12px 48px; }
    .dropzone { padding: 36px 12px; }
    .brand-header h1 { font-size: 1.4rem; }
    .admin-main { padding: 0 12px; }
}
