/* ========================================
   xEngine Dashboard — Dark Sidebar + Light Main
   Glassmorphism Sidebar + Clean Table UI
======================================== */

:root {
    /* Sidebar (dark) */
    --sidebar-bg: #0f1629;
    --sidebar-text: #c8d6e5;
    --sidebar-text-active: #ffffff;
    --sidebar-accent: #6366f1;
    --sidebar-hover: rgba(99,102,241,0.12);
    --sidebar-active-bg: rgba(99,102,241,0.18);
    --sidebar-border: rgba(255,255,255,0.08);

    /* Main (light) */
    --main-bg: #f5f7fa;
    --surface: #ffffff;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-muted: #a0aec0;
    --border: #e2e8f0;
    --accent: #6366f1;
    --accent-hover: #4f46e5;

    /* Shared */
    --radius: 12px;
    --radius-sm: 8px;
    --transition: all 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--main-bg);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ---- LOGIN OVERLAY ---- */
.login-overlay {
    position: fixed; inset: 0; z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 15, 30, 0.95);
    backdrop-filter: blur(20px);
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.login-card {
    text-align: center;
    padding: 3rem 3.5rem;
    border-radius: 24px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.1);
    backdrop-filter: blur(24px);
    max-width: 420px;
    width: 90%;
    animation: slideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1);
    color: #f1f5f9;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
    display: flex; align-items: center; justify-content: center; gap: 0.75rem;
    font-size: 2rem; font-weight: 800; margin-bottom: 1.5rem;
    background: linear-gradient(135deg, #818cf8, #a78bfa, #c084fc);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-logo i { -webkit-text-fill-color: initial; color: #818cf8; }

.login-title {
    font-size: 1.25rem; font-weight: 700;
    margin-bottom: 0.5rem;
}
.login-subtitle {
    font-size: 0.875rem; color: #94a3b8;
    line-height: 1.6; margin-bottom: 2rem;
}

.login-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.75rem;
    width: 100%; padding: 0.875rem 1.5rem;
    background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px; color: #f1f5f9;
    font-size: 0.95rem; font-weight: 600;
    cursor: pointer; transition: var(--transition);
}
.login-btn:hover {
    background: rgba(255,255,255,0.14);
    border-color: rgba(255,255,255,0.25);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px -8px rgba(99,102,241,0.3);
}
.login-btn:active { transform: translateY(0); }
.login-btn:disabled { opacity: 0.5; cursor: wait; }

.login-footer {
    margin-top: 2rem; font-size: 0.7rem;
    color: #64748b; letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* ---- LAYOUT ---- */
.app-container { display: flex; min-height: 100vh; }

/* ---- SIDEBAR (DARK) ---- */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    border-right: 1px solid var(--sidebar-border);
    overflow-y: auto;
    padding: 1.25rem 0;
}

