/* =====================================================================
   AFL Trade Machine — Dark Mode + Multi-Team Workspace
   ===================================================================== */

:root {
    --bg: #0b0f17;
    --bg-2: #0f1420;
    --surface: #151b29;
    --surface-2: #1c2333;
    --surface-3: #232b3d;

    --border: #2a3245;
    --border-strong: #3a4358;

    --text: #e6ebf5;
    --text-muted: #a3acc2;
    --text-faint: #6c7689;

    --blue: #3b82f6;
    --blue-light: #60a5fa;
    --blue-glow: rgba(59, 130, 246, 0.25);

    --pos: #34d399;
    --neg: #f87171;
    --warn-bg: #2a2418;
    --warn-border: #5a4a1c;
    --warn-text: #f5c98a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    background-image:
        radial-gradient(circle at 20% 0%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 100%, rgba(96, 165, 250, 0.05) 0%, transparent 50%);
    background-attachment: fixed;
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
}

header {
    background: linear-gradient(180deg, rgba(21, 27, 41, 0.95) 0%, rgba(11, 15, 23, 0.85) 100%);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    padding: 32px 32px 28px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

h1 {
    margin: 0 0 4px 0;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.4px;
    background: linear-gradient(135deg, var(--blue-light) 0%, #93c5fd 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: var(--blue-light);
}

#setup {
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}
#setup label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
#setup select { width: auto; min-width: 80px; }

h2 { font-size: 20px; font-weight: 600; margin: 0 0 14px 0; color: var(--text); letter-spacing: -0.3px; }
h3 { font-size: 15px; font-weight: 600; margin: 0 0 10px 0; color: var(--text); }
h4 {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.8px; color: var(--text-faint); margin: 12px 0 6px 0;
}

.muted { color: var(--text-muted); }
.muted.small { font-size: 12px; }

button {
    background-color: var(--blue);
    color: #ffffff;
    border: none;
    padding: 9px 20px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(59, 130, 246, 0.4);
}
button:hover {
    background-color: var(--blue-light);
    box-shadow: 0 2px 8px var(--blue-glow), 0 0 0 1px rgba(96, 165, 250, 0.5);
}
button:active { transform: translateY(1px); }
button:disabled { background-color: var(--surface-3); color: var(--text-faint); cursor: not-allowed; box-shadow: none; }

#backToSetup, #resetLeague, #cancelTrade, #clearSelectionBtn, #undoBtn, #saveAsBtn, #dismissSharedTrade {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-strong);
    box-shadow: none;
}
#backToSetup:hover, #resetLeague:hover, #cancelTrade:hover,
#clearSelectionBtn:hover, #undoBtn:not(:disabled):hover,
#saveAsBtn:hover, #dismissSharedTrade:hover {
    background-color: var(--surface-2);
    color: var(--text);
    border-color: var(--blue);
}
#undoBtn:disabled { opacity: 0.5; }

.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 28px 32px 56px;
    text-align: left;
}
.hidden { display: none !important; }

select {
    padding: 9px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    width: 100%;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    background-color: var(--surface-2);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%23a3acc2' d='M6 8L0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}
select:hover { border-color: var(--blue); background-color: var(--surface-3); }
select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-glow); }
select:disabled { opacity: 0.4; cursor: not-allowed; }
select option { background-color: var(--surface); color: var(--text); }

#teamSelection {
    background-color: var(--surface);
    padding: 28px 32px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}
#teamSelectors {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
    margin: 20px 0 24px;
}
.team-selector {
    background-color: var(--surface-2);
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: border-color 0.15s ease;
}
.team-selector:hover { border-color: var(--border-strong); }
.team-selector label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
    margin-bottom: 8px;
}
#teamSelection > button { margin-right: 8px; }

.league-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding: 0 4px;
    flex-wrap: wrap;
    gap: 12px;
}
.league-header h2 { margin: 0; }
.league-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.league-actions select { width: auto; min-width: 200px; }

