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

body {
    margin: 0;
    color: #1f2937;
    background: #f8fafc;
    font-family: system-ui, -apple-system, sans-serif;
    line-height: 1.5;
}

main {
    max-width: 64rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 2.5rem;
}

.login {
    max-width: 22rem;
    margin: clamp(1rem, 10vh, 6rem) auto 0;
}

.login form, .password-form form {
    display: grid;
    gap: 0.75rem;
}

.password-form {
    max-width: 22rem;
}

input[type="password"], input[type="text"], input[type="date"], select, button, .btn-link {
    padding: 0.65rem 0.85rem;
    font: inherit;
    border-radius: 0.5rem;
}

input[type="password"], input[type="text"], input[type="date"], select {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
    max-width: 100%;
}

input[type="text"]:focus, input[type="password"]:focus, input[type="date"]:focus, select:focus, button:focus-visible, .btn-link:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border: 1px solid #cbd5e1;
    line-height: 1.25;
}

.btn-link.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

.header-link {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
}

.header-link:hover {
    text-decoration: underline;
}

button {
    cursor: pointer;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #0f172a;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.btn-primary {
    background: #1d4ed8;
    border-color: #1d4ed8;
    color: #ffffff;
    font-weight: 600;
}

.btn-secondary {
    background: #ffffff;
    border-color: #cbd5e1;
    color: #1e293b;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.875rem;
}

