/* Sales Marathon — admin dashboard styles */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e3e6ea;
    --text: #1c2430;
    --text-muted: #66707d;
    --primary: #e8590c;
    --primary-soft: #fff0e6;
    --success: #2f9e44;
    --danger: #e03131;
    --info: #1971c2;
    --warning: #f08c00;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(20, 26, 34, 0.08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 0.5rem; }
a { color: var(--info); text-decoration: none; }

/* ---- Top bar ---- */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.6rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
}

.topbar-links { display: flex; gap: 0.25rem; flex: 1; }

.topbar-links a {
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 500;
}

.topbar-links a.active,
.topbar-links a:hover { background: var(--primary-soft); color: var(--primary); }

.topbar-user { display: flex; align-items: center; gap: 0.75rem; color: var(--text-muted); }

/* ---- Layout ---- */
.page { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
}

.card-title {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.stack { display: flex; flex-direction: column; gap: 0.9rem; }

/* ---- Stats / countdown ---- */
.stat-number { font-size: 2.2rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }

.countdown {
    font-variant-numeric: tabular-nums;
    font-size: 1.9rem;
    font-weight: 700;
    color: var(--primary);
}

/* ---- Status badges ---- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.badge-DRAFT { background: #eceff3; color: #4b5563; }
.badge-SCHEDULED { background: #e7f0fb; color: var(--info); }
.badge-ACTIVE { background: #e6f6e9; color: var(--success); }
.badge-COMPLETED { background: var(--primary-soft); color: var(--primary); }
.badge-CANCELLED { background: #fdecec; color: var(--danger); }

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }

th {
    text-align: left;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
}

td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }

tr:last-child td { border-bottom: none; }

.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Leaderboard ---- */
.leaderboard { display: flex; flex-direction: column; gap: 0.4rem; }

.leaderboard-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.6rem 0.9rem;
    background: var(--bg);
    border-radius: 8px;
    /* The transform transition powers the FLIP reorder animation; rows
       slide from their old rank to the new one. */
    transition: transform 0.55s cubic-bezier(0.22, 1, 0.36, 1),
                background-color 0.6s ease,
                box-shadow 0.35s ease;
}

.leaderboard-row.flash { background: #fff3bf; }

/* Lift a row while it is overtaking so it reads as passing the others. */
.leaderboard-row.moving {
    position: relative;
    z-index: 2;
    box-shadow: 0 6px 18px rgba(20, 26, 34, 0.18);
}

/* New rows (and new history entries) fade in rather than pop. */
.leaderboard-row.entering,
#history-body tr.entering {
    opacity: 0;
    transform: translateY(-8px);
}

#history-body tr {
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.leaderboard-score .score-value { display: inline-block; min-width: 2ch; text-align: right; }

@media (prefers-reduced-motion: reduce) {
    .leaderboard-row,
    #history-body tr { transition: none; }
}

/* ---- Avatars ---- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
    vertical-align: middle;
}

.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }

.name-cell { display: flex; align-items: center; gap: 0.6rem; }

/* Profile picker in the register/edit modal */
.avatar-picker { display: flex; align-items: center; gap: 1rem; }

.avatar-preview {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background-color: var(--primary-soft);
    background-size: cover;
    background-position: center;
    color: var(--primary);
    font-weight: 700;
    font-size: 1.4rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

/* ---- Inline notice ---- */
.notice {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.9rem 1.1rem;
    background: #e7f0fb;
    border: 1px solid #c3dafc;
    border-left: 4px solid var(--info);
    border-radius: var(--radius);
    color: #16405f;
}

.notice code {
    background: rgba(255, 255, 255, 0.7);
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ---- Quick-add buttons ---- */
.quick-add { display: flex; gap: 0.5rem; }
.quick-add .btn { flex: 1; font-weight: 700; }

.leaderboard-rank {
    width: 2.2rem;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    flex-shrink: 0;
}

.leaderboard-name { flex: 1; font-weight: 600; }

.leaderboard-score { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.leaderboard-score small { font-size: 0.7rem; font-weight: 500; color: var(--text-muted); }

/* ---- Podium ---- */
.podium {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1rem;
    margin: 2rem 0;
    flex-wrap: wrap;
}

.podium-place {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    padding: 1.5rem 2rem;
    min-width: 180px;
}

.podium-place .medal { font-size: 2.4rem; }

.podium-photo { position: relative; display: inline-block; }

.podium-photo .avatar { border: 3px solid var(--border); }
.podium-1 .podium-photo .avatar { border-color: #f5c518; }
.podium-2 .podium-photo .avatar { border-color: #b8bfc7; }
.podium-3 .podium-photo .avatar { border-color: #cd7f32; }

.podium-rank {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
    color: #fff;
    border: 2px solid var(--surface);
}

.podium-rank.rank-1 { background: #f5c518; color: #3d2f00; }
.podium-rank.rank-2 { background: #b8bfc7; color: #2b3138; }
.podium-rank.rank-3 { background: #cd7f32; }

.leaderboard-avatar { width: 34px; height: 34px; font-size: 12px; }
.podium-place .podium-name { font-weight: 700; font-size: 1.1rem; margin-top: 0.4rem; }
.podium-place .podium-score { color: var(--primary); font-weight: 700; font-size: 1.5rem; }
.podium-1 { order: 2; transform: translateY(-1.25rem); border-color: #f5c518; }
.podium-2 { order: 1; }
.podium-3 { order: 3; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; }
.field > span { font-weight: 600; }

.field input,
.field textarea,
.field select {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
    background: var(--surface);
}

.field input:focus,
.field textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: transparent; }

.form-error { color: var(--danger); font-size: 0.85rem; margin: 0; }

.checkbox-line { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: 8px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s ease;
}

.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.82rem; }
.btn-block { width: 100%; }

/* ---- Auth ---- */
.auth-card {
    max-width: 380px;
    margin: 8vh auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
}

.auth-title { text-align: center; }
.auth-subtitle { text-align: center; color: var(--text-muted); margin-top: -0.25rem; }

/* ---- Participant picker ---- */
.picker {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.picker-search { padding: 0.6rem; border-bottom: 1px solid var(--border); }

.picker-search input {
    width: 100%;
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font: inherit;
}

.picker-list { max-height: 280px; overflow-y: auto; }

.picker-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.picker-item:hover { background: var(--bg); }
.picker-item.disabled { opacity: 0.5; cursor: not-allowed; }
.picker-item small { color: var(--text-muted); }

.picker-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 0.75rem;
    background: var(--bg);
    font-size: 0.88rem;
}

/* ---- Modal ---- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 26, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 1rem;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 460px;
    padding: 1.5rem;
}

.modal h3 { margin-bottom: 1rem; }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.25rem; }

[hidden] { display: none !important; }

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: #fff;
    padding: 0.7rem 1.2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    z-index: 100;
    box-shadow: var(--shadow);
}

.toast.error { background: var(--danger); }

/* ---- Misc ---- */
.muted { color: var(--text-muted); }
.empty-state { color: var(--text-muted); text-align: center; padding: 2rem 1rem; }
.mb-1 { margin-bottom: 1rem; }
.actions-cell { display: flex; gap: 0.4rem; flex-wrap: wrap; }

/* ---- Password field with reveal toggle ---- */
.password-field { position: relative; display: flex; }

.password-field input { flex: 1; padding-right: 2.6rem; }

.password-toggle {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0.35rem 0.4rem;
    border-radius: 6px;
    opacity: 0.65;
}

.password-toggle:hover { opacity: 1; background: var(--bg); }
