/* ===== RESET & BASE ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #0a0e1a;
    --bg2: #111827;
    --panel: #1a2236;
    --panel2: #243049;
    --line: #2d3b5a;
    --text: #f0f4fa;
    --muted: #8899bb;
    --cyan: #22d3ee;
    --green: #34d399;
    --red: #f87171;
    --amber: #fbbf24;
    --purple: #a78bfa;
    --shadow: 0 8px 32px rgba(0, 0, 0, .4);
    --radius: 12px;
    --transition: .2s ease;
}

body {
    margin: 0;
    background: radial-gradient(ellipse at 20% 0%, rgba(34, 211, 238, .06), transparent 60%),
                radial-gradient(ellipse at 80% 100%, rgba(167, 139, 250, .05), transparent 60%),
                linear-gradient(135deg, var(--bg), var(--bg2));
    color: var(--text);
    font: 14px 'Inter', system-ui, -apple-system, sans-serif;
    min-height: 100vh;
}

button, input, select {
    font: inherit;
    color: inherit;
}

/* ===== LAYOUT ===== */
.app {
    display: flex;
    min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 220px;
    background: rgba(10, 14, 26, .92);
    backdrop-filter: blur(16px);
    border-right: 1px solid rgba(45, 59, 90, .3);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 10;
}