.dashboard {
    display: grid;
    gap: 1rem;
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.topbar-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.topbar-title h1 {
    margin: 0;
    font-size: 1.5rem;
}

.topbar-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.topbar-nav a {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 500;
}

.topbar-nav a:hover {
    text-decoration: underline;
}

.inline-form {
    margin: 0;
}

.env-badge, .meta-chip, .status-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.env-badge {
    background: #eff6ff;
    color: #1e40af;
    border-color: #bfdbfe;
}

.meta-chip {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}

.status-muted {
    background: #f1f5f9;
    color: #475569;
    border-color: #cbd5e1;
}

.status-ok {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}

.status-warn {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.status-danger {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.status-partial {
    background: #fffbeb;
    color: #92400e;
    border-color: #fcd34d;
}

.status-unknown {
    background: #f5f3ff;
    color: #5b21b6;
    border-color: #c4b5fd;
}

.banner {
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border: 1px solid #fecaca;
    background: #fef2f2;
    color: #991b1b;
    font-weight: 500;
}

.banner.banner-warn {
    border-color: #fde68a;
    background: #fffbeb;
    color: #92400e;
}

.panel-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
    gap: 1rem;
}

.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    min-width: 0;
}

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.card-header h2 {
    margin: 0;
    font-size: 1.125rem;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.kv-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem 1rem;
    margin: 0;
}

.kv-grid dt {
    font-size: 0.8rem;
    color: #64748b;
}

.kv-grid dd {
    margin: 0.1rem 0 0;
    font-weight: 600;
    word-break: break-word;
}

.countdown {
    font-variant-numeric: tabular-nums;
    font-size: 1.15rem;
    color: #1d4ed8;
}

.meta-note, .empty-note, .field-hint, .blocker-text {
    margin: 0.75rem 0 0;
    font-size: 0.875rem;
    color: #475569;
}

.field-hint.is-error {
    color: #b91c1c;
    font-weight: 500;
}

.draw-numbers {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.draw-ball {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 999px;
    background: #eff6ff;
    border: 2px solid #93c5fd;
    color: #1e3a8a;
    font-weight: 700;
    font-size: 1.05rem;
}

.amount-row {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.amount-row label {
    font-weight: 600;
}

.amount-input-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    max-width: 26rem;
}

.amount-input-wrap input {
    flex: 1;
    min-width: 0;
}

.amount-input-wrap button {
    flex-shrink: 0;
    white-space: nowrap;
}

.unit-label {
    font-weight: 600;
    color: #475569;
}

.saved-amount-line {
    margin: 0.25rem 0 0;
    font-size: 0.9rem;
    color: #334155;
}

.saved-amount-line strong {
    color: #1d4ed8;
    font-variant-numeric: tabular-nums;
}

.options-fieldset {
    border: 0;
    padding: 0;
    margin: 0 0 1rem;
}

.options-fieldset legend {
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.option-card {
    display: grid;
    gap: 0.25rem;
    padding: 0.8rem 0.85rem;
    border: 2px solid #cbd5e1;
    border-radius: 0.65rem;
    background: #f8fafc;
    cursor: pointer;
    user-select: none;
    transition: border-color 0.12s ease, background-color 0.12s ease;
}

.readonly-odds-card {
    cursor: default;
}

.option-card:focus-within {
    outline: 2px solid #2563eb;
    outline-offset: 2px;
}

.option-card.is-selected {
    border-color: #1d4ed8;
    background: #eff6ff;
    box-shadow: inset 0 0 0 1px #1d4ed8;
}

.option-checkbox {
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
    accent-color: #1d4ed8;
}

.option-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.option-name {
    font-size: 1.1rem;
    font-weight: 700;
}

.option-state {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
}

.option-card.is-selected .option-state {
    color: #1d4ed8;
}

.option-odds, .option-limit {
    font-size: 0.85rem;
    color: #334155;
    font-variant-numeric: tabular-nums;
}

.summary-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.summary-bar span {
    color: #64748b;
    font-size: 0.875rem;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

.blocker-text {
    margin: 0;
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    overflow-wrap: anywhere;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.75rem;
}

.stat-card {
    display: grid;
    gap: 0.2rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 0.85rem 1rem;
    min-width: 0;
}

.stat-label {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: #0f172a;
}

.stat-ok {
    color: #065f46;
}

.stat-danger {
    color: #991b1b;
}

.stat-unknown {
    color: #5b21b6;
}

.stat-sub {
    font-size: 0.78rem;
    color: #475569;
    overflow-wrap: anywhere;
}

.filter-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    gap: 0.75rem;
    align-items: end;
}

.filter-field {
    display: grid;
    gap: 0.3rem;
    min-width: 0;
}

.filter-field label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
}

.filter-field input, .filter-field select {
    width: 100%;
    min-width: 0;
    padding: 0.5rem 0.65rem;
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 0.85rem;
    border-top: 1px solid #e2e8f0;
}

.pagination-sizes, .pagination-pages {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}

.pagination-sizes a {
    color: #1d4ed8;
    text-decoration: none;
    padding: 0.2rem 0.45rem;
    border-radius: 0.35rem;
    border: 1px solid #cbd5e1;
}

.page-size-current {
    padding: 0.2rem 0.45rem;
    border-radius: 0.35rem;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.pagination-info {
    color: #475569;
}

.confirm-dialog {
    width: min(32rem, calc(100vw - 1.5rem));
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    padding: 0;
    border: 1px solid #cbd5e1;
    border-radius: 0.75rem;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.22);
}

.confirm-dialog::backdrop {
    background: rgba(15, 23, 42, 0.45);
}

.dialog-inner {
    padding: 1.25rem;
}

.dialog-inner h2 {
    margin: 0 0 0.25rem;
}

.dialog-subtitle {
    margin: 0 0 1rem;
    font-size: 0.875rem;
    color: #475569;
}

.dialog-error {
    margin: 0.85rem 0 0;
    padding: 0.6rem 0.75rem;
    border-radius: 0.5rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-size: 0.875rem;
}

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

.table-wrap {
    overflow-x: auto;
    margin-top: 0.75rem;
}

.table-spaced {
    margin-top: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th, .data-table td {
    padding: 0.6rem 0.65rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
}

.data-table th {
    font-size: 0.8rem;
    color: #475569;
    background: #f8fafc;
    white-space: nowrap;
}

.data-table a {
    color: #1d4ed8;
    text-decoration: none;
    font-weight: 500;
}

.data-table a:hover {
    text-decoration: underline;
}

.nowrap {
    white-space: nowrap;
}

.subtext {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 0.15rem;
}

.snapshot-cell {
    max-width: 15rem;
    word-break: break-word;
}

.message-cell {
    max-width: 16rem;
    word-break: break-word;
}

.code-block {
    margin: 0.75rem 0 0;
    padding: 0.85rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.82rem;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 24rem;
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .panel-grid {
        grid-template-columns: 1fr;
    }

    .summary-bar {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    main {
        padding: 1rem 0.75rem 2rem;
    }

    .card {
        padding: 0.85rem 0.9rem;
    }

    .options-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .kv-grid {
        grid-template-columns: 1fr;
    }

    .filter-form {
        grid-template-columns: 1fr;
    }

    .amount-input-wrap {
        max-width: 100%;
    }

    .dialog-actions {
        flex-direction: column-reverse;
    }

    .dialog-actions button {
        width: 100%;
    }
}