/* ---------- Last-trade narrative panel ---------- */
.last-trade-panel {
    position: relative;
    background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-md);
    padding: 14px 16px 14px 18px;
    margin: 0 0 18px auto;
    max-width: 480px;
    box-shadow: var(--shadow-md);
    animation: panelSlideIn 0.25s ease-out;
}
@keyframes panelSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.last-trade-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.last-trade-header h4 {
    margin: 0;
    color: var(--blue-light);
    font-size: 11px;
    letter-spacing: 0.8px;
}
.last-trade-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}
.last-trade-actions button {
    padding: 4px 10px;
    font-size: 11px;
    background: transparent;
    border: 1px solid var(--border-strong);
    color: var(--text-muted);
    box-shadow: none;
}
.last-trade-actions button:hover {
    background: var(--surface-2);
    border-color: var(--blue);
    color: var(--text);
    box-shadow: none;
}
#dismissLastTrade {
    padding: 2px 8px;
    font-size: 14px;
    line-height: 1;
}
.last-trade-body {
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}
.last-trade-body strong {
    color: var(--blue-light);
    font-weight: 600;
}
.last-trade-pts {
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-faint);
    border-top: 1px solid var(--border);
    padding-top: 6px;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    top: 24px;
    right: 24px;
    background: var(--surface);
    border: 1px solid var(--blue);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--blue-glow);
    z-index: 2000;
    animation: toastSlide 0.2s ease-out;
    max-width: 360px;
}
.toast.hidden { display: none; }
@keyframes toastSlide {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ---------- Team cards ---------- */
.teams-container { margin-bottom: 24px; }
.teams {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 14px;
}

.team-card {
    background-color: var(--surface);
    padding: 16px 18px 16px 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    position: relative;
    overflow: hidden;
}
.team-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 5px;
    background-color: var(--club-color, var(--blue));
    box-shadow: 0 0 12px var(--club-color, var(--blue));
    opacity: 0.85;
}
.team-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.team-card:hover::before { opacity: 1; }
.team-card h3 {
    margin: 0 0 4px 0;
    color: var(--text);
    font-size: 16px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-weight: 600;
}
.team-card .pill {
    display: inline-block;
    background-color: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
}
.team-card h4 {
    margin: 14px 0 6px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.team-card h4::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, var(--border) 0%, transparent 100%);
}
.team-players, .team-picks {
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 12px;
    background-color: var(--bg-2);
}
.team-item {
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.team-item:last-child { border-bottom: none; }
.team-item.muted { color: var(--text-faint); }
.team-item.traded {
    background-color: var(--warn-bg);
    border-bottom-color: var(--warn-border);
    color: var(--warn-text);
    border-radius: 4px;
    padding: 5px 8px;
    margin: 2px -6px;
    font-weight: 500;
}
.pts {
    color: var(--text-faint);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    background: var(--surface-2);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* ---------- Trade workspace ---------- */
.trade-workspace {
    background-color: var(--surface);
    padding: 20px 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    margin-bottom: 24px;
}
.workspace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 12px;
}
.workspace-header h3 { margin: 0; }
.workspace-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.workspace-hint {
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 0 14px 0;
    line-height: 1.6;
}

.trade-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}
.trade-column {
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}
.trade-column::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: var(--club-color, var(--blue));
    box-shadow: 0 0 8px var(--club-color, var(--blue));
}
.trade-col-header {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
    background-color: var(--surface);
}
.trade-col-header h4 {
    margin: 0;
    font-size: 13px;
    text-transform: none;
    letter-spacing: 0;
    color: var(--text);
    font-weight: 600;
}
.ws-section { padding: 10px 12px; }
.ws-section + .ws-section { border-top: 1px solid var(--border); }
.ws-section-title {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
    font-weight: 600;
    margin-bottom: 6px;
}
.ws-list {
    max-height: 220px;
    overflow-y: auto;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 6px;
}
.ws-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 4px;
    border-radius: 4px;
    transition: background 0.1s;
}
.ws-item:hover { background: var(--surface-2); }
.ws-label {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12.5px;
    cursor: pointer;
    overflow: hidden;
    min-width: 0;
}
.ws-label span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}
.ws-label input[type="checkbox"] {
    margin: 0;
    accent-color: var(--blue);
    cursor: pointer;
    flex-shrink: 0;
}
.target-select {
    width: auto;
    min-width: 90px;
    max-width: 130px;
    padding: 3px 22px 3px 8px;
    font-size: 11px;
    background-position: right 6px center;
    background-size: 9px 6px;
    flex-shrink: 0;
}
.target-select:disabled { opacity: 0.3; }