.brand {
    font-size: 20px;
    font-weight: 900;
    letter-spacing: -.02em;
    padding: 6px 12px 28px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand::before {
    content: "💹";
    font-size: 22px;
}
.brand span {
    color: var(--cyan);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.nav button {
    width: 100%;
    border: 1px solid transparent;
    background: transparent;
    color: var(--muted);
    padding: 10px 14px;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 500;
    font-size: 13px;
}
.nav button:hover {
    background: rgba(255, 255, 255, .04);
    color: #fff;
}
.nav button.active {
    background: rgba(34, 211, 238, .08);
    color: var(--cyan);
    border-color: rgba(34, 211, 238, .15);
}
.nav .icon {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

/* ===== MAIN ===== */
.main {
    flex: 1;
    max-width: 1400px;
    margin: auto;
    padding: 24px 28px;
    width: 100%;
    min-width: 0;
}

/* ===== HEADER ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(45, 59, 90, .25);
}
.header h1 {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -.02em;
}
.header .sub {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}
.header .sub .dot {
    color: var(--green);
}

.toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ===== PAGES ===== */
.page {
    display: none;
    animation: fade .25s ease;
}
.page.active {
    display: block;
}

@keyframes fade {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

/* ===== CARDS ===== */
.grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}

.grid-6 {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
}

.card {
    background: linear-gradient(145deg, rgba(26, 34, 54, .95), rgba(17, 24, 39, .95));
    border: 1px solid rgba(45, 59, 90, .35);
    border-radius: var(--radius);
    padding: 16px 18px;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.card:hover {
    border-color: rgba(34, 211, 238, .15);
}

.card .label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 700;
}
.card .value {
    font-size: 26px;
    font-weight: 900;
    margin-top: 4px;
    letter-spacing: -.01em;
}
.card .change {
    font-size: 12px;
    margin-top: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.card .change.up {
    color: var(--green);
}
.card .change.down {
    color: var(--red);
}
.card .progress-bar {
    width: 100%;
    height: 5px;
    background: rgba(255, 255, 255, .06);
    border-radius: 99px;
    margin-top: 8px;
    overflow: hidden;
}
.card .progress-bar .fill {
    height: 100%;
    border-radius: 99px;
    transition: width .8s ease;
    background: linear-gradient(90deg, var(--cyan), var(--green));
}
.card .progress-bar .fill.danger {
    background: linear-gradient(90deg, var(--amber), var(--red));
}
.card .progress-bar .fill.warning {
    background: linear-gradient(90deg, var(--cyan), var(--amber));
}
.card .sub-info {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}
.card .big-number {
    font-size: 32px;
    font-weight: 900;
    letter-spacing: -.02em;
}

.positive {
    color: var(--green);
}
.negative {
    color: var(--red);
}
.muted {
    color: var(--muted);
}

/* ===== PANELS ===== */
.panel {
    background: linear-gradient(145deg, rgba(26, 34, 54, .95), rgba(17, 24, 39, .95));
    border: 1px solid rgba(45, 59, 90, .35);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-top: 16px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.panel h2 {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel h2 .badge-chart {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    background: rgba(255, 255, 255, .04);
    padding: 2px 10px;
    border-radius: 999px;
    margin-left: auto;
}

/* ===== BUTTONS ===== */
.btn {
    background: linear-gradient(135deg, var(--cyan), #06b6d4);
    border: 0;
    color: #03111a;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(34, 211, 238, .2);
    transition: var(--transition);
    white-space: nowrap;
    font-size: 13px;
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(34, 211, 238, .3);
}

.btn-alt {
    background: var(--panel2);
    color: #dbe8f5;
    border: 1px solid var(--line);
    box-shadow: none;
}
.btn-alt:hover {
    background: #2a3a5a;
    box-shadow: none;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 11px;
}
.btn-danger {
    background: linear-gradient(135deg, var(--red), #dc2626);
    color: #fff;
    box-shadow: 0 4px 16px rgba(248, 113, 113, .2);
}
.btn-danger:hover {
    background: #dc2626;
}

.btn-success {
    background: linear-gradient(135deg, var(--green), #059669);
    color: #fff;
    box-shadow: 0 4px 16px rgba(52, 211, 153, .2);
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: var(--transition);
    font-size: 14px;
}
.btn-icon:hover {
    background: rgba(255, 255, 255, .05);
    color: #fff;
}
.btn-icon.danger:hover {
    background: rgba(248, 113, 113, .1);
    color: var(--red);
}

.actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

/* ===== TABLES ===== */
.table-wrap {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}
th, td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(45, 59, 90, .3);
    text-align: left;
    vertical-align: middle;
}
th {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
    white-space: nowrap;
}
tbody tr:hover {
    background: rgba(255, 255, 255, .02);
}
tbody tr:last-child td {
    border-bottom: 0;
}

/* ===== FORMS ===== */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.form-grid .full {
    grid-column: span 3;
}

.field label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    margin: 0 0 4px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.field input, .field select {
    width: 100%;
    background: #0d1422;
    color: #edf6ff;
    border: 1px solid var(--line);
    padding: 8px 12px;
    border-radius: 8px;
    outline: none;
    transition: var(--transition);
    font-size: 13px;
}
.field input:focus, .field select:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px rgba(34, 211, 238, .06);
}
.field input.error {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(248, 113, 113, .1);
}

/* ===== STATUS BADGES ===== */
.badge {
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.badge-win {
    background: rgba(52, 211, 153, .12);
    color: var(--green);
    border: 1px solid rgba(52, 211, 153, .15);
}
.badge-loss {
    background: rgba(248, 113, 113, .12);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, .15);
}
.badge-open {
    background: rgba(34, 211, 238, .1);
    color: var(--cyan);
    border: 1px solid rgba(34, 211, 238, .15);
}

/* ===== PROGRESS ===== */
.progress {
    height: 4px;
    background: #0d1422;
    border-radius: 99px;
    margin-top: 4px;
    overflow: hidden;
    width: 100%;
    max-width: 120px;
}
.progress .bar {
    height: 100%;
    background: linear-gradient(90deg, var(--cyan), #06b6d4);
    border-radius: 99px;
    transition: width .5s ease;
}

/* ===== MODAL ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .7);
    backdrop-filter: blur(6px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 99;
}
.modal.show {
    display: flex;
}
.modal-box {
    width: min(600px, 100%);
    background: linear-gradient(145deg, #1a2236, #111827);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px 28px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}
.modal-head h2 {
    font-size: 18px;
    font-weight: 700;
}
.modal-close {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    transition: var(--transition);
}
.modal-close:hover {
    color: #fff;
}

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #1a2236;
    border: 1px solid rgba(34, 211, 238, .25);
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .5);
    z-index: 999;
    max-width: 360px;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease, transform .3s ease;
    transform: translateY(16px);
}
.toast.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}
.toast.success {
    border-color: var(--green);
}
.toast.error {
    border-color: var(--red);
}
.toast .icon {
    font-size: 18px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1050px) {
    .grid, .grid-6 {
        grid-template-columns: repeat(2, 1fr);
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .sidebar {
        width: 60px;
        padding: 12px 6px;
    }
    .brand {
        font-size: 0;
        padding-left: 6px;
    }
    .brand::before {
        font-size: 20px;
    }
    .nav .label {
        display: none;
    }
    .nav button {
        padding: 10px 8px;
        justify-content: center;
    }
    .main {
        padding: 14px 12px;
    }
    .header h1 {
        font-size: 20px;
    }
    .grid, .grid-6, .form-grid {
        grid-template-columns: 1fr;
    }
    .form-grid .full {
        grid-column: span 1;
    }
    .panel {
        padding: 12px 14px;
    }
    .filter-bar .field {
        min-width: 100%;
    }
    table {
        font-size: 12px;
    }
    th, td {
        padding: 6px 8px;
    }
}

/* ===== V4 AUTH ===== */
.v4-overlay {
    position: fixed;
    inset: 0;
    background: rgba(3, 7, 15, .94);
    backdrop-filter: blur(10px);
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 20px;
}
.v4-auth {
    width: min(460px, 100%);
    background: #0d1422;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, .55);
    padding: 28px;
}
.v4-auth-brand {
    font-size: 28px;
    font-weight: 900;
    margin-bottom: 5px;
}
.v4-auth-brand span {
    color: var(--cyan);
}
.v4-auth-sub {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 22px;
}

.v4-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: #09101c;
    padding: 5px;
    border-radius: 10px;
    margin-bottom: 18px;
}
.v4-tabs button {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 9px;
    border-radius: 8px;
    cursor: pointer;
}
.v4-tabs button.active {
    background: rgba(34, 211, 238, .12);
    color: var(--cyan);
    font-weight: 800;
}
.v4-auth-note {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.6;
    margin-top: 14px;
}

.v4-userbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}
.v4-user {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--line);
    padding: 7px 10px;
    border-radius: 10px;
    font-size: 12px;
}
.v4-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #22d3ee, #a78bfa);
    color: #07101c;
    font-weight: 900;
}
.v4-plan {
    font-size: 10px;
    font-weight: 800;
    padding: 3px 6px;
    border-radius: 999px;
    background: rgba(245, 158, 11, .12);
    color: var(--amber);
    border: 1px solid rgba(245, 158, 11, .25);
}
.v4-badge {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
}
.v4-ok {
    background: rgba(52, 211, 153, .1);
    color: var(--green);
}
.v4-warn {
    background: rgba(245, 158, 11, .1);
    color: var(--amber);
}

.account-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}
.account-chip {
    background: rgba(255, 255, 255, .04);
    border: 1px solid var(--line);
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 12px;
}

/* ===== CHARTS ===== */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.chart-box {
    height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 4px 0;
}
.chart-box svg {
    width: 100%;
    height: 100%;
    max-height: 220px;
}
.chart-box .no-data {
    color: var(--muted);
    font-size: 14px;
    text-align: center;
}
.chart-box .no-data .icon {
    font-size: 32px;
    display: block;
    margin-bottom: 6px;
}

/* ===== CALENDAR ===== */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    width: 100%;
}
.calendar-grid .day-header {
    text-align: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    padding: 6px 0;
    letter-spacing: .05em;
}
.calendar-grid .day-cell {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(13, 20, 34, .6);
    border-radius: 8px;
    border: 1px solid transparent;
    transition: var(--transition);
    cursor: default;
    min-height: 50px;
    position: relative;
    padding: 4px;
}
.calendar-grid .day-cell .day-number {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}
.calendar-grid .day-cell .day-pnl {
    font-size: 9px;
    font-weight: 700;
    margin-top: 2px;
}
.calendar-grid .day-cell.empty {
    background: transparent;
    border-color: transparent;
}
.calendar-grid .day-cell.has-trade {
    border-color: rgba(34, 211, 238, .15);
    cursor: pointer;
}
.calendar-grid .day-cell.has-trade:hover {
    background: rgba(34, 211, 238, .05);
    border-color: var(--cyan);
    transform: scale(1.02);
}
.calendar-grid .day-cell .trade-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    position: absolute;
    bottom: 4px;
    right: 4px;
}
.calendar-grid .day-cell .trade-dot.win {
    background: var(--green);
}
.calendar-grid .day-cell .trade-dot.loss {
    background: var(--red);
}
.calendar-grid .day-cell .trade-dot.mixed {
    background: var(--amber);
}

.calendar-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 8px 0;
    font-size: 12px;
    color: var(--muted);
}
.calendar-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}
.calendar-legend .legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.calendar-legend .legend-dot.win {
    background: var(--green);
}
.calendar-legend .legend-dot.loss {
    background: var(--red);
}
.calendar-legend .legend-dot.mixed {
    background: var(--amber);
}

