/* ============================================================
   IB Partner Portal - Styles
   Premium dark theme for Introducing Broker portal
   ============================================================ */

/* ============ IB COLOR OVERRIDES ============ */
:root {
    --ib-accent: #8b5cf6;
    --ib-accent-hover: #7c3aed;
    --ib-accent-active: #6d28d9;
    --ib-accent-subtle: rgba(139, 92, 246, 0.1);
    --ib-accent-glow: rgba(139, 92, 246, 0.25);
    --ib-accent-text: #a78bfa;
    --ib-gradient: linear-gradient(135deg, #8b5cf6, #6d28d9);
    --ib-gradient-soft: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(109,40,217,0.05));
}

/* Override accent for IB portal */
.sidebar .nav-item.active {
    background: var(--ib-accent-subtle);
    color: var(--ib-accent-text);
    border-left-color: var(--ib-accent);
}
.sidebar .nav-item.active svg {
    color: var(--ib-accent-text);
}
.sidebar-title {
    color: var(--ib-accent-text) !important;
}
.sidebar-avatar {
    background: var(--ib-gradient) !important;
    box-shadow: 0 2px 8px var(--ib-accent-glow) !important;
}

/* ============ LOGIN SCREEN ============ */
/* Login styles are now inline in index.html for full split-screen layout */
/* Keep .login-error for JS compatibility */
.login-error.show {
    display: block !important;
}

/* ============ TOPBAR IB EXTRAS ============ */
.ib-topbar-balance {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
}
.ib-balance-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: var(--fw-medium);
}
.ib-balance-value {
    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    font-family: var(--font-mono);
    color: var(--profit);
    letter-spacing: -0.02em;
}
.ib-topbar-code {
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--ib-accent-text);
    background: var(--ib-accent-subtle);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    letter-spacing: 0.05em;
    font-family: var(--font-mono);
}

/* ============ DASHBOARD KPI CARDS ============ */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--sp-5);
    margin-bottom: var(--sp-6);
}
.kpi-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--sp-6);
    position: relative;
    overflow: hidden;
    transition: all var(--tr-normal);
}
.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.kpi-card:hover {
    border-color: var(--border-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}
.kpi-card--purple::before { background: var(--ib-gradient); }
.kpi-card--green::before { background: linear-gradient(135deg, #10b981, #059669); }
.kpi-card--blue::before { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.kpi-card--amber::before { background: linear-gradient(135deg, #f59e0b, #d97706); }

.kpi-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--sp-4);
}
.kpi-icon--purple { background: var(--ib-accent-subtle); color: var(--ib-accent-text); }
.kpi-icon--green { background: var(--profit-bg); color: var(--profit); }
.kpi-icon--blue { background: var(--info-bg); color: var(--info); }
.kpi-icon--amber { background: var(--warning-bg); color: var(--warning); }

.kpi-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: var(--sp-2);
}
.kpi-value {
    font-size: var(--fs-3xl);
    font-weight: var(--fw-bold);
    font-family: var(--font-mono);
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: var(--sp-2);
    letter-spacing: -0.02em;
}
.kpi-sub {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}
.kpi-sub .positive { color: var(--profit); font-weight: var(--fw-semibold); }
.kpi-sub .negative { color: var(--loss); font-weight: var(--fw-semibold); }

/* Glassmorphism effect */
.kpi-card--glass {
    background: rgba(17, 24, 39, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-color: rgba(255,255,255,0.06);
}

/* ============ DASHBOARD CHART ============ */
.dashboard-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--sp-5);
    margin-bottom: var(--sp-6);
}
.chart-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}
.chart-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}
.chart-card-header h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}
.chart-card-body {
    padding: var(--sp-4) var(--sp-5);
}
.chart-container {
    width: 100%;
    height: 300px;
}

/* ============ QUICK STATS PANEL ============ */
.quick-stats {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}
.quick-stats-header {
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}
.quick-stats-header h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
}
.quick-stat-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-6);
    border-bottom: 1px solid var(--border);
    transition: background var(--tr-fast);
}
.quick-stat-item:last-child {
    border-bottom: none;
}
.quick-stat-item:hover {
    background: var(--bg-hover);
}
.quick-stat-label {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.quick-stat-value {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
    font-family: var(--font-mono);
    color: var(--text-primary);
}

/* ============ RECENT ACTIVITY ============ */
.recent-activity {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}
.activity-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-3) var(--sp-5);
    border-bottom: 1px solid var(--border);
    transition: background var(--tr-fast);
}
.activity-item:last-child { border-bottom: none; }
.activity-item:hover { background: var(--bg-hover); }
.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.activity-dot--green { background: var(--profit); }
.activity-dot--blue { background: var(--info); }
.activity-dot--amber { background: var(--warning); }
.activity-text {
    flex: 1;
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.activity-text strong {
    color: var(--text-primary);
    font-weight: var(--fw-medium);
}
.activity-time {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
}

/* ============ DATA TABLES ============ */
.section-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
    margin-bottom: var(--sp-6);
}
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: var(--sp-3);
}
.section-header h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin: 0;
}
.section-toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    flex-wrap: wrap;
}
.section-body {
    padding: 0;
}
.section-body--padded {
    padding: var(--sp-6);
}

