/* ========================================================
   TradeMaster Portal — Light Green "Saplings" Theme
   White + light green palette representing growth
   Mobile-first responsive design for future app conversion
   ======================================================== */

:root {
    --bg-primary: #f4f9f4;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f0f5f0;
    --border: #d4e5d4;
    --border-light: #e8f0e8;
    --text-primary: #1a2e1a;
    --text-secondary: #4a6b4a;
    --text-muted: #8aaa8a;
    --accent: #2d8a4e;
    --accent-light: #3da563;
    --accent-hover: #248040;
    --accent-bg: rgba(45, 138, 78, 0.08);
    --green: #1a7a3a;
    --green-light: #e6f5ec;
    --green-bg: rgba(26, 122, 58, 0.1);
    --red: #d32f2f;
    --red-bg: rgba(211, 47, 47, 0.08);
    --yellow: #e6a817;
    --yellow-bg: rgba(230, 168, 23, 0.1);
    --sapling: #4caf50;
    --sapling-light: #c8e6c9;
    --radius: 14px;
    --radius-sm: 8px;
    --shadow: 0 2px 16px rgba(45, 138, 78, 0.08);
    --shadow-lg: 0 8px 32px rgba(45, 138, 78, 0.12);
    --transition: all 0.3s ease;
    --gradient-header: linear-gradient(135deg, #2d8a4e 0%, #4caf50 50%, #66bb6a 100%);
    --gradient-card: linear-gradient(180deg, #ffffff 0%, #f8fdf8 100%);
}

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

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

/* Subtle sapling pattern background */
body::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background:
        radial-gradient(circle at 10% 90%, rgba(76, 175, 80, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 90% 20%, rgba(76, 175, 80, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(45, 138, 78, 0.02) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

/* ---- HEADER ---- */
.header {
    background: var(--gradient-header);
    padding: 0 24px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(45, 138, 78, 0.2);
}

.header-logo {
    font-size: 1.4rem;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-logo::before {
    content: '\1F331';
    font-size: 1.3rem;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-username {
    font-size: 0.95rem;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
}

.btn-logout {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: #ffffff;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
    backdrop-filter: blur(4px);
}
.btn-logout:hover { background: rgba(255,255,255,0.25); }

/* ---- NAV ---- */
.nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    display: flex;
    gap: 0;
    padding: 0 24px;
    overflow-x: auto;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    position: relative;
    z-index: 50;
}

.nav-item {
    padding: 14px 22px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: var(--transition);
    white-space: nowrap;
}
.nav-item:hover { color: var(--accent); }
.nav-item.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ---- LOGIN SCREEN ---- */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(160deg, #f4f9f4 0%, #e8f5e9 40%, #f1f8e9 100%);
    position: relative;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    position: relative;
    z-index: 1;
}

.login-title {
    font-size: 2rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 4px;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-title::before { content: '\1F331'; font-size: 1.6rem; }

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    transition: var(--transition);
    outline: none;
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,138,78,0.12); }
.form-input:read-only { opacity: 0.6; cursor: not-allowed; }

select.form-input { appearance: auto; }

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--gradient-header);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
    box-shadow: 0 4px 12px rgba(45,138,78,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(45,138,78,0.35); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: var(--transition);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.login-toggle {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}
.login-toggle a {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
}
.login-toggle a:hover { text-decoration: underline; }

.error-msg {
    background: var(--red-bg);
    color: var(--red);
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
    border: 1px solid rgba(211,47,47,0.2);
    display: none;
}
.error-msg.visible { display: block; }

/* ---- MAIN CONTENT ---- */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 24px;
    position: relative;
    z-index: 1;
}

/* ---- TOP 3 STATS CARDS ---- */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 28px 24px;
    text-align: center;
    box-shadow: var(--shadow);
    transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    font-weight: 700;
}

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -1px;
}

.stat-value.profit { color: var(--green); }
.stat-value.loss { color: var(--red); }
.stat-value.neutral { color: var(--text-primary); }

.stat-input {
    font-size: 1.6rem;
    font-weight: 700;
    text-align: center;
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 10px;
    width: 80%;
    outline: none;
    transition: var(--transition);
}
.stat-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45,138,78,0.1); }

