/* ═══════════════════════════════════════════════════════════
   4XBO Markup Manager — Premium Minimalist Dark Theme
   ═══════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ── */
:root {
    --bg-primary:    #09090b;
    --bg-secondary:  #18181b;
    --bg-surface:    #1c1c1f;
    --bg-elevated:   #27272a;
    --bg-hover:      #3f3f46;

    --border-color:  rgba(212, 175, 55, 0.12);
    --border-focus:  rgba(234, 179, 8, 0.5);

    --text-primary:  #f4f4f5;
    --text-secondary:#a1a1aa;
    --text-muted:    #71717a;
    --text-heading:  #f4f4f5;

    --accent-primary:   #eab308;
    --accent-secondary: #ca8a04;
    --accent-success:   #10b981;
    --accent-warning:   #d97706;
    --accent-danger:    #ef4444;

    --gradient-primary: linear-gradient(135deg, #eab308, #ca8a04);
    --gradient-success: linear-gradient(135deg, #10b981, #059669);
    --gradient-danger:  linear-gradient(135deg, #ef4444, #dc2626);

    --glass-bg:     rgba(24, 24, 27, 0.88);
    --glass-border: rgba(212, 175, 55, 0.1);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ── Reset ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 14px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-image:
        radial-gradient(ellipse at 15% 0%, rgba(6,182,212,0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 85% 100%, rgba(139,92,246,0.03) 0%, transparent 50%);
}

/* ═══════════════ ANIMATIONS ═══════════════ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

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

@keyframes slideInRight {
    from { transform: translateX(30px); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 6px var(--accent-success); }
    50%      { box-shadow: 0 0 18px var(--accent-success), 0 0 40px rgba(16,185,129,0.15); }
}

@keyframes pulse-glow {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.7; }
}

@keyframes shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes numberPop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes rowSlideIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastIn  { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateX(50%); } }

@keyframes breathe {
    0%, 100% { box-shadow: 0 0 0 0 rgba(6,182,212,0.0); }
    50%      { box-shadow: 0 0 0 4px rgba(6,182,212,0.08); }
}

/* ═══════════════ APP LAYOUT (Sidebar + Content) ═══════════════ */
#app-container {
    display: flex;
    min-height: 100vh;
}

/* ═══════════════ SIDEBAR ═══════════════ */
#app-sidebar {
    width: 240px;
    min-width: 240px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 120;
    display: flex;
    flex-direction: column;
    background: rgba(10, 14, 22, 0.97);
    backdrop-filter: blur(24px);
    border-right: 1px solid var(--glass-border);
    overflow-y: auto;
    transition: transform var(--transition-slow);
    transform: translateX(-100%);
    box-shadow: var(--glass-shadow);
}

/* When sidebar is toggled open */
#app-container.sidebar-open #app-sidebar {
    transform: translateX(0);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 22px 18px;
    border-bottom: 1px solid var(--glass-border);
}
.sidebar-logo svg { flex-shrink: 0; color: #eab308; }
.sidebar-logo h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}
.sidebar-logo h1 .brand-4x { color: #eab308; }
.sidebar-logo h1 .brand-name { color: #ffffff; }

.sidebar-section-label {
    padding: 18px 22px 8px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    opacity: 0.6;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px 10px;
    gap: 2px;
}

.sidebar-nav .nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    background: none;
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.2px;
    position: relative;
    text-align: left;
    width: 100%;
}
.sidebar-nav .nav-btn svg {
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity var(--transition);
}
.sidebar-nav .nav-btn:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}
.sidebar-nav .nav-btn:hover svg {
    opacity: 0.9;
}
.sidebar-nav .nav-btn.active {
    background: rgba(234, 179, 8, 0.08);
    color: var(--accent-primary);
}
.sidebar-nav .nav-btn.active svg {
    opacity: 1;
    color: var(--accent-primary);
}
.sidebar-nav .nav-btn.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 20%;
    height: 60%;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--gradient-primary);
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.4);
}

.sidebar-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 8px 16px;
}

.sidebar-footer {
    padding: 16px 16px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.sidebar-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(17, 27, 46, 0.6);
    border: 1px solid var(--border-color);
    font-size: 0.76rem;
    font-weight: 500;
}
.sidebar-stats {
    display: flex;
    gap: 12px;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 500;
    padding: 0 4px;
}
.sidebar-stats span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ═══════════════ APP BODY (Header + Main) ═══════════════ */
#app-body {
    margin-left: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* ═══════════════ HEADER ═══════════════ */
/* 3-column grid: left content, center picker, right actions.
   1fr | auto | 1fr keeps the language picker visually centered no matter how
   wide the left or right groups grow, while the right column right-aligns its
   children (email + Logout) so the pill button never gets clipped. */
#app-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 28px;
    height: 54px;
    background: rgba(10, 16, 28, 0.9);
    backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 16px;
}

.header-left   { display: flex; align-items: center; gap: 12px; min-width: 0; justify-self: start;  }
.header-center { display: flex; align-items: center; justify-self: center; }
.header-right  { display: flex; align-items: center; gap: 14px; min-width: 0; justify-self: end; }

.header-right #user-display {
    color: #9ca3af;
    font-size: 13px;
    font-weight: 500;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#lang-picker {
    padding: 6px 28px 6px 12px;
    background: #09090b;
    border: 1px solid var(--gold-matte);
    border-radius: 8px;
    color: #f4f4f5;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    min-width: 130px;
}

