:root {
    --bg-base: #060b16;
    --bg-surface: #0d1526;
    --bg-card: rgba(15, 24, 44, 0.86);
    --bg-card-hover: rgba(21, 33, 59, 0.95);
    --border-subtle: rgba(148, 163, 184, 0.12);
    --border-accent: rgba(56, 189, 248, 0.35);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-cyan: #38bdf8;
    --accent-indigo: #6366f1;
    --emerald: #10b981;
    --emerald-bg: rgba(16, 185, 129, 0.14);
    --amber: #f59e0b;
    --amber-bg: rgba(245, 158, 11, 0.15);
    --rose: #f43f5e;
    --rose-bg: rgba(244, 63, 94, 0.15);
    --radius-lg: 18px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background-color: var(--bg-base);
    background-image:
        radial-gradient(circle at 12% 8%, rgba(56, 189, 248, 0.09) 0%, transparent 38%),
        radial-gradient(circle at 88% 15%, rgba(99, 102, 241, 0.09) 0%, transparent 40%);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

.mono { font-family: var(--font-mono); }
.text-emerald { color: var(--emerald) !important; }
.text-rose { color: var(--rose) !important; }
.text-amber { color: var(--amber) !important; }
.text-cyan { color: var(--accent-cyan) !important; }
.text-muted { color: var(--text-secondary); }

/* ================= LAYOUT DESKTOP (SIDEBAR FIX STANGA + SCROLL DOAR DREAPTA) + MOBILE ================= */
.app-shell {
    display: grid;
    grid-template-columns: 256px 1fr;
    height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.sidebar {
    background: rgba(10, 17, 32, 0.96);
    border-right: 1px solid var(--border-subtle);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    backdrop-filter: blur(18px);
    z-index: 30;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 8px 22px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 18px;
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent-cyan), var(--accent-indigo));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 18px;
    color: #fff;
    box-shadow: 0 8px 20px rgba(56, 189, 248, 0.28);
    flex-shrink: 0;
}

.brand-title {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 11px;
    color: var(--accent-cyan);
    font-weight: 600;
}

.nav-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 11px 14px;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.18s ease;
    text-align: left;
}

.nav-btn:hover {
    background: rgba(148, 163, 184, 0.07);
    color: var(--text-primary);
}

.nav-btn.active {
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.16), rgba(99, 102, 241, 0.16));
    border-color: var(--border-accent);
    color: #fff;
}

.sidebar-footer {
    border-top: 1px solid var(--border-subtle);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.shield-pill {
    background: var(--emerald-bg);
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 11.5px;
    color: #a7f3d0;
}

.main-area {
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 64px;
}

/* ================= TOPBAR ================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 25;
    background: rgba(6, 11, 22, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.status-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.badge-paper {
    background: var(--amber-bg);
    color: #fbbf24;
    border-color: rgba(245, 158, 11, 0.35);
}

.badge-live {
    background: var(--rose-bg);
    color: #fb7185;
    border-color: rgba(244, 63, 94, 0.4);
}

.badge-ok {
    background: var(--emerald-bg);
    color: #34d399;
    border-color: rgba(16, 185, 129, 0.35);
}

.badge-neutral {
    background: rgba(148, 163, 184, 0.1);
    color: #cbd5e1;
    border-color: var(--border-subtle);
}

.dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.dot.pulse {
    animation: pulseAnim 1.8s infinite;
}

@keyframes pulseAnim {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.85); }
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ================= BUTTONS & INPUTS ================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 15px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.16s ease;
    font-family: inherit;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #0ea5e9, #4f46e5);
    color: #fff;
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.25);
}

.btn-primary:hover:not(:disabled) {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

.btn-emerald {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.45);
    color: #34d399;
}

.btn-emerald:hover:not(:disabled) {
    background: rgba(16, 185, 129, 0.28);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.16);
    border-color: rgba(244, 63, 94, 0.45);
    color: #fb7185;
}

.btn-danger:hover:not(:disabled) {
    background: rgba(244, 63, 94, 0.28);
}

.btn-ghost {
    background: rgba(148, 163, 184, 0.08);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.btn-ghost:hover:not(:disabled) {
    background: rgba(148, 163, 184, 0.15);
}

.btn-sm {
    padding: 6px 10px;
    font-size: 12px;
}

.content-wrap {
    padding: 22px 24px;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}

.tab-pane {
    display: none;
    animation: fadeIn 0.2s ease;
}

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

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

/* ================= KPI CARDS & GRIDS ================= */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    backdrop-filter: blur(12px);
    min-width: 0;
    max-width: 100%;
}

