/* ════════════════════════════════════════════════════════════════════════
 * SafeProperty — ENTERPRISE REFINEMENT LAYER
 * ------------------------------------------------------------------------
 * Loaded AFTER safeproperty.css. This file does NOT replace the base theme;
 * it re-tunes the design tokens and the highest-traffic components toward a
 * compact, data-dense, enterprise-grade feel — benchmarked against Linear,
 * Stripe Dashboard and Salesforce Lightning — while keeping the SafeProperty
 * orange identity.
 *
 * Design decisions:
 *   • Density:   compact. 15px content, 13px tables, tighter vertical rhythm.
 *   • Radius:    reduced from consumer (12–24px) to enterprise (6–12px).
 *   • Shadows:   softer, layered, lower-contrast (less "card floating").
 *   • Colour:    orange used as an intentional accent, not large fills.
 *   • A11y:      visible :focus-visible rings on all interactive elements.
 * ════════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────────────────────────────────────────────────────
   1. TOKEN RE-TUNING  (cascades to every var(--sp-*) consumer)
───────────────────────────────────────────────────────────────────────── */
:root {
    /* Tighter, more "software" corner radii */
    --sp-radius:        8px;
    --sp-radius-sm:     6px;
    --sp-radius-lg:     10px;
    --sp-radius-xl:     14px;
    /* pill stays 9999px */

    /* Layered, low-contrast shadows (enterprise surfaces sit closer to page) */
    --sp-shadow:        0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
    --sp-shadow-card:   0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.04);
    --sp-shadow-md:     0 2px 6px rgba(15, 23, 42, 0.07), 0 4px 12px rgba(15, 23, 42, 0.05);
    --sp-shadow-lg:     0 8px 24px rgba(15, 23, 42, 0.10), 0 2px 6px rgba(15, 23, 42, 0.05);

    /* Compact base: 15px content rhythm */
    --sp-font-base:     15px;

    /* Consistent 4px spacing scale for the refinement layer */
    --sp-space-1: 4px;
    --sp-space-2: 8px;
    --sp-space-3: 12px;
    --sp-space-4: 16px;
    --sp-space-5: 20px;
    --sp-space-6: 24px;

    /* Crisper hairline borders */
    --sp-border-strong: #cbd5e1;
}

html.dark-mode {
    --sp-shadow:        0 1px 2px rgba(0, 0, 0, 0.40);
    --sp-shadow-card:   0 1px 3px rgba(0, 0, 0, 0.40);
    --sp-shadow-md:     0 2px 8px rgba(0, 0, 0, 0.45);
    --sp-shadow-lg:     0 10px 28px rgba(0, 0, 0, 0.55);
    --sp-border-strong: #475569;
}

/* Respect the existing font-size switcher, but re-anchor the compact default */
html.font-medium { --sp-font-base: 15px; font-size: 15px; }
html.font-small  { --sp-font-base: 13px; font-size: 13px; }
html.font-large  { --sp-font-base: 17px; font-size: 17px; }

/* ─────────────────────────────────────────────────────────────────────────
   2. GLOBAL TYPE QUALITY
───────────────────────────────────────────────────────────────────────── */
html, body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    font-feature-settings: "cv11", "ss01";   /* Inter: friendlier digits/letters */
    letter-spacing: -0.006em;                  /* subtle optical tightening */
}

/* Tabular, aligned numerals everywhere numbers are read in columns */
.sp-kpi-value,
.sp-stat-value,
.mud-table-cell,
.sp-price,
.sp-amount,
table { font-variant-numeric: tabular-nums; }

/* ─────────────────────────────────────────────────────────────────────────
   3. APP SHELL — tighter, fits more on screen
───────────────────────────────────────────────────────────────────────── */
.sp-sidebar  { width: 244px; }
@media (max-width: 1280px) { .sp-sidebar { width: 224px; } }

.sp-topbar {
    height: 56px;
    padding: 0 20px;
    box-shadow: none;
    border-bottom: 1px solid var(--sp-border);
}

