/* ===================================
   Dark Trading Terminal - Mobile First
   Layered cold-dark surfaces + cyan accent ramp.
   Fonts: Inter (UI), JetBrains Mono (numerals) — self-hosted.
   =================================== */

/* Self-hosted variable fonts */
@font-face {
    font-family: 'Inter';
    src: url('/static/fonts/inter-var-latin.woff2') format('woff2');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'JetBrains Mono';
    src: url('/static/fonts/jetbrains-mono-var-latin.woff2') format('woff2');
    font-weight: 100 800;
    font-style: normal;
    font-display: swap;
}

/* CSS Variables for theming */
:root {
    /* Surface ramp: page -> panel -> card -> raised (cold blue-tinted darks) */
    --surface-0: #070709;
    --surface-1: #0e0e12;
    --surface-2: #16161c;
    --surface-3: #1e1e26;

    /* Cyan accent ramp */
    --accent-300: #7fdcff;
    --accent-400: #38ccff;
    --accent-500: #00bfff;
    --accent-600: #0090cc;
    --accent-glow: rgba(0, 191, 255, 0.25);

    /* Semantic */
    --pos: #2fd47a;
    --neg: #ff5d6c;
    --warn: #ffb454;

    /* Text */
    --color-text-primary: #f2f4f8;
    --color-text-secondary: #a8aeba;
    --color-text-muted: #6e7480;

    /* Borders */
    --color-border: #23232c;
    --color-border-light: #2e2e3a;

    /* Gradient recipes */
    --grad-panel: linear-gradient(180deg, var(--surface-2) 0%, var(--surface-1) 100%);
    --grad-accent: linear-gradient(135deg, var(--accent-400) 0%, var(--accent-600) 100%);
    --grad-hairline: linear-gradient(90deg, transparent 0%, rgba(0, 191, 255, 0.35) 50%, transparent 100%);

    /* Elevation: drop shadow + 1px inner top highlight (edge-lit panels) */
    --edge-light: inset 0 1px 0 rgba(255, 255, 255, 0.04);
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.35), var(--edge-light);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45), var(--edge-light);
    --shadow-lg: 0 10px 28px rgba(0, 0, 0, 0.55), var(--edge-light);
    --shadow-blue: 0 0 12px var(--accent-glow);

    /* Fonts */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', Consolas, monospace;

    /* Back-compat aliases (per-page style blocks still reference these) */
    --color-black: #000000;
    --color-black-soft: var(--surface-0);
    --color-charcoal: var(--surface-1);
    --color-charcoal-medium: var(--surface-2);
    --color-charcoal-light: var(--surface-3);
    --color-blue: var(--accent-500);
    --color-blue-hover: var(--accent-400);
    --color-blue-dark: var(--accent-600);
}

/* Reset & Base Styles - Mobile First */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-ui);
    /* faint cyan bloom at the top of the page for depth; flat dark below.
       NOTE: no background-attachment: fixed — broken on iOS Safari (primary client) */
    background:
        radial-gradient(1100px 500px at 50% -12%, rgba(0, 191, 255, 0.055), transparent 60%),
        var(--surface-0);
    color: var(--color-text-primary);
    line-height: 1.3;
    min-height: 100vh;
    padding: 0.25rem;
}

/* Numerals: monospaced + tabular everywhere data is dense */
.num,
td.num,
th.num,
.stat-value,
.stat-number {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--color-text-primary);
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.35rem; /* Reduced from 0.5rem */
}

h1 {
    font-size: 1.15rem; /* Reduced from 1.4rem */
    font-weight: 700;
}

h2 {
    font-size: 1rem; /* Reduced from 1.2rem */
}

h3 {
    font-size: 0.9rem; /* Reduced from 1.05rem */
}

p {
    margin-bottom: 0.35rem; /* Reduced from 0.5rem */
    color: var(--color-text-secondary);
    font-size: 0.85rem; /* Smaller paragraph text */
}

a {
    color: var(--color-blue);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--color-blue-hover);
    text-decoration: underline;
}

/* Layout Components */
.container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.6rem;
    background: var(--grad-panel);
    border-radius: 8px;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    overflow: visible; /* Ensure container doesn't clip sticky elements */
}

header {
    background-color: var(--color-charcoal);
    padding: 0.5rem 0.35rem; /* Reduced */
    border-bottom: 1px solid var(--color-border);
    margin: -0.25rem -0.25rem 0.6rem -0.25rem;
}

