/* FightEdge — Web UI Dark Theme */
/* Reuses design language from HTML report overhaul */

:root {
    --bg-primary: #08080c;
    --bg-card: rgba(17,17,20,0.9);
    --bg-card-hover: rgba(25,25,30,0.95);
    --bg-subtle: rgba(255,255,255,0.02);
    --border-subtle: rgba(255,255,255,0.04);
    --border-hover: rgba(255,255,255,0.08);
    --text-primary: #e0e0e0;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --text-dim: #4b5563;
    --text-heading: #fff;
    --accent-teal: #4ecdc4;
    --accent-teal-light: #6ee7de;
    --accent-teal-dark: #3dbdad;
    --accent-red: #ff6b6b;
    --accent-red-light: #ff8e8e;
    --accent-blue: #3b82f6;
    --accent-purple: #a855f7;
    --accent-orange: #f97316;
    --accent-yellow: #f9ca24;
    --accent-green: #10b981;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-card: 0 4px 24px rgba(0,0,0,0.3);
    --bg-sidebar: rgba(12,12,16,0.95);
    --bg-input: rgba(255,255,255,0.04);
    --bg-input-hover: rgba(255,255,255,0.06);
    --bg-input-option: #1a1a1e;
    --bg-bar: #1a1a1e;
    --bg-mobile-header: rgba(12,12,16,0.98);
    --bg-footer: rgba(15,15,20,0.95);
    --bg-overlay: rgba(0,0,0,0.6);
    --btn-primary-text: #000;
    --nav-hover-bg: rgba(255,255,255,0.03);
    --nav-active-bg: rgba(78,205,196,0.05);
    --chip-bg-alpha: 0.15;
    --row-hover: rgba(255,255,255,0.02);
    --row-border: rgba(255,255,255,0.02);
    color-scheme: dark;
}

/* ── Light Theme ─────────────────────── */
[data-theme="light"] {
    --bg-primary: #f5f6f8;
    --bg-card: rgba(255,255,255,0.95);
    --bg-card-hover: rgba(255,255,255,1);
    --bg-subtle: rgba(0,0,0,0.02);
    --border-subtle: rgba(0,0,0,0.08);
    --border-hover: rgba(0,0,0,0.14);
    --text-primary: #1a1a2e;
    --text-secondary: #4a5568;
    --text-muted: #718096;
    --text-dim: #a0aec0;
    --text-heading: #0f0f1a;
    --accent-teal: #2bb5ac;
    --accent-teal-light: #3cc9c0;
    --accent-teal-dark: #229e96;
    --accent-red: #e53e3e;
    --accent-red-light: #fc8181;
    --accent-blue: #2b6cb0;
    --accent-purple: #805ad5;
    --accent-orange: #dd6b20;
    --accent-yellow: #d69e2e;
    --accent-green: #059669;
    --shadow-card: 0 2px 12px rgba(0,0,0,0.06);
    --bg-sidebar: rgba(255,255,255,0.98);
    --bg-input: rgba(0,0,0,0.03);
    --bg-input-hover: rgba(0,0,0,0.06);
    --bg-input-option: #fff;
    --bg-bar: #e2e8f0;
    --bg-mobile-header: rgba(255,255,255,0.98);
    --bg-footer: rgba(255,255,255,0.96);
    --bg-overlay: rgba(0,0,0,0.3);
    --btn-primary-text: #fff;
    --nav-hover-bg: rgba(0,0,0,0.03);
    --nav-active-bg: rgba(43,181,172,0.08);
    --chip-bg-alpha: 0.1;
    --row-hover: rgba(0,0,0,0.02);
    --row-border: rgba(0,0,0,0.04);
    color-scheme: light;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes barGrow { from { width: 0%; } to { width: var(--bar-w); } }

/* ── Scroll Reveal Keyframes ── */
@keyframes revealUp    { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes revealFade  { from { opacity: 0; } to { opacity: 1; } }
@keyframes revealScale { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }
@keyframes revealLeft  { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: translateX(0); } }
@keyframes revealRight { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }

/* ── Scroll Reveal: Hidden State ── */
[data-reveal] { opacity: 0; }

/* ── Scroll Reveal: Visible State ── */
[data-reveal].is-visible {
    animation-duration: 0.6s;
    animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
    animation-fill-mode: both;
    animation-delay: calc(var(--reveal-delay, 0) * 1ms);
}
[data-reveal="fade-up"].is-visible    { animation-name: revealUp; }
[data-reveal="fade-in"].is-visible    { animation-name: revealFade; }
[data-reveal="scale-in"].is-visible   { animation-name: revealScale; }
[data-reveal="slide-left"].is-visible { animation-name: revealLeft; }
[data-reveal="slide-right"].is-visible{ animation-name: revealRight; }

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    [data-reveal] { opacity: 1 !important; transform: none !important; }
    [data-reveal].is-visible { animation: none !important; }
}

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

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