.logo { display: flex; align-items: center; gap: 10px; color: var(--accent-primary); }
.logo h1 {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.logo svg { flex-shrink: 0; }

.status-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    border-radius: 20px;
    background: rgba(17, 27, 46, 0.9);
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    display: inline-block;
}
.status-dot.disconnected { background: var(--accent-danger); box-shadow: 0 0 6px var(--accent-danger); }
.status-dot.connected    { background: var(--accent-success); box-shadow: 0 0 6px var(--accent-success); animation: pulse-green 2s infinite; }

.stats-mini { display: flex; gap: 16px; font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.stats-mini span { display: flex; align-items: center; gap: 4px; }

/* ═══════════════ NAVIGATION (legacy, now in sidebar) ═══════════════ */
#main-nav {
    display: none;
}

/* ═══════════════ MAIN CONTENT ═══════════════ */
#main-content { padding: 24px 28px; max-width: 1400px; margin: 0 auto; flex: 1; }

.tab-panel { display: none; animation: fadeIn 0.4s ease; }
.tab-panel.active { display: block; }

/* ═══════════════ GLASS PANELS ═══════════════ */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
    transition: border-color var(--transition);
}
.glass-panel:hover {
    border-color: rgba(99, 134, 202, 0.15);
}

.panel { padding: 24px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.panel-header h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-heading);
    letter-spacing: -0.3px;
}
.panel-subtitle { color: var(--text-secondary); font-size: 0.85rem; margin-top: 4px; font-weight: 400; }

/* ═══════════════ FORMS ═══════════════ */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; max-width: 900px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

.form-inline-row { display: flex; flex-direction: row; align-items: flex-end; gap: 16px; width: 100%; }
.form-inline-row .form-group { flex: 1; min-width: 200px; }
.form-inline-row .form-actions { flex: 0 0 auto; display: flex; gap: 10px; }

.form-vertical-stack { display: flex; flex-direction: column; gap: 16px; max-width: 320px; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}
.form-group label small { text-transform: none; letter-spacing: 0; color: var(--text-muted); }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
select {
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 400;
    transition: var(--transition);
    outline: none;
    width: 100%;
}
input:focus, select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(6,182,212,0.1);
}
input::placeholder { color: var(--text-muted); font-weight: 400; }

.form-actions { display: flex; align-items: flex-end; gap: 10px; }

/* ═══════════════ BUTTONS ═══════════════ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
    letter-spacing: 0.2px;
    position: relative;
    overflow: hidden;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-primary {
    background: var(--gradient-primary);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(6,182,212,0.3);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-glow { box-shadow: 0 0 20px rgba(6,182,212,0.15); }
.btn-glow:hover:not(:disabled) { box-shadow: 0 0 30px rgba(6,182,212,0.35); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}
.btn-danger:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(239,68,68,0.3);
}

.btn-sm { padding: 6px 14px; font-size: 0.78rem; }

/* ─── Guide badge (chart "What does this show?" chips) ──────────────
   Dark rounded chip with a pink "?" and gold "Guide" label, sits at the
   top-right of each chart panel header. Clicking it opens a small popover
   anchored under the badge with a chart-specific explanation. */
.guide-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(15, 17, 23, 0.95);
    border: 1px solid rgba(234, 179, 8, 0.35);
    color: var(--gold-matte);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
    transition: all var(--transition);
    white-space: nowrap;
}
.guide-badge:hover {
    border-color: var(--gold-matte);
    box-shadow: 0 2px 10px rgba(234, 179, 8, 0.18);
    transform: translateY(-1px);
}
.guide-badge .guide-badge-q {
    color: #ec4899;
    font-weight: 800;
    font-size: 13px;
}

.guide-popover {
    position: absolute;
    z-index: 200;
    max-width: 340px;
    min-width: 240px;
    padding: 12px 14px;
    background: rgba(10, 16, 28, 0.98);
    border: 1px solid var(--gold-matte);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(234, 179, 8, 0.12);
    color: #e5e7eb;
    font-size: 12.5px;
    line-height: 1.55;
    backdrop-filter: blur(20px);
}
.guide-popover::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 22px;
    width: 10px;
    height: 10px;
    background: rgba(10, 16, 28, 0.98);
    border-left: 1px solid var(--gold-matte);
    border-top: 1px solid var(--gold-matte);
    transform: rotate(45deg);
}
.guide-popover-list {
    margin: 0;
    padding: 0 0 0 22px;
    list-style-type: decimal;
}
.guide-popover-list li {
    margin-bottom: 6px;
    padding-left: 2px;
}
.guide-popover-list li:last-child {
    margin-bottom: 0;
}
.guide-popover-list li::marker {
    color: var(--gold-matte);
    font-weight: 700;
}

/* Pill / rounded button used for the header Logout — keeps the chip look
   even when the rest of the header gets tight. */
.btn-pill {
    padding: 7px 18px;
    font-size: 0.82rem;
    border-radius: 999px;
    white-space: nowrap;
    line-height: 1;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.btn-icon {
    width: 32px; height: 32px; padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    background: none; border: 1px solid var(--border-color);
    color: var(--text-muted); cursor: pointer;
    transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); transform: scale(1.05); }
