/* nextgen-server web UI - global styles. Plain CSS; no framework. */

:root {
    --fg: #1a1a1a;
    --fg-mute: #666;
    --fg-dim: #999;
    --bg: #fafafa;
    --bg-card: #fff;
    --border: #e0e0e0;
    --border-strong: #b8b8b8;
    --accent: #1f6feb;
    --accent-mute: #dfe9fb;
    --good: #197b30;
    --bad: #b3261e;
}

html { box-sizing: border-box; }
*, *::before, *::after { box-sizing: inherit; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-variant-numeric: tabular-nums;
}

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

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85em;
}

/* ---- top nav --------------------------------------------------------- */

.nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0.75em 0;
}
.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.25em;
    display: flex;
    align-items: center;
    gap: 1.5em;
    flex-wrap: wrap;
}
.nav h1 {
    font-size: 1em;
    font-weight: 600;
    margin: 0;
    margin-right: 0.5em;
}
.nav a {
    color: var(--fg);
    font-weight: 500;
}
.nav a.active {
    color: var(--accent);
    border-bottom: 2px solid var(--accent);
    padding-bottom: 2px;
}
.nav .nav-end {
    margin-left: auto;
    color: var(--fg-dim);
    font-size: 0.9em;
    display: flex;
    align-items: center;
    gap: 0.5em;
}
.nav .nav-end a { color: var(--fg-mute); }
.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--fg-dim);
    transition: background 0.3s;
}
.dot.live { background: var(--good); animation: pulse 2s infinite; }
.dot.stale { background: var(--bad); }
.dot.online { background: var(--good); margin-right: 0.4em; }
.dot.offline { background: var(--fg-dim); margin-right: 0.4em; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* ---- main column ----------------------------------------------------- */

main {
    max-width: 1200px;
    margin: 1.5em auto 4em;
    padding: 0 1.25em;
}

h2 {
    font-size: 1.15em;
    font-weight: 600;
    margin: 1.5em 0 0.5em;
}
h2:first-of-type { margin-top: 0; }

.muted { color: var(--fg-mute); }
.dim { color: var(--fg-dim); }

/* ---- stat strip ------------------------------------------------------ */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75em;
    margin-bottom: 1.5em;
}
.stat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75em 1em;
}
.stat .label {
    font-size: 0.8em;
    color: var(--fg-mute);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.stat .value {
    font-size: 1.6em;
    font-weight: 600;
    margin-top: 0.15em;
}
.stat .sub {
    font-size: 0.85em;
    color: var(--fg-dim);
    margin-top: 0.15em;
}

/* ---- toolbar above tables ------------------------------------------- */

.toolbar {
    display: flex;
    align-items: center;
    gap: 0.75em;
    margin: 0.5em 0;
    flex-wrap: wrap;
}
.toolbar input[type="search"] {
    flex: 0 1 320px;
    padding: 0.5em 0.75em;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    font: inherit;
    background: var(--bg-card);
}
.toolbar input[type="search"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-mute);
}
.toolbar .counts {
    color: var(--fg-mute);
    font-size: 0.9em;
}

/* ---- tables ---------------------------------------------------------- */

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    /* No `overflow: hidden` here: it would clip absolutely-positioned
     * children (the .photo-thumb-popup that pops up on hover) at the
     * table edges. Round the corner cells explicitly below so the
     * row-hover background still paints inside the rounded outline. */
}
/* Round the corners of the first/last cells in the first/last rows so a
 * hover background or selected-row tint doesn't paint square over the
 * table's rounded outer corners (replaces the dropped `overflow: hidden`
 * trick on the table). */
tr:first-child > :first-child { border-top-left-radius: 4px; }
tr:first-child > :last-child { border-top-right-radius: 4px; }
tr:last-child > :first-child { border-bottom-left-radius: 4px; }
tr:last-child > :last-child { border-bottom-right-radius: 4px; }
th, td {
    padding: 0.5em 0.75em;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th {
    background: #f3f3f3;
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fg-mute);
    border-bottom: 2px solid var(--border-strong);
    user-select: none;
}
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--fg); }
th.sort-asc::after { content: " ▲"; color: var(--accent); }
th.sort-desc::after { content: " ▼"; color: var(--accent); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f6f9ff; }
td.numeric, th.numeric { text-align: right; }
.empty {
    padding: 2em;
    text-align: center;
    color: var(--fg-mute);
}

