/* Custom Fonts Import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;850&display=swap');

/* Color Variables & Styling Tokens */
:root {
    --bg-main: #0b0f19;
    --bg-surface: rgba(17, 24, 39, 0.7);
    --bg-card: rgba(30, 41, 59, 0.45);
    --border-glow: rgba(124, 58, 237, 0.15);
    --border-subtle: rgba(255, 255, 255, 0.06);
    
    --color-primary: #8b5cf6;
    --color-primary-glow: rgba(139, 92, 246, 0.3);
    --color-accent: #f59e0b;
    
    --color-gain: #10b981;
    --color-gain-bg: rgba(16, 185, 129, 0.08);
    --color-loss: #ef4444;
    --color-loss-bg: rgba(239, 68, 68, 0.08);
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-dark: #6b7280;
    
    --font-sans: 'Inter', sans-serif;
    --font-heading: 'Outfit', sans-serif;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.1) 0px, transparent 50%),
        radial-gradient(at 50% 0%, rgba(139, 92, 246, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(245, 158, 11, 0.04) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* Scrollbar customization */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(11, 15, 25, 0.5);
}
::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

/* Typography styling */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    letter-spacing: -0.02em;
}

/* App Layout */
.app-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Header Section */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-subtle);
    flex-wrap: wrap;
    gap: 1rem;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-logo {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--color-primary), #6366f1);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px var(--color-primary-glow);
}

.brand-logo i {
    font-size: 1.25rem;
    color: white;
}

.brand-details h1 {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.1;
    background: linear-gradient(to right, #f3f4f6, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-details span {
    font-size: 0.75rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.status-panel {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Glass Card Component */
.glass-card {
    background: var(--bg-surface);
    backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--border-subtle);
    border-radius: 18px;
    padding: 1.5rem;
    transition: var(--transition-smooth);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

.glass-card:hover {
    border-color: var(--border-glow);
    box-shadow: 0 8px 32px 0 rgba(139, 92, 246, 0.05);
}

/* Accounts Management Tray */
.accounts-tray {
    display: none; /* Controlled dynamically in JS */
    animation: fadeIn 0.3s ease;
    margin-top: -1rem;
}

.accounts-tray.active {
    display: block;
}

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

.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Account Management Card Item */
.account-item-card {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 0.75rem;
    transition: var(--transition-smooth);
}

.account-item-card:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(15, 23, 42, 0.8);
}

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

.account-label-text {
    font-weight: 700;
    font-size: 1rem;
    color: white;
}

.account-meta-details {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.account-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.04);
    padding-top: 0.75rem;
}

.status-indicator-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-indicator-pill.active {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-gain);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-indicator-pill.expired {
    background: rgba(239, 68, 68, 0.1);
    color: var(--color-loss);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-indicator-pill.invalid {
    background: rgba(245, 158, 11, 0.1);
    color: var(--color-accent);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* Summary Grid cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 120px;
    position: relative;
    overflow: hidden;
}

.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 60px;
    height: 60px;
    background: radial-gradient(circle, var(--color-primary-glow) 0%, transparent 70%);
    opacity: 0.3;
    pointer-events: none;
}

.stat-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0.5rem 0;
}

.stat-subtext {
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-subtext.positive {
    color: var(--color-gain);
}

.stat-subtext.negative {
    color: var(--color-loss);
}

/* Per-Owner Mini Summary Cards Grid */
.owner-cards-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.owner-cards-header h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.owner-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

/* Owner Mini Card */
.owner-mini-card {
    background: rgba(30, 41, 59, 0.25);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    transition: var(--transition-smooth);
}

.owner-mini-card.active {
    border-left: 3.5px solid var(--color-primary);
}

.owner-mini-card.expired {
    border-left: 3.5px solid var(--color-loss);
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.04);
}

.owner-card-label {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.owner-card-value {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 750;
    color: white;
}

.owner-card-pnl {
    font-size: 0.75rem;
    font-weight: 600;
}

/* Visualizer Section */
.visualizer-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 992px) {
    .visualizer-section {
        grid-template-columns: 1fr;
    }
}