.btn-icon.edit:hover { color: var(--accent-primary); border-color: var(--accent-primary); }
.btn-icon.delete:hover { color: var(--accent-danger); border-color: var(--accent-danger); }

/* ═══════════════ STATUS CARDS ═══════════════ */
.status-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 20px; }

.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    transition: all var(--transition);
    animation: fadeInUp 0.5s ease both;
}
.stat-card:nth-child(1) { animation-delay: 0s; }
.stat-card:nth-child(2) { animation-delay: 0.08s; }
.stat-card:nth-child(3) { animation-delay: 0.16s; }
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 48px rgba(0,0,0,0.4);
    border-color: rgba(99, 134, 202, 0.2);
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: var(--radius-md);
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-heading); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; font-weight: 500; letter-spacing: 0.3px; }

/* ═══════════════ KPI CARDS (Client Lookup) ═══════════════ */
.risk-manager-cards .stat-card {
    padding: 18px 20px;
    border-radius: var(--radius-md);
    animation: fadeInUp 0.4s ease both;
}
.risk-manager-cards .stat-card:nth-child(1) { animation-delay: 0s; }
.risk-manager-cards .stat-card:nth-child(2) { animation-delay: 0.06s; }
.risk-manager-cards .stat-card:nth-child(3) { animation-delay: 0.12s; }
.risk-manager-cards .stat-card:nth-child(4) { animation-delay: 0.18s; }
.risk-manager-cards .stat-card:nth-child(5) { animation-delay: 0.24s; }

/* Number animation for KPI values */
.kpi-value {
    font-size: 22px;
    font-weight: 800;
    font-family: var(--font-mono);
    letter-spacing: -0.5px;
    transition: color 0.3s ease;
}
.kpi-label {
    font-size: 9px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
    margin-top: 4px;
}

/* ═══════════════ TABLES ═══════════════ */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}
.data-table thead th {
    padding: 11px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    background: rgba(12, 18, 32, 0.8);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
}
.data-table tbody td {
    padding: 10px 16px;
    border-bottom: 1px solid rgba(99,134,202,0.05);
    color: var(--text-primary);
    vertical-align: middle;
    font-weight: 400;
}
.data-table tbody tr {
    transition: background var(--transition);
    animation: rowSlideIn 0.3s ease both;
}
.data-table tbody tr:nth-child(1) { animation-delay: 0s; }
.data-table tbody tr:nth-child(2) { animation-delay: 0.02s; }
.data-table tbody tr:nth-child(3) { animation-delay: 0.04s; }
.data-table tbody tr:nth-child(4) { animation-delay: 0.06s; }
.data-table tbody tr:nth-child(5) { animation-delay: 0.08s; }
.data-table tbody tr:hover { background: rgba(6,182,212,0.03); }

.empty-row td {
    text-align: center;
    padding: 50px !important;
    color: var(--text-muted);
    font-style: normal;
    font-weight: 400;
    letter-spacing: 0.2px;
}

/* Table cell badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.badge-success { background: rgba(16,185,129,0.12); color: #34d399; }
.badge-danger  { background: rgba(239,68,68,0.12); color: #f87171; }
.badge-info    { background: rgba(6,182,212,0.12); color: #22d3ee; }
.badge-warning { background: rgba(245,158,11,0.12); color: #fbbf24; }
.badge-muted   { background: rgba(100,116,139,0.12); color: #94a3b8; }

.markup-range {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--accent-primary);
    font-weight: 500;
}

/* Cell-level PNL coloring */
.pnl-positive { color: #10b981; font-weight: 600; font-family: var(--font-mono); font-size: 0.82rem; }
.pnl-negative { color: #ef4444; font-weight: 600; font-family: var(--font-mono); font-size: 0.82rem; }
.pnl-zero     { color: var(--text-muted); font-weight: 500; font-family: var(--font-mono); font-size: 0.82rem; }

/* Monospace cells */
.cell-mono {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ═══════════════ SEARCH BAR ═══════════════ */
.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.search-bar svg { color: var(--text-muted); flex-shrink: 0; }
.search-bar input { max-width: 280px; }
.search-bar select { max-width: 200px; }

/* ═══════════════ LIVE INDICATOR ═══════════════ */
.live-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    animation: pulse-green 1.5s infinite;
    margin-right: 6px;
}

/* ═══════════════ TOGGLE SWITCH ═══════════════ */
.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 500;
}
.toggle-label input { display: none; }
.toggle-slider {
    width: 38px;
    height: 20px;
    background: var(--bg-hover);
    border-radius: 10px;
    position: relative;
    transition: var(--transition);
}
.toggle-slider::after {
    content: '';
    width: 14px; height: 14px;
    border-radius: 50%;
    background: white;
    position: absolute;
    top: 3px; left: 3px;
    transition: var(--transition);
}
.toggle-label input:checked + .toggle-slider { background: var(--accent-primary); }
.toggle-label input:checked + .toggle-slider::after { left: 21px; }

/* Table toggle */
.table-toggle {
    width: 36px; height: 20px;
    background: var(--bg-hover);
    border-radius: 10px;
    position: relative;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}
.table-toggle::after {
    content: '';
    width: 14px; height: 14px;
    border-radius: 50%;
    background: white;
    position: absolute;
    top: 3px; left: 3px;
    transition: var(--transition);
}
.table-toggle.on { background: var(--accent-success); }
.table-toggle.on::after { left: 19px; }

/* ═══════════════ CHECKBOX ═══════════════ */
.checkbox-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.checkbox-label:hover { background: rgba(255,255,255,0.02); color: var(--text-primary); }
.checkbox-label input[type="checkbox"] {
    width: 18px; height: 18px;
    accent-color: var(--accent-primary);
}

/* ════════════ LOGIN ENHANCEMENTS ════════════ */
@keyframes pulse {
    0% { opacity: 0.8; transform: scale(0.95); box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.7); }
    50% { opacity: 1; transform: scale(1.05); box-shadow: 0 0 0 10px rgba(14, 165, 233, 0); }
    100% { opacity: 0.8; transform: scale(0.95); box-shadow: 0 0 0 0 rgba(14, 165, 233, 0); }
}

