:root {
    --bg: #f4f4f6;
    --surface: #ffffff;
    --sidebar: #1d1d1f;
    --sidebar-soft: #2b2b2d;
    --text: #1a171b;
    --muted: #707a85;
    --border: #e1e4ea;
    --accent: #af0623;
    --accent-dark: #7d0419;
    --success: #1f8f5f;
    --success-soft: #e8f8f1;
    --error: #b42318;
    --error-soft: #fdecea;
    --warning: #8a6d1d;
    --warning-soft: #fff4d6;
    --shadow: 0 2px 12px rgba(16, 24, 40, 0.08);
    --radius: 16px;
    --spacing: 16px;
    --sidebar-width: 250px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: Inter, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

img { max-width: 100%; display: block; }

a { color: inherit; text-decoration: none; }

button, input, select, textarea {
    font: inherit;
}

#shell {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

#sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar);
    color: white;
    padding: 24px 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--accent);
    font-weight: 700;
}

.brand-box strong {
    display: block;
    font-size: 0.95rem;
}

.brand-box small {
    color: rgba(255, 255, 255, 0.7);
    display: block;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    display: block;
    padding: 11px 12px;
    border-radius: 10px;
    color: rgba(255, 255, 255, 0.8);
    transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
    background: var(--sidebar-soft);
    color: #fff;
}

#main {
    flex: 1;
    padding: 26px 32px 40px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1,
.public-header h1 {
    margin: 0;
    font-size: clamp(1.8rem, 2vw, 2.6rem);
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.7rem;
    color: var(--muted);
    margin: 0 0 8px;
}

.cards {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    padding: 18px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.stat-card {
    padding: 0;
}

.stat-card-body {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
    display: block;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--muted);
}

.stat-icon {
    width: 48px;
    height: 48px;
    background: rgba(175, 6, 35, 0.08);
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    font-size: 1.4rem;
    flex-shrink: 0;
}

.table-card {
    margin-top: 24px;
}

.table-wrapper {
    overflow-x: auto;
}

.winning-time-cell {
    min-width: 170px;
    white-space: nowrap;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

thead th {
    background: #1f2730;
    color: white;
    text-align: left;
    padding: 12px 14px;
    font-size: 0.8rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

tbody td {
    padding: 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:nth-child(odd) {
    background: rgba(0, 0, 0, 0.01);
}

.status-badge,
.winner-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 0.74rem;
    font-weight: 600;
}

.status-badge {
    background: rgba(112, 122, 133, 0.12);
    color: var(--text);
}

.status-badge.open { background: rgba(31, 143, 95, 0.12); color: var(--success); }
.status-badge.closed { background: rgba(112, 122, 133, 0.12); color: var(--muted); }
.status-badge.upcoming { background: rgba(138, 109, 29, 0.1); color: var(--warning); }
.status-badge.won { background: rgba(31, 143, 95, 0.12); color: var(--success); }
.status-badge.lost { background: rgba(180, 35, 24, 0.1); color: var(--error); }
.status-badge.draft { background: rgba(112, 122, 133, 0.12); color: var(--muted); }

.winner-badge {
    background: rgba(31, 143, 95, 0.12);
    color: var(--success);
}

.case-thumb {
    width: 48px;
    height: 48px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.action-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.case-order-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 146px;
}

.case-order-number {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--sidebar-soft);
    color: #fff;
    font-weight: 700;
    flex: 0 0 auto;
}

.case-arrow-controls {
    display: flex;
    gap: 4px;
}

.case-move-button {
    min-width: 40px;
    min-height: 40px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
}

.case-move-button:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
}

.case-move-button:focus-visible {
    outline: 3px solid rgba(175, 6, 35, 0.28);
    outline-offset: 2px;
}

.case-move-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.case-drag-handle {
    cursor: grab;
    touch-action: none;
    font-size: 1.25rem;
    color: var(--muted);
}

.case-drag-handle:active {
    cursor: grabbing;
}

#caseOrderList tr.is-dragging {
    opacity: 0.4;
}

#caseOrderList tr.is-drop-target {
    box-shadow: inset 0 3px 0 var(--accent);
}

.order-dirty-notice {
    margin-bottom: 14px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-secondary {
    background: white;
    border-color: var(--border);
    color: var(--text);
}

.btn-small {
    padding: 7px 10px;
    font-size: 0.8rem;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.95rem;
    color: var(--text);
}

label span {
    font-weight: 600;
}

input, select, textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: white;
    color: var(--text);
}

textarea { resize: vertical; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    flex-direction: row;
    gap: 10px;
    padding-top: 8px;
}

.checkbox-row input {
    width: auto;
    accent-color: var(--accent);
}

.footer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.notice {
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}

.notice.success {
    background: var(--success-soft);
    border-color: rgba(31, 143, 95, 0.2);
    color: var(--success);
}

.notice.error {
    background: var(--error-soft);
    border-color: rgba(180, 35, 24, 0.14);
    color: var(--error);
}

.notice.info,
.notice.warning {
    background: var(--warning-soft);
    border-color: rgba(138, 109, 29, 0.14);
    color: var(--warning);
}

.muted { color: var(--muted); }
.tiny { font-size: 0.8rem; }
.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 28px 16px;
}

.preview-image {
    width: 160px;
    height: 110px;
    object-fit: cover;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f4f2f3, #e7ebf1);
}

.login-card {
    width: min(420px, calc(100vw - 40px));
    background: white;
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    padding: 30px;
}

.login-card h1 {
    margin: 0 0 20px;
}

