/* DK MLB DFS Optimizer -- Mobile-First CSS */

/* ── Design Tokens ────────────────────────────────────────────── */

:root {
    --bg-primary: #0a0a1a;
    --bg-card: #141428;
    --bg-card-alt: #0f3460;
    --bg-input: #1a1a35;
    --text-primary: #e0e0ff;
    --text-secondary: #8888aa;
    --text-muted: #556080;
    --accent: #e94560;
    --accent-hover: #ff6b81;
    --accent-dim: rgba(233, 69, 96, 0.15);
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --border: #1e1e3a;
    --radius: 12px;
    --radius-sm: 8px;

    /* Position colors */
    --pos-p: #4299e1;
    --pos-c: #9c27b0;
    --pos-if: #ed8936;
    --pos-of: #4caf50;
}

/* ── Reset ────────────────────────────────────────────────────── */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px 40px;
    width: 100%;
}

/* ── Header ───────────────────────────────────────────────────── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.app-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.header-badge {
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 500;
}

.header-badge.active {
    background: var(--accent);
    color: #fff;
}

/* ── Screens ──────────────────────────────────────────────────── */

.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }

.screen-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0;
    white-space: nowrap;
}

/* ── Buttons ──────────────────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    color: #fff;
    width: 100%;
}

.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
    background: transparent;
    color: var(--accent);
    padding: 8px 12px;
    min-height: 40px;
    font-size: 0.9rem;
}

.btn-large {
    margin-top: 16px;
    padding: 16px;
    font-size: 1rem;
}

.btn-download {
    margin-top: 24px;
    font-size: 1.05rem;
}

.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.btn-link:hover { color: var(--text-primary); }

/* ── Slate Screen ─────────────────────────────────────────────── */

.slate-picker { padding: 0; }

.slate-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.slate-date-label {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 4px 0;
    border-bottom: 1px solid var(--bg-input);
}

.slate-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s;
    width: 100%;
    text-align: left;
    -webkit-tap-highlight-color: transparent;
}

.slate-btn:active { transform: scale(0.98); }
.slate-btn:hover { border-color: var(--accent); }

.slate-label {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.slate-games {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

.slate-name {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.slate-loading,
.slate-error {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.divider-or {
    text-align: center;
    margin: 20px 0;
    position: relative;
    color: var(--text-muted);
}

.divider-or::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    border-top: 1px solid var(--border);
}

.divider-or span {
    background: var(--bg-primary);
    padding: 0 12px;
    position: relative;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.1em;
}

/* ── Upload Zone ──────────────────────────────────────────────── */

.upload-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}

.upload-zone:active,
.upload-zone.dragover {
    border-color: var(--accent);
    background: var(--accent-dim);
}

.upload-icon {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 10px;
    letter-spacing: 0.05em;
}

.upload-title {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* ── Slate Loaded Card ────────────────────────────────────────── */

.slate-loaded {
    margin-top: 20px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
}

.loaded-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.loaded-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}

.enrich-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 4px;
}

.enrich-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 10px 6px;
    text-align: center;
}

.enrich-val {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.enrich-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 2px;
}

/* ── Pool Screen ──────────────────────────────────────────────── */

.pool-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.pool-header .screen-title {
    flex: 1;
}

/* ── Filter Bar ───────────────────────────────────────────────── */

.filter-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 8px 0;
}

.pos-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.pos-chip {
    padding: 5px 11px;
    border-radius: 14px;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, color 0.15s;
}

.pos-chip.active {
    background: var(--accent-dim);
    color: var(--accent);
    border-color: var(--accent);
}

.filter-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.filter-select {
    flex: 0 0 auto;
    padding: 7px 10px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    min-height: 36px;
    appearance: none;
}

.filter-input {
    flex: 1;
    padding: 7px 10px;
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    min-height: 36px;
    outline: none;
}

.filter-input:focus {
    border-color: var(--accent);
}

.filter-input::placeholder { color: var(--text-muted); }

/* ── Pool Stats Bar ───────────────────────────────────────────── */

.pool-stats-bar {
    display: flex;
    gap: 6px;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 6px 0 4px;
    flex-wrap: wrap;
}

