/* ============================================================
   KBO Magic Number Dashboard — style.css
   Clean Light Theme, COIS Lab navy ↔ teal palette
   ============================================================ */

/* --- Design Tokens --- */
:root {
    --container-max: 920px;
    --drawer-width: 416px;
    --drawer-gap: 14px;

    /* COIS palette */
    --navy: #0d2240;
    --teal: #1a9e8f;
    --teal-light: #23c4b2;
    --accent: #0f7a6e;

    /* Background tones */
    --bg: #f8f9fb;
    --bg-card: #ffffff;
    --bg-card-hover: #fafbfd;

    /* Borders & shadows */
    --border: #e2e6ed;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);

    /* Text */
    --text-primary: #1a1f2e;
    --text-secondary: #5a6478;
    --text-dim: #8893a7;

    /* Status */
    --green: #059669;
    --green-bg: rgba(5, 150, 105, 0.08);
    --yellow: #d97706;
    --orange: #ea580c;
    --red: #dc2626;
    --red-bg: rgba(220, 38, 38, 0.06);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
}

/* --- Layout --- */
.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 48px 20px 32px;
}

/* --- Header --- */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 6px 16px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--accent);
    text-transform: uppercase;
    margin-bottom: 16px;
}

.badge::before {
    content: '⚾';
    font-size: 12px;
}

h1 {
    font-size: 42px;
    font-weight: 900;
    color: var(--navy);
    letter-spacing: -1px;
    line-height: 1.1;
    margin-bottom: 8px;
}

header {
    text-align: center;
    margin-bottom: 32px;
}

#update-info {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

.page-nav {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: -12px 0 20px;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 88px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
}

.page-link:hover {
    border-color: #cfd6e0;
    color: var(--navy);
    transform: translateY(-1px);
}

.page-link.is-current {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
}

/* --- Info Legend --- */
.info-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 13px;
    box-shadow: var(--shadow-sm);
}

.legend-item {
    display: flex;
    align-items: baseline;
    gap: 10px;
}

.legend-label {
    font-weight: 700;
    color: var(--accent);
    min-width: 64px;
    flex-shrink: 0;
}

.legend-desc {
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.4;
}

.legend-divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 2px 0;
}

.legend-hint .legend-desc {
    color: var(--text-tertiary, #999);
    font-size: 12px;
}

.legend-hint .legend-dot {
    font-size: 22px;
    line-height: 1;
    vertical-align: -2.5px;
    margin-right: 4px;
}

.legend-desc code {
    font-family: 'JetBrains Mono', 'Inter', monospace;
    font-size: 12px;
    font-weight: 700;
    color: var(--navy);
    background: rgba(13, 34, 64, 0.06);
    padding: 1px 4px;
    border-radius: 6px;
}

/* --- Team Grid --- */
#team-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.content-layout {
    display: block;
    position: relative;
}

.board-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    min-width: 0;
}

/* --- Team Card --- */
.team-card {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 88px;
    padding: 16px 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    animation: cardSlide 0.4s ease-out both;
}

.team-card.no-entry-animation {
    animation: none;
}

.team-card[role="button"] {
    cursor: pointer;
}

@keyframes cardSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.team-card:hover {
    box-shadow: var(--shadow-md);
    border-color: #d0d5df;
    transform: translateY(-1px);
}

.team-card.is-selected {
    border-color: rgba(13, 34, 64, 0.35);
    box-shadow: 0 8px 20px rgba(13, 34, 64, 0.12);
}

.team-card.eliminated {
    opacity: 1;
}

/* Rank badge */
.rank-badge {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
}

.rank-badge.top {
    background: rgba(26, 158, 143, 0.1);
    color: var(--accent);
}

.rank-badge.rank-1 {
    background: linear-gradient(135deg, #fbbf24, #d97706);
    color: white;
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.3);
}

