:root {
    --bg: #0a0a0a;
    --surface: #121212;
    --surface-2: #1a1a1a;
    --purple: #9d4edd;
    --purple-light: #c77dff;
    --text: #e0e0e0;
    --muted: #aaa;
    --faint: #555;
    --border: rgba(157, 78, 221, 0.28);
    --border-strong: rgba(157, 78, 221, 0.45);
    --danger: #ff6b8a;
    --ok: #7dffa3;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    position: relative;
}

.bg-grid {
    position: fixed;
    inset: 0;
    background-image:
        linear-gradient(var(--purple) 1px, transparent 1px),
        linear-gradient(90deg, var(--purple) 1px, transparent 1px);
    background-size: 70px 70px;
    opacity: 0.07;
    z-index: 0;
    pointer-events: none;
    animation: gridMove 40s linear infinite;
}

@keyframes gridMove {
    0% { background-position: 0 0; }
    100% { background-position: 70px 70px; }
}

#root {
    position: relative;
    z-index: 1;
    min-height: 100vh;
}

h1, h2, h3, .brand {
    font-family: "Space Grotesk", Inter, sans-serif;
    font-weight: 600;
    letter-spacing: -0.02em;
}

a { color: var(--purple-light); }

/* —— Shell —— */
.app-shell {
    max-width: 1080px;
    margin: 0 auto;
    padding: 0 16px 48px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 1.5rem 0 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.brand {
    font-size: 1.75rem;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--purple-light);
    box-shadow: 0 0 14px var(--purple-light);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.topbar-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 0.95rem;
}

.section-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.section-nav button,
.tab-nav button,
button {
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    background: linear-gradient(90deg, var(--purple), var(--purple-light));
    color: #fff;
    width: auto;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

button.ghost,
.section-nav button,
.tab-nav button {
    background: transparent;
    color: var(--muted);
    border-color: var(--border);
}

.section-nav button.active,
.tab-nav button.active {
    color: var(--purple-light);
    border-color: var(--border-strong);
    background: rgba(157, 78, 221, 0.12);
}

button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
}

.panel h2 {
    margin: 0 0 0.35rem;
    font-size: 1.35rem;
    color: #fff;
}

.panel .lede {
    margin: 0 0 1.25rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.status-banner {
    margin-bottom: 1rem;
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(157, 78, 221, 0.1);
    color: var(--purple-light);
    font-weight: 500;
    font-size: 0.92rem;
    min-height: 1.2em;
}

.status-banner.error {
    border-color: rgba(255, 107, 138, 0.4);
    background: rgba(255, 107, 138, 0.08);
    color: var(--danger);
}

.status-banner.ok {
    border-color: rgba(125, 255, 163, 0.35);
    background: rgba(125, 255, 163, 0.08);
    color: var(--ok);
}

/* —— Login —— */
.login-screen {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 16px;
    text-align: center;
}

.login-screen .brand {
    font-size: 2.2rem;
    margin-bottom: 0.5rem;
}

.login-screen .tag {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 1.5rem;
    padding: 10px 22px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: rgba(157, 78, 221, 0.1);
    color: var(--purple-light);
    font-weight: 500;
    font-size: 0.9rem;
}

.login-screen h1 {
    font-size: clamp(2.4rem, 6vw, 3.6rem);
    line-height: 1.05;
    margin: 0 0 0.5rem;
    background: linear-gradient(90deg, #fff, var(--purple-light));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-screen .subtitle {
    color: var(--muted);
    margin: 0 0 2rem;
    font-size: 1.15rem;
}

.login-panel {
    width: 100%;
    max-width: 400px;
    text-align: left;
}

/* —— Forms —— */
label.field {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
}

input, select, textarea {
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--purple-light);
    box-shadow: 0 0 0 2px rgba(157, 78, 221, 0.2);
}

input.readonly {
    color: var(--faint);
    background: #0e0e0e;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 640px) {
    .row { grid-template-columns: 1fr; }
}

.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.hint {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.json-editor {
    min-height: 260px;
    font-family: Consolas, "Courier New", monospace;
    font-size: 13px;
    line-height: 1.4;
}

/* —— Upload —— */
.file-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 16px;
    margin-bottom: 16px;
    border: 1px dashed var(--border-strong);
    border-radius: 12px;
    background: rgba(157, 78, 221, 0.06);
    cursor: pointer;
    color: var(--purple-light);
    font-weight: 600;
    text-align: center;
}

.file-drop input {
    display: none;
}

.file-drop span.muted {
    font-weight: 400;
    color: var(--muted);
    font-size: 0.85rem;
}

.image-preview {
    display: block;
    max-width: 100%;
    max-height: 280px;
    margin: 0 auto 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.image-info {
    display: block;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: center;
}

/* —— Feedback —— */
.feedback-toolbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 14px;
}

.feedback-search {
    margin-bottom: 0;
}

@media (max-width: 640px) {
    .feedback-toolbar {
        grid-template-columns: 1fr;
    }
}

.feedback-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.feedback-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-2);
    overflow: hidden;
}

.feedback-card-top {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: stretch;
}

.feedback-delete {
    margin: 10px 12px 10px 0;
    align-self: center;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.feedback-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    width: 100%;
    background: transparent;
    color: inherit;
    border: none;
    border-radius: 0;
    text-align: left;
}

.feedback-card-header:hover {
    background: rgba(157, 78, 221, 0.08);
}