@keyframes float {
    0% { transform: translateY(0px) rotate(0deg); }
    50% { transform: translateY(-20px) rotate(5deg); }
    100% { transform: translateY(0px) rotate(0deg); }
}

@keyframes blob-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.blob {
    position: absolute;
    filter: blur(80px);
    z-index: 1;
    opacity: 0.5;
    animation: blob-spin 20s infinite linear;
}

.blob-1 {
    top: -10%; left: -10%;
    width: 500px; height: 500px;
    background: rgba(234, 179, 8, 0.15);
    border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
}

.blob-2 {
    bottom: -10%; right: -10%;
    width: 600px; height: 600px;
    background: rgba(202, 138, 4, 0.12);
    border-radius: 60% 40% 30% 70% / 50% 60% 40% 50%;
    animation-direction: reverse;
}

.vivid-input:focus {
    border-color: #eab308 !important;
    box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.25) !important;
    transform: translateY(-2px);
}

.btn-vivid:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(234, 179, 8, 0.45) !important;
}

.login-box {
    animation: float 6s ease-in-out infinite;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
}

/* ═══════════════ MODAL ═══════════════ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    backdrop-filter: blur(8px);
    z-index: 200;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
.modal-overlay.open { display: flex; }

.modal {
    width: 90vw;
    max-width: 720px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    animation: slideUp 0.35s ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h3 { font-size: 1.1rem; color: var(--text-heading); font-weight: 600; }
.modal-close {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: none; border: none;
    color: var(--text-muted); font-size: 1.5rem;
    cursor: pointer; border-radius: var(--radius-sm);
    transition: var(--transition);
}
.modal-close:hover { background: rgba(239,68,68,0.1); color: var(--accent-danger); }

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-section { margin-bottom: 24px; }
.modal-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-primary);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.markup-section {
    background: rgba(6,182,212,0.03);
    border: 1px solid rgba(6,182,212,0.08);
    border-radius: var(--radius-md);
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
}

/* ═══════════════ TOAST ═══════════════ */
#toast-container {
    position: fixed;
    top: 66px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 11px 18px;
    border-radius: var(--radius-md);
    background: rgba(22, 32, 54, 0.95);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
    animation: toastIn 0.35s ease, toastOut 0.35s ease 3.65s;
    max-width: 340px;
}
.toast.success { border-left: 3px solid var(--accent-success); }
.toast.error   { border-left: 3px solid var(--accent-danger); }
.toast.info    { border-left: 3px solid var(--accent-primary); }

/* ═══════════════ LOG CONTROLS ═══════════════ */
.log-controls { display: flex; align-items: center; gap: 16px; }

/* ═══════════════ HISTORY SUMMARY BAR ═══════════════ */
.history-summary {
    font-family: var(--font-mono);
    font-size: 0.78rem !important;
    font-weight: 500;
}
.history-summary strong {
    font-weight: 700;
}

/* ═══════════════ CONNECTION PANEL ═══════════════ */
.connection-panel { max-width: 900px; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 900px) {
    /* No longer need sidebar minifying since it's hidden by default */
}
@media (max-width: 768px) {
    #main-content { padding: 16px; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .checkbox-grid { grid-template-columns: 1fr; }
    .modal { width: 95vw; max-height: 90vh; }
    .search-bar { flex-direction: column; align-items: stretch; }
    .search-bar input, .search-bar select { max-width: none; }
    .risk-manager-cards { flex-wrap: wrap !important; }
}

/* ═══════════════ SCROLLBAR ═══════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(74, 90, 116, 0.3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(74, 90, 116, 0.5); }

/* ═══════════════ SELECTION ═══════════════ */
::selection { background: rgba(6,182,212,0.25); color: white; }

/* ═══════════════ CUSTOM MULTI-SELECT DROPDOWN ═══════════════ */
.multi-select-wrap {
    position: relative;
}
.multi-select-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: border-color 0.2s;
    min-height: 36px;
    user-select: none;
}
.multi-select-display:hover,
.multi-select-display:focus {
    border-color: var(--border-focus);
    outline: none;
}
.multi-select-display span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.multi-select-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border-focus);
    border-radius: 8px;
    z-index: 1000;
    max-height: 220px;
    overflow-y: auto;
    padding: 6px 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    animation: dropdownSlide 0.15s ease-out;
}
@keyframes dropdownSlide {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.multi-select-dropdown.open {
    display: block;
}
.multi-select-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-primary);
    transition: background 0.15s;
}
.multi-select-item:hover {
    background: var(--bg-hover);
}
.multi-select-item input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* ═══════════════ DRAG & DROP REORDERING ═══════════════ */
.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    text-align: center;
    width: 30px;
    transition: color 0.2s;
}
.drag-handle:active {
    cursor: grabbing;
}
tr.draggable-row:hover .drag-handle {
    color: var(--text-primary);
}
tr.draggable-row.dragging {
    opacity: 0.4;
    background-color: var(--bg-hover) !important;
}
tr.draggable-row.drag-over {
    border-top: 2px solid var(--accent-primary);
}