.calendar-tooltip {
    display: none;
    position: absolute;
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    min-width: 140px;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
    font-size: 12px;
    top: -10px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    pointer-events: none;
}
.calendar-grid .day-cell:hover .calendar-tooltip {
    display: block;
}
.calendar-tooltip .tt-pair {
    color: var(--text);
    font-weight: 600;
}
.calendar-tooltip .tt-pnl {
    font-weight: 700;
}
.calendar-tooltip .tt-pnl.positive {
    color: var(--green);
}
.calendar-tooltip .tt-pnl.negative {
    color: var(--red);
}

/* ===== IMPORTER ===== */
.import-box {
    border: 1px dashed var(--line);
    border-radius: 12px;
    padding: 18px;
    text-align: center;
    background: rgba(255, 255, 255, .02);
}
.import-box input {
    margin-top: 10px;
}

/* ===== V4 ACCOUNT GRID ===== */
.v4-account-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}
.v4-stat {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(255, 255, 255, .02);
}
.v4-stat .k {
    font-size: 11px;
    color: var(--muted);
}
.v4-stat .v {
    font-size: 20px;
    font-weight: 900;
    margin-top: 5px;
}

/* ===== FILTER BAR ===== */
.filter-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
}
.filter-bar .field {
    min-width: 140px;
    margin: 0;
}