header h1 {
    margin-bottom: 0;
    font-size: 1rem; /* Reduced from 1.2rem */
}

main {
    padding: 0.35rem 0; /* Reduced from 0.5rem */
}

/* Forms - Mobile First */
.form-group {
    margin-bottom: 0.6rem; /* Reduced from 1rem */
}

label {
    display: block;
    margin-bottom: 0.25rem; /* Reduced from 0.35rem */
    font-weight: 500;
    color: var(--color-text-primary);
    font-size: 0.8rem; /* Reduced from 0.85rem */
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 0.35rem 0.5rem; /* Reduced from 0.5rem 0.75rem */
    background-color: var(--color-charcoal-medium);
    border: 1px solid var(--color-border);
    border-radius: 4px; /* Reduced from 6px */
    color: var(--color-text-primary);
    font-size: 0.85rem; /* Reduced from 0.9rem */
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

input[type="email"]:focus,
input[type="password"]:focus,
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: var(--accent-500);
    /* visible focus ring (a11y) + soft glow */
    box-shadow: 0 0 0 3px var(--accent-glow);
    background-color: var(--surface-0);
}

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

/* Buttons */
button,
.btn {
    display: inline-block;
    width: 100%;
    padding: 0.4rem 0.75rem;
    background: var(--grad-accent);
    color: #04121a; /* dark ink on bright cyan reads sharper than white */
    border: none;
    border-radius: 6px;
    font-family: var(--font-ui);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: all 0.18s ease;
    text-align: center;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent; /* clean touch feedback (mobile-first) */
}

button:hover,
.btn:hover {
    filter: brightness(1.08);
    box-shadow: 0 0 14px var(--accent-glow), var(--edge-light);
    transform: translateY(-1px);
}

button:active,
.btn:active {
    transform: translateY(1px);
    filter: brightness(0.95);
    box-shadow: none;
}

button:disabled,
.btn:disabled {
    background-color: var(--color-charcoal-light);
    color: var(--color-text-muted);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

button.secondary,
.btn.secondary {
    background: transparent;
    border: 1px solid var(--color-border-light);
    color: var(--color-text-secondary);
    font-weight: 500;
    box-shadow: none;
}

button.secondary:hover,
.btn.secondary:hover {
    background: rgba(0, 191, 255, 0.06);
    border-color: var(--accent-500);
    color: var(--accent-400);
    filter: none;
    box-shadow: 0 0 10px rgba(0, 191, 255, 0.12);
}

/* Segmented range buttons (shared by backtest + pnl-history pages) */
.range-btn {
    padding: 0.3rem 0.5rem;
    font-size: 0.7rem;
    min-width: 2.5rem;
    background: var(--surface-2);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    width: auto;
    box-shadow: none;
    font-weight: 500;
}

.range-btn:hover {
    background: var(--surface-3);
    border-color: var(--accent-500);
    color: var(--accent-400);
    transform: none;
    box-shadow: none;
    filter: none;
}

.range-btn.active {
    background: var(--grad-accent);
    border-color: transparent;
    color: #04121a;
    font-weight: 600;
}

/* Messages/Alerts */
.message,
.error,
.success {
    margin-top: 0.5rem; /* Reduced from 0.75rem */
    padding: 0.5rem; /* Reduced from 0.75rem */
    border-radius: 4px; /* Reduced from 6px */
    text-align: center;
    font-size: 0.8rem; /* Reduced from 0.85rem */
    display: none;
}

.message.show,
.error.show,
.success.show {
    display: block;
}

.error {
    color: var(--neg);
    background-color: rgba(255, 93, 108, 0.08);
    border: 1px solid rgba(255, 93, 108, 0.3);
}

.success {
    color: var(--pos);
    background-color: rgba(47, 212, 122, 0.08);
    border: 1px solid rgba(47, 212, 122, 0.3);
}

/* Navigation */
.nav {
    text-align: center;
    margin: 0.75rem 0; /* Reduced from 1.5rem */
}

.nav a {
    color: var(--color-blue);
    font-size: 0.8rem; /* Reduced from 0.9rem */
}

/* Navbar - Collapsible Accordion Menu */
.navbar {
    background: var(--grad-panel);
    border-bottom: 2px solid transparent;
    border-image: var(--grad-hairline) 1;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 191, 255, 0.1);
}

.navbar-container {
    max-width: 100%;
    margin: 0 auto;
    padding: 0.5rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
}