.rank-badge.rank-2 {
    background: linear-gradient(135deg, #9ca3af, #6b7280);
    color: white;
    box-shadow: 0 2px 8px rgba(156, 163, 175, 0.3);
}

.rank-badge.rank-3 {
    background: linear-gradient(135deg, #d97706, #92400e);
    color: white;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.2);
}

.rank-badge.out {
    background: var(--bg);
    color: var(--text-dim);
}

/* Team info */
.team-info {
    flex: 1;
    min-width: 0;
}

.team-logo-wrap {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.team-logo {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.team-name {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.team-record {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 400;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
}

.meta-group {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.team-record .meta-group + .meta-group::before,
.detail-subtitle .meta-group + .meta-group::before,
.detail-row-subtitle .meta-group + .meta-group::before {
    content: '·';
    color: var(--text-dim);
    margin-right: 10px;
}

/* Numbers section (dual column) */
.numbers-section {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex: 0 0 188px;
    flex-shrink: 0;
}

.number-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1 1 0;
    min-width: 0;
}

.number-divider {
    width: 1px;
    height: 36px;
    background: var(--border);
}

.magic-number {
    font-family: 'JetBrains Mono', 'Inter', monospace;
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 2px;
}

.magic-number.safe {
    color: var(--green);
}

.magic-number.warning {
    color: var(--yellow);
}

.magic-number.danger {
    color: var(--orange);
}

.magic-number.muted {
    color: var(--text-dim);
}

.magic-number.eliminated {
    color: var(--red);
    font-size: 14px;
    font-weight: 700;
}

.magic-number.clinched {
    color: var(--green);
    font-size: 22px;
    font-weight: 800;
}

.magic-label {
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 600;
    letter-spacing: 0.3px;
    margin-top: 2px;
}

/* --- Playoff Cutline --- */
.playoff-line {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.playoff-line.visible {
    display: flex;
}

.playoff-line::before,
.playoff-line::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--teal), transparent);
}

/* --- Loading --- */
.loading {
    text-align: center;
    padding: 80px 20px;
    color: var(--text-secondary);
}

.spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.error-msg {
    text-align: center;
    padding: 60px 20px;
    color: var(--red);
}

.team-detail-panel {
    position: fixed;
    right: max(20px, calc((100vw - var(--container-max)) / 2 + 20px));
    top: 28px;
    bottom: 28px;
    width: min(var(--drawer-width), calc(100vw - 48px));
    max-height: calc(100vh - 56px);
    padding: 22px 22px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: block;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate3d(18px, 0, 0);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
    box-shadow: 0 18px 42px rgba(13, 34, 64, 0.14);
    z-index: 20;
}

.team-detail-panel.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
}

@media (min-width: 1480px) {
    .team-detail-panel {
        position: absolute;
        top: 0;
        right: auto;
        bottom: 0;
        left: calc(100% + var(--drawer-gap));
        width: var(--drawer-width);
        max-height: none;
    }
}

@media (max-width: 1280px) and (min-width: 961px) {
    .team-detail-panel {
        right: 16px;
        top: 18px;
        bottom: 18px;
        width: min(360px, calc(100vw - 32px));
        max-height: calc(100vh - 36px);
    }
}

.detail-empty {
    color: var(--text-secondary);
}

.detail-empty h2 {
    color: var(--navy);
    font-size: 24px;
    margin-bottom: 8px;
}

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    position: sticky;
    top: -22px;
    background: var(--bg-card);
    padding-top: 22px;
    padding-bottom: 10px;
    z-index: 1;
}

.detail-heading {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

.detail-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.detail-close:hover {
    border-color: #cfd6e0;
    color: var(--navy);
}

.detail-team {
    font-size: 30px;
    font-weight: 900;
    color: var(--navy);
    line-height: 1.1;
    margin-bottom: 6px;
}

.detail-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
}

.detail-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.detail-status.safe {
    color: var(--green);
    background: var(--green-bg);
}

.detail-status.warning {
    color: var(--yellow);
    background: rgba(217, 119, 6, 0.12);
}

.detail-status.danger {
    color: var(--red);
    background: var(--red-bg);
}

.detail-headline {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1.5;
    margin-bottom: 16px;
}

.detail-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.detail-metric {
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
}

.detail-metric-label {
    display: block;
    color: var(--text-dim);
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 6px;
}

.detail-metric-value {
    color: var(--navy);
    font-size: 20px;
    font-weight: 900;
    line-height: 1;
}

.detail-section {
    margin-top: 18px;
}

.detail-section h3 {
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.3px;
    margin-bottom: 10px;
}

.detail-section-note {
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.45;
    margin: -2px 0 10px;
}

.detail-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    list-style: none;
}

.detail-list li {
    position: relative;
    padding-left: 14px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.55;
}

