@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

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

:root {
    --bg: #F8F9FC;
    --card: #FFFFFF;
    --subcard: #F4F5FA;
    --sidebar: #FFFFFF;
    --text: #12141C;
    --text-muted: #6B7280;
    --border: rgba(15, 17, 23, .08);

    --accent: #6366F1;
    --accent-soft: rgba(99, 102, 241, .18);
    --positive: #22C55E;
    --negative: #EF4444;

    --setup-breakout: #6366F1;
    --setup-reversal: #F59E0B;
    --setup-trend: #14B8A6;
    --setup-range: #EC4899;

    --emotion-disciplinado: #22C55E;
    --emotion-confiante: #6366F1;
    --emotion-paciente: #14B8A6;
    --emotion-fomo: #EF4444;
    --emotion-ganancioso: #F59E0B;

    --radius-card: 18px;
    --radius-subcard: 12px;
}

:root[data-theme="dark"] {
    --bg: #0F1117;
    --card: #1A1D27;
    --subcard: #20232F;
    --sidebar: #0B0D12;
    --text: #F5F6FA;
    --text-muted: #9096A8;
    --border: rgba(255, 255, 255, .08);
}

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

.mono {
    font-family: 'JetBrains Mono', monospace;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 24px;
}

.subcard {
    background: var(--subcard);
    border-radius: var(--radius-subcard);
    padding: 14px 16px;
}

/* ---------- Auth screen (Fase 1) ---------- */

.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
}

.auth-card {
    width: 100%;
    max-width: 360px;
}

.auth-card h1 {
    font-size: 1.25rem;
    margin-bottom: 16px;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.auth-card input {
    font: inherit;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg);
    color: var(--text);
}

.auth-card button {
    font: inherit;
    padding: 10px 14px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #FFFFFF;
    cursor: pointer;
}

.error {
    color: var(--negative);
    font-size: 0.875rem;
    margin-bottom: 12px;
}

/* ---------- App shell ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 232px;
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 28px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
}

.logo-mark {
    flex-shrink: 0;
    display: block;
}

.logo-text-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.logo-line {
    line-height: 1.15;
}

.logo-line-primary {
    font-weight: 800;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
    color: var(--text);
}

.logo-line-accent {
    font-weight: 800;
    font-size: 0.8rem;
    letter-spacing: 0.03em;
    color: #6366F1;
}

.logo-line-muted {
    font-weight: 500;
    font-size: 0.62rem;
    letter-spacing: 0.14em;
    color: var(--text-muted);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 10px;
    font: inherit;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    width: 100%;
}

.nav-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.nav-item:hover {
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: #FFFFFF;
}

.user-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--subcard);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366F1, #14B8A6);
    flex-shrink: 0;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.topbar h1 {
    font-size: 1.3rem;
    font-weight: 800;
}

.topbar p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-primary {
    font: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    background: var(--accent);
    color: #FFFFFF;
    cursor: pointer;
}

.theme-toggle {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    color: var(--text);
    cursor: pointer;
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.content {
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ---------- Dashboard ---------- */

.label {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.equity-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
}

.equity-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 800;
    margin-top: 6px;
}

.range-tabs {
    display: flex;
    gap: 4px;
    background: var(--subcard);
    padding: 4px;
    border-radius: 10px;
}

.range-tabs button {
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.range-tabs button.active {
    background: var(--accent);
    color: #FFFFFF;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.7rem;
    font-weight: 800;
    margin: 6px 0 4px;
}

.stat-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
}

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

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

.bottom-grid {
    display: grid;
    grid-template-columns: 1.3fr 1fr;
    gap: 16px;
}

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

.card-header h2 {
    font-size: 1rem;
    font-weight: 700;
}

.card-header a {
    font-size: 0.82rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-long {
    background: rgba(34, 197, 94, .15);
    color: var(--positive);
}

.badge-short {
    background: rgba(239, 68, 68, .15);
    color: var(--negative);
}

.pnl-cell {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
}

.calendar-month-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-dow {
    text-align: center;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--text-muted);
    padding-bottom: 4px;
}