/* ===== EMPTY STATE ===== */
.empty {
    padding: 24px;
    text-align: center;
    color: var(--muted);
}
.empty .icon {
    font-size: 36px;
    display: block;
    margin-bottom: 8px;
}

/* ===== CHART ANIMATIONS ===== */
.chart-box svg polyline, .chart-box svg path {
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
    animation: drawChart 1.2s ease forwards;
}
.chart-box svg rect {
    animation: fadeInBars 0.6s ease forwards;
    opacity: 0;
}
.chart-box svg rect:nth-child(1) { animation-delay: 0.05s; }
.chart-box svg rect:nth-child(2) { animation-delay: 0.10s; }
.chart-box svg rect:nth-child(3) { animation-delay: 0.15s; }
.chart-box svg rect:nth-child(4) { animation-delay: 0.20s; }
.chart-box svg rect:nth-child(5) { animation-delay: 0.25s; }
.chart-box svg rect:nth-child(6) { animation-delay: 0.30s; }
.chart-box svg rect:nth-child(7) { animation-delay: 0.35s; }
.chart-box svg rect:nth-child(8) { animation-delay: 0.40s; }
.chart-box svg rect:nth-child(9) { animation-delay: 0.45s; }
.chart-box svg rect:nth-child(10) { animation-delay: 0.50s; }
.chart-box svg rect:nth-child(11) { animation-delay: 0.55s; }
.chart-box svg rect:nth-child(12) { animation-delay: 0.60s; }

@keyframes drawChart {
    to { stroke-dashoffset: 0; }
}
@keyframes fadeInBars {
    from { opacity: 0; transform: scaleY(0); transform-origin: bottom; }
    to { opacity: 1; transform: scaleY(1); }
}
/* ===== PWA INSTALL BANNER ===== */
.install-banner {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(145deg, #1a2236, #111827);
    border: 1px solid rgba(34, 211, 238, 0.2);
    border-radius: 12px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 100;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 90%;
    animation: slideUp 0.5s ease;
}

@keyframes slideUp {
    from {
        transform: translateX(-50%) translateY(100px);
        opacity: 0;
    }
    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

@media (max-width: 600px) {
    .install-banner {
        flex-wrap: wrap;
        justify-content: center;
        bottom: 20px;
        padding: 12px;
    }
}