.sp-content {
    /* sp-topbar is position:fixed at 64px height — offset content so the
       welcome card isn't hidden behind the topbar */
    padding: 84px 24px 20px;
    scroll-behavior: smooth;
}
@media (min-width: 1600px) {
    /* Cap line length / center content on ultra-wide enterprise monitors */
    .sp-content { padding: 84px 32px 22px; }
}

/* Thinner, calmer scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { border: 2px solid transparent; background-clip: padding-box; }

/* ─────────────────────────────────────────────────────────────────────────
   4. PAGE HEADERS — smaller, denser
───────────────────────────────────────────────────────────────────────── */
.sp-page-header { margin-bottom: 18px; }
.sp-page-title  { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.01em; }
.sp-page-sub    { font-size: 0.8125rem; }

/* ─────────────────────────────────────────────────────────────────────────
   5. KPI / STAT CARDS — compact, lighter weight, intentional accent
───────────────────────────────────────────────────────────────────────── */
.sp-dashboard-kpis { gap: 12px; }

.sp-kpi-card {
    padding: 14px 16px;
    gap: 12px;
    border-width: 1px;
    border-radius: var(--sp-radius);
    box-shadow: var(--sp-shadow-card);
}
.sp-kpi-card:hover {
    box-shadow: var(--sp-shadow-md);
    border-color: var(--sp-border-strong);
}
.sp-kpi-icon  { width: 38px; height: 38px; border-radius: 8px; font-size: 1.1rem; }
.sp-kpi-value { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.sp-kpi-label {
    font-size: 0.6875rem;
    letter-spacing: 0.04em;
    font-weight: 600;
    color: var(--sp-text-secondary);
}
.sp-kpi-trend { font-size: 0.6875rem; font-weight: 600; }

/* ─────────────────────────────────────────────────────────────────────────
   6. WELCOME / HERO BANNER — slimmer, less "marketing"
───────────────────────────────────────────────────────────────────────── */
.sp-dashboard-welcome {
    padding: 18px 22px;
    border-radius: var(--sp-radius-lg);
}
.sp-dashboard-greeting { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }
.sp-dashboard-sub      { font-size: 0.8125rem; }

/* ─────────────────────────────────────────────────────────────────────────
   7. GENERIC CARDS / PANELS
───────────────────────────────────────────────────────────────────────── */
.sp-dashboard-card,
.sp-panel,
.sp-section-card {
    border-width: 1px;
    border-radius: var(--sp-radius-lg);
    box-shadow: var(--sp-shadow-card);
}
.sp-dashboard-grid { gap: 16px; }

/* ─────────────────────────────────────────────────────────────────────────
   8. MUDBLAZOR COMPONENT DENSITY  (these override the base file's !important)
───────────────────────────────────────────────────────────────────────── */

/* Surfaces: hairline border + soft shadow instead of heavy outline */
.mud-paper, .mud-card {
    border: 1px solid var(--sp-border) !important;
    box-shadow: var(--sp-shadow-card) !important;
    border-radius: var(--sp-radius-lg) !important;
}
.mud-paper.mud-elevation-0 { box-shadow: none !important; }

/* Buttons: enterprise sizing — not chunky, crisp label */
.mud-button-root {
    border-radius: var(--sp-radius-sm) !important;
    text-transform: none !important;
    font-weight: 600 !important;
    letter-spacing: 0 !important;
    min-height: 36px !important;
    padding: 6px 14px !important;
}
.mud-button-root.mud-button-filled {
    box-shadow: none !important;
}
.mud-button-root.mud-button-filled:hover {
    box-shadow: var(--sp-shadow) !important;
}
.mud-button-root.mud-size-small  { min-height: 30px !important; padding: 4px 10px !important; font-size: 0.8125rem !important; }
.mud-button-root.mud-size-large  { min-height: 42px !important; padding: 8px 20px !important; }

/* Tables: dense rows, sticky header, quiet zebra — the core of a data app */
.mud-table-root        { font-size: 0.8125rem !important; }
.mud-table-cell {
    padding: 8px 14px !important;
    height: auto !important;
}
.mud-table-head .mud-table-cell {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--sp-bg-secondary) !important;
    font-size: 0.6875rem !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--sp-text-secondary) !important;
    border-bottom: 1px solid var(--sp-border-strong) !important;
    white-space: nowrap;
}
.mud-table-row:hover .mud-table-cell { background: var(--sp-table-hover) !important; }
.mud-table-dense .mud-table-cell { padding: 5px 12px !important; }