.calendar-cell {
    min-height: 72px;
    border-radius: 8px;
    background: var(--subcard);
    padding: 6px;
    overflow: hidden;
}

.calendar-cell.empty {
    background: transparent;
}

.calendar-cell.win {
    background: rgba(34, 197, 94, var(--intensity, .2));
}

.calendar-cell.loss {
    background: rgba(239, 68, 68, var(--intensity, .2));
}

.calendar-cell-inner {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.calendar-day-num {
    align-self: flex-start;
    font-size: 0.64rem;
    font-weight: 600;
    color: var(--text-muted);
}

.calendar-cell-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1px;
    text-align: center;
}

.calendar-day-pnl {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.62rem;
    line-height: 1.2;
    word-break: break-word;
}

.calendar-day-pct {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.56rem;
    color: var(--text-muted);
    line-height: 1.1;
}

.calendar-legend {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-swatch {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

.legend-swatch.win {
    background: var(--positive);
}

.legend-swatch.loss {
    background: var(--negative);
}

.placeholder-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 240px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ---------- Setup / emotion / status badges ---------- */

.badge-open {
    background: var(--accent-soft);
    color: #FFFFFF;
}

.badge-closed {
    background: var(--subcard);
    color: var(--text-muted);
}

.setup-breakout {
    background: rgba(99, 102, 241, .15);
    color: var(--setup-breakout);
}

.setup-reversal {
    background: rgba(245, 158, 11, .15);
    color: var(--setup-reversal);
}

.setup-trend {
    background: rgba(20, 184, 166, .15);
    color: var(--setup-trend);
}

.setup-range {
    background: rgba(236, 72, 153, .15);
    color: var(--setup-range);
}

.emotion-disciplinado {
    background: rgba(34, 197, 94, .15);
    color: var(--emotion-disciplinado);
}

.emotion-confiante {
    background: rgba(99, 102, 241, .15);
    color: var(--emotion-confiante);
}

.emotion-paciente {
    background: rgba(20, 184, 166, .15);
    color: var(--emotion-paciente);
}

.emotion-fomo {
    background: rgba(239, 68, 68, .15);
    color: var(--emotion-fomo);
}

.emotion-ganancioso {
    background: rgba(245, 158, 11, .15);
    color: var(--emotion-ganancioso);
}

/* ---------- Trades screen ---------- */

.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

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

.chip {
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 14px;
    border: none;
    border-radius: 999px;
    background: var(--subcard);
    color: var(--text-muted);
    cursor: pointer;
}

.chip.active {
    background: var(--accent);
    color: #FFFFFF;
}

.exchange-select {
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--subcard);
    color: var(--text);
    cursor: pointer;
}

.trade-count {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.table-scroll {
    overflow-x: auto;
}

.table-scroll table {
    min-width: 640px;
}

tbody tr.trade-row {
    cursor: pointer;
}

tbody tr.trade-row:hover td {
    background: var(--subcard);
}

/* ---------- Detail screen ---------- */

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    background: none;
    border: none;
    font-family: inherit;
    cursor: pointer;
    padding: 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 16px;
    align-items: start;
}

.detail-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
}

.detail-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.2rem;
    font-weight: 800;
}

.detail-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.detail-pnl {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.6rem;
    font-weight: 800;
}

.mini-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.mini-grid .subcard {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mini-grid .label {
    font-size: 0.68rem;
}

.mini-grid .value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1rem;
}

.info-rows {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.88rem;
}

.info-row .value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
}

.tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.notes-text {
    font-size: 0.88rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.screenshot-drop {
    border: 1px dashed var(--border);
    border-radius: var(--radius-subcard);
    padding: 16px;
    text-align: center;
}

.screenshot-drop input[type="file"] {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.screenshot-preview {
    margin-top: 12px;
    max-width: 100%;
    border-radius: var(--radius-subcard);
    display: block;
}

.upload-status {
    font-size: 0.78rem;
    margin-top: 8px;
    color: var(--text-muted);
}

/* ---------- New trade screen ---------- */

.form-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 16px;
    align-items: start;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.field label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
    font: inherit;
    font-size: 0.9rem;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--subcard);
    color: var(--text);
    width: 100%;
}