.detail-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--teal);
}

.detail-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.detail-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    padding: 12px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.detail-row-title {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 800;
    margin-bottom: 4px;
}

.detail-row-subtitle {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.45;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
}

.detail-row-value {
    align-self: center;
    color: var(--navy);
    font-size: 15px;
    font-weight: 900;
    white-space: nowrap;
}

@media (max-width: 960px) {
    .team-detail-panel {
        right: 12px;
        left: 12px;
        top: auto;
        bottom: 12px;
        width: auto;
        max-height: min(78vh, 720px);
        transform: translateY(18px);
    }
}

@media (max-height: 820px) and (min-width: 961px) {
    .team-detail-panel {
        top: 14px;
        bottom: 14px;
        max-height: calc(100vh - 28px);
    }
}

/* --- Footer --- */
footer {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 32px 0 16px;
    margin-top: 24px;
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.8;
}

footer strong {
    color: var(--accent);
}

.footer-logo {
    width: 100px;
    flex-shrink: 0;
    opacity: 0.85;
    transition: opacity 0.3s;
}

.footer-logo:hover {
    opacity: 1;
}

.footer-text {
    text-align: left;
    line-height: 1.7;
}

.footer-text a {
    color: var(--accent);
    text-decoration: none;
}

.footer-sub {
    font-size: 11px;
    color: var(--text-dim);
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .container {
        padding: 32px 12px 24px;
    }

    h1 {
        font-size: 30px;
    }

    .page-nav {
        margin-top: -8px;
        flex-wrap: wrap;
    }

    .info-legend {
        padding: 12px 14px;
    }

    .legend-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    .legend-label {
        min-width: 0;
    }

    .detail-metrics {
        grid-template-columns: 1fr;
    }

    .team-card {
        padding: 14px 16px;
        gap: 12px;
    }

    .team-name {
        font-size: 15px;
    }

    .team-record {
        font-size: 11px;
        gap: 2px 8px;
    }

    .meta-group:first-child {
        flex-basis: 100%;
    }

    .team-record .meta-group + .meta-group::before,
    .detail-subtitle .meta-group + .meta-group::before,
    .detail-row-subtitle .meta-group + .meta-group::before {
        content: '';
        margin-right: 0;
    }

    .detail-team {
        font-size: 26px;
    }

    .detail-subtitle,
    .detail-row-subtitle {
        gap: 2px 8px;
    }

    .detail-row {
        align-items: start;
    }

    .detail-row-value {
        justify-self: end;
        padding-top: 2px;
    }

    .magic-number {
        font-size: 22px;
    }

    .numbers-section {
        flex-basis: 132px;
        gap: 8px;
    }

    .number-col {
        min-width: 0;
    }

    .rank-badge {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }

    footer {
        flex-direction: column;
        text-align: center;
    }

    .footer-text {
        text-align: center;
    }
}

/* --- Feedback --- */
.feedback-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.feedback-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}

.feedback-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 34, 64, 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.feedback-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.feedback-modal {
    position: relative;
    width: min(440px, calc(100vw - 32px));
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 28px 24px;
    box-shadow: 0 20px 50px rgba(13, 34, 64, 0.18);
    transform: translateY(16px);
    transition: transform 0.25s ease;
}

.feedback-overlay.is-open .feedback-modal {
    transform: translateY(0);
}

.feedback-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text-secondary);
    font-size: 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.feedback-close:hover {
    border-color: #cfd6e0;
    color: var(--navy);
}

.feedback-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--navy);
    margin-bottom: 6px;
}

.feedback-desc {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.feedback-textarea {
    width: 100%;
    min-height: 120px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.6;
    resize: vertical;
    transition: border-color 0.2s ease;
}

.feedback-textarea:focus {
    outline: none;
    border-color: var(--teal);
}

.feedback-textarea::placeholder {
    color: var(--text-dim);
}

.feedback-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
}

.feedback-charcount {
    font-size: 11px;
    color: var(--text-dim);
    font-weight: 500;
}

.feedback-submit {
    padding: 10px 24px;
    border: none;
    border-radius: 999px;
    background: var(--navy);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.feedback-submit:hover {
    background: #152d4f;
    transform: translateY(-1px);
}

.feedback-submit:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.feedback-done {
    text-align: center;
    padding: 24px 0 8px;
}

.feedback-done p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}
