/* ============================================================
   SAAS.CSS — Premium enterprise dashboard shell
   Layered ON TOP of components.css (loaded last). Purely additive:
   adds the desktop SaaS layout (left sidebar + full-width header),
   refines surfaces toward a Linear/Stripe/Vercel aesthetic, and
   provides the docked Confidence / Información / Atajos cards.

   No JS hooks are renamed or removed — every existing id/class is
   preserved. Disabling this stylesheet returns the original layout.
   ============================================================ */

:root {
    --sidebar-w:    248px;
    --header-h:     72px;
    --radius-xl:    16px;
    --radius-card:  14px;
    --ring-primary: color-mix(in srgb, var(--color-primary) 22%, transparent);
}

/* ---- App shell : header on top, sidebar + content below -------- */
.app-body {
    display: flex;
    align-items: flex-start;
    flex: 1;
    width: 100%;
}

.app-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* The centered content column gets a touch more room beside the rail */
.app-content .container { max-width: 1320px; }

/* ---- Full-bleed, glassy header -------------------------------- */
.app-header {
    background: color-mix(in srgb, var(--bg-header) 86%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(12px);
    backdrop-filter: saturate(180%) blur(12px);
    z-index: 120;
}
.app-header .header-content { max-width: none; }

.brand-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    background: linear-gradient(140deg, var(--color-primary), color-mix(in srgb, var(--color-primary) 60%, #7c3aed));
    box-shadow: 0 6px 16px var(--ring-primary);
}

.header-text { display: flex; flex-direction: column; gap: 1px; }
.header-text h1 { font-size: 1.18rem; font-weight: 680; }

.header-subtitle {
    font-size: 0.80rem;
    color: var(--color-text-secondary);
    line-height: 1.2;
    letter-spacing: .1px;
}

/* ---- Left sidebar (cosmetic scroll-nav) ----------------------- */
.app-sidebar {
    position: sticky;
    top: var(--header-h);
    align-self: stretch;
    flex-shrink: 0;
    width: var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    overflow-y: auto;
    padding: 20px 14px;
    background: var(--bg-surface);
    border-right: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-heading {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: .9px;
    text-transform: uppercase;
    color: var(--color-text-muted);
    padding: 4px 12px 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 550;
    border: 1px solid transparent;
    transition: background-color var(--transition), color var(--transition);
}
.nav-item .icon { color: var(--color-text-muted); flex-shrink: 0; }

.nav-item:hover {
    background: var(--bg-surface-alt);
    color: var(--color-text);
}
.nav-item:hover .icon { color: var(--color-primary); }

.nav-item.nav-active {
    background: color-mix(in srgb, var(--color-primary) 10%, transparent);
    color: var(--color-primary);
    border-color: color-mix(in srgb, var(--color-primary) 22%, transparent);
}
.nav-item.nav-active .icon { color: var(--color-primary); }

/* Keyboard focus is visually distinct from the active state (m5). */
.nav-item:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Unavailable nav item: target section is currently hidden (C1). */
.nav-item.nav-disabled {
    opacity: .42;
    cursor: not-allowed;
    pointer-events: none;
}

/* Long labels (FR/NL) never overflow the rail (m6). */
.sidebar-heading,
.nav-item span:not(.icon) {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-item span:not(.icon) { min-width: 0; }

.sidebar-spacer { flex: 1; }

.sidebar-privacy {
    margin-top: 8px;
    padding: 12px;
    font-size: 0.74rem;
    line-height: 1.45;
    color: var(--color-text-muted);
    background: var(--bg-surface-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

/* ---- Anchor targets clear the sticky header + quick-actions bar -
   Header (72px) + quick-actions (~58px) ≈ 150px of sticky chrome. */
#sandboxArea,
#statsDashboard,
#tokenmapPanel,
#historyPanel,
#memoryPanel,
#configPanel,
.sandbox-area .panel {
    scroll-margin-top: 150px;
}

/* ---- Premium surface polish (soft shadow + larger radius) ----- */
.stats-dashboard,
.sandbox-area .panel,
.history-panel,
.memory-panel,
.tokenmap-panel,
.custom-patterns-panel > details,
.dash-card {
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-md);
}

/* ---- Statistics cards ----------------------------------------- */
.stats-grid { gap: 16px; }

.stat-card {
    position: relative;
    border-radius: var(--radius-card);
    padding: 18px 18px 16px;
    background: var(--bg-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* accent rail per card type */
.stat-card::before {
    content: "";
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--color-primary);
    opacity: .9;
}
.stat-card.stat-total::before { background: var(--color-primary); }
.stat-card.stat-pii::before   { background: var(--pii-text); }
.stat-card.stat-pci::before   { background: var(--pci-text); }
.stat-card.stat-risk::before  { background: var(--color-warning); }

.stat-card .stat-number { font-size: 2.1rem; font-weight: 720; letter-spacing: -1px; }
.stat-card .stat-label {
    font-size: 0.78rem;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    letter-spacing: .4px;
    font-weight: 600;
}

/* ---- Detection-summary chips (statsBreakdown) ----------------- */
.breakdown { gap: 8px; }
.breakdown-item {
    border-radius: 999px;
    padding: 5px 12px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--color-border);
    font-size: 0.80rem;
    font-weight: 550;
}
.breakdown-item .bd-count {
    font-weight: 750;
    color: var(--color-primary);
}

/* ---- Buttons : crisper primary action ------------------------- */
.btn-sanitize,
.quick-action-primary {
    box-shadow: 0 6px 16px var(--ring-primary);
}
.btn { border-radius: var(--radius-md); }
.quick-actions { z-index: 90; }

/* ---- Success badge on the Salida panel (CSS-only, truthful) ---
   Only shown once a sanitize run has produced a .report-clean block. */
.sanitize-badge {
    display: none;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 650;
    color: var(--color-success);
    background: color-mix(in srgb, var(--color-success) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-success) 35%, transparent);
}
.sanitize-badge .icon { color: var(--color-success); }
.output-panel:has(.report-clean) .sanitize-badge,
.output-panel.has-clean-report .sanitize-badge { display: inline-flex; }  /* :has + JS-class fallback */

/* ---- Accessible touch targets for table action buttons (m2) ---- */
.tm-act-btn,
.mem-act-btn {
    min-height: 36px;
    padding: 7px 11px;
}
@media (pointer: coarse) {
    .tm-act-btn,
    .mem-act-btn { min-height: 44px; }
}

/* ---- Bottom docked cards : Confianza / Información / Atajos ---- */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.dash-card {
    background: var(--bg-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-card);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dash-card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--color-heading);
}
.dash-card-title .icon { color: var(--color-primary); }

.dash-card p { font-size: 0.85rem; color: var(--color-text-secondary); line-height: 1.55; }

/* Confidence card */
.confidence-card .conf-value {
    font-size: 2.4rem;
    font-weight: 760;
    letter-spacing: -1.5px;
    color: var(--color-heading);
    line-height: 1;
}
.confidence-bar {
    height: 10px;
    border-radius: 999px;
    background: var(--bg-controls);
    overflow: hidden;
}
.confidence-fill {
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--color-success), color-mix(in srgb, var(--color-success) 70%, var(--color-primary)));
    transition: width .6s cubic-bezier(.22,.61,.36,1);
}

/* Shortcuts card */
.dock-shortcuts { display: flex; flex-direction: column; gap: 8px; }
.dock-shortcut {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}
.dock-shortcut kbd {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.74rem;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--bg-surface-alt);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-xs);
    color: var(--color-text);
}

/* ---- Responsive : collapse the rail on tablets/phones --------- */
@media (max-width: 1023px) {
    .app-sidebar { display: none; }
}

@media (min-width: 1600px) {
    .app-content .container { max-width: 1440px; }
}
