/* ═══════════════════════════════════════════════════════════════════════
   FOFLARE CLOUD — PREMIUM PANEL DESIGN SYSTEM (panel.css)
   Shared tokens + light/dark theming for the customer control panel.

   Scope:
   • The 20 server-control pages (they keep their page-scoped component CSS;
     this file supplies the shared foundation: typography scale, surfaces,
     focus rings, scrollbars, skeleton shimmer, toasts, empty/error states).
   • The redesigned dashboard + my-services pages (built entirely on these
     tokens).
   Theming:
   • Dark is default. `html[data-theme="light"]` redefines every token —
     the same markup instantly renders a clean light panel.
   • Every server-control page previously hard-forced a dark-only palette,
     so this file also carries targeted light-mode overrides for the shared
     panel chrome (sidebar + page background) to make the theme toggle work
     across the panel for the first time.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    /* Palette (dark) */
    --ffp-bg: #070b14;
    --ffp-bg-soft: #0b1120;
    --ffp-surface: #0e1526;
    --ffp-surface-2: #131c30;
    --ffp-surface-3: #18233b;
    --ffp-hover: rgba(56, 189, 248, 0.07);
    --ffp-border: rgba(148, 163, 184, 0.14);
    --ffp-border-strong: rgba(148, 163, 184, 0.26);
    --ffp-text: #e6edf7;
    --ffp-text-soft: #b6c2d9;
    --ffp-text-muted: #8494af;
    --ffp-primary: #38bdf8;
    --ffp-primary-strong: #0ea5e9;
    --ffp-primary-contrast: #04121f;
    --ffp-accent: #8b5cf6;
    --ffp-success: #34d399;
    --ffp-success-bg: rgba(52, 211, 153, 0.10);
    --ffp-success-line: rgba(52, 211, 153, 0.35);
    --ffp-warning: #fbbf24;
    --ffp-warning-bg: rgba(251, 191, 36, 0.10);
    --ffp-warning-line: rgba(251, 191, 36, 0.35);
    --ffp-danger: #f87171;
    --ffp-danger-bg: rgba(248, 113, 113, 0.10);
    --ffp-danger-line: rgba(248, 113, 113, 0.38);
    --ffp-info: #60a5fa;
    --ffp-info-bg: rgba(96, 165, 250, 0.10);
    --ffp-info-line: rgba(96, 165, 250, 0.35);
    --ffp-shadow-sm: 0 1px 2px rgba(2, 6, 17, 0.5);
    --ffp-shadow: 0 10px 30px -12px rgba(2, 6, 17, 0.75);
    --ffp-shadow-lg: 0 24px 60px -20px rgba(2, 6, 17, 0.85);
    --ffp-focus: rgba(56, 189, 248, 0.55);

    /* Typography */
    --ffp-font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --ffp-font-display: 'Rajdhani', 'Inter', system-ui, sans-serif;
    --ffp-font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

    /* Rhythm */
    --ffp-radius-sm: 8px;
    --ffp-radius: 12px;
    --ffp-radius-lg: 16px;
    --ffp-radius-xl: 20px;
    --ffp-gap: 16px;
    --ffp-transition: 160ms cubic-bezier(0.33, 1, 0.68, 1);

    color-scheme: dark;
}

/* ── Light theme: one block redefines the whole system ── */
html[data-theme="light"] {
    --ffp-bg: #f2f5fa;
    --ffp-bg-soft: #ffffff;
    --ffp-surface: #ffffff;
    --ffp-surface-2: #f6f8fc;
    --ffp-surface-3: #eef2f8;
    --ffp-hover: rgba(14, 165, 233, 0.06);
    --ffp-border: rgba(15, 23, 42, 0.10);
    --ffp-border-strong: rgba(15, 23, 42, 0.20);
    --ffp-text: #101a2c;
    --ffp-text-soft: #38465e;
    --ffp-text-muted: #5d6b85;
    --ffp-primary: #0284c7;
    --ffp-primary-strong: #0369a1;
    --ffp-primary-contrast: #ffffff;
    --ffp-accent: #7c3aed;
    --ffp-success: #059669;
    --ffp-success-bg: rgba(5, 150, 105, 0.08);
    --ffp-success-line: rgba(5, 150, 105, 0.30);
    --ffp-warning: #b45309;
    --ffp-warning-bg: rgba(180, 83, 9, 0.08);
    --ffp-warning-line: rgba(180, 83, 9, 0.30);
    --ffp-danger: #dc2626;
    --ffp-danger-bg: rgba(220, 38, 38, 0.07);
    --ffp-danger-line: rgba(220, 38, 38, 0.30);
    --ffp-info: #2563eb;
    --ffp-info-bg: rgba(37, 99, 235, 0.07);
    --ffp-info-line: rgba(37, 99, 235, 0.28);
    --ffp-shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --ffp-shadow: 0 10px 30px -14px rgba(15, 23, 42, 0.18);
    --ffp-shadow-lg: 0 24px 60px -24px rgba(15, 23, 42, 0.25);

    color-scheme: light;
}