.field textarea {
    resize: vertical;
    min-height: 80px;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.direction-toggle {
    display: flex;
    gap: 8px;
}

.direction-toggle button {
    flex: 1;
    font: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--subcard);
    color: var(--text-muted);
    cursor: pointer;
}

.direction-toggle button.active-long {
    background: rgba(34, 197, 94, .15);
    color: var(--positive);
    border-color: var(--positive);
}

.direction-toggle button.active-short {
    background: rgba(239, 68, 68, .15);
    color: var(--negative);
    border-color: var(--negative);
}

.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
}

.btn-secondary {
    font: inherit;
    font-weight: 600;
    font-size: 0.85rem;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--subcard);
    color: var(--text);
    cursor: pointer;
}

.calc-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tip-card {
    background: var(--accent-soft);
    border: 1px solid rgba(99, 102, 241, .35);
    color: var(--text);
    font-size: 0.85rem;
    line-height: 1.5;
}

.form-error {
    color: var(--negative);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* ---------- Stats screen ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    width: 100%;
    gap: 16px;
    align-items: start;
}

.stats-col {
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.stats-col .card {
    min-width: 0;
}

.setup-rank-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.setup-rank-item:last-child {
    margin-bottom: 0;
}

.setup-rank-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.setup-rank-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 0.9rem;
}

.setup-rank-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.bar-track {
    height: 8px;
    border-radius: 999px;
    background: var(--subcard);
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 999px;
}

.bar-fill.setup-breakout {
    background: var(--setup-breakout);
}

.bar-fill.setup-reversal {
    background: var(--setup-reversal);
}

.bar-fill.setup-trend {
    background: var(--setup-trend);
}

.bar-fill.setup-range {
    background: var(--setup-range);
}

.bar-value {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.weekday-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    height: 160px;
    margin-top: 16px;
}

.weekday-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    flex: 1;
    height: 100%;
    gap: 6px;
}

.weekday-bar-track {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: flex-end;
}

.weekday-bar-fill {
    width: 100%;
    border-radius: 6px 6px 0 0;
    min-height: 4px;
}

.weekday-bar-fill.positive-bar {
    background: var(--positive);
}

.weekday-bar-fill.negative-bar {
    background: var(--negative);
}

.weekday-bar-value {
    font-size: 0.7rem;
}

.weekday-bar-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
}

.gauge-wrap {
    position: relative;
    width: 180px;
    height: 180px;
    max-width: 180px;
    max-height: 180px;
    margin: 20px auto;
    flex-shrink: 0;
}

.gauge-svg {
    display: block;
    width: 100%;
    height: 100%;
    max-width: 180px;
    max-height: 180px;
    transform: rotate(-90deg);
}

.gauge-track {
    fill: none;
    stroke: var(--subcard);
    stroke-width: 10;
}

.gauge-value {
    fill: none;
    stroke: var(--accent);
    stroke-width: 10;
    stroke-linecap: round;
    transition: stroke-dashoffset .4s ease;
}

.gauge-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.gauge-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 2rem;
    font-weight: 800;
}

.gauge-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.mini-metric-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.mini-metric-value {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 1.1rem;
    margin-top: 4px;
}

.pill-positive {
    background: rgba(34, 197, 94, .15);
    color: var(--positive);
}

.pill-negative {
    background: rgba(239, 68, 68, .15);
    color: var(--negative);
}

/* ---------- Settings screen ---------- */

.settings-wrap {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 640px;
}

.exchange-block {
    padding: 14px 0;
    border-top: 1px solid var(--border);
}

.exchange-block:first-of-type {
    border-top: none;
    padding-top: 8px;
}

.exchange-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.exchange-block-name {
    font-weight: 700;
    font-size: 0.92rem;
}

.settings-hint {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 8px;
}

.form-success {
    color: var(--positive);
    font-size: 0.85rem;
    margin-bottom: 12px;
}

@media (max-width: 960px) {
    .bottom-grid,
    .detail-grid,
    .form-grid,
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 720px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
    }

    .nav {
        flex-direction: row;
    }

    .user-card {
        display: none;
    }
}