/* ── Layout ───────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    padding: 24px 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 16px;
}
.sidebar-brand h1 {
    font-size: 16px;
    font-weight: 800;
    color: var(--accent-teal);
    letter-spacing: -0.3px;
}
.sidebar-brand .version {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 2px;
}

.nav-group { margin-bottom: 16px; }
.nav-group-label {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    padding: 0 20px;
    margin-bottom: 6px;
}
.nav-link {
    display: block;
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.15s;
}
.nav-link:hover {
    color: var(--text-primary);
    background: var(--nav-hover-bg);
    border-left-color: var(--border-hover);
}
.nav-link.active {
    color: var(--accent-teal);
    background: var(--nav-active-bg);
    border-left-color: var(--accent-teal);
    font-weight: 600;
}
.nav-link .icon { margin-right: 8px; }

.main-content {
    margin-left: 240px;
    flex: 1;
    padding: 32px;
    max-width: 1100px;
}

/* ── Page Headers ─────────────────────── */
.page-header {
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-subtle);
}
.page-header h1 {
    font-size: 28px;
    font-weight: 800;
    color: var(--text-heading);
    letter-spacing: -0.5px;
}
.page-header .subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Cards ────────────────────────────── */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-card);
    padding: 24px;
    margin-bottom: 20px;
}
.card:hover { border-color: var(--border-hover); }
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.card-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-heading);
}

/* ── Stat Grid ────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--bg-subtle);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}
.stat-card .value {
    font-size: 28px;
    font-weight: 800;
    color: var(--accent-teal);
}
.stat-card .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* ── Tables ───────────────────────────── */
.table-container { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-subtle);
}
tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--row-border);
    color: var(--text-secondary);
}
tbody tr:hover { background: var(--row-hover); }

/* ── Forms ────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
input[type="text"], input[type="email"], input[type="password"], select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
}
select option {
    background: var(--bg-input-option);
    color: var(--text-primary);
    padding: 8px;
}
input[type="text"]:focus, input[type="email"]:focus, input[type="password"]:focus, select:focus {
    border-color: var(--accent-teal);
    box-shadow: 0 0 0 3px rgba(78,205,196,0.08);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: none;
    transition: all 0.15s;
    text-decoration: none;
}
.btn-primary {
    background: linear-gradient(135deg, var(--accent-teal), var(--accent-teal-dark));
    color: var(--btn-primary-text);
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-secondary {
    background: var(--bg-input-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
}
.btn-secondary:hover { background: var(--bg-input); color: var(--text-heading); }

/* ── Chips / Badges ───────────────────── */
.chip {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}
.chip-teal { background: rgba(78,205,196,0.15); color: var(--accent-teal); }
.chip-red { background: rgba(255,107,107,0.15); color: var(--accent-red); }
.chip-yellow { background: rgba(249,202,36,0.15); color: var(--accent-yellow); }
.chip-green { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.chip-blue { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.chip-muted { background: rgba(255,255,255,0.06); color: var(--text-muted); }

/* ── Probability Bar ──────────────────── */
.prob-bar {
    display: flex;
    height: 14px;
    border-radius: 7px;
    overflow: hidden;
    background: var(--bg-bar);
    margin: 12px 0;
}
.prob-bar .side-a {
    background: linear-gradient(90deg, var(--accent-red), var(--accent-red-light));
    animation: barGrow 0.8s ease-out;
}
.prob-bar .side-b {
    background: linear-gradient(90deg, var(--accent-teal), var(--accent-teal-light));
    animation: barGrow 0.8s ease-out;
}

/* ── Fight Card ───────────────────────── */
.fight-card {
    border-left: 4px solid var(--text-dim);
}
.fight-card.high { border-left-color: var(--accent-teal); box-shadow: 0 4px 24px rgba(78,205,196,0.08); }
.fight-card.medium { border-left-color: var(--accent-yellow); }

/* ── Loading / HTMX ──────────────────── */
.htmx-indicator {
    display: none;
    color: var(--accent-teal);
    font-size: 13px;
}
.htmx-request .htmx-indicator { display: inline; }
.htmx-request .htmx-hide { opacity: 0.5; pointer-events: none; }

/* ── Mobile Header (hidden on desktop) ── */
.mobile-header {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--bg-mobile-header);
    border-bottom: 1px solid var(--border-subtle);
    z-index: 200;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    backdrop-filter: blur(12px);
}
.mobile-header .brand {
    font-size: 16px;
    font-weight: 800;
    color: var(--accent-teal);
}
.hamburger {
    width: 44px; height: 44px;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 5px; cursor: pointer;
    background: none; border: none; padding: 0;
}
.hamburger span {
    display: block; width: 22px; height: 2px;
    background: var(--text-secondary);
    border-radius: 2px; transition: all 0.3s;
}
.hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.hamburger.active span:nth-child(2) { opacity: 0; }
.hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* ── Mobile Sidebar Overlay ── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-overlay);
    z-index: 99;
}
.sidebar-backdrop.active { display: block; }