/* ═══════════════════════ 1. BASE / TYPOGRAPHY ═══════════════════════ */

.ffp-page {
    font-family: var(--ffp-font);
    color: var(--ffp-text);
    background: var(--ffp-bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.ffp-container {
    width: min(100% - 2 * 20px, 1240px);
    margin-inline: auto;
}

.ffp-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    padding: 26px 0 20px;
}

.ffp-page-title {
    font-family: var(--ffp-font-display);
    font-size: clamp(1.55rem, 1.1rem + 1.8vw, 2.1rem);
    font-weight: 700;
    letter-spacing: 0.01em;
    margin: 0;
    color: var(--ffp-text);
    line-height: 1.15;
}

.ffp-page-sub {
    margin: 6px 0 0;
    color: var(--ffp-text-muted);
    font-size: 0.92rem;
    max-width: 60ch;
}

/* ═══════════════════════ 2. CARDS / SURFACES ═══════════════════════ */

.ffp-card {
    background: var(--ffp-surface);
    border: 1px solid var(--ffp-border);
    border-radius: var(--ffp-radius-lg);
    box-shadow: var(--ffp-shadow-sm);
    transition: border-color var(--ffp-transition), box-shadow var(--ffp-transition), transform var(--ffp-transition);
}

.ffp-card--hover:hover {
    border-color: var(--ffp-border-strong);
    box-shadow: var(--ffp-shadow);
    transform: translateY(-2px);
}

.ffp-card-pad { padding: 20px; }

.ffp-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ffp-border);
}

.ffp-card-title {
    font-family: var(--ffp-font-display);
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    color: var(--ffp-text);
}

.ffp-card-sub { margin: 2px 0 0; font-size: 0.8rem; color: var(--ffp-text-muted); }

.ffp-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: var(--ffp-gap);
}

.ffp-stat {
    display: flex;
    gap: 14px;
    align-items: flex-start;
    padding: 18px;
}

.ffp-stat-icon {
    width: 42px; height: 42px;
    flex-shrink: 0;
    border-radius: var(--ffp-radius);
    display: grid;
    place-items: center;
    font-size: 1.05rem;
    background: var(--ffp-info-bg);
    color: var(--ffp-info);
    border: 1px solid var(--ffp-info-line);
}

.ffp-stat-icon--success { background: var(--ffp-success-bg); color: var(--ffp-success); border-color: var(--ffp-success-line); }
.ffp-stat-icon--warning { background: var(--ffp-warning-bg); color: var(--ffp-warning); border-color: var(--ffp-warning-line); }
.ffp-stat-icon--danger { background: var(--ffp-danger-bg); color: var(--ffp-danger); border-color: var(--ffp-danger-line); }

.ffp-stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ffp-text-muted);
}

.ffp-stat-value {
    font-family: var(--ffp-font-display);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ffp-text);
    line-height: 1.2;
}

.ffp-stat-hint { font-size: 0.78rem; color: var(--ffp-text-muted); margin-top: 2px; }

/* ═══════════════════════ 3. BUTTONS ═══════════════════════ */

.ffp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-family: var(--ffp-font);
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--ffp-transition), border-color var(--ffp-transition),
                color var(--ffp-transition), transform var(--ffp-transition), box-shadow var(--ffp-transition);
}

.ffp-btn:focus-visible { outline: 2px solid var(--ffp-focus); outline-offset: 2px; }