.mobile-brand-bar {
    display: none;
}

.sidebar-overlay {
    display: none;
}

.sidebar-close-btn {
    display: none;
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid var(--border-subtle);
    color: #fff;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    font-size: 16px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dash-burger-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4.5px;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.1);
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
}

.dash-burger-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: #f8fafc;
    border-radius: 2px;
    transition: transform 0.22s ease, opacity 0.18s ease;
}

.dash-burger-btn.open span:nth-child(1) { transform: translateY(6.5px) rotate(45deg); }
.dash-burger-btn.open span:nth-child(2) { opacity: 0; }
.dash-burger-btn.open span:nth-child(3) { transform: translateY(-6.5px) rotate(-45deg); }

.pillar-strip-card {
    margin-bottom: 20px;
    padding: 14px 18px;
    border: 1px solid rgba(56, 189, 248, 0.22);
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.92), rgba(17, 24, 39, 0.88));
}

.pillar-strip-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.pillar-badges-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 12.5px;
    min-width: 0;
}

.action-btn-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-save-all {
    padding: 12px 24px;
    font-size: 14px;
}

.radar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 12px;
}

.radar-grid > *,
.kpi-grid > *,
.grid-2 > *,
.grid-equal > *,
.form-grid > * {
    min-width: 0;
    max-width: 100%;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.kpi-value {
    font-size: 23px;
    font-weight: 800;
    font-family: var(--font-mono);
    letter-spacing: -0.03em;
}

.kpi-sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1.65fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.grid-equal {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chart-box {
    position: relative;
    height: 280px;
    width: 100%;
}

.period-tabs {
    display: inline-flex;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.period-btn {
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 700;
    padding: 5px 10px;
    border-radius: 6px;
    cursor: pointer;
}

.period-btn.active {
    background: rgba(56, 189, 248, 0.2);
    color: var(--accent-cyan);
}

/* ================= TABLES & RESPONSIVE CARDS ================= */
.table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

td {
    padding: 12px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.07);
    vertical-align: middle;
}

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

/* ================= FORMS ================= */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.trade-ticket-grid {
    grid-template-columns: repeat(4, 1fr);
    align-items: end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    max-width: 100%;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    font-size: 12px;
    font-weight: 600;
    color: #cbd5e1;
}

input, select, textarea {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    background: rgba(9, 14, 28, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: inherit;
    outline: none;
    text-overflow: ellipsis;
    transition: border-color 0.16s ease;
}

code, #vaultDiagnosticsBox {
    overflow-wrap: anywhere;
    word-break: break-word;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.14);
}

/* ================= AI REASONING FEED ================= */
.ai-log-item {
    background: rgba(9, 15, 29, 0.72);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 10px;
}

.ai-log-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.quant-chips {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.q-chip {
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid var(--border-subtle);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: #cbd5e1;
}

/* ================= ALERTS & TOAST ================= */
.banner-warn {
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.38);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    margin-bottom: 18px;
    color: #fde68a;
    font-size: 13px;
}

.toast-container {
    position: fixed;
    top: 18px;
    right: 18px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}

.toast {
    background: #0f172a;
    border: 1px solid var(--border-accent);
    color: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
    font-size: 13px;
}

/* ================= MOBILE BOTTOM NAV ================= */
.mobile-nav {
    display: none;
}

/* ================= RESPONSIVE TABLET & MOBILE BREAKPOINTS ================= */
@media (max-width: 1180px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .grid-2 {
        grid-template-columns: 1fr;
    }
    .trade-ticket-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
        height: auto;
        max-height: none;
        overflow: visible;
    }
    .sidebar {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 284px;
        max-width: 84vw;
        height: 100dvh;
        z-index: 100;
        background: rgba(8, 14, 28, 0.99);
        border-right: 1px solid var(--border-accent);
        box-shadow: 18px 0 48px rgba(0, 0, 0, 0.75);
        transform: translateX(-105%);
        transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-close-btn {
        display: inline-flex;
    }
    .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(2, 6, 16, 0.72);
        backdrop-filter: blur(4px);
        z-index: 90;
        display: none;
    }
    .sidebar-overlay.open {
        display: block;
    }
    .mobile-brand-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 14px;
        background: rgba(8, 13, 26, 0.96);
        border-bottom: 1px solid var(--border-subtle);
        position: sticky;
        top: 0;
        z-index: 35;
        backdrop-filter: blur(16px);
    }
    .main-area {
        height: auto;
        overflow-y: visible;
        overflow-x: hidden;
        padding-bottom: 86px;
    }
    .topbar {
        position: relative;
        top: auto;
        padding: 12px 14px;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .status-strip {
        width: 100%;
        justify-content: flex-start;
        gap: 6px;
    }
    .topbar-actions {
        display: grid;
        grid-template-columns: 1fr 1fr auto;
        width: 100%;
        gap: 8px;
    }
    .grid-2, .grid-equal, .form-grid, .trade-ticket-grid {
        grid-template-columns: 1fr;
    }
    .content-wrap {
        padding: 14px 12px;
    }
    .kpi-value {
        font-size: 20px;
    }
    .mobile-nav {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(8, 13, 26, 0.97);
        backdrop-filter: blur(18px);
        border-top: 1px solid var(--border-subtle);
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
        z-index: 50;
    }
    .mob-btn {
        background: transparent;
        border: none;
        color: var(--text-secondary);
        padding: 6px 2px;
        border-radius: 10px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        font-size: 10px;
        font-weight: 700;
        cursor: pointer;
        min-width: 0;
    }
    .mob-btn.active {
        color: var(--accent-cyan);
        background: rgba(56, 189, 248, 0.12);
    }
}

