/* ===================== AMIS INSIGHT — EXECUTIVE THEME ===================== */
:root {
    --navy: #0A2540;
    --navy-2: #0E2F52;
    --navy-deep: #061a2e;
    --gold: #C9A227;
    --gold-soft: #E8D9A0;
    --teal: #1C7C70;
    --bg: #F4F6FB;
    --surface: #FFFFFF;
    --border: #E3E8F0;
    --text: #0A2540;
    --muted: #5A7089;
    --success: #1C7C70;
    --warning: #E08A00;
    --danger: #C62828;
    --shadow-sm: 0 1px 3px rgba(10,37,64,.06);
    --shadow: 0 4px 20px rgba(10,37,64,.08);
    --shadow-lg: 0 10px 40px rgba(10,37,64,.12);
    --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    direction: rtl;
}

/* ===================== LAYOUT ===================== */
.ins-layout { display: flex; min-height: 100vh; }

/* ===================== SIDEBAR ===================== */
.ins-sidebar {
    width: 248px;
    background: linear-gradient(180deg, var(--navy) 0%, var(--navy-deep) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width .25s ease;
    box-shadow: 4px 0 24px rgba(10,37,64,.18);
    z-index: 50;
}
.ins-sidebar.collapsed { width: 76px; }

.ins-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
    width: 40px; height: 40px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--gold) 0%, #b8901f 100%);
    border-radius: 11px;
    display: grid; place-items: center;
    font-weight: 900; font-size: 22px; color: var(--navy);
    box-shadow: 0 4px 14px rgba(201,162,39,.4);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.brand-sub { font-size: 12px; color: var(--gold-soft); font-weight: 600; }

/* NAV — scrolls inside the sidebar so items never overflow past the navy background (short/responsive viewports) */
.ins-nav { padding: 14px 12px; flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 4px; }
.ins-nav::-webkit-scrollbar { width: 6px; }
.ins-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.16); border-radius: 3px; }
.ins-nav::-webkit-scrollbar-track { background: transparent; }
.ins-nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.16) transparent; }
.ins-nav-section {
    font-size: 10px; color: #6f8fb0; padding: 8px 12px 6px;
    text-transform: uppercase; letter-spacing: 1.5px; font-weight: 700;
}
.ins-nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: 11px;
    color: #c3d4e8; text-decoration: none; font-size: 14px; font-weight: 600;
    transition: all .18s ease; position: relative;
}
.ins-nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.ins-nav-item.active {
    background: linear-gradient(135deg, rgba(201,162,39,.22), rgba(201,162,39,.08));
    color: var(--gold-soft);
}
.ins-nav-item.active::before {
    content: ''; position: absolute; right: 0; top: 20%; bottom: 20%;
    width: 3px; border-radius: 3px; background: var(--gold);
}
.ins-nav-icon { font-size: 19px; width: 24px; text-align: center; flex-shrink: 0; }
.ins-nav-label { white-space: nowrap; }