.ffp-btn--primary {
    background: linear-gradient(135deg, var(--ffp-primary), var(--ffp-primary-strong));
    color: var(--ffp-primary-contrast);
    box-shadow: 0 6px 18px -8px rgba(56, 189, 248, 0.65);
}
.ffp-btn--primary:hover { filter: brightness(1.07); transform: translateY(-1px); }

.ffp-btn--secondary {
    background: var(--ffp-surface-2);
    border-color: var(--ffp-border-strong);
    color: var(--ffp-text);
}
.ffp-btn--secondary:hover { background: var(--ffp-surface-3); border-color: var(--ffp-primary); }

.ffp-btn--danger { background: var(--ffp-danger-bg); color: var(--ffp-danger); border-color: var(--ffp-danger-line); }
.ffp-btn--danger:hover { background: var(--ffp-danger); color: #fff; }

.ffp-btn--success { background: var(--ffp-success-bg); color: var(--ffp-success); border-color: var(--ffp-success-line); }
.ffp-btn--success:hover { background: var(--ffp-success); color: #04120c; }

.ffp-btn--ghost { background: transparent; color: var(--ffp-text-soft); }
.ffp-btn--ghost:hover { background: var(--ffp-hover); color: var(--ffp-text); }

.ffp-btn:disabled, .ffp-btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    filter: none !important;
}

.ffp-btn--sm { padding: 7px 13px; font-size: 0.8rem; border-radius: 8px; }
.ffp-btn--block { width: 100%; }

/* ═══════════════════════ 4. BADGES / PILLS ═══════════════════════ */

.ffp-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 1px solid;
    line-height: 1.4;
}

.ffp-badge--success { background: var(--ffp-success-bg); color: var(--ffp-success); border-color: var(--ffp-success-line); }
.ffp-badge--warning { background: var(--ffp-warning-bg); color: var(--ffp-warning); border-color: var(--ffp-warning-line); }
.ffp-badge--danger  { background: var(--ffp-danger-bg);  color: var(--ffp-danger);  border-color: var(--ffp-danger-line); }
.ffp-badge--info    { background: var(--ffp-info-bg);    color: var(--ffp-info);    border-color: var(--ffp-info-line); }
.ffp-badge--neutral { background: var(--ffp-surface-2);  color: var(--ffp-text-muted); border-color: var(--ffp-border); }

.ffp-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.ffp-dot--pulse { animation: ffp-pulse 1.6s ease-in-out infinite; }
@keyframes ffp-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ═══════════════════════ 5. FORMS ═══════════════════════ */

.ffp-field { display: flex; flex-direction: column; gap: 6px; }
.ffp-label { font-size: 0.8rem; font-weight: 600; color: var(--ffp-text-soft); }
.ffp-input, .ffp-select, .ffp-textarea {
    width: 100%;
    padding: 10px 13px;
    border-radius: 10px;
    border: 1px solid var(--ffp-border-strong);
    background: var(--ffp-bg-soft);
    color: var(--ffp-text);
    font-family: var(--ffp-font);
    font-size: 0.9rem;
    transition: border-color var(--ffp-transition), box-shadow var(--ffp-transition);
}
.ffp-input:focus, .ffp-select:focus, .ffp-textarea:focus {
    outline: none;
    border-color: var(--ffp-primary);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}
.ffp-input::placeholder { color: var(--ffp-text-muted); }

/* ═══════════════════════ 6. EMPTY / ERROR / LOADING STATES ═══════════════════════ */

.ffp-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 12px;
    padding: 52px 24px;
    border: 1px dashed var(--ffp-border-strong);
    border-radius: var(--ffp-radius-lg);
    background: var(--ffp-bg-soft);
}

.ffp-state-icon {
    width: 58px; height: 58px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 1.4rem;
    background: var(--ffp-surface-2);
    color: var(--ffp-text-muted);
    border: 1px solid var(--ffp-border);
}
.ffp-state--error .ffp-state-icon { background: var(--ffp-danger-bg); color: var(--ffp-danger); border-color: var(--ffp-danger-line); }
.ffp-state-title { font-family: var(--ffp-font-display); font-size: 1.1rem; font-weight: 700; margin: 0; }
.ffp-state-text { margin: 0; color: var(--ffp-text-muted); font-size: 0.88rem; max-width: 44ch; }

