* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    color: #111827;
    background: #f4f6fb;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
input, textarea {
    width: 100%;
    border: 1px solid #d7dce8;
    border-radius: 14px;
    padding: 12px 14px;
    background: #fff;
    outline: none;
    transition: border .2s, box-shadow .2s;
}
input:focus, textarea:focus {
    border-color: #5067ff;
    box-shadow: 0 0 0 4px rgba(80, 103, 255, .12);
}
textarea { resize: vertical; }
label span {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: #5b6475;
    font-weight: 700;
}
.eyebrow {
    margin: 0 0 8px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .16em;
    color: #667085;
    text-transform: uppercase;
}
.badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: #111827;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}
.badge.soft { background: #eef2ff; color: #4450d7; }
.primary-btn, .ghost-btn {
    border: 0;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 900;
    cursor: pointer;
    transition: transform .18s, box-shadow .18s, opacity .18s;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}
.primary-btn {
    color: #fff;
    background: linear-gradient(135deg, #4d6bff, #8e49ff);
    box-shadow: 0 14px 30px rgba(77, 107, 255, .28);
}
.ghost-btn {
    color: #111827;
    background: #fff;
    border: 1px solid #e3e6ef;
}
.primary-btn:hover, .ghost-btn:hover { transform: translateY(-1px); opacity: .95; }
.primary-btn.full { width: 100%; }
.alert {
    padding: 13px 14px;
    border-radius: 14px;
    margin: 14px 0;
    font-weight: 800;
}
.alert.success { background: #e9f9ef; color: #137333; border: 1px solid #b7efc5; }
.alert.error { background: #fff0f0; color: #b42318; border: 1px solid #ffc7c7; }
.muted { color: #667085; font-size: 13px; line-height: 1.7; }
.danger-text { color: #d92d20 !important; }
.link-danger {
    border: 0;
    background: transparent;
    color: #d92d20;
    font-weight: 900;
    cursor: pointer;
    padding: 4px 0;
}
.hidden-form { display: none; }

/* Front */
.front-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at 15% 10%, rgba(93, 95, 239, .32), transparent 28%),
        radial-gradient(circle at 80% 0%, rgba(255, 184, 77, .24), transparent 32%),
        linear-gradient(135deg, #0f172a 0%, #121826 52%, #1f1235 100%);
    color: #fff;
}
.front-shell {
    width: min(1180px, calc(100% - 28px));
    margin: 0 auto;
    padding: 28px 0 44px;
}
.front-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}
.front-header h1 {
    margin: 0;
    font-size: clamp(30px, 5vw, 58px);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.front-notice {
    max-width: 760px;
    margin: 14px 0 0;
    color: rgba(255,255,255,.75);
    line-height: 1.8;
}
.admin-mini-link {
    display: none !important;
    flex: none;
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    border: 1px solid rgba(255,255,255,.18);
    color: rgba(255,255,255,.86);
    font-weight: 800;
    backdrop-filter: blur(10px);
}
.carousel, .empty-hero {
    position: relative;
    overflow: hidden;
    width: 100%;
    height: clamp(180px, 33vw, 420px);
    border-radius: 28px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    box-shadow: 0 24px 70px rgba(0,0,0,.28);
    margin-bottom: 22px;
}
.slide {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity .6s ease;
    pointer-events: none;
}
.slide.active { opacity: 1; pointer-events: auto; }
.slide img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.slide:after, .empty-hero:after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, rgba(0,0,0,.48), transparent 60%);
    pointer-events: none;
}
.slide-title {
    position: absolute;
    left: 24px;
    bottom: 24px;
    z-index: 2;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(0,0,0,.38);
    backdrop-filter: blur(10px);
    font-weight: 900;
}
.carousel-dots {
    position: absolute;
    right: 20px;
    bottom: 18px;
    display: flex;
    gap: 8px;
    z-index: 3;
}
.dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 0;
    padding: 0;
    background: rgba(255,255,255,.44);
    cursor: pointer;
}
.dot.active { background: #fff; width: 22px; border-radius: 999px; }
.empty-hero {
    display: flex;
    align-items: center;
    padding: 34px;
    background: linear-gradient(135deg, rgba(80,103,255,.28), rgba(255,255,255,.08));
}
.empty-hero > div { position: relative; z-index: 2; }
.empty-hero p { margin: 0 0 10px; color: rgba(255,255,255,.62); font-weight: 900; letter-spacing: .18em; }
.empty-hero h2 { margin: 0; font-size: clamp(24px, 4vw, 44px); }
.front-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr);
    gap: 22px;
}
.draw-card, .status-card {
    border-radius: 28px;
    background: rgba(255,255,255,.95);
    color: #111827;
    padding: 26px;
    box-shadow: 0 24px 70px rgba(0,0,0,.22);
}
.card-heading h2 {
    margin: 12px 0 0;
    font-size: clamp(24px, 3vw, 36px);
    letter-spacing: -0.03em;
}
.draw-form {
    display: grid;
    gap: 16px;
    margin-top: 20px;
}
.result-card {
    margin: 18px 0;
    padding: 22px;
    border-radius: 24px;
    background: linear-gradient(135deg, #111827, #312e81);
    color: #fff;
    text-align: center;
    overflow: hidden;
    position: relative;
}
.result-card:before {
    content: "";
    position: absolute;
    inset: -40px auto auto -40px;
    width: 130px;
    height: 130px;
    background: rgba(255,255,255,.12);
    border-radius: 50%;
}
.result-card p { margin: 0 0 8px; color: rgba(255,255,255,.75); }
.result-group {
    font-size: clamp(44px, 9vw, 88px);
    font-weight: 1000;
    line-height: 1;
    letter-spacing: -0.06em;
    margin: 10px 0;
}
.result-name, .result-time { color: rgba(255,255,255,.82); line-height: 1.7; }

.result-slot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    color: #fff;
    font-weight: 1000;
    letter-spacing: .02em;
}
.result-lock {
    margin-top: 10px;
    color: rgba(255,255,255,.72);
    font-size: 13px;
    line-height: 1.6;
}
.status-card { align-self: start; }
.status-top {
    display: grid;
    gap: 8px;
    padding-bottom: 18px;
    border-bottom: 1px solid #eef0f6;
}
.status-top strong { font-size: 42px; letter-spacing: -0.05em; }
.status-top small { color: #667085; font-weight: 800; }
.group-list {
    display: grid;
    gap: 12px;
    margin-top: 18px;
}
.group-chip {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 18px;
    background: #f7f8fd;
    border: 1px solid #eef0f6;
}
.group-chip b { display: block; font-size: 17px; }
.group-chip span { display: block; margin-top: 3px; color: #667085; font-size: 12px; font-weight: 800; }
.group-chip strong { font-size: 18px; }
.group-chip em { font-style: normal; font-size: 12px; font-weight: 900; color: #4450d7; background: #eef2ff; padding: 6px 9px; border-radius: 999px; }
.group-chip.disabled { opacity: .45; }

/* Admin Login */
.admin-login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #eef2ff, #f8fafc 55%, #fff7ed);
}
.login-card {
    width: min(420px, 100%);
    background: #fff;
    border-radius: 28px;
    padding: 30px;
    box-shadow: 0 24px 70px rgba(17, 24, 39, .12);
}
.login-card h1 { margin: 0 0 18px; font-size: 32px; letter-spacing: -0.04em; }
.login-card form { display: grid; gap: 16px; }
.back-link { display: inline-block; margin-top: 12px; color: #4450d7; font-weight: 900; }

/* Admin */
.admin-body { min-height: 100vh; background: #f4f6fb; }
.admin-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}
.sidebar {
    position: sticky;
    top: 0;
    align-self: start;
    min-height: 100vh;
    padding: 22px;
    background: #111827;
    color: #fff;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 30px;
}
.brand > span {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: linear-gradient(135deg, #4d6bff, #8e49ff);
    font-weight: 1000;
    font-size: 24px;
}
.brand b { display: block; font-size: 18px; }
.brand small { color: rgba(255,255,255,.55); }
.sidebar nav { display: grid; gap: 8px; }
.sidebar nav a, .sidebar-actions a {
    padding: 12px 14px;
    border-radius: 14px;
    color: rgba(255,255,255,.76);
    font-weight: 800;
}
.sidebar nav a:hover, .sidebar-actions a:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar-actions {
    display: grid;
    gap: 8px;
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid rgba(255,255,255,.12);
}
.admin-main {
    width: min(1220px, 100%);
    padding: 26px;
}
.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 20px;
}
.admin-header h1 { margin: 0; font-size: clamp(28px, 4vw, 46px); letter-spacing: -0.05em; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}
.metric-card {
    background: #fff;
    border: 1px solid #e8ebf3;
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 12px 30px rgba(17,24,39,.05);
}
.metric-card span { color: #667085; font-weight: 800; }
.metric-card strong { display: block; margin-top: 8px; font-size: 36px; letter-spacing: -0.04em; }
.panel {
    background: #fff;
    border: 1px solid #e8ebf3;
    border-radius: 28px;
    padding: 22px;
    margin: 18px 0;
    box-shadow: 0 12px 30px rgba(17,24,39,.05);
}
.panel-title {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-end;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid #edf0f6;
}
.panel-title h2 { margin: 0; font-size: 26px; letter-spacing: -0.03em; }
.panel-title > span { color: #667085; font-size: 13px; line-height: 1.6; text-align: right; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.full-row { grid-column: 1 / -1; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.responsive-table { overflow-x: auto; border: 1px solid #edf0f6; border-radius: 18px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #edf0f6; vertical-align: middle; }
th { background: #f8fafc; color: #667085; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }
.small-input { width: 90px; }
.switch { display: inline-flex; align-items: center; gap: 8px; }
.switch input, .check-line input { width: auto; box-shadow: none; }
.switch span, .check-line span { margin: 0; }
.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-top: 18px;
}
.sub-panel, .upload-panel, .reset-form {
    display: grid;
    gap: 14px;
    padding: 18px;
    border: 1px solid #edf0f6;
    border-radius: 22px;
    background: #fafbff;
}
.sub-panel h3 { margin: 0; font-size: 18px; }
.danger-zone { background: #fff8f8; border-color: #ffe2e2; }
.check-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #475467;
    font-size: 14px;
    font-weight: 800;
}
.upload-panel {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
}
.image-grid-admin {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}
.image-admin-card {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid #edf0f6;
    border-radius: 20px;
    background: #fafbff;
}
.image-admin-card img {
    width: 100%;
    aspect-ratio: 16 / 7;
    object-fit: cover;
    border-radius: 16px;
    background: #e5e7eb;
}
.empty-cell { text-align: center; color: #667085; padding: 28px; }
.reset-form { margin-bottom: 16px; grid-template-columns: 1fr auto; align-items: center; }

@media (max-width: 920px) {
    .front-grid, .admin-layout, .two-col, .form-grid { grid-template-columns: 1fr; }
    .sidebar {
        position: static;
        min-height: auto;
        border-radius: 0 0 24px 24px;
    }
    .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .admin-main { padding: 18px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .upload-panel { grid-template-columns: 1fr; }
    .image-grid-admin { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .front-shell { width: min(100% - 20px, 1180px); padding-top: 18px; }
    .front-header, .admin-header, .panel-title { display: block; }
    .front-header h1 { margin-right: 0; }
    .admin-mini-link { display: inline-flex; margin-top: 14px; }
    .carousel, .empty-hero { border-radius: 20px; height: 210px; }
    .draw-card, .status-card, .panel { padding: 18px; border-radius: 22px; }
    .group-chip { grid-template-columns: 1fr auto; }
    .group-chip em { grid-column: 1 / -1; justify-self: start; }
    .metric-grid, .image-grid-admin { grid-template-columns: 1fr; }
    .sidebar nav { grid-template-columns: 1fr; }
    .reset-form { grid-template-columns: 1fr; }
    .panel-title > span { display: block; text-align: left; margin-top: 8px; }
}

/* v3 additions */
.group-hint {
    display: inline-flex;
    width: fit-content;
    margin-top: 2px;
    color: #4450d7 !important;
    background: #eef2ff;
    padding: 6px 10px;
    border-radius: 999px;
}
.group-chip {
    width: 100%;
    border: 1px solid #eef0f6;
    text-align: left;
    color: inherit;
    cursor: pointer;
}
.group-chip:hover {
    border-color: #c7d2fe;
    box-shadow: 0 10px 24px rgba(68,80,215,.08);
    transform: translateY(-1px);
}
.group-chip:focus-visible {
    outline: 3px solid rgba(80,103,255,.28);
    outline-offset: 2px;
}
.group-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
}
.group-modal.show { display: flex; }
.group-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15,23,42,.68);
    backdrop-filter: blur(8px);
}
.group-modal-card {
    position: relative;
    width: min(620px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    overflow: auto;
    background: #fff;
    color: #111827;
    border-radius: 28px;
    padding: 24px;
    box-shadow: 0 30px 80px rgba(0,0,0,.35);
}
.group-modal-card h2 {
    margin: 0 0 10px;
    font-size: 28px;
    letter-spacing: -0.03em;
}
.group-modal-close {
    position: absolute;
    right: 16px;
    top: 16px;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 999px;
    background: #f2f4f7;
    color: #111827;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}
.group-modal-summary {
    margin-bottom: 14px;
    color: #667085;
    font-weight: 800;
}
.group-member-list {
    display: grid;
    gap: 10px;
}
.group-member-row {
    display: grid;
    grid-template-columns: 110px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 13px 14px;
    border: 1px solid #edf0f6;
    border-radius: 16px;
    background: #fafbff;
}
.group-member-row strong { color: #4450d7; }
.group-member-row span { font-weight: 900; min-width: 0; word-break: break-word; }
.group-member-row em { font-style: normal; color: #667085; font-size: 12px; }
.group-member-empty {
    padding: 24px;
    border-radius: 18px;
    background: #f8fafc;
    color: #667085;
    text-align: center;
    font-weight: 900;
}
.records-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.export-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.inline-reset-form {
    margin: 0;
    display: flex;
    gap: 12px;
    align-items: center;
}
@media (max-width: 640px) {
    .group-member-row { grid-template-columns: 1fr; gap: 5px; }
    .records-toolbar, .inline-reset-form { display: grid; grid-template-columns: 1fr; align-items: stretch; }
    .export-actions { display: grid; grid-template-columns: 1fr 1fr; }
}