.logo {
    display: flex; align-items: center; gap: 0.6rem;
    font-size: 1.3rem; font-weight: 800;
    padding: 0 1.25rem;
    margin-bottom: 2rem;
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.logo-icon { -webkit-text-fill-color: initial; color: #818cf8; }

.sidebar nav > ul {
    list-style: none;
    display: flex; flex-direction: column;
}

.sidebar nav > ul > li > a {
    text-decoration: none;
    color: var(--sidebar-text);
    font-weight: 500; font-size: 0.85rem;
    padding: 0.65rem 1.25rem;
    display: flex; align-items: center; gap: 0.75rem;
    transition: var(--transition);
    border-left: 3px solid transparent;
}

.sidebar nav > ul > li > a:hover {
    color: var(--sidebar-text-active);
    background: var(--sidebar-hover);
}

.sidebar nav > ul > li.active > a,
.sidebar nav > ul > li.active > a.parent-link {
    color: var(--sidebar-text-active);
    background: var(--sidebar-active-bg);
    border-left-color: var(--sidebar-accent);
    font-weight: 600;
}

.sidebar nav > ul > li { cursor: pointer; }

/* Chevron */
.chevron {
    margin-left: auto;
    font-size: 0.6rem;
    transition: transform 0.25s;
}
.has-children.expanded .chevron {
    transform: rotate(180deg);
}

/* Sub-menu */
.sub-menu {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.has-children.expanded .sub-menu {
    max-height: 400px;
}

.sub-menu li a {
    text-decoration: none;
    color: var(--sidebar-text);
    font-size: 0.8rem;
    font-weight: 400;
    padding: 0.45rem 1.25rem 0.45rem 3rem;
    display: block;
    transition: var(--transition);
}
.sub-menu li a:hover {
    color: var(--sidebar-text-active);
    background: var(--sidebar-hover);
}
.sub-menu li.active a {
    color: #a5b4fc;
    font-weight: 600;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid var(--sidebar-border);
    padding: 1rem 1.25rem 0.5rem;
}
.sidebar-footer a {
    text-decoration: none; color: #64748b;
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.4rem 0; font-size: 0.8rem;
    transition: color 0.3s;
}
.sidebar-footer a:hover { color: #ef4444; }

.user-info { margin-bottom: 0.5rem; }
.user-info-name { font-size: 0.8rem; font-weight: 600; color: #e2e8f0; }
.user-info-email { font-size: 0.7rem; color: #64748b; word-break: break-all; }

/* ---- MAIN CONTENT (LIGHT) ---- */
.main-content {
    flex: 1;
    margin-left: 240px;
    min-height: 100vh;
    background: var(--main-bg);
}

/* Header */
.main-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}

.search-bar {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.55rem 1rem;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    width: 380px;
    transition: var(--transition);
}
.search-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}
.search-bar input {
    background: transparent; border: none; outline: none;
    color: var(--text-primary); width: 100%; font-size: 0.875rem;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-bar i { color: var(--text-muted); font-size: 0.85rem; }

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

.report-count {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem; color: var(--text-secondary);
}

.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.7rem; overflow: hidden;
    background: linear-gradient(135deg, #4f46e5, #6366f1);
    color: #fff;
}

/* ---- TABLE VIEW ---- */
.table-view { padding: 1.5rem 2rem; }

.table-header { margin-bottom: 1.25rem; }
.table-header h1 {
    font-size: 1.5rem; font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.view-subtitle {
    font-size: 0.85rem; color: var(--text-muted);
    margin-top: 0.2rem;
}

.table-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

/* Table */
.reports-table {
    width: 100%;
    border-collapse: collapse;
}

.reports-table thead {
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
}

.reports-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.reports-table th:hover { color: var(--text-primary); }
.reports-table th .sort-icon {
    margin-left: 0.3rem;
    font-size: 0.6rem;
    opacity: 0.4;
}
.reports-table th.sorted .sort-icon { opacity: 1; color: var(--accent); }

.reports-table td {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid #f1f5f9;
}

.reports-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}
.reports-table tbody tr:hover {
    background: #f0f4ff;
}
.reports-table tbody tr:active {
    background: #e8edff;
}

/* Ticker cell */
.cell-ticker {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.9rem;
    letter-spacing: -0.2px;
}

/* Sector cell */
.cell-sector {
    font-size: 0.8rem;
}

/* Recommendation badges */
.rec-badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.rec-buy       { background: #dcfce7; color: #15803d; }
.rec-accumulate{ background: #d1fae5; color: #047857; }
.rec-hold      { background: #fef9c3; color: #a16207; }
.rec-watch     { background: #dbeafe; color: #1d4ed8; }
.rec-surf      { background: #e0f2fe; color: #0369a1; }
.rec-reduce    { background: #fee2e2; color: #b91c1c; }
.rec-out       { background: #f1f5f9; color: #64748b; }
.rec-sell      { background: #fecaca; color: #dc2626; }
.rec-na        { background: #f1f5f9; color: #94a3b8; }

/* Date cell */
.cell-date { font-size: 0.8rem; color: var(--text-muted); }

/* Table info bar */
.table-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---- REPORT VIEW ---- */
.report-view { display: none; }

.report-header {
    display: flex; align-items: center; gap: 1.5rem;
    padding: 0.75rem 2rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 57px; z-index: 40;
}

.back-btn {
    display: flex; align-items: center; gap: 0.4rem;
    padding: 0.45rem 0.9rem;
    background: var(--main-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.8rem; font-weight: 600;
    cursor: pointer; transition: var(--transition);
}
.back-btn:hover {
    background: var(--border);
    color: var(--text-primary);
}

.report-meta {
    display: flex; align-items: center; gap: 0.75rem;
}
.report-ticker-name {
    font-size: 1.1rem; font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.report-sector-badge {
    padding: 0.2rem 0.5rem;
    background: #f1f5f9;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.report-rec-badge {
    padding: 0.2rem 0.55rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
}

.report-iframe-container {
    height: calc(100vh - 115px);
    background: #fff;
}

.report-iframe-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ---- LOADER ---- */
.loader {
    text-align: center; padding: 3rem;
    color: var(--text-muted); font-size: 0.95rem;
}
.loader i { margin-right: 0.5rem; }

/* ---- RESPONSIVE ---- */
@media (max-width: 1024px) {
    .sidebar { width: 200px; }
    .main-content { margin-left: 200px; }
    .search-bar { width: 260px; }
}

@media (max-width: 768px) {
    .app-container { flex-direction: column; }
    .sidebar {
        position: relative; width: 100%; height: auto;
        flex-direction: row; justify-content: space-between; align-items: center;
        padding: 0.75rem 1rem;
    }
    .sidebar nav > ul { flex-direction: row; overflow-x: auto; gap: 0.15rem; }
    .sidebar nav > ul > li > a { font-size: 0.75rem; padding: 0.4rem 0.6rem; white-space: nowrap; }
    .sub-menu { display: none; }
    .sidebar-footer { display: none; }
    .logo { margin-bottom: 0; font-size: 1.1rem; }
    .main-content { margin-left: 0; }
    .search-bar { width: 100%; }
    .table-view { padding: 1rem; }
    .main-header { padding: 0.75rem 1rem; }
    .login-card { padding: 2rem 1.5rem; }

    .reports-table th,
    .reports-table td { padding: 0.55rem 0.6rem; font-size: 0.78rem; }
}