/* ---- TOGGLE SWITCH ---- */
.engine-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
    margin-bottom: 28px;
    padding: 24px;
    background: var(--gradient-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.toggle-label {
    font-size: 1rem;
    font-weight: 700;
    min-width: 140px;
}
.toggle-label.off { color: var(--red); text-align: right; }
.toggle-label.on { color: var(--green); text-align: left; }

.toggle-switch {
    position: relative;
    width: 80px;
    height: 42px;
    cursor: pointer;
}

.toggle-switch input { display: none; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: #e57373;
    border-radius: 42px;
    transition: var(--transition);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.15);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 34px;
    height: 34px;
    background: white;
    border-radius: 50%;
    top: 4px;
    left: 4px;
    transition: var(--transition);
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider { background: var(--sapling); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(38px); }

/* ---- PIPELINE VISUALIZATION ---- */
.pipeline-section {
    margin-top: 24px;
}

.pipeline-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pipeline-title::before { content: '\2699\FE0F'; }

.pipeline-stage {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
    box-shadow: 0 1px 4px rgba(0,0,0,0.03);
}
.pipeline-stage:hover { box-shadow: var(--shadow); }

.pipeline-stage-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    font-weight: 700;
    flex-shrink: 0;
}
.pipeline-stage-icon.pass { background: var(--green-light); color: var(--green); }
.pipeline-stage-icon.fail { background: var(--red-bg); color: var(--red); }
.pipeline-stage-icon.pending { background: var(--accent-bg); color: var(--accent); }

.pipeline-stage-info { flex: 1; }
.pipeline-stage-name { font-weight: 700; font-size: 0.9rem; color: var(--text-primary); }
.pipeline-stage-detail { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }
.pipeline-stage-count {
    font-size: 0.85rem;
    padding: 4px 14px;
    border-radius: 20px;
    font-weight: 700;
}
.pipeline-stage-count.pass { background: var(--green-light); color: var(--green); }
.pipeline-stage-count.fail { background: var(--red-bg); color: var(--red); }

/* ---- HISTORY / CALENDAR ---- */
.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.month-nav {
    display: flex;
    align-items: center;
    gap: 16px;
}

.month-nav button {
    background: var(--bg-card);
    border: 1.5px solid var(--border);
    color: var(--accent);
    width: 38px;
    height: 38px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 700;
    transition: var(--transition);
}
.month-nav button:hover { background: var(--green-light); border-color: var(--accent); }

.month-name {
    font-size: 1.15rem;
    font-weight: 700;
    min-width: 180px;
    text-align: center;
    color: var(--accent);
}

.date-range-filter {
    display: flex;
    align-items: center;
    gap: 8px;
}
.date-range-filter input[type="date"] {
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

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

.calendar-header-cell {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    padding: 10px 0;
    font-weight: 700;
}

.calendar-cell {
    background: var(--bg-card);
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 8px;
    min-height: 76px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}
.calendar-cell:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.calendar-cell.empty { background: transparent; border-color: transparent; cursor: default; }
.calendar-cell.empty:hover { box-shadow: none; }
.calendar-cell.today { border-color: var(--accent); border-width: 2px; background: var(--accent-bg); }

.calendar-day { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
.calendar-pnl {
    font-size: 0.85rem;
    font-weight: 800;
    text-align: center;
}
.calendar-pnl.profit { color: var(--green); }
.calendar-pnl.loss { color: var(--red); }
.calendar-trades {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 2px;
}

/* ---- TRADE DETAIL TABLE ---- */
.trade-table-container {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow);
}

.trade-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    background: var(--bg-card);
}