/* ═══════════════ DEAL DETAILS MODAL ═══════════════ */
.deal-modal {
    max-width: 800px;
    padding: 0;
    overflow: hidden;
    background: #ffffff; /* Typically light for this kind of detailed view, but let's keep it dark to match theme */
    background: var(--bg-secondary);
}
.deal-modal .modal-header {
    background: rgba(0,0,0,0.2);
    padding: 15px 20px;
    margin: 0;
    border-bottom: 1px solid var(--border-color);
}
.deal-modal .modal-header h2 {
    font-size: 0.9rem;
    color: var(--text-muted);
}
.deal-section {
    padding: 5px 20px 15px 20px;
    border-bottom: 1px solid var(--border-color);
}
.deal-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 12px;
    margin-top: 15px;
}
.deal-grid {
    display: flex;
    gap: 40px;
}
.deal-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.deal-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-primary);
}
.deal-row span:first-child {
    color: var(--text-muted);
}
.deal-highlight {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent-primary);
    padding: 2px 6px;
    border-radius: 4px;
}
.text-primary { color: var(--accent-primary); }
.text-muted { color: var(--text-muted); }
.deal-modal .modal-footer {
    background: rgba(0,0,0,0.1);
    padding: 15px 20px;
}

@keyframes value-flash {
    0% { background-color: rgba(255, 215, 0, 0.3); color: #fff; border-radius: 4px; }
    100% { background-color: transparent; }
}
.value-updated {
    animation: value-flash 1s ease-out;
}

/* ═══════════════════════════════════════════════════════════
   THEME OVERLAY — Matte gold borders, gradient text, background pattern
   Appended at end so it cascades over the original rules.
   ═══════════════════════════════════════════════════════════ */

:root {
    --gold-matte:    #b8860b;
    --gold-deep:     #8a6311;
    --gold-light:    #d4af37;
    --gold-bright:   #fcd34d;
    --gold-amber:    #f59e0b;

    --border-color:  rgba(184, 134, 11, 0.32);
    --border-strong: rgba(212, 175, 55, 0.55);
    --border-focus:  rgba(252, 211, 77, 0.7);

    --gradient-text:  linear-gradient(135deg, #fcd34d 0%, #eab308 45%, #d4af37 80%, #b8860b 100%);
    --gradient-gold:  linear-gradient(135deg, #fcd34d 0%, #eab308 35%, #b8860b 65%, #d4af37 100%);
    --gradient-faint: linear-gradient(135deg, rgba(252,211,77,0.95), rgba(184,134,11,0.95));
}

/* ─── Background template — subtle gold diamond grid + warm gold ambient ─── */
body {
    background-color: #0a0a0c;
    background-image:
        radial-gradient(ellipse 100% 60% at 50% -10%, rgba(212, 175, 55, 0.07) 0%, transparent 60%),
        radial-gradient(ellipse 70% 45% at 0% 100%,   rgba(184, 134, 11, 0.05) 0%, transparent 60%),
        radial-gradient(ellipse 70% 45% at 100% 100%, rgba(212, 175, 55, 0.04) 0%, transparent 60%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'><g fill='none' stroke='%23d4af37' stroke-opacity='0.06' stroke-width='1'><path d='M22 4 L40 22 L22 40 L4 22 Z'/></g></svg>");
    background-attachment: fixed;
    background-size: auto, auto, auto, 44px 44px;
    background-repeat: no-repeat, no-repeat, no-repeat, repeat;
}

/* ─── Gradient text on all headings, brand, KPIs, and emphasized labels ─── */
h1, h2, h3,
.panel-header h2,
.modal-header h3,
.modal-header h2,
.kpi-value,
.kpi-label,
.brand-4x,
.brand-name,
.sidebar-section-label,
#user-display,
#status-text,
#sidebar-status-text,
#stat-processed,
#stat-markup,
#sidebar-stat-processed,
#sidebar-stat-markup,
.history-summary strong {
    background: var(--gradient-text);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent !important;
}

/* Login page title (inline-coloured in HTML — needs explicit gradient) */
#login-page h2,
#login-page h2 span {
    background: var(--gradient-text);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent !important;
}

/* Deal-modal yellow values (Account Name) stay golden gradient too */
#deal-account-name,
#deal-name {
    background: var(--gradient-text);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* ─── Matte golden borders on every surface ─── */
.panel,
.glass-panel,
.modal,
.stat-card {
    border: 1px solid var(--border-color);
}

.glass-panel,
.panel {
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.62),
        0 1px 0 rgba(252, 211, 77, 0.08) inset;
}

.stat-card:hover,
.glass-panel.stat-card:hover {
    border-color: var(--border-strong);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.65),
        0 0 22px rgba(212, 175, 55, 0.18);
}

#app-sidebar {
    border-right: 1px solid var(--border-color);
}

#app-header {
    border-bottom: 1px solid var(--border-color);
}

.sidebar-divider {
    background: linear-gradient(90deg, transparent, var(--border-strong), transparent);
    height: 1px;
}