/* Table tweaks */
.ib-table { width: 100%; }
.ib-table th {
    padding: 12px 16px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}
.ib-table td {
    padding: 12px 16px;
    font-size: var(--fs-sm);
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.ib-table tbody tr {
    transition: background var(--tr-fast);
}
.ib-table tbody tr:hover {
    background: var(--bg-hover);
}
.ib-table tbody tr:last-child td {
    border-bottom: none;
}
.ib-table .col-money {
    font-family: var(--font-mono);
    text-align: right;
    font-weight: var(--fw-medium);
}
.ib-table .col-number {
    font-family: var(--font-mono);
    text-align: right;
}

/* ============ STATUS BADGES ============ */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    border-radius: var(--radius-full);
    white-space: nowrap;
}
.status-badge--credited,
.status-badge--active,
.status-badge--approved {
    background: var(--profit-bg);
    color: var(--profit);
}
.status-badge--pending {
    background: var(--warning-bg);
    color: var(--warning);
}
.status-badge--rejected,
.status-badge--inactive {
    background: var(--loss-bg);
    color: var(--loss);
}
.status-badge--processing {
    background: var(--info-bg);
    color: var(--info);
}
.status-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* ============ COMMISSION TABLE COLORS ============ */
.commission-amount {
    font-family: var(--font-mono);
    font-weight: var(--fw-semibold);
}
.commission-amount--credited {
    color: var(--profit);
}
.commission-amount--pending {
    color: var(--text-tertiary);
}

/* ============ CLIENT ROW ============ */
.client-info {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
}
.client-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    flex-shrink: 0;
}
.client-name {
    font-weight: var(--fw-medium);
    color: var(--text-primary);
}
.client-email {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
}

/* ============ REFERRAL LINKS ============ */
.links-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: var(--sp-5);
    padding: var(--sp-6);
}
.link-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    transition: all var(--tr-normal);
}
.link-card:hover {
    border-color: var(--ib-accent);
    box-shadow: 0 0 20px var(--ib-accent-glow);
}
.link-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-4);
}
.link-card-name {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--text-primary);
}
.link-card-campaign {
    font-size: var(--fs-xs);
    color: var(--ib-accent-text);
    background: var(--ib-accent-subtle);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}
.link-url-box {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: var(--sp-2) var(--sp-3);
    margin-bottom: var(--sp-4);
}
.link-url-text {
    flex: 1;
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.link-copy-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--ib-accent-subtle);
    color: var(--ib-accent-text);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--tr-fast);
    flex-shrink: 0;
}
.link-copy-btn:hover {
    background: var(--ib-accent);
    color: white;
}
.link-copy-btn.copied {
    background: var(--profit);
    color: white;
}
.link-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-3);
}
.link-stat {
    text-align: center;
}
.link-stat-value {
    font-size: var(--fs-lg);
    font-weight: var(--fw-bold);
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.link-stat-label {
    font-size: 10px;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ============ CREATE LINK FORM ============ */
.create-link-form {
    display: flex;
    align-items: flex-end;
    gap: var(--sp-3);
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
    background: var(--bg-tertiary);
    flex-wrap: wrap;
}
.create-link-form .form-group {
    flex: 1;
    min-width: 180px;
    margin-bottom: 0;
}
.create-link-form .btn {
    background: var(--ib-gradient);
    border-color: var(--ib-accent);
    color: white;
    height: 38px;
    flex-shrink: 0;
}
.create-link-form .btn:hover {
    box-shadow: 0 0 16px var(--ib-accent-glow);
}

/* ============ WITHDRAWAL SECTION ============ */
.withdrawal-layout {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: var(--sp-6);
}
.withdrawal-form-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}
.withdrawal-form-header {
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}
.withdrawal-form-header h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin: 0;
}
.withdrawal-form-body {
    padding: var(--sp-6);
}
.withdrawal-form-body .form-group {
    margin-bottom: var(--sp-5);
}
.withdrawal-form-body .btn-primary {
    background: var(--ib-gradient);
    border-color: var(--ib-accent);
    width: 100%;
    padding: 12px;
    font-size: var(--fs-md);
}
.withdrawal-form-body .btn-primary:hover {
    box-shadow: 0 0 20px var(--ib-accent-glow);
}
.withdrawal-available {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4);
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    margin-bottom: var(--sp-5);
    border: 1px solid var(--border);
}
.withdrawal-available-label {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
}
.withdrawal-available-value {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    font-family: var(--font-mono);
    color: var(--profit);
}