.feedback-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.feedback-meta strong {
    color: #fff;
    font-weight: 600;
}

.feedback-meta .sub {
    color: var(--muted);
    font-size: 0.85rem;
}

.feedback-preview {
    margin-top: 6px;
    color: var(--text);
    font-size: 0.9rem;
    line-height: 1.4;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(157, 78, 221, 0.1);
    color: var(--purple-light);
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.badge.status-Received { color: var(--muted); border-color: #333; background: #151515; }
.badge.status-Detected { color: #7eb6ff; border-color: rgba(126, 182, 255, 0.35); background: rgba(126, 182, 255, 0.08); }
.badge.status-CommentaryReady { color: var(--ok); border-color: rgba(125, 255, 163, 0.35); background: rgba(125, 255, 163, 0.08); }
.badge.status-Incomplete { color: var(--danger); border-color: rgba(255, 107, 138, 0.35); background: rgba(255, 107, 138, 0.08); }

.feedback-detail {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border);
}

.feedback-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 320px) 1fr;
    gap: 16px;
    padding-top: 14px;
}

@media (max-width: 720px) {
    .feedback-detail-grid { grid-template-columns: 1fr; }
}

.feedback-image-shell {
    position: relative;
    display: inline-block;
    max-width: 100%;
    line-height: 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #000;
    overflow: hidden;
}

.feedback-thumb {
    display: block;
    max-width: 100%;
    max-height: 320px;
    width: auto;
    height: auto;
}

.feedback-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.feedback-box {
    position: absolute;
    border: 2px solid #7eb6ff;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.4) inset;
    background: rgba(126, 182, 255, 0.08);
}

.feedback-box-label {
    position: absolute;
    top: 0;
    left: 0;
    max-width: min(180px, 100%);
    padding: 3px 6px;
    border-radius: 0 0 6px 0;
    background: rgba(126, 182, 255, 0.92);
    color: #08111f;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.feedback-box-plate {
    border-color: #8fd9a8;
    background: rgba(143, 217, 168, 0.12);
}

.feedback-box-label-plate {
    background: rgba(143, 217, 168, 0.95);
    color: #0a1a10;
    font-family: "Space Grotesk", "Inter", sans-serif;
    letter-spacing: 0.04em;
}

.detection-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.detection-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}

.plate-list-item {
    display: block !important;
}

.plate-list-main {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: baseline;
}

.plate-text {
    font-family: "Space Grotesk", "Inter", sans-serif;
    font-weight: 600;
    letter-spacing: 0.06em;
    font-size: 1.05rem;
}

.plate-meta,
.plate-list-sub {
    color: var(--muted, #8b95a8);
    font-size: 0.78rem;
}

.plate-list-sub {
    margin-top: 0.2rem;
}

.commentary-block {
    margin-top: 12px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(157, 78, 221, 0.08);
    border: 1px solid var(--border);
    line-height: 1.5;
    white-space: pre-wrap;
}

.commentary-block .model {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.8rem;
}

.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}

.empty-state strong {
    display: block;
    color: #fff;
    font-family: "Space Grotesk", Inter, sans-serif;
    font-size: 1.15rem;
    margin-bottom: 6px;
}

/* —— Analytics —— */
.analytics-section-title {
    margin: 1.4rem 0 0.75rem;
    font-size: 1.05rem;
    color: #fff;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}

.metric-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(157, 78, 221, 0.08);
    padding: 14px 14px 12px;
}

.metric-label {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 6px;
}

.metric-value {
    font-family: "Space Grotesk", Inter, sans-serif;
    font-size: 1.65rem;
    font-weight: 600;
    color: #fff;
    line-height: 1.1;
}

.metric-hint {
    margin-top: 6px;
    color: var(--faint);
    font-size: 0.75rem;
    line-height: 1.3;
}

/* —— Admin media search —— */
.media-search-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 16px;
}

@media (max-width: 640px) {
    .media-search-form {
        grid-template-columns: 1fr;
    }
}

.media-search-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.media-search-tile {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #000;
    color: inherit;
    width: 100%;
    text-align: left;
}

.media-search-tile:hover {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 1px rgba(157, 78, 221, 0.25);
}

.media-search-tile img {
    display: block;
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.media-search-tile-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    color: var(--muted);
    font-size: 0.85rem;
    background: var(--surface-2);
}

.media-search-tile-meta {
    padding: 8px 10px;
    font-size: 0.78rem;
    color: var(--muted);
    background: var(--surface);
    border-top: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.72);
}

.modal-panel {
    width: min(960px, 100%);
    max-height: min(90vh, 900px);
    overflow: auto;
    border: 1px solid var(--border-strong);
    border-radius: 12px;
    background: var(--surface);
    padding: 16px 18px 18px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-header h3 {
    margin: 0;
    color: #fff;
}

.modal-body .feedback-detail-grid {
    padding-top: 0;
}

/* —— Tables —— */
.table-wrap {
    overflow-x: auto;
    margin-top: 12px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.table th, .table td {
    border-bottom: 1px solid #222;
    text-align: left;
    padding: 10px 8px;
}

.table th {
    color: var(--muted);
    font-weight: 500;
}

.role-select {
    width: auto;
    min-width: 120px;
    margin: 0;
}

.footer-note {
    text-align: center;
    color: var(--faint);
    font-size: 0.85rem;
    margin-top: 2rem;
}
