/* Options Logic v2 — Base Styles */

:root, [data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a3a;
    --bg-input: #0f1923;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --text-muted: #666;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --green: #4caf50;
    --red: #f44336;
    --orange: #ff9800;
    --border: #2a3a4a;
    --sidebar-width: 240px;
}

[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f5f5f5;
    --text-primary: #1a1a2e;
    --text-secondary: #555;
    --text-muted: #888;
    --accent: #1976d2;
    --accent-hover: #1565c0;
    --green: #2e7d32;
    --red: #c62828;
    --orange: #e65100;
    --border: #ddd;
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ---------------------------------------------------------------------------
   Layout
--------------------------------------------------------------------------- */

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 0 1rem 1.2rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.sidebar-brand a {
    display: block;
}

.sidebar-logo {
    width: 100%;
    height: auto;
}

/* Theme-aware logo switching */
.sidebar-logo-light { display: none; }
.sidebar-logo-dark { display: block; }
[data-theme="light"] .sidebar-logo-dark { display: none; }
[data-theme="light"] .sidebar-logo-light { display: block; }

.sidebar-nav {
    list-style: none;
    padding: 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: all 0.15s;
}
.sidebar-nav .nav-icon {
    flex-shrink: 0;
    opacity: 0.7;
}
.sidebar-nav a:hover .nav-icon,
.sidebar-nav a.active .nav-icon {
    opacity: 1;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: rgba(79, 195, 247, 0.1);
    color: var(--accent);
    border-right: 3px solid var(--accent);
}

/* Collapsible submenu */
.has-submenu .submenu-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
}
.has-submenu .submenu-toggle .submenu-chevron {
    margin-left: auto;
}
.submenu-chevron {
    transition: transform 0.2s;
}
.has-submenu.open .submenu-chevron {
    transform: rotate(180deg);
}
.submenu {
    list-style: none;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.has-submenu.open .submenu {
    max-height: 800px;
}
.submenu a {
    padding-left: 2.5rem !important;
    font-size: 0.85rem !important;
}
/* Nested submenu (e.g. Strategies inside Options) */
.has-nested .nested-toggle {
    display: flex;
    align-items: center;
    padding-left: 2.5rem !important;
    font-size: 0.85rem !important;
    cursor: pointer;
}
.has-nested .nested-toggle .submenu-chevron {
    margin-left: auto;
    transition: transform 0.2s;
}
.has-nested.open .nested-toggle .submenu-chevron {
    transform: rotate(180deg);
}
.nested-submenu {
    list-style: none;
    padding: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}
.has-nested.open .nested-submenu {
    max-height: 500px;
}
.nested-submenu a {
    padding-left: 3.5rem !important;
    font-size: 0.8rem !important;
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-muted);
}
.sidebar-footer-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.theme-toggle-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 3px 5px;
    cursor: pointer;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    transition: color 0.15s, border-color 0.15s;
}
.theme-toggle-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem;
    padding-top: 0;
    min-height: 100vh;
}

/* ---------------------------------------------------------------------------
   Topbar
--------------------------------------------------------------------------- */

.topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0.6rem 0;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    z-index: 50;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.topbar-flag {
    font-size: 1.25rem;
    line-height: 1;
}

.topbar-clock {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    position: relative;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    transition: background 0.15s;
}

.topbar-user:hover {
    background: rgba(79, 195, 247, 0.08);
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid var(--border);
}

.topbar-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.topbar-initials {
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.topbar-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.topbar-chevron {
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.topbar-user:hover .topbar-chevron {
    color: var(--text-primary);
}

/* Dropdown menu */
.topbar-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-width: 180px;
    padding: 0.4rem 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 200;
}

.topbar-dropdown.open {
    display: block;
}

.topbar-dropdown a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: background 0.1s;
}

.topbar-dropdown a:hover {
    background: rgba(79, 195, 247, 0.1);
    color: var(--accent);
}

.topbar-dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 0.3rem 0;
}

/* ---------------------------------------------------------------------------
   Cards
--------------------------------------------------------------------------- */

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

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

/* Summary cards row */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
}

.summary-card .label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.summary-card .value {
    font-size: 1.5rem;
    font-weight: 700;
}

.summary-card .value.positive { color: var(--green); }
.summary-card .value.negative { color: var(--red); }
.summary-card .desc {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.4rem;
    opacity: 0.7;
    line-height: 1.3;
}

/* Expand button */
.expand-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
}
.expand-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }

/* Capital detail table */
.capital-detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.capital-detail-table th {
    text-align: left;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.capital-detail-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

/* Capital controls */
.capital-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.capital-controls input,
.capital-controls select {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.35rem 0.6rem;
    border-radius: 4px;
    font-size: 0.8rem;
}
.capital-controls input { flex: 1; }
.capital-controls select { min-width: 140px; }
.capital-controls input::placeholder { color: var(--text-secondary); opacity: 0.6; }
.capital-filtered-total {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    text-align: right;
}

/* Hidden utility */
.hidden { display: none; }

/* Standalone color utilities */
.positive { color: var(--green); }
.negative { color: var(--red); }

/* ---------------------------------------------------------------------------
   Tables
--------------------------------------------------------------------------- */

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    text-align: left;
    padding: 0.75rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table tr:hover {
    background: rgba(79, 195, 247, 0.05);
}

/* Analysis tables — lightweight, evenly spaced columns */
.analysis-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.analysis-table th {
    text-align: left;
    padding: 0.4rem 1rem;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.8rem;
    white-space: nowrap;
}

.analysis-table td {
    padding: 0.3rem 1rem;
    white-space: nowrap;
}

/* ---------------------------------------------------------------------------
   Badges
--------------------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-open { background: rgba(76, 175, 80, 0.2); color: var(--green); }
.badge-closed { background: rgba(244, 67, 54, 0.2); color: var(--red); }
.badge-rolled { background: rgba(255, 152, 0, 0.2); color: var(--orange); }

/* ---------------------------------------------------------------------------
   Forms & Buttons
--------------------------------------------------------------------------- */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.3rem;
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.9rem;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
}

select.form-control {
    appearance: none;
    cursor: pointer;
}

.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary {
    background: var(--accent);
    color: #000;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-sm {
    padding: 0.3rem 0.7rem;
    font-size: 0.75rem;
}

/* ---------------------------------------------------------------------------
   Filters bar
--------------------------------------------------------------------------- */

.filters-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filters-bar .form-control {
    width: auto;
    min-width: 140px;
}

/* ---------------------------------------------------------------------------
   Modal
--------------------------------------------------------------------------- */

.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ---------------------------------------------------------------------------
   Login page
--------------------------------------------------------------------------- */

.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 2rem;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
}

.login-logo {
    display: block;
    margin: 0 auto 1rem;
    width: 100%;
    max-width: 380px;
    height: auto;
}

.login-box h1 {
    text-align: center;
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: var(--accent);
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 2rem;
}

.login-box .btn-primary {
    width: 100%;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

.flash-error {
    background: rgba(244, 67, 54, 0.15);
    border: 1px solid rgba(244, 67, 54, 0.3);
    color: var(--red);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.flash-success {
    background: rgba(76, 175, 80, 0.15);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: var(--green);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.login-signup-link {
    text-align: center;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.optional {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
}

/* ---------------------------------------------------------------------------
   Analytics sections
--------------------------------------------------------------------------- */

.analytics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.stat-row:last-child {
    border-bottom: none;
}

.stat-row .stat-label {
    color: var(--text-secondary);
}

.stat-row .stat-value {
    font-weight: 600;
}

.stat-row .stat-value.positive { color: var(--green); }
.stat-row .stat-value.negative { color: var(--red); }
.stat-row .stat-value.warning { color: var(--orange); }

.expiring-alert {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: rgba(255, 152, 0, 0.1);
    border: 1px solid rgba(255, 152, 0, 0.3);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--orange);
    margin-bottom: 1rem;
}

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

.charts-row {
    display: grid;
    gap: 1rem;
    margin-bottom: 1rem;
}

.charts-row-3 {
    grid-template-columns: repeat(3, 1fr);
}

.charts-row-2 {
    grid-template-columns: repeat(2, 1fr);
}

.chart-subtitle {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: -0.25rem;
    padding-bottom: 0.5rem;
}

/* Period filter bar */
.period-filter {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
}

.period-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-right: 0.5rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.period-btn {
    padding: 0.3rem 0.7rem;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    background: transparent;
    text-decoration: none;
    transition: all 0.15s;
}

.period-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.period-btn.active {
    background: rgba(79, 195, 247, 0.15);
    color: var(--accent);
    border-color: var(--accent);
}

/* Win/Loss clickable links */
.wl-link {
    cursor: pointer;
    text-decoration: none;
    border-bottom: 1px dashed currentColor;
    transition: opacity 0.15s;
}

.wl-link:hover {
    opacity: 0.8;
}

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   Tabs
--------------------------------------------------------------------------- */

.tab-bar {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1rem;
    overflow-x: auto;
    gap: 0;
}

.tab-btn {
    padding: 0.6rem 1.2rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.tab-btn .tab-count {
    display: inline-block;
    background: rgba(79, 195, 247, 0.15);
    color: var(--accent);
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    font-size: 0.7rem;
    margin-left: 0.3rem;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .charts-row-3,
    .charts-row-2 { grid-template-columns: 1fr; }
    .analytics-grid { grid-template-columns: 1fr; }
}