/* ============ PROFILE PAGE ============ */
.profile-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--sp-6);
}
.profile-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    overflow: hidden;
}
.profile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--border);
}
.profile-card-header h3 {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin: 0;
}
.profile-card-body {
    padding: var(--sp-5) var(--sp-6);
}
.profile-field {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border);
}
.profile-field:last-child {
    border-bottom: none;
}
.profile-field-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: var(--fw-medium);
    min-width: 120px;
}
.profile-field-value {
    font-size: var(--fs-sm);
    color: var(--text-primary);
    font-weight: var(--fw-medium);
    text-align: right;
}

/* Profile hero */
.profile-hero {
    display: flex;
    align-items: center;
    gap: var(--sp-6);
    padding: var(--sp-8) var(--sp-6);
    background: var(--ib-gradient-soft);
    border-bottom: 1px solid var(--border);
}
.profile-hero-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--ib-gradient);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-2xl);
    font-weight: var(--fw-bold);
    box-shadow: 0 4px 16px var(--ib-accent-glow);
    flex-shrink: 0;
}
.profile-hero-info h2 {
    font-size: var(--fs-xl);
    margin-bottom: var(--sp-1);
}
.profile-hero-info p {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    margin: 0;
}

/* ============ SUB-PARTNERS ============ */
.sub-partner-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-5);
    margin-bottom: var(--sp-6);
}

/* ============ DATE FILTER ============ */
.date-filter {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
}
.date-filter .input {
    width: 140px;
    font-size: var(--fs-xs);
    padding: 7px 10px;
}
.date-filter-sep {
    color: var(--text-tertiary);
    font-size: var(--fs-sm);
}

/* ============ COMMISSION SUMMARY BAR ============ */
.commission-summary {
    display: flex;
    align-items: center;
    gap: var(--sp-8);
    padding: var(--sp-5) var(--sp-6);
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}
.commission-summary-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.commission-summary-label {
    font-size: var(--fs-xs);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.commission-summary-value {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.commission-summary-value--highlight {
    color: var(--profit);
}

/* ============ SEARCH INPUT ============ */
.search-input-wrapper {
    position: relative;
}
.search-input-wrapper .input {
    padding-left: 34px;
    width: 220px;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    border-color: transparent;
}
.search-input-wrapper .input:focus {
    background: var(--bg-input);
    border-color: var(--ib-accent);
    box-shadow: 0 0 0 3px var(--ib-accent-subtle);
}
.search-input-wrapper svg {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

/* ============ EMPTY STATE ============ */
.ib-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--sp-12) var(--sp-6);
    text-align: center;
}
.ib-empty-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--sp-4);
}
.ib-empty-title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    margin-bottom: var(--sp-2);
}
.ib-empty-text {
    font-size: var(--fs-sm);
    color: var(--text-secondary);
    max-width: 320px;
}

/* ============ LOADING SKELETON ============ */
.ib-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-16);
}

/* ============ RESPONSIVE ============ */
@media (max-width: 1280px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .dashboard-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .withdrawal-layout {
        grid-template-columns: 1fr;
    }
    .profile-grid {
        grid-template-columns: 1fr;
    }
    .ib-topbar-balance {
        display: none;
    }
}

@media (max-width: 768px) {
    .kpi-grid {
        grid-template-columns: 1fr;
    }
    .links-grid {
        grid-template-columns: 1fr;
        padding: var(--sp-4);
    }
    .section-header {
        padding: var(--sp-4);
    }
    .commission-summary {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--sp-4);
        padding: var(--sp-4);
    }
    .sub-partner-summary {
        grid-template-columns: 1fr;
    }
    .date-filter {
        flex-wrap: wrap;
    }
    .date-filter .input {
        width: 120px;
    }
    .search-input-wrapper .input {
        width: 160px;
    }
    .create-link-form {
        flex-direction: column;
        align-items: stretch;
    }
    .create-link-form .form-group {
        min-width: 100%;
    }
    .ib-topbar-code {
        display: none;
    }
    .page-content {
        padding: var(--sp-4) !important;
    }
    .profile-hero {
        flex-direction: column;
        text-align: center;
    }
}

/* ============ SCROLLBAR OVERRIDE FOR TABLES ============ */
.section-body {
    overflow-x: auto;
}
.section-body::-webkit-scrollbar {
    height: 4px;
}

/* ============ PAGE TRANSITIONS ============ */
.page-enter {
    animation: fadeIn 0.2s ease, slideUp 0.25s ease;
}

/* ============ TOAST IB OVERRIDE ============ */
.toast-success {
    border-left-color: var(--profit) !important;
}
.toast-error {
    border-left-color: var(--loss) !important;
}