/* Inputs: compact, crisp focus */
.mud-input.mud-input-outlined .mud-input-slot { min-height: 40px; }
.mud-input-outlined .mud-input-outlined-border { border-radius: var(--sp-radius-sm) !important; }
.mud-input.mud-input-outlined.mud-input-focused .mud-input-outlined-border {
    border-width: 1.5px !important;
    border-color: var(--sp-primary) !important;
}
.mud-input-label { font-size: 0.8125rem; }

/* Chips: smaller, pill, used for status */
.mud-chip {
    height: 22px !important;
    font-size: 0.6875rem !important;
    font-weight: 600 !important;
    border-radius: var(--sp-radius-pill) !important;
}

/* Tabs: underline style, compact */
.mud-tabs-toolbar { min-height: 42px !important; }
.mud-tab {
    text-transform: none !important;
    font-weight: 600 !important;
    font-size: 0.8125rem !important;
    min-height: 42px !important;
    letter-spacing: 0 !important;
}

/* Dialogs: tighter, modern radius */
.mud-dialog { border-radius: var(--sp-radius-lg) !important; box-shadow: var(--sp-shadow-lg) !important; }
.mud-dialog-title { font-size: 1rem !important; font-weight: 700 !important; padding: 16px 20px !important; }
.mud-dialog-content { padding: 16px 20px !important; }

/* Menus / popovers: refined */
.mud-popover, .mud-list { border-radius: var(--sp-radius) !important; box-shadow: var(--sp-shadow-lg) !important; }
.mud-list-item { min-height: 38px !important; font-size: 0.8125rem !important; }

/* ─────────────────────────────────────────────────────────────────────────
   9. ACCESSIBILITY — visible keyboard focus (most enterprise audits flag this)
───────────────────────────────────────────────────────────────────────── */
a:focus-visible,
button:focus-visible,
.mud-button-root:focus-visible,
.sp-tab:focus-visible,
.sp-nav-item:focus-visible,
[tabindex]:focus-visible,
.mud-input-slot:focus-within {
    outline: 2px solid var(--sp-primary);
    outline-offset: 2px;
    border-radius: var(--sp-radius-sm);
}

/* Remove the default mouse-click outline only when not keyboard-navigating */
:focus:not(:focus-visible) { outline: none; }

/* ─────────────────────────────────────────────────────────────────────────
   10. MISC POLISH
───────────────────────────────────────────────────────────────────────── */
/* Status chips/badges: consistent soft-tint treatment */
.sp-badge, .sp-status, .sp-tag {
    border-radius: var(--sp-radius-pill);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* Section titles a touch smaller in the app (kept large on marketing pages) */
.sp-app-shell .sp-section-title { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }

/* Dividers a hair lighter */
.mud-divider { opacity: 0.9; }

/* Tab underline tracks the brand */
.sp-tab.sp-tab--active, .sp-tab.active { border-bottom-color: var(--sp-primary); color: var(--sp-primary); }

/* Loading spinner — base CSS referenced .sp-spinner but never defined it,
   so loading states rendered as a dead square. Define it here. */
.sp-spinner {
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    border: 3px solid var(--sp-border);
    border-top-color: var(--sp-primary);
    border-radius: 50%;
    animation: sp-spin 0.7s linear infinite;
}
@keyframes sp-spin { to { transform: rotate(360deg); } }

/* Reduce motion for users who ask for it — but keep functional spinners moving */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
    .sp-spinner { animation-duration: 0.7s !important; }
}