.ffp-skeleton {
    border-radius: var(--ffp-radius);
    background: linear-gradient(100deg, var(--ffp-surface-2) 40%, var(--ffp-surface-3) 50%, var(--ffp-surface-2) 60%);
    background-size: 200% 100%;
    animation: ffp-shimmer 1.4s linear infinite;
    min-height: 72px;
}
@keyframes ffp-shimmer { to { background-position: -200% 0; } }

.ffp-spinner {
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 2px solid var(--ffp-border-strong);
    border-top-color: var(--ffp-primary);
    animation: ffp-spin 0.7s linear infinite;
    display: inline-block;
    vertical-align: -3px;
}
@keyframes ffp-spin { to { transform: rotate(360deg); } }

/* ═══════════════════════ 7. TOASTS ═══════════════════════ */

.ffp-toasts {
    position: fixed;
    top: calc(var(--nav-h, 70px) + 12px);
    right: 16px;
    z-index: 100090;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: min(360px, calc(100vw - 32px));
    pointer-events: none;
}

.ffp-toast {
    display: flex;
    gap: 11px;
    align-items: flex-start;
    padding: 13px 15px;
    border-radius: var(--ffp-radius);
    background: var(--ffp-surface);
    border: 1px solid var(--ffp-border-strong);
    box-shadow: var(--ffp-shadow-lg);
    color: var(--ffp-text);
    font-size: 0.86rem;
    line-height: 1.45;
    pointer-events: auto;
    animation: ffp-toast-in 220ms cubic-bezier(0.21, 1.02, 0.73, 1);
}
.ffp-toast--out { animation: ffp-toast-out 180ms ease forwards; }
@keyframes ffp-toast-in { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes ffp-toast-out { to { opacity: 0; transform: translateX(24px); } }

.ffp-toast-icon { font-size: 1rem; line-height: 1.2; flex-shrink: 0; }
.ffp-toast--success .ffp-toast-icon { color: var(--ffp-success); }
.ffp-toast--error .ffp-toast-icon { color: var(--ffp-danger); }
.ffp-toast--warning .ffp-toast-icon { color: var(--ffp-warning); }
.ffp-toast--info .ffp-toast-icon { color: var(--ffp-info); }

/* ═══════════════════════ 8. MODALS ═══════════════════════ */

.ffp-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100100;
    background: rgba(2, 6, 17, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    padding: 18px;
    align-items: center;
    justify-content: center;
    overflow-y: auto;
}
.ffp-modal.show { display: flex; }

.ffp-modal-card {
    width: 100%;
    max-width: 460px;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    background: var(--ffp-surface);
    border: 1px solid var(--ffp-border-strong);
    border-radius: var(--ffp-radius-xl);
    box-shadow: var(--ffp-shadow-lg);
    animation: ffp-modal-in 200ms cubic-bezier(0.21, 1.02, 0.73, 1);
}
@keyframes ffp-modal-in { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

.ffp-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ffp-border);
    flex-shrink: 0;
}
.ffp-modal-title { font-family: var(--ffp-font-display); font-size: 1.08rem; font-weight: 700; margin: 0; }
.ffp-modal-close {
    width: 32px; height: 32px;
    display: grid; place-items: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--ffp-text-muted);
    font-size: 1.15rem;
    cursor: pointer;
    transition: background var(--ffp-transition), color var(--ffp-transition);
}
.ffp-modal-close:hover { background: var(--ffp-danger-bg); color: var(--ffp-danger); }

.ffp-modal-body { padding: 20px; overflow-y: auto; }
.ffp-modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--ffp-border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.ffp-modal-foot .ffp-btn { flex: 1 1 auto; min-width: 120px; }

/* ═══════════════════════ 9. RESPONSIVE UTILITIES ═══════════════════════ */

.ffp-grid { display: grid; gap: var(--ffp-gap); }
.ffp-grid--2 { grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); }
.ffp-grid--3 { grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }

@media (max-width: 640px) {
    .ffp-page-header { padding-top: 18px; }
    .ffp-modal { padding: 10px; }
    .ffp-modal-card { max-height: calc(100vh - 20px); }
    .ffp-modal-foot .ffp-btn { flex: 1 1 100%; }
    .ffp-btn--block-on-mobile { width: 100%; }
}