.pool-stats-bar .sep { color: var(--border); }

/* ── Pool Table ───────────────────────────────────────────────── */

.pool-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    max-height: calc(100dvh - 320px);
    overflow-y: auto;
}

.pool-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
    min-width: 480px;
}

.pool-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 2;
    cursor: default;
    padding: 8px 6px;
    text-align: left;
    border-bottom: 2px solid var(--accent);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    user-select: none;
}

.pool-table th.sortable { cursor: pointer; }
.pool-table th.sortable:hover { color: var(--text-primary); }

.pool-table th.sort-active { color: var(--accent); }

.pool-table th.sort-asc::after  { content: " \u2191"; }
.pool-table th.sort-desc::after { content: " \u2193"; }

.pool-table td {
    padding: 6px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.pool-table tr:hover td { background: #181830; }

.pool-table tr.excluded td {
    opacity: 0.4;
    text-decoration: line-through;
}

.pool-table tr.locked {
    border-left: 3px solid var(--success);
}

/* Minimum row height for touch targets */
.pool-table td, .pool-table th {
    min-height: 44px;
    height: 44px;
}

/* Column widths */
.col-actions { width: 56px; white-space: nowrap; }
.col-pos     { width: 44px; }
.col-salary  { width: 62px; text-align: right; }
.col-proj    { width: 48px; text-align: right; }
.col-value   { width: 42px; text-align: right; }
.col-order   { width: 36px; text-align: center; }
.col-game    { width: 72px; }
.col-status  { width: 28px; text-align: center; }

/* ── Table Cell Types ─────────────────────────────────────────── */

.player-name-text {
    font-size: 0.82rem;
    font-weight: 500;
}

.team-badge {
    display: inline-block;
    font-size: 0.65rem;
    background: var(--bg-input);
    color: var(--text-muted);
    padding: 1px 5px;
    border-radius: 3px;
    margin-left: 5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    vertical-align: middle;
}

.pos-tag {
    display: inline-block;
    font-weight: 700;
    font-size: 0.7rem;
    padding: 2px 5px;
    border-radius: 4px;
    color: #fff;
    text-align: center;
    min-width: 24px;
}

.pos-tag.pos-P  { background: var(--pos-p); }
.pos-tag.pos-C  { background: var(--pos-c); }
.pos-tag.pos-IF { background: var(--pos-if); }
.pos-tag.pos-OF { background: var(--pos-of); }

.col-proj.editable { cursor: pointer; }
.col-proj.editable:hover { color: var(--accent); }
.col-proj.overridden { color: var(--warning); font-weight: 700; }

.inline-edit {
    width: 52px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    color: var(--text-primary);
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 3px;
    outline: none;
}

/* ── Toggle Icons ─────────────────────────────────────────────── */

.toggle-icon {
    display: inline-block;
    cursor: pointer;
    opacity: 0.25;
    font-size: 14px;
    margin: 0 1px;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s;
    line-height: 1;
}

.toggle-icon:hover { opacity: 0.6; }
.toggle-icon.active { opacity: 1; }
.lock-icon.active { filter: hue-rotate(120deg) saturate(2); }

/* ── Status Icons ─────────────────────────────────────────────── */

.status-confirmed { color: var(--success); font-size: 0.9rem; font-weight: bold; }
.status-unconfirmed { color: var(--text-muted); font-size: 0.85rem; }
.status-probable {
    color: var(--warning);
    font-size: 0.65rem;
    font-weight: bold;
    background: rgba(255, 152, 0, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
}

/* ── Mode Grid ────────────────────────────────────────────────── */

.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 12px;
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    min-height: 100px;
}

.mode-btn:active { transform: scale(0.96); }
.mode-btn:hover { border-color: var(--accent); }
.mode-btn.generated { border-color: var(--success); }
.mode-btn-wide { grid-column: 1 / -1; }

.mode-icon {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

.mode-btn[data-mode="cash"] .mode-icon { color: var(--success); }

.mode-label {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.mode-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ── Results ──────────────────────────────────────────────────── */

.results-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.results-summary {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    display: flex;
    justify-content: space-around;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.results-stat { text-align: center; }

.results-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
}

.results-stat-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Lineup Cards ─────────────────────────────────────────────── */

.lineup-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.lineup-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    overflow: hidden;
}

.lineup-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    gap: 6px;
}

.lineup-card-title {
    font-size: 0.88rem;
    font-weight: 600;
    flex: 1;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.lineup-card-meta {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.lineup-card-toggle {
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.lineup-card.expanded .lineup-card-toggle { transform: rotate(180deg); }

.lineup-card-body {
    display: none;
    padding: 0 14px 12px;
}

.lineup-card.expanded .lineup-card-body { display: block; }

.player-row {
    display: grid;
    grid-template-columns: 36px 1fr 52px 48px;
    align-items: center;
    padding: 6px 0;
    border-top: 1px solid rgba(255,255,255,0.04);
    font-size: 0.82rem;
}

.player-pos {
    font-weight: 700;
    font-size: 0.72rem;
    padding: 2px 4px;
    border-radius: 4px;
    text-align: center;
    color: #fff;
}

.player-pos.pos-P  { background: var(--pos-p); }
.player-pos.pos-C  { background: var(--pos-c); }
.player-pos.pos-IF,
.player-pos.pos-1B,
.player-pos.pos-2B,
.player-pos.pos-3B,
.player-pos.pos-SS { background: var(--pos-if); }
.player-pos.pos-OF { background: var(--pos-of); }

.player-name {
    padding-left: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-meta {
    display: flex;
    align-items: center;
    gap: 5px;
}

.player-team {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.player-order {
    font-size: 0.62rem;
    color: var(--text-secondary);
    background: rgba(255,255,255,0.08);
    padding: 1px 4px;
    border-radius: 3px;
}

.player-salary {
    text-align: right;
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.player-proj {
    text-align: right;
    font-weight: 600;
    font-size: 0.84rem;
}

/* ── Stack Badge ──────────────────────────────────────────────── */

.stack-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 700;
    background: rgba(233, 69, 96, 0.2);
    color: var(--accent);
    border: 1px solid rgba(233, 69, 96, 0.35);
    letter-spacing: 0.02em;
}

/* ── Copy Lineup Button ───────────────────────────────────────── */

.btn-copy-lineup {
    margin-top: 10px;
    padding: 6px 14px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-copy-lineup:hover {
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

/* ── Exposure Chart ───────────────────────────────────────────── */

.exposure-section { margin-top: 20px; }

.section-title {
    font-size: 0.92rem;
    font-weight: 600;
    margin-bottom: 10px;
}

.exposure-chart {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 400px;
    overflow-y: auto;
}

.exposure-row {
    display: grid;
    grid-template-columns: 110px 1fr 38px;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
}

.exposure-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-secondary);
}

.exposure-bar-track {
    height: 7px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.exposure-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.exposure-pct {
    text-align: right;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ── Loading Overlay ──────────────────────────────────────────── */

.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 26, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-text {
    margin-top: 16px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* ── Toast ────────────────────────────────────────────────────── */

.toast-container {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: calc(100% - 32px);
    max-width: 480px;
    pointer-events: none;
}

.toast {
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-size: 0.85rem;
    animation: slideIn 0.22s ease;
    pointer-events: auto;
}

.toast.error  { border-color: var(--accent); background: var(--accent-dim); }
.toast.success { border-color: var(--success); background: rgba(76, 175, 80, 0.12); }

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Mobile (<=375px) ─────────────────────────────────────────── */

@media (max-width: 375px) {
    #app { padding: 0 12px 24px; }

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

    .mode-btn { padding: 16px 8px; min-height: 88px; }

    .player-row {
        grid-template-columns: 32px 1fr 44px 42px;
        font-size: 0.78rem;
    }

    .exposure-row { grid-template-columns: 90px 1fr 34px; }

    .pool-table { font-size: 12px; }
}

/* ── Tablet (>=481px) ─────────────────────────────────────────── */

@media (min-width: 481px) {
    #app { padding: 0 24px 48px; }

    .pool-table-wrap {
        max-height: calc(100dvh - 280px);
    }
}