/* Active nav button — golden left edge + warm gradient wash */
.nav-btn.active {
    background: linear-gradient(90deg, rgba(212, 175, 55, 0.18), rgba(212, 175, 55, 0.04));
    border-left: 3px solid var(--gold-matte);
}

/* Inputs / selects / textareas — matte gold border + warm focus glow */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
select,
textarea {
    border: 1px solid var(--border-color) !important;
    transition: border-color var(--transition), box-shadow var(--transition);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
select:focus,
textarea:focus {
    border-color: var(--gold-matte) !important;
    box-shadow: 0 0 0 3px rgba(184, 134, 11, 0.18) !important;
    outline: none;
}

/* Tables — gold underline + warm row hover */
.data-table thead th {
    border-bottom: 2px solid var(--border-strong);
}

.data-table tbody tr:hover {
    background: rgba(212, 175, 55, 0.045);
}

/* Buttons — primary becomes a polished gold pill */
.btn-primary,
.btn.btn-primary,
.btn-vivid {
    background: var(--gradient-gold) !important;
    color: #09090b !important;
    border: 1px solid var(--gold-matte) !important;
    font-weight: 700 !important;
    transition: filter var(--transition), box-shadow var(--transition), transform var(--transition);
}

.btn-primary:hover,
.btn.btn-primary:hover,
.btn-vivid:hover {
    filter: brightness(1.08);
    box-shadow: 0 0 22px rgba(212, 175, 55, 0.45);
    transform: translateY(-1px);
}

.btn-secondary,
.btn.btn-secondary {
    border: 1px solid var(--border-color) !important;
    transition: border-color var(--transition), color var(--transition);
}

.btn-secondary:hover,
.btn.btn-secondary:hover {
    border-color: var(--gold-matte) !important;
}

/* Connection / sidebar status pills */
#status-badge,
#sidebar-status {
    border: 1px solid var(--border-color);
}

/* History summary footer bar */
.history-summary {
    border: 1px solid var(--border-color);
}

/* Modal overlays — slightly stronger glow ring */
.modal-overlay.open .modal,
.modal-overlay.open > .modal {
    box-shadow:
        0 14px 60px rgba(0, 0, 0, 0.7),
        0 0 0 1px var(--border-strong);
}

/* Login card — emphasised matte gold frame */
#login-page > div {
    border: 1px solid var(--border-color);
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.75),
        0 0 0 1px var(--border-strong),
        0 0 60px rgba(212, 175, 55, 0.08);
}

/* Tab panel section headers and reports labels stay readable but tinted */
.sidebar-section-label {
    letter-spacing: 1.4px;
    font-weight: 600;
}

/* Yellow accents in the HTML (inline style="color:#eab308") get upgraded to gradient */
span[style*="#eab308"],
strong[style*="#eab308"],
[style*="color:#eab308"],
[style*="color: #eab308"] {
    background: var(--gradient-text);
    -webkit-background-clip: text;
            background-clip: text;
    -webkit-text-fill-color: transparent !important;
}

/* ─── Full-screen layout — main content stretches edge-to-edge of the viewport ─── */
#main-content {
    max-width: none !important;
    margin: 0 !important;
    width: 100%;
    padding: 24px 32px;
}

/* ─── Sidebar user profile block (DarkPan-style avatar at top) ─── */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    margin: 8px 12px 14px 12px;
    background: rgba(212, 175, 55, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--gradient-gold);
    color: #09090b;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.15);
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 13px;
    font-weight: 600;
    color: #f4f4f5;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-user-role {
    font-size: 11px;
    color: var(--gold-matte);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* Small inline-text action under the user role (e.g., Change Password) —
   only shown for SuperAdmin. Uses the gold accent so it reads as a link
   without competing with the bigger Logout pill in the header. */
.sidebar-user-action {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: var(--gold-matte);
    text-decoration: none;
    border-bottom: 1px dotted rgba(234,179,8,0.4);
    cursor: pointer;
    transition: color var(--transition);
}
.sidebar-user-action:hover {
    color: #facc15;
    border-bottom-color: #facc15;
}

/* ─── Dashboard KPI cards (DarkPan-style) ─── */
.dash-kpi-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.dash-kpi-card {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 20px;
    background: var(--glass-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
    transition: border-color 0.25s, transform 0.25s, box-shadow 0.25s;
}

.dash-kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
    box-shadow:
        0 12px 36px rgba(0, 0, 0, 0.6),
        0 0 22px rgba(212, 175, 55, 0.15);
}

.dash-kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-kpi-body {
    flex: 1;
    min-width: 0;
}

.dash-kpi-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.dash-kpi-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
    background: var(--gradient-text);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

/* ─── Recent Slippage Applied — scrollable container with sticky header ─── */
.dash-recent-scroll {
    max-height: 600px;
    overflow-y: auto;
    position: relative;
}

.dash-recent-scroll .data-table thead th {
    position: sticky;
    top: 0;
    background: #18181b;
    z-index: 5;
    border-bottom: 2px solid var(--border-strong);
}

/* Custom scrollbar that matches the gold theme */
.dash-recent-scroll::-webkit-scrollbar {
    width: 8px;
}
.dash-recent-scroll::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}
.dash-recent-scroll::-webkit-scrollbar-thumb {
    background: var(--gold-matte);
    border-radius: 4px;
}
.dash-recent-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--gold-light);
}