.chart-container {
    min-height: 320px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 300px;
    overflow-y: auto;
    padding-right: 0.25rem;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    transition: var(--transition-smooth);
}

.breakdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--color-primary-glow);
}

.breakdown-symbol {
    font-weight: 700;
    font-size: 0.9rem;
}

.breakdown-allocation {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.allocation-bar-bg {
    width: 60px;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
}

.allocation-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), #a78bfa);
    border-radius: 3px;
}

.allocation-percent {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 35px;
    text-align: right;
}

/* 11-Column Holdings Wide Table Styling with Sticky Headers */
.holdings-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.table-controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    flex-wrap: wrap;
    gap: 1.5rem;
}

/* Owner Pill Checkbox Filters */
.owner-filter-bar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.owner-checkbox-list {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.owner-pill-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.9rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    transition: var(--transition-smooth);
}

.owner-pill-label input {
    display: none;
}

.owner-pill-label.checked {
    background: var(--color-primary-glow);
    border-color: var(--color-primary);
    color: white;
}

.owner-pill-label:hover {
    background: rgba(255, 255, 255, 0.1);
}

.table-wrapper {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    background: rgba(11, 15, 25, 0.6);
    position: relative;
    max-height: 600px;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
    table-layout: auto;
}

thead {
    background: #0d131f;
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 20;
}

th {
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    vertical-align: top;
    white-space: nowrap;
    border-bottom: 1px solid var(--border-subtle);
}

/* Header sort layout */
.th-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    cursor: pointer;
    user-select: none;
    padding-bottom: 0.4rem;
}

.th-content:hover {
    color: white;
}

.sort-indicator {
    font-size: 0.75rem;
    opacity: 0.25;
    transition: var(--transition-smooth);
}

.sort-indicator.active {
    opacity: 1;
    color: var(--color-primary);
}

/* Header inline search input boxes */
.header-filter {
    width: 100%;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    color: white;
    font-size: 0.7rem;
    font-family: var(--font-sans);
    font-weight: normal;
    text-transform: none;
}

.header-filter::placeholder {
    color: var(--text-dark);
}

.header-filter:focus {
    outline: none;
    border-color: var(--color-primary);
    background: rgba(15, 23, 42, 1);
}

tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: var(--transition-smooth);
    background: rgba(17, 24, 39, 0.3);
}

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

tbody tr:hover {
    filter: brightness(1.15);
}

tbody tr:hover td.sticky-col,
tbody tr:hover td.sticky-col-2 {
    background: rgba(22, 28, 45, 1) !important;
}

td {
    padding: 0.8rem 1rem;
    vertical-align: middle;
    white-space: nowrap;
}

/* Sticky columns for Horizontal Scrolling readability */
.sticky-col {
    position: sticky;
    left: 0;
    z-index: 10;
    background: #0d131f;
    width: 110px;
}

.sticky-col-2 {
    position: sticky;
    left: 110px; /* Offset based on first column width */
    z-index: 10;
    background: #0d131f;
    box-shadow: 4px 0 10px -5px rgba(0, 0, 0, 0.7);
    border-right: 1.5px solid var(--border-subtle);
    width: 120px;
}

thead th.sticky-col {
    z-index: 22;
    background: #0b0f19;
}

thead th.sticky-col-2 {
    z-index: 22;
    background: #0b0f19;
    box-shadow: 4px 0 10px -5px rgba(0, 0, 0, 0.7);
    border-right: 1.5px solid var(--border-subtle);
}

/* Owner color coding row background highlights */
tbody tr.owner-color-0 {
    background: rgba(139, 92, 246, 0.04); /* subtle violet */
}
tbody tr.owner-color-0 td.sticky-col,
tbody tr.owner-color-0 td.sticky-col-2 {
    background: #111424; /* matches violet tint */
}