/* ═══════════════════════ 10. PANEL CHROME LIGHT-MODE OVERRIDES ═══════════════════════
   Server-control pages hard-force dark surfaces. These targeted overrides
   make the html[data-theme="light"] toggle apply to the shared chrome so the
   whole panel switches coherently. Page-scoped component palettes remain
   readable because they sit on the now-light base surfaces. */

html[data-theme="light"] body,
html[data-theme="light"] .sc-layout,
html[data-theme="light"] .sc-content {
    background: var(--ffp-bg) !important;
    color: var(--ffp-text) !important;
}

/* ── Server sidebar (server-sidebar.ejs: --fc-* tokens) ── */
html[data-theme="light"] #fc-server-shell {
    --fc-bg: #ffffff;
    --fc-bg-2: #f4f7fb;
    --fc-text: #16213a;
    --fc-text-2: #4a5872;
    --fc-line: rgba(15, 23, 42, 0.12);
    --fc-line-2: rgba(15, 23, 42, 0.2);
    --fc-card: #ffffff;
    --fc-hover: rgba(2, 132, 199, 0.07);
    --fc-accent: #0284c7;
    --fc-accent-2: #38bdf8;
}
html[data-theme="light"] .sc-sidebar,
html[data-theme="light"] #scSidebar {
    background: #ffffff !important;
    border-right-color: rgba(15, 23, 42, 0.1) !important;
}

/* ── Generic page-root hard-dark overrides used by all panel pages ── */
html[data-theme="light"] .cc-ui,
html[data-theme="light"] .cf-ui,
html[data-theme="light"] .cfw-ui,
html[data-theme="light"] .sdm-ui,
html[data-theme="light"] .pm-ui,
html[data-theme="light"] .bk-ui,
html[data-theme="light"] .stt-ui {
    background: transparent !important;
    color: var(--ffp-text) !important;
}

/* Keep scrollbars readable in both themes */
.ffp-page ::-webkit-scrollbar, .sc-content ::-webkit-scrollbar { width: 10px; height: 10px; }
.ffp-page ::-webkit-scrollbar-thumb, .sc-content ::-webkit-scrollbar-thumb {
    background: var(--ffp-border-strong);
    border-radius: 6px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.ffp-page ::-webkit-scrollbar-thumb:hover, .sc-content ::-webkit-scrollbar-thumb:hover { background-color: var(--ffp-text-muted); }
.ffp-page ::-webkit-scrollbar-track, .sc-content ::-webkit-scrollbar-track { background: transparent; }

/* Reduced motion: calm everything down */
@media (prefers-reduced-motion: reduce) {
    .ffp-card, .ffp-btn, .ffp-toast, .ffp-modal-card { transition: none !important; animation: none !important; }
    .ffp-skeleton { animation: none; }
    .ffp-dot--pulse { animation: none; }
}


/* ═══════════════════════ 10. FOFLARE NEXT-GEN PREMIUM UI UPGRADE ═══════════════════════ */
.sc-layout {
    background:
        radial-gradient(1100px 520px at 14% -6%, rgba(56, 189, 248, 0.085), transparent 62%),
        radial-gradient(920px 460px at 88% 4%, rgba(139, 92, 246, 0.075), transparent 60%),
        var(--ffp-bg);
}
html[data-theme="light"] .sc-layout {
    background:
        radial-gradient(1100px 520px at 14% -6%, rgba(2, 132, 199, 0.06), transparent 62%),
        var(--ffp-bg);
}
.cfw-panel, .cfp-panel, .cpi-panel, .cc-card, .ffp-card {
    box-shadow: 0 12px 32px -12px rgba(2, 6, 23, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.045);
}
.cfw-panel-raised, .cpi-panel-raised, .cfp-panel-raised {
    background: linear-gradient(135deg, rgba(16, 25, 43, 0.94) 0%, rgba(12, 19, 34, 0.94) 100%) !important;
    border: 1px solid rgba(56, 189, 248, 0.20) !important;
    box-shadow: 0 16px 40px -16px rgba(2, 6, 23, 0.78), inset 0 1px 0 rgba(255, 255, 255, 0.06) !important;
}