/* ─── Two-up chart row (Dashboard + Charts tab) ─── */
.dash-chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 1100px) {
    .dash-kpi-row { grid-template-columns: repeat(2, 1fr); }
    .dash-chart-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .dash-kpi-row { grid-template-columns: 1fr; }
}

/* ─── Rule editor modal — extra breathing room (was congested) ─── */
#rule-modal .modal-body {
    padding: 28px 32px;
}

#rule-modal .modal-section {
    margin-bottom: 32px;
    padding-bottom: 10px;
}

#rule-modal .form-grid-2,
#rule-modal .form-grid-3 {
    gap: 22px;
    margin-bottom: 18px !important;
}

#rule-modal .form-group {
    gap: 8px;
    margin-bottom: 4px;
}

#rule-modal .form-group label {
    margin-bottom: 2px;
}

#rule-modal .markup-section,
#rule-modal .modal-section.markup-section {
    padding: 22px 24px 18px 24px;
    border-radius: 10px;
    background: rgba(212, 175, 55, 0.025);
    border: 1px solid var(--border-color);
}

/* ════════════════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON — header pill, shows the icon you'd switch TO
   ════════════════════════════════════════════════════════════════════ */
#theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    padding: 0;
    margin-left: 10px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--gold-matte, #b8860b);
    color: var(--gold-matte, #b8860b);
    cursor: pointer;
    transition: all var(--transition);
}
#theme-toggle:hover {
    background: rgba(234, 179, 8, 0.12);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(234, 179, 8, 0.18);
}
/* In dark mode: show the sun (clicking → switch to light) */
html[data-theme="dark"]  #theme-toggle .theme-icon-moon { display: none; }
html[data-theme="dark"]  #theme-toggle .theme-icon-sun  { display: block; }
/* In light mode: show the moon (clicking → switch to dark) */
html[data-theme="light"] #theme-toggle .theme-icon-sun  { display: none; }
html[data-theme="light"] #theme-toggle .theme-icon-moon { display: block; }

/* ════════════════════════════════════════════════════════════════════
   LIGHT THEME
   Every visual layer (backgrounds, borders, text, glass panels, tables,
   inputs, badges, modals, sidebar, header) is flipped to a high-contrast
   white-and-gold palette. Goal: every label and every column readable
   without any guesswork.
   ════════════════════════════════════════════════════════════════════ */