/* ---------- Balance bar ---------- */
.balance-bar {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}
.balance-empty {
    color: var(--text-faint);
    font-size: 13px;
    text-align: center;
    font-style: italic;
}
.balance-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}
.balance-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px 6px 0;
    font-size: 13px;
    overflow: hidden;
}
.balance-stripe {
    width: 4px;
    align-self: stretch;
    flex-shrink: 0;
}
.balance-team {
    color: var(--text-muted);
    font-weight: 500;
    padding-left: 8px;
}
.balance-pts {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-left: auto;
    padding-left: 8px;
}
.balance-item.pos .balance-pts { color: var(--pos); }
.balance-item.neg .balance-pts { color: var(--neg); }
.balance-item.zero .balance-pts { color: var(--text-muted); }

.balance-summary {
    font-size: 12px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    margin-top: 4px;
    font-weight: 500;
}
.balance-summary.balanced {
    background: rgba(52, 211, 153, 0.08);
    border: 1px solid rgba(52, 211, 153, 0.2);
    color: var(--pos);
}
.balance-summary.unbalanced {
    background: rgba(248, 113, 113, 0.08);
    border: 1px solid rgba(248, 113, 113, 0.2);
    color: var(--neg);
}
.balance-note {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 8px;
    font-style: italic;
}

/* ---------- Draft table ---------- */
#draftTable {
    background-color: var(--surface);
    padding: 20px 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    max-height: 500px;
    overflow-y: auto;
}
#draftTable h3 {
    margin-bottom: 14px;
    position: sticky;
    top: 0;
    background-color: var(--surface);
    padding-bottom: 10px;
    z-index: 2;
    border-bottom: 1px solid var(--border);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background-color: var(--surface-2); }
th {
    background-color: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    text-align: left;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 45px;
    z-index: 1;
}
td { padding: 9px 14px; border-bottom: 1px solid var(--border); color: var(--text); }
tbody tr { transition: background-color 0.1s ease; }
tbody tr:hover { background-color: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background-color: var(--border-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------- Modal (hardened) ---------- */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.75);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: left;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.modal.show { display: flex; animation: modalFadeIn 0.15s ease-out; }
@keyframes modalFadeIn { from {opacity: 0;} to {opacity: 1;} }

.modal-content {
    background-color: #1a2236;
    color: var(--text);
    padding: 24px 28px;
    border-radius: var(--radius-lg);
    width: 540px;
    max-width: 100%;
    min-height: 200px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border-strong);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(59, 130, 246, 0.25);
    position: relative;
    z-index: 1001;
    animation: modalSlideUp 0.2s ease-out;
}
@keyframes modalSlideUp {
    from { transform: translateY(8px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-content h3 {
    margin-top: 0;
    margin-bottom: 16px;
    font-size: 17px;
    color: var(--blue-light);
    font-weight: 600;
}
.modal-content > button {
    margin-top: 8px;
    margin-right: 8px;
}
#tradeSummary, #sharedTradeBody { margin-bottom: 20px; }
#tradeSummary:empty::before {
    content: "No trade selected.";
    color: var(--text-muted);
    font-style: italic;
}
.summary-block {
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin: 8px 0;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text);
}
.summary-block strong { color: var(--blue-light); font-weight: 600; display: inline-block; margin-bottom: 4px; }
.summary-block em { color: var(--text-faint); font-style: italic; }
#sharedTradeBody {
    background-color: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--blue);
    border-radius: var(--radius-sm);
    padding: 14px 18px;
    font-size: 14px;
    line-height: 1.7;
}
#sharedTradeBody strong { color: var(--blue-light); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
    .trade-columns { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
    header { padding: 24px 20px 20px; }
    .container { padding: 20px 16px 36px; }
    h1 { font-size: 24px; }
    .teams { grid-template-columns: 1fr; }
    .trade-columns { grid-template-columns: 1fr; }
    #teamSelectors { grid-template-columns: 1fr; }
    .league-header { flex-direction: column; align-items: flex-start; }
    .ws-label span { font-size: 12px; }
    .target-select { min-width: 100px; }
    .last-trade-panel { max-width: none; }
    .toast { top: 12px; right: 12px; left: 12px; max-width: none; }
}

.perceived {
    color: var(--blue-light);
    font-size: 12px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.perceived-combined {
    color: var(--blue-light);
    font-size: 12px;
    font-style: italic;
    display: inline-block;
    margin-top: 4px;
}
.pts-inline {
    color: var(--text-faint);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