.navbar-toggle {
    background: none;
    border: none;
    box-shadow: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 28px;
    height: 24px;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
}

.navbar-toggle span {
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, var(--color-blue) 0%, var(--color-blue-hover) 100%);
    border-radius: 2px;
    transition: all 0.3s ease;
    box-shadow: 0 0 6px rgba(0, 191, 255, 0.4);
}

.navbar-toggle:hover span {
    background: linear-gradient(90deg, var(--color-blue-hover) 0%, #00d4ff 100%);
    box-shadow: 0 0 10px rgba(0, 191, 255, 0.6);
}

.navbar-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 0;
    overflow: hidden;
    visibility: hidden;
    opacity: 0;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out, visibility 0.2s ease-out;
    width: 100%;
    background: linear-gradient(180deg, var(--surface-1) 0%, var(--surface-0) 100%);
    border-top: 1px solid transparent;
    padding: 0 0.75rem;
    box-shadow: none;
    z-index: 99;
}

.navbar-menu.active {
    max-height: 320px;
    visibility: visible;
    opacity: 1;
    padding: 0 0.75rem 0.5rem 0.75rem;
    transition: max-height 0.3s ease-in, opacity 0.2s ease-in, visibility 0.2s ease-in;
    border-top: 1px solid rgba(0, 191, 255, 0.2);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 191, 255, 0.05);
}

.navbar-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: all 0.25s ease;
    display: block;
    position: relative;
    border-left: 2px solid transparent;
}

.navbar-link:hover {
    background: linear-gradient(90deg, rgba(0, 191, 255, 0.1) 0%, transparent 100%);
    color: var(--color-blue);
    text-shadow: 0 0 12px rgba(0, 191, 255, 0.5);
    border-left-color: var(--color-blue);
    text-decoration: none;
}

.navbar-link.active {
    color: var(--color-blue);
    background: linear-gradient(90deg, rgba(0, 191, 255, 0.15) 0%, transparent 100%);
    border-left-color: var(--color-blue);
    text-shadow: 0 0 8px rgba(0, 191, 255, 0.4);
}

/* Desktop: Show menu always, horizontal layout */
@media (min-width: 768px) {
    .navbar-container {
        flex-direction: row;
        justify-content: flex-end;
        position: relative;
    }

    .navbar-toggle {
        display: none;
    }

    .navbar-menu {
        /* Reset all mobile collapse/hide properties */
        position: static;
        top: auto;
        left: auto;
        right: auto;
        display: flex;
        flex-direction: row;
        align-items: center;
        max-height: unset;
        height: auto;
        overflow: visible;
        visibility: visible;
        opacity: 1;
        transition: none;
        width: auto;
        padding: 0;
        gap: 0;
        border-top: none;
        box-shadow: none;
        background: transparent;
        z-index: auto;
    }

    .navbar-menu.active {
        max-height: unset;
    }

    .navbar-link {
        padding: 0.4rem 0.75rem;
        white-space: nowrap;
        border-left: none;
        border-bottom: 2px solid transparent;
        border-radius: 0;
    }

    .navbar-link:hover {
        background: transparent;
        border-left: none;
        border-bottom-color: var(--color-blue);
        box-shadow: 0 2px 8px rgba(0, 191, 255, 0.3);
    }

    .navbar-link.active {
        background: transparent;
        border-left: none;
        border-bottom-color: var(--color-blue);
        box-shadow: 0 2px 6px rgba(0, 191, 255, 0.25);
    }
}

/* Tables - Modern Dark Tables */
.table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: 70vh; /* Allow vertical scrolling with a max height */
    margin: 1rem 0;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    position: relative;
    display: block; /* Ensure it's a block element for proper scrolling */
    transform: translateZ(0); /* Force hardware acceleration for iOS */
    -webkit-transform: translateZ(0);
}

.table-wrapper::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: var(--color-charcoal-medium);
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: var(--color-charcoal-light);
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: var(--color-blue);
}

table {
    width: 100%;
    min-width: 400px; /* Reduced from 500px */
    border-collapse: separate; /* Changed from collapse - required for sticky positioning */
    border-spacing: 0; /* Remove spacing to maintain appearance */
    background-color: var(--color-charcoal);
    border-radius: 4px; /* Reduced from 6px */
    box-shadow: var(--shadow-sm);
    font-size: 0.75rem; /* Base font size for table - reduced from 0.85rem */
}