tbody tr.owner-color-1 {
    background: rgba(59, 130, 246, 0.04);  /* subtle blue */
}
tbody tr.owner-color-1 td.sticky-col,
tbody tr.owner-color-1 td.sticky-col-2 {
    background: #0e1628; /* matches blue tint */
}

tbody tr.owner-color-2 {
    background: rgba(16, 185, 129, 0.04);  /* subtle emerald */
}
tbody tr.owner-color-2 td.sticky-col,
tbody tr.owner-color-2 td.sticky-col-2 {
    background: #0d1a22; /* matches emerald tint */
}

tbody tr.owner-color-3 {
    background: rgba(245, 158, 11, 0.04);  /* subtle amber */
}
tbody tr.owner-color-3 td.sticky-col,
tbody tr.owner-color-3 td.sticky-col-2 {
    background: #19181b; /* matches amber tint */
}

tbody tr.owner-color-4 {
    background: rgba(236, 72, 153, 0.04);  /* subtle pink */
}
tbody tr.owner-color-4 td.sticky-col,
tbody tr.owner-color-4 td.sticky-col-2 {
    background: #191421; /* matches pink tint */
}

.stock-symbol {
    font-weight: 750;
    color: #ffffff;
    display: inline-block;
}

.stock-exchange {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.pnl-badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.75rem;
}

.pnl-badge.positive {
    background: var(--color-gain-bg);
    color: var(--color-gain);
}

.pnl-badge.negative {
    background: var(--color-loss-bg);
    color: var(--color-loss);
}

/* Flashing price alert ticks */
.tick-up {
    animation: flash-green 0.8s ease-out;
}

.tick-down {
    animation: flash-red 0.8s ease-out;
}

@keyframes flash-green {
    0% { background-color: rgba(16, 185, 129, 0.25); }
    100% { background-color: transparent; }
}

@keyframes flash-red {
    0% { background-color: rgba(239, 68, 68, 0.25); }
    100% { background-color: transparent; }
}

/* Buttons and UI elements */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition-smooth);
    font-family: var(--font-sans);
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #6d28d9);
    color: white;
    box-shadow: 0 4px 14px var(--color-primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--color-primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Authentication Required Overlays */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(7, 10, 18, 0.92);
    backdrop-filter: blur(20px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.auth-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.auth-card {
    max-width: 480px;
    width: 100%;
    text-align: center;
    padding: 2.5rem;
    border: 1px solid rgba(139, 92, 246, 0.25);
    background: radial-gradient(circle at 50% 0%, rgba(139, 92, 246, 0.12) 0%, rgba(17, 24, 39, 0.8) 100%);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(139, 92, 246, 0.05);
    animation: scaleIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes scaleIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.auth-icon {
    font-size: 3rem;
    color: var(--color-primary);
    margin-bottom: 1.25rem;
    display: inline-block;
}

.auth-card h2 {
    font-size: 1.75rem;
    margin-bottom: 0.75rem;
    color: white;
}

.auth-card p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
    line-height: 1.6;
}

.auth-action-box {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Key Configuration Form */
.key-config-toggle {
    margin-top: 1.5rem;
    font-size: 0.8rem;
    color: var(--color-primary);
    cursor: pointer;
    text-decoration: underline;
    font-weight: 500;
}

.keys-form {
    display: none;
    flex-direction: column;
    gap: 1rem;
    text-align: left;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-subtle);
    animation: fadeIn 0.3s ease;
}

.keys-form.active {
    display: flex;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-group label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}

.form-input {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 0.6rem 0.8rem;
    color: white;
    font-family: var(--font-sans);
    font-size: 0.85rem;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.15);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Custom UI Toggles and Controls */
.controls-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    align-items: center;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-subtle);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--color-primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.flex-center {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Responsive adjust */
@media (max-width: 600px) {
    .app-container {
        padding: 1rem;
    }
    
    header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .status-panel {
        width: 100%;
        justify-content: space-between;
    }
}