@media (max-width: 580px) {
    .kpi-grid {
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 14px;
    }
    .radar-grid {
        grid-template-columns: 1fr;
    }
    .topbar-actions {
        grid-template-columns: 1fr 1fr;
    }
    #btnQuickScan {
        grid-column: 1 / -1;
    }
    .card {
        padding: 14px 13px;
        border-radius: 14px;
    }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .period-tabs {
        width: 100%;
        justify-content: space-between;
    }
    .period-btn {
        flex: 1;
        text-align: center;
        padding: 6px 4px;
    }
    .chart-box {
        height: 220px;
    }
    .pillar-strip-card {
        padding: 12px;
    }
    .pillar-badges-wrap {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 6px;
    }
    .badge {
        white-space: normal;
        line-height: 1.35;
        border-radius: 10px;
        justify-content: flex-start;
    }
    .btn {
        white-space: normal;
        text-align: center;
        line-height: 1.3;
    }
    .action-btn-row {
        flex-direction: column;
        width: 100%;
    }
    .action-btn-row .btn,
    .btn-save-all,
    #killSwitchBox,
    #btnResetKillSwitch {
        width: 100%;
    }
    input, select, textarea {
        font-size: 16px; /* Previne zoom-ul automat nedorit pe iOS Safari / Chrome Mobile */
        padding: 10px;
    }
    th, td {
        padding: 9px 8px;
        font-size: 12px;
    }
    .toast-container {
        top: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
    }
}