/* Photo thumbnail column. The camera-supplied embedded thumbnail is
 * 160x120 baseline JPEG (lifted from EXIF / TIFF-IFD). Inline display
 * is sized to roughly match the row's text height (30px) so the
 * thumbnail column doesn't stretch every row; width is auto so the
 * native 4:3 aspect ratio is preserved (no crop). Hover the cell to
 * pop the native-size version up to the side for a closer look. */
td.thumb-cell {
    width: 1px;     /* shrink-wrap to the image */
    padding: 0.15em 0.5em;
    position: relative;
}
img.photo-thumb {
    display: block;
    height: 30px;
    width: auto;
    border-radius: 2px;
    background: var(--bg);
    cursor: zoom-in;
}
/* Hover the cell -> reveal the native-size thumbnail floating to the
 * right of its row. transform + transition keeps the appearance snappy
 * without flickering as the cursor crosses cell edges. pointer-events
 * off so the popup doesn't itself trap hover. */
td.thumb-cell img.photo-thumb-popup {
    display: block;
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%) scale(0.96);
    width: 160px;
    height: 120px;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
    background: var(--bg-card);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease, transform 0.1s ease;
    z-index: 10;
}
td.thumb-cell:hover img.photo-thumb-popup {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

/* ---- star rating ----------------------------------------------------- */

/* Inline 5-star widget. Each star is a <button> so it's keyboard-focusable
 * and clearly interactive; styled to look like text with a tight cluster.
 * Hover previews higher ratings; the current rating is the .filled state. */
.stars {
    display: inline-flex;
    align-items: center;
    gap: 1px;
    line-height: 1;
}
.stars .star {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0 1px;
    font-size: 1.1em;
    color: #d6d6d6;
    line-height: 1;
    transition: color 0.08s;
}
.stars .star.filled { color: #f5a623; }
.stars:hover .star { color: #d6d6d6; }
.stars .star:hover,
.stars .star:hover ~ .star,
.stars:hover .star.filled { color: #d6d6d6; } /* reset on hover */
.stars .star:hover { color: #f5a623; }
.stars .star:hover ~ .star { color: #d6d6d6; }
/* Highlight the hovered star + all earlier siblings - achieved with the
 * inverted markup approach below would need flex-direction:row-reverse;
 * keep the natural order and use :has() so older Safari doesn't break. */
.stars:has(.star:hover) .star { color: #d6d6d6; }
.stars:has(.star:nth-child(1):hover) .star:nth-child(-n+1) { color: #f5a623; }
.stars:has(.star:nth-child(2):hover) .star:nth-child(-n+2) { color: #f5a623; }
.stars:has(.star:nth-child(3):hover) .star:nth-child(-n+3) { color: #f5a623; }
.stars:has(.star:nth-child(4):hover) .star:nth-child(-n+4) { color: #f5a623; }
.stars:has(.star:nth-child(5):hover) .star:nth-child(-n+5) { color: #f5a623; }
.stars.pending { opacity: 0.5; }

/* ---- photo detail page ---------------------------------------------- */

.photo-detail {
    display: grid;
    grid-template-columns: minmax(0, 320px) 1fr;
    gap: 2em;
    align-items: start;
}
.photo-detail-preview {
    display: flex;
    flex-direction: column;
    gap: 0.75em;
    align-items: stretch;
}
img.photo-detail-thumb,
.photo-detail-thumb-empty {
    display: block;
    width: 100%;
    /* The 4:3 EXIF thumbnail is 160x120; CSS scales it up to fill the
     * column without distorting (object-fit isn't needed - the source
     * is already 4:3). image-rendering: pixelated isn't ideal for a
     * photo, but the 2x-ish upscale here keeps the source recognisable
     * without a blurry blow-up. */
    aspect-ratio: 4 / 3;
    border-radius: 4px;
    border: 1px solid var(--border-strong);
    background: var(--bg-card);
}
.photo-detail-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--fg-mute);
    font-size: 0.9em;
}
.photo-detail-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25em;
}
.photo-detail-actions-note {
    font-size: 0.85em;
    margin-top: 0.25em;
}
.photo-detail-rating {
    display: flex;
    justify-content: center;
    padding: 0.25em 0;
}
.photo-detail-rating .star { font-size: 1.6em; }
.photo-detail-heading {
    margin: 0 0 1em;
    font-size: 1.15em;
    font-weight: 600;
}
.photo-detail-meta h3 {
    margin: 1.75em 0 0.5em;
    font-size: 1em;
    font-weight: 600;
}

dl.kv-list {
    display: grid;
    grid-template-columns: 7em 1fr;
    column-gap: 1em;
    row-gap: 0.4em;
    margin: 0 0 1em;
}
dl.kv-list dt {
    color: var(--fg-mute);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    align-self: center;
}
dl.kv-list dd {
    margin: 0;
}

.rendition-table {
    width: auto;
    min-width: 460px;
}
.rendition-table th,
.rendition-table td {
    padding: 0.4em 0.75em;
}
.rendition-yes {
    color: var(--good);
    font-weight: 500;
}

/* Stack the preview above the metadata on narrow screens. */
@media (max-width: 720px) {
    .photo-detail {
        grid-template-columns: 1fr;
    }
}

/* ---- error card (e.g. /photos/<uuid>/original on relay failure) ----- */

.error-card {
    max-width: 640px;
    margin: 2em auto;
    padding: 1.5em 1.75em;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-soft, transparent);
}
.error-card h2 {
    margin-top: 0;
}
.error-card .error-summary {
    font-size: 1.05em;
    margin: 0.5em 0 1em;
}
.error-card .error-suggestions {
    margin: 0.25em 0 1em 1.25em;
    line-height: 1.55;
}

/* ---- in-page original viewer (lightbox) ----------------------------- */
/*
 * Used by app.js attachOriginalViewer: clicking "View original" or the
 * thumbnail spins up an overlay that fetches the bytes async. Success
 * paints the image inside; failure paints an inline message + retry.
 * Either way the user stays on the photo detail page.
 */

.original-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.original-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    cursor: pointer;
}
.original-overlay-card {
    position: relative;
    max-width: 92vw;
    max-height: 92vh;
    background: var(--bg, #111);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75em 0.75em 0.6em;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
}
.original-overlay-close {
    position: absolute;
    top: 0.25em;
    right: 0.5em;
    background: transparent;
    border: 0;
    color: var(--fg-mute);
    font-size: 1.6em;
    line-height: 1;
    cursor: pointer;
    padding: 0.1em 0.4em;
}
.original-overlay-close:hover {
    color: var(--fg);
}
.original-overlay-caption {
    font-size: 0.85em;
    color: var(--fg-mute);
    margin: 0 1.75em 0.5em 0.25em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.original-overlay-body {
    flex: 1 1 auto;
    min-width: 280px;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.original-overlay-body img {
    max-width: 100%;
    max-height: 84vh;
    object-fit: contain;
    display: block;
}
.original-overlay-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--fg);
    border-radius: 50%;
    animation: kv-spin 0.9s linear infinite;
    margin-right: 0.75em;
}
.original-overlay-status {
    color: var(--fg-mute);
    font-size: 0.95em;
}
@keyframes kv-spin {
    to { transform: rotate(360deg); }
}

.original-overlay-error {
    max-width: 460px;
    text-align: center;
    padding: 1em 0.5em;
}
.original-overlay-error-label {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 0.4em;
}
.original-overlay-error-detail {
    color: var(--fg-mute);
    margin: 0.25em 0 0.75em;
    line-height: 1.45;
}
.original-overlay-error-meta {
    color: var(--fg-mute);
    font-size: 0.8em;
    font-family: var(--mono, monospace);
    margin-bottom: 1em;
}
.original-overlay-error-actions {
    display: flex;
    gap: 0.6em;
    justify-content: center;
}
.original-overlay-error-actions .btn-retry,
.original-overlay-error-actions .btn-secondary {
    display: inline-block;
    padding: 0.45em 1em;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--fg);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95em;
}
.original-overlay-error-actions .btn-retry {
    border-color: var(--fg);
}
.original-overlay-error-actions .btn-retry:hover,
.original-overlay-error-actions .btn-secondary:hover {
    background: var(--bg-soft, rgba(255, 255, 255, 0.05));
}

/* ---- pair page ------------------------------------------------------ */

.pair-card {
    display: grid;
    grid-template-columns: minmax(0, 220px) 1fr;
    gap: 2em;
    align-items: start;
    margin-top: 1em;
}
.pair-qr {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px;
    /* The qrcode lib emits a viewBox-sized SVG; let it scale to the
     * column width and stay square. */
    line-height: 0;
}
.pair-qr svg {
    display: block;
    width: 100%;
    height: auto;
}
.pair-info dd.mono { word-break: break-all; }

@media (max-width: 720px) {
    .pair-card { grid-template-columns: 1fr; }
}