.trade-table th {
    text-align: left;
    padding: 14px 16px;
    background: var(--green-light);
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.trade-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    white-space: nowrap;
}

.trade-table tr:hover td { background: var(--accent-bg); }

.trade-total-row {
    background: var(--green-light) !important;
    font-weight: 700;
}
.trade-total-row td { background: var(--green-light) !important; }

/* ---- RANGE SUMMARY CARD ---- */
.summary-card {
    background: var(--gradient-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 28px;
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    box-shadow: var(--shadow);
}

.summary-item { text-align: center; }
.summary-item-label { font-size: 0.8rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 700; }
.summary-item-value { font-size: 1.3rem; font-weight: 800; margin-top: 4px; }

/* ---- MODAL ---- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-overlay.visible { display: flex; }

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px;
    max-width: 440px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 12px; color: var(--text-primary); }
.modal-body { color: var(--text-secondary); margin-bottom: 24px; font-size: 0.95rem; line-height: 1.6; }
.modal-warning { color: var(--red); font-weight: 700; }

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-actions .btn-danger {
    background: var(--red);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 700;
    transition: var(--transition);
}
.modal-actions .btn-danger:hover { opacity: 0.85; }

/* ---- DATE SELECTOR ---- */
.date-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}
.date-selector input[type="date"] {
    background: var(--bg-input);
    border: 1.5px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

/* ---- EMPTY STATE ---- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state-text { font-size: 1.1rem; font-weight: 500; }

/* ---- LOADING ---- */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .stats-row { grid-template-columns: 1fr; }
    .stat-value { font-size: 1.5rem; }
    .calendar-grid { font-size: 0.75rem; }
    .calendar-cell { min-height: 56px; padding: 4px; }
    .main-content { padding: 16px; }
    .login-card { padding: 32px 24px; }
    .header { padding: 0 16px; }
    .nav { padding: 0 16px; }
    .engine-toggle-container { flex-wrap: wrap; }
    .summary-card { grid-template-columns: repeat(2, 1fr); }
}

/* ---- SECTION VISIBILITY ---- */
.section { display: none; }
.section.active { display: block; }

/* ---- PROFILE FORM ---- */
.profile-form {
    max-width: 600px;
    margin: 0 auto;
    background: var(--bg-card);
    padding: 36px;
    border-radius: var(--radius);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow);
}

.profile-section-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--accent);
    margin: 28px 0 14px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--green-light);
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 480px) {
    .form-row { grid-template-columns: 1fr; }
    .profile-form { padding: 24px 20px; }
}

/* ---- 5-YEAR BACKTEST CARD ---- */
.backtest-card {
    background: linear-gradient(135deg, #0d2b1e 0%, #1a4a2e 50%, #0d2b1e 100%);
    border: 1px solid rgba(45, 138, 78, 0.3);
    border-radius: var(--radius);
    padding: 24px 28px;
    margin-bottom: 24px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
    color: #fff;
}

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

.backtest-card-title {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #66bb6a;
}

.backtest-period {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.5);
    font-weight: 600;
}

.backtest-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.bt-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 110px;
}

.bt-stat-label {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.45);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
}

.bt-stat-value {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.bt-stat-value.profit { color: #66bb6a; }
.bt-stat-value.loss   { color: #ef5350; }
.bt-stat-value.neutral { color: #ffffff; }

.bt-arrow {
    font-size: 1.4rem;
    color: rgba(255,255,255,0.3);
    padding: 0 4px;
}

.bt-divider {
    width: 1px;
    height: 40px;
    background: rgba(255,255,255,0.15);
    margin: 0 8px;
}

@media (max-width: 640px) {
    .backtest-stats { gap: 12px; }
    .bt-stat { min-width: 90px; }
    .bt-stat-value { font-size: 1.1rem; }
    .bt-divider { display: none; }
    .bt-arrow { display: none; }
}