html[data-theme="light"] {
    --bg-primary:    #f4f4f5;
    --bg-secondary:  #ffffff;
    --bg-surface:    #ffffff;
    --bg-elevated:   #fafafa;
    --bg-hover:      #f3f4f6;

    --border-color:  rgba(0, 0, 0, 0.10);
    --border-focus:  rgba(180, 83, 9, 0.45);
    --border-strong: rgba(0, 0, 0, 0.18);

    --text-primary:   #111113;
    --text-secondary: #3f3f46;
    --text-muted:     #52525b;
    --text-heading:   #111113;

    --accent-primary:   #b45309; /* darker gold for AA contrast on white */
    --accent-secondary: #92400e;

    --glass-bg:     rgba(255, 255, 255, 0.94);
    --glass-border: rgba(180, 83, 9, 0.18);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);

    --gradient-primary: linear-gradient(135deg, #b45309, #92400e);
    --gradient-text:    linear-gradient(135deg, #92400e 0%, #b45309 100%);
    --gradient-gold:    linear-gradient(135deg, #92400e 0%, #b45309 50%, #ca8a04 100%);
    --gradient-faint:   linear-gradient(135deg, rgba(180,83,9,0.95), rgba(146,64,14,0.95));

    --gold-matte: #92400e;
}

/* Body background: warm off-white + subtle gold diamond pattern (mirrors
   the dark layout but tuned for white). */
html[data-theme="light"] body {
    background-color: #f6f6f7;
    background-image:
        radial-gradient(ellipse 100% 60% at 50% -10%, rgba(180, 83, 9, 0.06)  0%, transparent 60%),
        radial-gradient(ellipse 70% 45%  at 0% 100%, rgba(146, 64, 14, 0.04)  0%, transparent 60%),
        radial-gradient(ellipse 70% 45%  at 100% 100%, rgba(180, 83, 9, 0.04) 0%, transparent 60%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='44' viewBox='0 0 44 44'><g fill='none' stroke='%23b45309' stroke-opacity='0.06' stroke-width='1'><path d='M22 4 L40 22 L22 40 L4 22 Z'/></g></svg>");
    color: var(--text-primary);
}

/* Login page — the inline <div> has a hard-coded dark background; override. */
html[data-theme="light"] #login-page { background: #f6f6f7 !important; }

/* Header */
html[data-theme="light"] #app-header {
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .header-right #user-display { color: #52525b; }

/* Sidebar */
html[data-theme="light"] #app-sidebar {
    background: #ffffff;
    border-right: 1px solid rgba(0, 0, 0, 0.08);
}
html[data-theme="light"] .sidebar-user      { background: #fafafa; border-color: rgba(0,0,0,0.08); }
html[data-theme="light"] .sidebar-user-name { color: #18181b; }
html[data-theme="light"] .sidebar-divider   {
    background: linear-gradient(90deg, transparent, rgba(0,0,0,0.12), transparent);
}
html[data-theme="light"] .nav-btn {
    color: #3f3f46;
}
html[data-theme="light"] .nav-btn:hover {
    background: rgba(180, 83, 9, 0.06);
    color: #111113;
}
html[data-theme="light"] .nav-btn.active {
    background: linear-gradient(90deg, rgba(180, 83, 9, 0.12), rgba(180, 83, 9, 0.03));
    color: #111113;
    border-left-color: #b45309;
}

/* Glass panels (cards, modals body) — switch from semi-transparent dark
   to semi-transparent white. */
html[data-theme="light"] .glass-panel,
html[data-theme="light"] .panel {
    background: #ffffff;
    border: 1px solid rgba(180, 83, 9, 0.14);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}

/* Headings — the gradient-text rule fills h1/h2/h3 with the gold gradient.
   On white that already works because we changed the gradient to darker
   shades above. Just give them a fallback color for browsers without
   background-clip:text. */
html[data-theme="light"] h1,
html[data-theme="light"] h2,
html[data-theme="light"] h3,
html[data-theme="light"] .panel-header h2,
html[data-theme="light"] .modal-header h3,
html[data-theme="light"] .modal-header h2,
html[data-theme="light"] .kpi-value,
html[data-theme="light"] .kpi-label,
html[data-theme="light"] .brand-name {
    color: #92400e; /* fallback when background-clip:text unsupported */
}
/* Inside the brand: "4X" stays gold, "Backoffice" goes near-black on light */
html[data-theme="light"] .brand-name { color: #111113; -webkit-text-fill-color: #111113; background: none; }

/* Form inputs */
html[data-theme="light"] input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html[data-theme="light"] select,
html[data-theme="light"] textarea {
    background: #ffffff !important;
    color: #111113 !important;
    border: 1px solid rgba(0, 0, 0, 0.18) !important;
}
html[data-theme="light"] input:focus,
html[data-theme="light"] select:focus,
html[data-theme="light"] textarea:focus {
    border-color: #b45309 !important;
    box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.15) !important;
}
html[data-theme="light"] input::placeholder { color: #9ca3af; }

/* Tables — strong contrast for every row + column header */
html[data-theme="light"] .data-table thead th {
    background: #f9fafb;
    color: #111113;
    border-bottom: 2px solid rgba(0, 0, 0, 0.12);
    font-weight: 700;
}
html[data-theme="light"] .data-table tbody td {
    color: #18181b;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}
html[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(180, 83, 9, 0.04);
}
html[data-theme="light"] .data-table .empty-row td {
    color: #71717a;
}
/* Sticky header used in dashboard "Recent Slippage" scrollable table */
html[data-theme="light"] .dash-recent-scroll .data-table thead th {
    background: #f9fafb;
}

/* History filter summary chip */
html[data-theme="light"] .history-summary {
    background: rgba(0, 0, 0, 0.04) !important;
    color: #111113;
}
html[data-theme="light"] .history-summary strong {
    color: #92400e;
    -webkit-text-fill-color: #92400e;
    background: none;
}

/* Modal */
html[data-theme="light"] .modal-overlay { background: rgba(0, 0, 0, 0.45); }
html[data-theme="light"] .modal {
    background: #ffffff;
    border: 1px solid rgba(180, 83, 9, 0.25);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.15);
}
html[data-theme="light"] .modal-header,
html[data-theme="light"] .modal-footer {
    border-color: rgba(0, 0, 0, 0.08);
}

/* Status badges — keep the colour-coding readable on white by darkening
   each badge background slightly. */
html[data-theme="light"] .badge { color: #ffffff; }
html[data-theme="light"] .badge-info    { background: #2563eb; }
html[data-theme="light"] .badge-success { background: #059669; }
html[data-theme="light"] .badge-warning { background: #d97706; }
html[data-theme="light"] .badge-danger  { background: #dc2626; }
html[data-theme="light"] .badge-muted   { background: #64748b; }

/* Header pill — "Connected" status */
html[data-theme="light"] .status-badge {
    background: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.08);
    color: #111113;
}
html[data-theme="light"] #status-text,
html[data-theme="light"] .status-badge span {
    color: #111113;
    -webkit-text-fill-color: #111113;
    background: none;
}

/* Guide popover */
html[data-theme="light"] .guide-popover {
    background: #ffffff;
    color: #111113;
    border: 1px solid #b45309;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}
html[data-theme="light"] .guide-popover::before { background: #ffffff; border-color: #b45309; }
html[data-theme="light"] .guide-badge {
    background: #ffffff;
    border-color: rgba(180, 83, 9, 0.4);
    color: #92400e;
}

/* Toasts */
html[data-theme="light"] .toast { color: #ffffff; }

/* Secondary buttons */
html[data-theme="light"] .btn-secondary {
    background: #f9fafb;
    color: #111113;
    border: 1px solid rgba(0, 0, 0, 0.18);
}
html[data-theme="light"] .btn-secondary:hover {
    background: #f3f4f6;
}

/* Avatar */
html[data-theme="light"] .sidebar-user-avatar {
    color: #ffffff;
}

/* Toggle switch on rules table — make sure both states are visible */
html[data-theme="light"] .table-toggle {
    background: #d4d4d8;
}
html[data-theme="light"] .table-toggle.on {
    background: #059669;
}

/* Code-style monospace IDs (User Management table) */
html[data-theme="light"] code { color: #92400e; }