/* Highlighted "develop the system" promo nav item */
.ins-nav-promo { margin-top: 10px; background: linear-gradient(135deg, rgba(201,162,39,.22), rgba(201,162,39,.10)); color: var(--gold-soft); border: 1px solid rgba(201,162,39,.4); }
.ins-nav-promo:hover { background: linear-gradient(135deg, rgba(201,162,39,.34), rgba(201,162,39,.16)); color: #fff; }
.ins-nav-promo .ins-nav-icon { color: var(--gold); }

/* ===== Permissions: disabled (locked) nav items ===== */
.ins-nav-item.disabled { opacity: .42; cursor: not-allowed; color: #8aa0bb; pointer-events: auto; }
.ins-nav-item.disabled:hover { background: transparent; color: #8aa0bb; }
.ins-nav-lock { margin-inline-start: auto; font-size: 11px; opacity: .85; }
.ins-sidebar.collapsed .ins-nav-item.disabled .ins-nav-lock {
    position: absolute; bottom: 5px; inset-inline-end: 7px; margin: 0; font-size: 9px;
}

/* ===== Permissions: full-page "no access" panel ===== */
.access-locked { display: grid; place-items: center; min-height: 62vh; padding: 30px; }
.access-locked-card {
    text-align: center; max-width: 460px; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius); padding: 42px 32px; box-shadow: var(--shadow);
}
.access-locked-icon {
    width: 74px; height: 74px; margin: 0 auto 18px; border-radius: 50%;
    display: grid; place-items: center; background: #FDECEC; color: var(--danger); font-size: 30px;
}
.access-locked-card h2 { font-size: 19px; font-weight: 900; color: var(--navy); margin: 0 0 8px; }
.access-locked-card p { color: var(--muted); font-size: 14px; line-height: 1.7; margin: 0 0 20px; }
.access-locked-btn {
    display: inline-flex; gap: 8px; align-items: center; background: var(--navy); color: #fff;
    padding: 10px 18px; border-radius: 10px; text-decoration: none; font-weight: 800; font-size: 13px;
}
.access-locked-btn:hover { filter: brightness(1.1); }

/* ===== Permissions: "cash hidden" lock placeholder (financial gating) ===== */
.fin-lock {
    display: inline-flex; align-items: center; gap: 7px; color: var(--muted);
    font-weight: 800; font-size: 15px; letter-spacing: .2px;
}
.fin-lock i { color: var(--gold); font-size: 14px; }
.fin-lock-sm { font-size: 12px; gap: 5px; }
.fin-lock-panel {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
    padding: 26px 18px; text-align: center; color: var(--muted);
    background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 10px, transparent 10px, transparent 20px);
    border: 1px dashed var(--border); border-radius: 12px;
}
.fin-lock-panel .fl-ic { font-size: 24px; color: var(--gold); }
.fin-lock-panel .fl-t { font-weight: 800; color: var(--navy); font-size: 14px; }
.fin-lock-panel .fl-s { font-size: 12px; }

.ins-sidebar-footer {
    padding: 14px 18px; font-size: 11px; color: #6f8fb0;
    border-top: 1px solid rgba(255,255,255,.08);
}

/* ===================== MAIN ===================== */
.ins-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* TOPBAR */
.ins-topbar {
    height: 66px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 40;
    box-shadow: var(--shadow-sm);
}
.topbar-start { display: flex; align-items: center; gap: 14px; }
.ins-icon-btn {
    width: 40px; height: 40px; border: none; border-radius: 10px;
    background: var(--bg); color: var(--navy); font-size: 18px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    text-decoration: none; transition: background .18s;
}
.ins-icon-btn:hover { background: var(--border); }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title .t-main { font-weight: 800; font-size: 17px; color: var(--navy); }
.topbar-title .t-sub { font-size: 11px; color: var(--muted); }

.topbar-end { display: flex; align-items: center; gap: 10px; }
.ins-pill {
    background: var(--bg); color: var(--navy);
    padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600;
    border: 1px solid var(--border);
}
.ins-pill.live { color: var(--danger); display: flex; align-items: center; gap: 6px; }
.pulse {
    width: 8px; height: 8px; border-radius: 50%; background: var(--danger);
    animation: pulse 1.4s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(198,40,40,.5); }
    70% { box-shadow: 0 0 0 7px rgba(198,40,40,0); }
    100% { box-shadow: 0 0 0 0 rgba(198,40,40,0); }
}
.ins-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--navy), var(--navy-2));
    color: #fff; display: grid; place-items: center; font-size: 16px;
}
.ins-user { display: flex; align-items: center; gap: 8px; }
.ins-user-name { font-size: 12px; font-weight: 700; color: var(--navy); }
.ins-icon-btn.logout { color: var(--danger); }
.ins-icon-btn.logout:hover { background: #FCE8E8; }
[data-theme="dark"] .ins-user-name { color: var(--text); }

/* CONTENT */
.ins-content { padding: 24px; flex: 1; }

/* ===================== KPI HERO CARDS ===================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}
.kpi-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: transform .18s, box-shadow .18s;
}
.kpi-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.kpi-card::after {
    content: ''; position: absolute; top: 0; left: 0; width: 5px; height: 100%;
    background: var(--accent, var(--navy));
}
.kpi-card.gold   { --accent: var(--gold); }
.kpi-card.teal   { --accent: var(--teal); }
.kpi-card.danger { --accent: var(--danger); }
.kpi-card.warn   { --accent: var(--warning); }
.kpi-card.info   { --accent: #1565C0; }

.kpi-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.kpi-icon {
    width: 38px; height: 38px; border-radius: 10px;
    background: color-mix(in srgb, var(--accent) 14%, white);
    color: var(--accent); display: grid; place-items: center; font-size: 18px;
}
.kpi-value { font-size: 32px; font-weight: 900; color: var(--navy); line-height: 1; letter-spacing: -.5px; }
.kpi-value .unit { font-size: 14px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.kpi-foot { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 12px; font-weight: 700; }
.kpi-trend.up   { color: var(--success); }
.kpi-trend.down { color: var(--danger); }
.kpi-foot .muted { color: var(--muted); font-weight: 500; }

/* ===================== PANELS ===================== */
.ins-panel {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    overflow: hidden;
}
.ins-panel-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
    flex-wrap: wrap; gap: 10px;
}
.ins-panel-title { font-size: 15px; font-weight: 800; color: var(--navy); display: flex; align-items: center; gap: 8px; }
.ins-panel-body { padding: 20px; }