thead {
    background-color: var(--color-charcoal-medium);
    position: relative;
    z-index: 1;
}

th {
    padding: 0.3rem 0.5rem;
    text-align: left;
    font-weight: 600;
    color: var(--color-text-muted); /* quiet headers let the data speak */
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    background-color: var(--color-charcoal-medium);
    white-space: nowrap; /* Prevent text wrapping */
}

/* Make header row sticky (except first column which has its own rule) */
th:not(:first-child) {
    position: sticky;
    top: 0;
    z-index: 10; /* Higher than body cells but lower than first column header */
    transform: translateZ(0); /* Hardware acceleration for iOS */
    -webkit-transform: translateZ(0);
    will-change: transform; /* Hint for browser optimization */
}

/* Freeze the first column (time/date column) */
td:first-child {
    position: sticky;
    left: 0;
    z-index: 5; /* Lower than header but above regular cells */
    background-color: var(--color-charcoal); /* Match table background */
    border-right: 2px solid var(--color-border); /* Visual separation when scrolling */
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.3); /* Shadow for depth when scrolling */
    transform: translateZ(0); /* Hardware acceleration for iOS */
    -webkit-transform: translateZ(0);
}

/* First column header needs higher z-index and different background */
th:first-child {
    position: sticky;
    left: 0;
    top: 0; /* Also sticky vertically */
    z-index: 15; /* Highest - above everything when scrolling both ways */
    background-color: var(--color-charcoal-medium); /* Match header background */
    border-right: 2px solid var(--color-border); /* Visual separation when scrolling */
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); /* Shadow for both horizontal and vertical scrolling */
    transform: translateZ(0); /* Hardware acceleration for iOS */
    -webkit-transform: translateZ(0);
    will-change: transform; /* Hint for browser optimization */
}

td {
    padding: 0.25rem 0.5rem; /* Reduced from 0.4rem 0.75rem */
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    font-size: 0.75rem; /* Reduced from 0.8rem */
    white-space: nowrap; /* Prevent text wrapping */
}

/* Remove right border from last column in each row */
td:last-child,
th:last-child {
    border-right: none;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: var(--surface-3);
}

/* Ensure first column cells maintain background on hover */
tbody tr:hover td:first-child {
    background-color: var(--surface-3);
}

/* Ensure header cells maintain background color when sticky */
thead th {
    background-color: var(--color-charcoal-medium) !important;
}

/* Add shadow to header row when scrolling vertically (except first column) */
thead th:not(:first-child) {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Cards */
.card {
    background: var(--grad-panel);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-border-light);
}

.card-header {
    font-weight: 600;
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--color-text-primary);
    padding-bottom: 0.75rem;
    /* hairline gradient divider — signature detail under section headers */
    border-bottom: 1px solid transparent;
    border-image: var(--grad-hairline) 1;
}

.card-body {
    color: var(--color-text-secondary);
}

/* Utilities */
.text-center {
    text-align: center;
}

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

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Loading States */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.spinner {
    border: 2px solid var(--color-border);
    border-top-color: var(--color-blue);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    margin-right: 0.5rem;
}

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

/* Desktop & Tablet - 768px and up */
@media (min-width: 768px) {
    body {
        padding: 2rem;
    }

    .container {
        max-width: 600px;
        padding: 2.5rem;
    }

    h1 {
        font-size: 2rem;
    }

    button,
    .btn {
        width: auto;
        padding: 0.875rem 2rem;
        display: inline-block;
    }

    header {
        padding: 2rem;
    }

    header h1 {
        font-size: 2rem;
    }
}

/* Large Desktop - 1024px and up */
@media (min-width: 1024px) {
    .container {
        max-width: 800px;
        padding: 1rem; /* Reduced from 1.5rem */
    }

    table {
        font-size: 0.75rem; /* Reduced from 0.85rem */
    }

    th {
        padding: 0.35rem 0.6rem; /* Reduced from 0.6rem 0.9rem */
    }

    td {
        padding: 0.3rem 0.6rem; /* Reduced from 0.5rem 0.9rem */
    }
}

/* Extra Large - 1280px and up */
@media (min-width: 1280px) {
    .container {
        max-width: 1200px;
    }
}

/* ===================================
   Targets Table — trade colouring
   =================================== */

.trade-positive {
    color: var(--pos);
}

.trade-negative {
    color: var(--neg);
}

.trade-zero {
    color: var(--color-text-muted);
}