/* ── Responsive: Tablet ─────────────── */
@media (max-width: 1024px) {
    .main-content { padding: 24px; max-width: 100%; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* ── Responsive: Mobile ─────────────── */
@media (max-width: 768px) {
    .mobile-header { display: flex; }
    .main-content {
        margin-left: 0;
        padding: 16px;
        padding-top: 72px; /* space for fixed mobile header */
        max-width: 100%;
    }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 150;
        width: 260px;
        padding-top: 16px;
    }
    .sidebar.open { transform: translateX(0); }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card .value { font-size: 22px; }
    .page-header h1 { font-size: 22px; }
    .page-header .subtitle { font-size: 12px; }
    .card { padding: 16px; margin-bottom: 14px; }
    .card-header { flex-direction: column; align-items: flex-start; gap: 8px; }
    .card-title { font-size: 14px; }
    /* Buttons: bigger touch targets */
    .btn { padding: 12px 20px; min-height: 44px; }
    .nav-link { padding: 12px 20px; min-height: 44px; display: flex; align-items: center; }
    /* Tables: horizontal scroll */
    .table-container { -webkit-overflow-scrolling: touch; }
    table { min-width: 500px; }
    /* Stack grids — catches ALL inline grid layouts */
    div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns: 2fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns:2fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns: 3fr 2fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns:3fr 2fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns: repeat(3"] { grid-template-columns: 1fr 1fr !important; }
    div[style*="grid-template-columns:repeat(3"] { grid-template-columns: 1fr 1fr !important; }
    div[style*="grid-template-columns: repeat(4"] { grid-template-columns: 1fr 1fr !important; }
    div[style*="grid-template-columns:repeat(4"] { grid-template-columns: 1fr 1fr !important; }
    div[style*="grid-template-columns:repeat(auto-fit"] { grid-template-columns: 1fr 1fr !important; }
    /* Flex containers: ensure wrapping and reduce min-widths */
    div[style*="display:flex"][style*="gap"] { flex-wrap: wrap !important; }
    div[style*="display: flex"][style*="gap"] { flex-wrap: wrap !important; }
    div[style*="min-width:200px"] { min-width: 100% !important; }
    div[style*="min-width:160px"] { min-width: 100% !important; }
    /* Value finder / fade signal flex items: shrink on mobile */
    div[style*="min-width:70px"] { min-width: 50px !important; }
    div[style*="min-width:60px"] { min-width: 45px !important; }
    div[style*="min-width:55px"] { min-width: 40px !important; }
    /* What-If form: stack controls vertically */
    form[hx-post*="what-if"] > div { flex-direction: column !important; align-items: stretch !important; }
    form[hx-post*="what-if"] label { width: 100% !important; }
    form[hx-post*="what-if"] select { width: 100% !important; }
    /* Tables: better horizontal scroll indication */
    .table-container { position: relative; }
    .table-container::after {
        content: '← scroll →';
        display: block;
        text-align: center;
        font-size: 10px;
        color: var(--text-dim);
        padding: 4px 0;
    }
    /* Scroll reveals: shorter/snappier on mobile */
    [data-reveal].is-visible { animation-duration: 0.4s; }
    [data-reveal="slide-left"].is-visible,
    [data-reveal="slide-right"].is-visible { animation-name: revealUp; }
    /* Fight report props grid: stack on mobile */
    .props-grid { grid-template-columns: 1fr !important; }
    /* Fight report tables: allow smaller min-width for tight tables */
    .fight-card table { min-width: auto; }
    /* Larger touch targets for form inputs */
    input[type="text"], input[type="email"], input[type="password"], select {
        padding: 14px 16px; font-size: 16px; /* prevents iOS zoom on focus */
    }
}

/* ── Responsive: Small Phone ────────── */
@media (max-width: 480px) {
    .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 18px; }
    .stat-card .label { font-size: 9px; }
    .page-header h1 { font-size: 20px; }
    .card { padding: 14px; border-radius: var(--radius-md); }
    table { font-size: 11px; min-width: 350px; }
    thead th { padding: 6px; font-size: 9px; }
    tbody td { padding: 6px; }
    .chip { padding: 2px 6px; font-size: 9px; }
    /* Force all multi-column grids to stack */
    div[style*="grid-template-columns: 1fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
    div[style*="grid-template-columns:repeat(auto-fit"] { grid-template-columns: 1fr !important; }
    /* Prob bar: ensure min-height for tap */
    .prob-bar { height: 10px !important; border-radius: 5px !important; }
    /* Hide scroll hint after first interaction */
    .table-container::after { font-size: 9px; }
    /* Reduce padding on dense layouts */
    .card-header { padding: 10px 14px; }
    /* Form inputs: full width */
    input, select, textarea { width: 100% !important; box-sizing: border-box; }
}

/* ── Theme Toggle ────────────────────── */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    margin-top: 4px;
    cursor: pointer;
    background: none;
    border: none;
    font-family: inherit;
    font-size: 12px;
    color: var(--text-muted);
    transition: color 0.15s;
    width: 100%;
    text-align: left;
}
.theme-toggle:hover { color: var(--text-primary); }
.theme-toggle-track {
    width: 36px; height: 20px;
    background: var(--bg-input-hover);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}
.theme-toggle-thumb {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--accent-teal);
    position: absolute;
    top: 1px; left: 1px;
    transition: transform 0.2s;
}
[data-theme="light"] .theme-toggle-thumb {
    transform: translateX(16px);
}
.theme-toggle-icon { font-size: 14px; }

