/* Magshot web UI — vanilla, light + dark, mobile-first.
   Stays under 200 lines so the whole UI is reviewable at a glance. */

:root {
    --bg: #ffffff;
    --fg: #1a1a1a;
    --muted: #6b6b6b;
    --accent: #0a84ff;
    --border: #e4e4e4;
    --tile-bg: #f4f4f4;
    --error: #d23f3f;
    --max: 1200px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --fg: #f0f0f0;
        --muted: #9a9a9a;
        --border: #2c2c2c;
        --tile-bg: #232323;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--fg);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

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

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

/* MARK: - Login */

#login {
    max-width: 360px;
    margin: 10vh auto;
    padding: 0 20px;
}

#login h1 {
    margin: 0 0 4px;
    font-size: 28px;
}

#login form {
    margin-top: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#login label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--muted);
}

#login input {
    padding: 10px 12px;
    font: inherit;
    color: var(--fg);
    background: var(--tile-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

#login button {
    margin-top: 8px;
    padding: 12px;
    font: inherit;
    font-weight: 600;
    color: white;
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}

#login button:disabled {
    opacity: 0.5;
    cursor: wait;
}

#login-status {
    margin-top: 12px;
    min-height: 1.4em;
}

#login-status.error {
    color: var(--error);
}

/* MARK: - App shell */

#topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
}

#logo {
    font-weight: 700;
    color: var(--fg);
    font-size: 17px;
}

#status {
    flex: 1;
    font-size: 13px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

#status .sync-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: transparent;
    transition: background-color .15s;
}

#status.is-syncing {
    color: var(--fg);
    font-weight: 500;
}

#status.is-syncing .sync-dot {
    background: var(--accent);
    animation: pulse-dot 1.1s ease-in-out infinite;
    box-shadow: 0 0 0 0 var(--accent);
}

@keyframes pulse-dot {
    0%   { transform: scale(1);   box-shadow: 0 0 0 0 rgba(10,132,255,.55); }
    70%  { transform: scale(1.2); box-shadow: 0 0 0 8px rgba(10,132,255,0); }
    100% { transform: scale(1);   box-shadow: 0 0 0 0 rgba(10,132,255,0); }
}

#signout {
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    color: var(--fg);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
}

#upload-btn {
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    color: white;
    background: var(--accent);
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

#upload-btn:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* MARK: - Toasts */

#toast-host {
    position: fixed;
    right: 16px;
    bottom: 16px;
    display: flex;
    flex-direction: column-reverse;
    gap: 8px;
    z-index: 100;
    pointer-events: none;
}

.toast {
    padding: 10px 14px;
    background: var(--tile-bg);
    color: var(--fg);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    max-width: 320px;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    transform: translateX(120%);
    transition: transform .2s ease-out;
    pointer-events: auto;
}

.toast.shown { transform: translateX(0); }
.toast.info { border-color: var(--accent); }
.toast.success { border-color: #2c8a3a; }
.toast.error { border-color: var(--error); }

/* MARK: - Pending upload tile */

.shot-tile.pending {
    position: relative;
}

.shot-tile.pending img {
    opacity: 0.6;
}

.pending-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 2px 6px;
    background: rgba(0,0,0,.6);
    color: white;
    font-size: 11px;
    border-radius: 4px;
    pointer-events: none;
}

#view {
    max-width: var(--max);
    margin: 0 auto;
    padding: 20px;
}

/* MARK: - People grid */

.people-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 16px;
}

.person-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--fg);
}

.person-tile .avatar {
    width: 100%;
    aspect-ratio: 1;
    background: var(--tile-bg);
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 32px;
}

.person-tile .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.person-tile .name {
    font-size: 13px;
    text-align: center;
    line-height: 1.2;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* MARK: - Shot grid (inside person detail) */

.shot-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 20px;
}

.shot-tile {
    aspect-ratio: 3 / 4;
    background: var(--tile-bg);
    border-radius: 6px;
    overflow: hidden;
    display: block;
}

.shot-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.shot-tile.loading::after {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent);
    animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* MARK: - Photo viewer */

.viewer {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70vh;
    background: var(--tile-bg);
    border-radius: 8px;
}

.viewer img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
}

/* MARK: - Headings + buttons */

h2 {
    margin: 0 0 16px;
    font-size: 22px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-link {
    font-size: 14px;
    color: var(--muted);
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 60px 20px;
}

/* MARK: - Initial loader (over the empty app shell during the
   multi-MB first sign-in pull) */

.initial-loader {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg);
    color: var(--muted);
    z-index: 50;
}

.initial-loader .spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* MARK: - Debug page */

.debug-page {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px 64px;
}

.debug-page h1 {
    margin: 0 0 16px;
    font-size: 24px;
}

.debug-page h2 {
    margin: 28px 0 12px;
    font-size: 18px;
}

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

.debug-stat {
    background: var(--tile-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
}

.debug-stat .label {
    font-size: 12px;
    color: var(--muted);
}

.debug-stat .value {
    font-size: 20px;
    font-variant-numeric: tabular-nums;
    margin-top: 4px;
}

.debug-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.debug-table th, .debug-table td {
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}

.debug-table th {
    color: var(--muted);
    font-weight: 500;
}

.debug-table tr.error td {
    color: #d83a3a;
}

.debug-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    color: var(--muted);
    overflow-wrap: anywhere;
}