/* SECTION TITLE */
.ins-section-title {
    font-size: 13px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: 1px; margin: 4px 0 14px;
}

/* ===================== TABLES ===================== */
.ins-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ins-table thead th {
    background: var(--navy); color: #fff; padding: 11px 14px; font-weight: 600;
    text-align: center; white-space: nowrap; position: sticky; top: 0;
}
.ins-table thead th.ra { text-align: right; }
.ins-table tbody td { padding: 11px 14px; text-align: center; border-bottom: 1px solid var(--border); white-space: nowrap; }
.ins-table tbody td.ra { text-align: right; font-weight: 700; color: var(--navy); }
.ins-table tbody tr:hover td { background: #F8FAFE; }
.ins-table .total-row td { background: #EEF3FA; font-weight: 800; color: var(--navy); }

/* ===================== BADGES / CHIPS ===================== */
.ins-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.ins-badge.ok   { background: #E3F3F0; color: var(--teal); }
.ins-badge.wait { background: #FFF3E0; color: var(--warning); }
.ins-badge.bad  { background: #FCE8E8; color: var(--danger); }

/* ===================== BUTTON ICON ↔ TEXT SPACING ===================== */
/* App buttons render an icon next to a label; inline-flex + gap guarantees a
   consistent space between them — RTL-safe, works for a leading OR trailing
   icon, and is a no-op for icon-only buttons. */
.sf-btn, .ig-btn, .set-btn, .ins-btn, .t-btn, .eye-btn, .ai-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
}

/* ===================== LOADING ===================== */
.ins-loading { display: grid; place-items: center; padding: 60px; color: var(--muted); }

/* ===================== ERROR UI ===================== */
#blazor-error-ui {
    background: #fff; bottom: 0; box-shadow: 0 -2px 12px rgba(0,0,0,.15);
    display: none; left: 0; padding: 12px 22px; position: fixed; width: 100%;
    z-index: 1000; color: var(--danger); font-weight: 600;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; left: 16px; top: 12px; }

/* ===================== RTL FIX FOR MUDBLAZOR ===================== */
.mud-input-label { right: 0; left: auto; transform-origin: right top; }
.mud-input-outlined .mud-input-label { right: .75rem; left: auto; }
.mud-select .mud-select-input { direction: rtl; text-align: right; }

/* ===================== SCROLLBAR ===================== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5cfdd; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #a9b6c9; }

/* ===================== DARK MODE ===================== */
[data-theme="dark"] {
    --bg: #0F1620;
    --surface: #18222F;
    --text: #E6EDF5;
    --muted: #93A6BC;
    --border: #283645;
}
[data-theme="dark"] h1,
[data-theme="dark"] .kpi-value,
[data-theme="dark"] .kpi-label,
[data-theme="dark"] .ins-panel-title,
[data-theme="dark"] .topbar-title .t-main,
[data-theme="dark"] .ins-table tbody td,
[data-theme="dark"] .ins-table tbody td.ra { color: var(--text); }
[data-theme="dark"] .ins-topbar { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .ins-icon-btn { background: #0F1620; color: var(--text); }
[data-theme="dark"] .ins-pill { background: #0F1620; color: var(--text); border-color: var(--border); }
[data-theme="dark"] .ins-table tbody tr:hover td { background: #1F2C3B; }
[data-theme="dark"] .ins-table .total-row td { background: #22303F; color: var(--text); }
[data-theme="dark"] .kpi-value .unit { color: var(--muted); }
[data-theme="dark"] .chip, [data-theme="dark"] .ig-btn.ghost,
[data-theme="dark"] .sf-field select, [data-theme="dark"] .sf-field input,
[data-theme="dark"] .ig-field input, [data-theme="dark"] .ins-field select,
[data-theme="dark"] .ins-field input, [data-theme="dark"] .ai-input input,
[data-theme="dark"] .ai-suggestion, [data-theme="dark"] .t-input input { background: #0F1620; color: var(--text); }

/* ===================== PRINT ===================== */
@media print {
    .ins-sidebar, .ins-topbar, .no-print { display: none !important; }
    .ins-main { display: block; }
    .ins-content { padding: 0 !important; }
    .ins-panel, .kpi-card { box-shadow: none !important; border: 1px solid #ccc; break-inside: avoid; }
    body, html { background: #fff !important; }
}

/* Form controls never exceed their container (long <select> option text would otherwise
   force a width wider than the screen and get clipped by panels' overflow:hidden). */
.ins-content select, .ins-content input, .ins-content textarea { max-width: 100%; }

/* ===================== RESPONSIVE ===================== */
/* Defaults (desktop): backdrop + mobile menu button are hidden */
.ins-backdrop { display: none; }
.nav-toggle-mobile { display: none; }
/* Reusable horizontal-scroll wrapper for wide tables on small screens */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- TABLET & PHONE: sidebar becomes an off-canvas drawer (≤1024px) ---------- */
@media (max-width: 1024px) {
    .nav-toggle-desktop { display: none; }
    .nav-toggle-mobile { display: grid; place-items: center; }

    .ins-sidebar {
        position: fixed;
        top: 0; right: 0;
        height: 100vh; height: 100dvh;
        width: 264px;
        transform: translateX(100%);              /* off-screen to the right (RTL) */
        transition: transform .28s ease;
        box-shadow: -10px 0 36px rgba(10,37,64,.28);
    }
    .ins-sidebar.collapsed { width: 264px; }      /* never icon-collapse inside the drawer */
    .ins-sidebar.mobile-open { transform: translateX(0); }

    .ins-backdrop {
        display: block;
        position: fixed; inset: 0;
        background: rgba(6,26,46,.5);
        opacity: 0; visibility: hidden;
        transition: opacity .28s ease, visibility .28s ease;
        z-index: 45;
    }
    .ins-backdrop.show { opacity: 1; visibility: visible; }

    .ins-content { padding: 18px; }
    .ins-topbar { padding: 0 16px; }
}

/* ---------- PHONE (≤768px) ---------- */
@media (max-width: 768px) {
    .ins-content { padding: 14px; }
    .ins-topbar { height: 60px; padding: 0 12px; }
    .topbar-start { gap: 10px; }
    .topbar-end { gap: 7px; }
    .topbar-title .t-sub { display: none; }
    .topbar-title .t-main { font-size: 15px; }
    .hide-sm { display: none !important; }

    .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
    .kpi-card { padding: 16px 16px; }
    .kpi-card::after { width: 4px; }
    .kpi-value { font-size: 26px; }
    .kpi-icon { width: 34px; height: 34px; font-size: 16px; }

    .ins-panel { margin-bottom: 14px; }
    .ins-panel-head { padding: 13px 15px; }
    .ins-panel-title { font-size: 14px; }
    .ins-panel-body { padding: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .ins-section-title { font-size: 12px; }
    .ins-content h1 { font-size: 20px !important; }
}

/* ---------- SMALL PHONE (≤480px) ---------- */
@media (max-width: 480px) {
    .ins-content { padding: 11px; }
    .ins-topbar { padding: 0 10px; }
    .topbar-end { gap: 5px; }
    .ins-pill.live { display: none; }             /* free space on the smallest screens */
    .kpi-grid { grid-template-columns: 1fr; }
    .kpi-value { font-size: 24px; }
    .ins-icon-btn { width: 38px; height: 38px; }
}