/* ── Light theme: fix inline hardcoded colors ── */
[data-theme="light"] .sidebar {
    border-right-color: var(--border-subtle);
}
[data-theme="light"] .mobile-header {
    border-bottom-color: var(--border-subtle);
}
/* Override inline color:#fff -- dark text in light mode */
[data-theme="light"] [style*="color:#fff"],
[data-theme="light"] [style*="color: #fff"],
[data-theme="light"] [style*="color:white"] {
    color: var(--text-heading) !important;
}
/* Override inline dark backgrounds -- light in light mode */
[data-theme="light"] [style*="background:#0f0f14"],
[data-theme="light"] [style*="background: #0f0f14"],
[data-theme="light"] [style*="background:#0f0f"],
[data-theme="light"] [style*="background:rgba(15,15,20"],
[data-theme="light"] [style*="background:rgba(17,17,20"],
[data-theme="light"] [style*="background:rgba(12,12,16"],
[data-theme="light"] [style*="background:rgba(8,8,12"],
[data-theme="light"] [style*="background: rgba(15,15,20"],
[data-theme="light"] [style*="background: rgba(17,17,20"] {
    background: var(--bg-card) !important;
}
/* Override inline subtle bg overlays */
[data-theme="light"] [style*="background:rgba(255,255,255,0.03"],
[data-theme="light"] [style*="background:rgba(255,255,255,0.04"],
[data-theme="light"] [style*="background:rgba(255,255,255,0.02"],
[data-theme="light"] [style*="background:rgba(255,255,255,0.06"] {
    background: var(--bg-subtle) !important;
}
/* Override inline color:#000 on teal buttons -- white text */
[data-theme="light"] [style*="color:#000"][style*="background:linear-gradient"],
[data-theme="light"] [style*="color:#000"][style*="background:var(--accent-teal)"],
[data-theme="light"] a[style*="color:#000"][style*="background:linear-gradient"] {
    color: var(--btn-primary-text) !important;
}

/* ── Print ───────────────────────────── */
@media print {
    body { background: #fff; color: #111; }
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .card { background: #f9f9f9; border: 1px solid #ddd; box-shadow: none; }
}