.public-body {
    background: #f5f5f7;
}

.public-shell {
    width: min(1200px, calc(100% - 28px));
    margin: 24px auto 40px;
    padding: 24px 18px 48px;
}

.public-header {
    text-align: center;
    margin-bottom: 26px;
}

.launch-waiting {
    max-width: 760px;
    margin: 10vh auto 0;
    text-align: center;
}

.launch-waiting h2 {
    margin-top: 0;
}

.launch-countdown {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-top: 28px;
}

.launch-countdown > div {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.launch-countdown strong {
    font-size: clamp(1.5rem, 5vw, 2.5rem);
    line-height: 1;
}

.launch-countdown span {
    color: var(--muted);
    font-size: 0.85rem;
}

.public-header .eyebrow {
    text-align: center;
    margin-bottom: 8px;
}

.intro {
    max-width: 720px;
    margin: 12px auto 0;
    color: var(--muted);
    font-size: 1rem;
}

.cases-grid {
    display: grid;
    grid-template-columns: repeat(var(--calendar-columns-desktop, 4), minmax(0, 1fr));
    gap: 18px;
    margin-top: 28px;
}

.day-card {
    position: relative;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    padding: 18px 14px;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: left;
    color: var(--text);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    box-shadow: var(--shadow);
}

.day-card:hover:not(:disabled) {
    transform: translateY(-2px);
    border-color: rgba(175, 6, 35, 0.3);
}

.day-card:disabled {
    opacity: 0.72;
    cursor: not-allowed;
}

.day-card.is-open {
    border-color: rgba(31, 143, 95, 0.4);
    background: linear-gradient(180deg, rgba(31, 143, 95, 0.04), rgba(255, 255, 255, 1));
}

.day-card.is-won {
    background: linear-gradient(180deg, rgba(31, 143, 95, 0.05), rgba(255, 255, 255, 1));
}

.day-card.is-closed {
    opacity: 0.82;
    background: linear-gradient(180deg, rgba(112, 122, 133, 0.04), rgba(255, 255, 255, 1));
}

.day-number {
    font-size: 2.2rem;
    font-weight: 800;
    line-height: 1;
}

.day-status {
    color: var(--muted);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    overflow-wrap: anywhere;
}

.day-title {
    display: block;
    margin-top: 8px;
    font-weight: 600;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.modal {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    z-index: 20;
}

.modal.hidden {
    display: none;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(17, 17, 20, 0.52);
}

.modal-panel {
    position: relative;
    width: min(620px, calc(100vw - 30px));
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    background: white;
    border-radius: 22px;
    padding: 24px;
    box-shadow: var(--shadow);
    z-index: 1;
}

.modal-close {
    position: absolute;
    right: 14px;
    top: 10px;
    background: transparent;
    border: none;
    font-size: 2rem;
    color: var(--muted);
    cursor: pointer;
}

.case-modal-body {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.case-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.case-modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
}

.case-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.case-image {
    width: 100%;
    max-height: 240px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid var(--border);
}

.form-message {
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.95rem;
}

.form-message.success {
    background: var(--success-soft);
    color: var(--success);
}

.form-message.error {
    background: var(--error-soft);
    color: var(--error);
}

.participation-result {
    display: grid;
    justify-items: center;
    gap: 12px;
    width: 100%;
    padding: clamp(22px, 6vw, 36px) 18px;
    border: 2px solid transparent;
    border-radius: 18px;
    text-align: center;
}

.participation-result.is-won {
    color: var(--success);
    background: var(--success-soft);
    border-color: var(--success);
}

.participation-result.is-lost {
    color: var(--error);
    background: var(--error-soft);
    border-color: var(--error);
}

.participation-result.is-pending {
    color: var(--text);
    background: rgba(112, 122, 133, 0.1);
    border-color: var(--border);
}

.participation-result__label {
    max-width: 100%;
    font-size: clamp(2rem, 10vw, 4rem);
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0.035em;
    overflow-wrap: anywhere;
}

.participation-result__message {
    max-width: 42ch;
    margin: 0;
    font-size: clamp(1rem, 4vw, 1.2rem);
    line-height: 1.5;
    overflow-wrap: anywhere;
}

@media (max-width: 600px) {
    .modal {
        padding: 12px;
    }

    .modal-panel {
        width: 100%;
        max-height: calc(100vh - 24px);
        max-height: calc(100dvh - 24px);
        padding: 22px 18px;
        border-radius: 18px;
    }

    .case-modal-header {
        align-items: flex-start;
        padding-right: 26px;
    }

    .participation-result {
        padding-inline: 12px;
    }
}

.filter-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (max-width: 900px) {
    .cases-grid {
        grid-template-columns: repeat(var(--calendar-columns-tablet, 3), minmax(0, 1fr));
    }

    #shell {
        display: block;
    }

    #sidebar {
        width: 100%;
    }

    #main {
        padding: 20px;
    }
}

@media (max-width: 600px) {
    .launch-countdown {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .cases-grid {
        grid-template-columns: repeat(var(--calendar-columns-mobile, 2), minmax(0, 1fr));
        gap: 12px;
    }

    .day-card {
        padding: 14px 8px;
    }

    .day-number {
        font-size: 1.9rem;
    }

    .winning-time-cell {
        min-width: 135px;
        max-width: 150px;
        white-space: normal;
    }

    .case-order-controls {
        gap: 6px;
        min-width: 136px;
    }

    .case-move-button {
        min-width: 44px;
        min-height: 44px;
    }

    .case-arrow-controls {
        gap: 6px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
