/* ============================================================
   SCANBO HEALTH — Enterprise SaaS Design System
   Inspired by Sarvam.ai aesthetic: clean, minimal, modern
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;500;600;700;800&display=swap');

/* ─── Design Tokens ────────────────────────────────────────── */
:root {
    /* Palette */
    --primary: #1172BA;
    --primary-rgb: 17, 114, 186;
    --primary-contrast: #FFFFFF;
    --secondary: #64748B;
    --secondary-rgb: 100, 116, 139;
    --secondary-contrast: #FFFFFF;

    --success: #16A34A;
    --success-rgb: 22, 163, 74;
    --warning: #D97706;
    --warning-rgb: 217, 119, 6;
    --error: #C45757;
    --error-rgb: 196, 87, 87;
    --info: #0284C7;
    --info-rgb: 2, 132, 199;

    --grey-50: #F8FAFC;
    --grey-100: #F1F5F9;
    --grey-200: #E2E8F0;
    --grey-300: #CBD5E1;
    --grey-400: #94A3B8;
    --grey-500: #64748B;
    --grey-600: #475569;
    --grey-700: #334155;
    --grey-800: #1E293B;
    --grey-900: #0F172A;
    --grey-900-rgb: 15, 23, 42;
    --white-rgb: 255, 255, 255;

    --action-hover: rgba(15, 23, 42, 0.06);
    --primary-soft: rgba(var(--primary-rgb), 0.12);
    --primary-mid: rgba(var(--primary-rgb), 0.22);

    /* Background + Surface */
    --bg: var(--grey-50);
    --bg-page: var(--grey-50);
    --surface: #FFFFFF;
    --surface-2: #F8FAFC;
    --border: var(--grey-200);
    --border-strong: var(--grey-300);

    /* Text */
    --text-primary: var(--grey-900);
    --text-secondary: var(--grey-700);
    --text-muted: var(--grey-500);
    --text-inverse: #FFFFFF;

    /* Semantic surfaces */
    --success-bg: rgba(var(--success-rgb), 0.12);
    --success-border: rgba(var(--success-rgb), 0.4);
    --warning-bg: rgba(var(--warning-rgb), 0.12);
    --warning-border: rgba(var(--warning-rgb), 0.4);
    --error-bg: rgba(var(--error-rgb), 0.12);
    --error-border: rgba(var(--error-rgb), 0.4);
    --info-bg: rgba(var(--info-rgb), 0.12);
    --info-border: rgba(var(--info-rgb), 0.4);

    /* Chips */
    --chip-surface-alpha: 0.12;
    --chip-border-alpha: 0.4;

    /* Shadows */
    --elevation1: 0 2px 6px rgba(15, 23, 42, 0.05);
    --elevation2: 0 6px 14px rgba(15, 23, 42, 0.08);
    --elevation4: 0 12px 24px rgba(15, 23, 42, 0.12);
    --cardShadow: rgba(15, 23, 42, 0.06) 0px 12px 24px;
    --card-shadow: rgba(15, 23, 42, 0.06) 0px 12px 24px;
    --shadow-xs: var(--elevation1);
    --shadow-sm: var(--elevation2);
    --shadow-md: var(--elevation4);
    --shadow-lg: var(--elevation4);
    --shadow-xl: var(--elevation4);

    /* Radius */
    --radius-card: 8px;
    --radius-surface: 12px;
    --radius-control: 10px;
    --r-sm: 8px;
    --r-md: 10px;
    --r-lg: 12px;
    --r-xl: 12px;
    --r-full: 9999px;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 32px;

    /* Typography */
    --font-family-base: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --fs-h1: 2.25rem;
    --fs-h2: 1.875rem;
    --fs-h3: 1.5rem;
    --fs-h4: 1.25rem;
    --fs-h5: 1.125rem;
    --fs-h6: 1rem;
    --fs-subtitle: 1rem;
    --fs-body: 0.9375rem;
    --fs-button: 0.9375rem;
    --fs-caption: 0.75rem;
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;
    --lh-heading: 1.25;
    --lh-body: 1.6;

    /* Sidebar */
    --sidebar-width: 256px;
    --topbar-height: 60px;
    --sidebar-bg: #FFFFFF;
    --sidebar-text: var(--grey-600);
    --sidebar-active: rgba(var(--primary-rgb), 0.08);
    --sidebar-hover: rgba(var(--primary-rgb), 0.04);
}

/* ─── Reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family-base);
    font-size: var(--fs-body);
    background: var(--bg-page);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    line-height: var(--lh-body);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary);
    text-decoration: none;
}



/* ─── Spinner ──────────────────────────────────────────────── */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(var(--primary-rgb), 0.15);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
    flex-shrink: 0;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn.loading .spinner {
    display: block;
}

.btn.loading .btn-text {
    opacity: 0.7;
}

.page-loader {
    position: fixed;
    inset: 0;
    background: var(--surface);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.page-loader .loader-logo {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    margin-bottom: 8px;
}

.page-loader .loader-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.page-loader .loader-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ─── Copy Button ──────────────────────────────────────────── */
.copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
    flex-shrink: 0;
}

.copy-btn:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
    color: var(--primary);
}

.copy-btn.copied {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success);
}

/* ─── Credential Display ───────────────────────────────────── */
.credential-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 14px;
    margin-bottom: 10px;
}

.credential-row code {
    flex: 1;
    font-family: inherit;
    font-size: 0.8rem;
    color: var(--text-primary);
    word-break: break-all;
    overflow-wrap: anywhere;
    line-height: 1.4;
}

.credential-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 4px;
    display: block;
}

.dashboard-shell {
    display: flex;
    min-height: 100vh;
}


.topbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.topbar-icon-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    border: 1px solid rgba(var(--primary-rgb), 0.22);
    background: rgba(var(--primary-rgb), 0.06);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.16s ease;
}

.topbar-icon-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.topbar-icon-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
    box-shadow: var(--shadow-xs);
}

.topbar-icon-badge {
    position: absolute;
    top: 6px;
    right: 7px;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 0 0 2px var(--surface);
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--primary-soft);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
}


/* ─── Empty States ─────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 64px 32px;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

.empty-state h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 360px;
    margin: 0 auto 24px;
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
    .plans-grid {
        grid-template-columns: 1fr 1fr;
    }

    .plan-banner {
        flex-direction: column;
        align-items: flex-start;
        gap: 20px;
    }

    .plan-banner-right {
        text-align: left;
    }

    .grid-2 {
        grid-template-columns: 1fr;
    }

    .grid-3 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .topbar-menu-btn {
        display: inline-flex;
    }

    .auth-side {
        display: none;
    }

    .auth-form-panel {
        padding: 24px 20px;
    }

    .auth-form-inner {
        max-width: 100%;
    }

    .login-card {
        padding: 24px 20px;
        margin: 0 auto;
        max-width: 100%;
        box-sizing: border-box;
    }

    .login-card-title {
        font-size: 1.5rem;
    }

    .auth-note-card {
        flex-direction: column;
        align-items: stretch;
    }

    .auth-note-btn {
        width: 100%;
    }

    .plans-grid {
        grid-template-columns: 1fr;
    }

    .grid-3 {
        grid-template-columns: 1fr;
    }

    .phone-input-row {
        grid-template-columns: 1fr;
    }

    .page-content {
        padding: var(--space-lg);
    }

    .topbar {
        padding: 0 var(--space-lg);
    }

    .app-card-header {
        flex-direction: column;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .plan-banner {
        padding: 24px 20px;
    }

    .plan-banner-details {
        grid-template-columns: 1fr;
    }

    #devicesList.devices-grid {
        grid-template-columns: 1fr;
    }

    .custom-result {
        flex-direction: column;
        align-items: flex-start;
    }

    .custom-result .btn {
        width: 100%;
    }

    .profile-field-row {
        flex-direction: column;
    }

    .profile-field-value {
        text-align: left;
    }

    .cred-stat-grid {
        grid-template-columns: 1fr;
    }

    .cred-app-group-header {
        flex-direction: column;
    }

    .cred-app-group-meta {
        align-items: flex-start;
        max-width: none;
    }

    .cred-app-group-id {
        text-align: left;
    }

    .cred-entry-meta {
        grid-template-columns: 1fr;
    }

    /* Credentials table → stacked list on mobile */
    .cred-table-responsive .cred-table thead {
        display: none;
    }

    .cred-table-responsive .cred-table,
    .cred-table-responsive .cred-table tbody,
    .cred-table-responsive .cred-table tr,
    .cred-table-responsive .cred-table td {
        display: block;
    }

    .cred-table-responsive .cred-table tbody tr.cred-table-row {
        padding: var(--space-lg);
        margin-bottom: var(--space-md);
        border: 1px solid var(--border);
        border-radius: var(--radius-card);
        background: var(--surface);
        box-shadow: var(--elevation1);
    }

    .cred-table-responsive .cred-table tbody tr.cred-table-row:last-child {
        margin-bottom: 0;
    }

    .cred-table-responsive .cred-table td {
        padding: var(--space-sm) 0;
        border: none;
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        gap: var(--space-xs);
    }

    .cred-table-responsive .cred-table td::before {
        content: attr(data-cell);
        font-size: var(--fs-caption);
        font-weight: var(--fw-bold);
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: 0.04em;
        flex: 0 0 100%;
        margin-bottom: 2px;
    }

    .cred-table-responsive .cred-table td.cred-cell-date::after,
    .cred-table-responsive .cred-table .cred-code-row,
    .cred-table-responsive .cred-table .cred-row-actions {
        flex: 1 1 100%;
    }

    .cred-table-responsive .cred-table .cred-row-actions {
        padding-top: var(--space-sm);
        margin-top: var(--space-xs);
        border-top: 1px solid var(--border);
    }

    .cred-generate-actions .cred-generate-group {
        flex-direction: column;
        align-items: flex-start;
    }

    .cred-generate-bar-form {
        flex-direction: column;
        align-items: stretch;
    }

    .cred-generate-field,
    .cred-generate-field--btn {
        min-width: 0;
    }

    .cred-generate-field--btn {
        align-self: stretch;
    }

    .cred-generate-field--btn .btn {
        width: 100%;
    }

    .cred-row-actions--table {
        flex-direction: column;
        align-items: stretch;
    }

    .cred-row-actions--table .cred-action-btn {
        width: 100%;
    }
}

/* ─── No-sub State ─────────────────────────────────────────── */
.noSub-gate {
    background: var(--surface);
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--r-xl);
    padding: 64px;
    text-align: center;
}

/* ─── Trial Badge Float ─────────────────────────────────────── */
.trial-badge-float {
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--success);
    color: white;
    padding: 4px 14px;
    border-radius: 0 0 8px 8px;
    font-size: 0.65rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ─── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: rgba(var(--primary-rgb), 0.25);
    border-radius: 10px;
    border: 1px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: rgba(var(--primary-rgb), 0.45);
}

/* ─── Global Theme Enforcement ─────────────────────────────── */
*,
*::before,
*::after {
    font-family: var(--font-family-base) !important;
}

h1 {
    font-size: var(--fs-h1) !important;
    font-weight: var(--fw-bold) !important;
}

h2 {
    font-size: var(--fs-h2) !important;
    font-weight: var(--fw-bold) !important;
}

h3 {
    font-size: var(--fs-h3) !important;
    font-weight: var(--fw-bold) !important;
}

h4 {
    font-size: var(--fs-h4) !important;
    font-weight: var(--fw-bold) !important;
}

h5 {
    font-size: var(--fs-h5) !important;
    font-weight: var(--fw-bold) !important;
}

h6 {
    font-size: var(--fs-h6) !important;
    font-weight: var(--fw-bold) !important;
}


/* ─── Scanbo HIMS shell refresh: MUI components styled like the reference ─── */
:root {
    --primary: #0874bf;
    --primary-rgb: 8, 116, 191;
    --info: #0874bf;
    --info-rgb: 8, 116, 191;
    --success: #22a276;
    --success-rgb: 34, 162, 118;
    --warning: #d89018;
    --warning-rgb: 216, 144, 24;
    --error: #ef6b75;
    --error-rgb: 239, 107, 117;
    --bg-page: #eaf4fb;
    --surface-2: #f5f9fd;
    --border: #cfe2f2;
    --border-strong: #b8d2e8;
    --text-primary: #203040;
    --text-secondary: #516273;
    --text-muted: #7e94a8;
    --primary-soft: #d6ebfa;
    --sidebar-width: 260px;
    --topbar-height: 70px;
    --sidebar-bg: #145d91;
    --sidebar-text: #ffffff;
    --sidebar-active: #ffffff;
    --sidebar-hover: rgba(255, 255, 255, 0.13);
    --cardShadow: 0 8px 24px rgba(43, 83, 111, 0.08);
}

body {
    background: var(--bg-page);
}

.page-content {
    max-width: none;
    padding: 0 0 54px;
}

.page-header,
#tab-dashboard .page-header {
    margin-bottom: 12px;
    padding: 22px 26px !important;
    border-radius: 18px;
    background: #cfe5f5 !important;
    border: 1px solid #c5deef;
}

.page-header-info h1,
#tab-dashboard .page-header-info h1 {
    font-size: 1.24rem !important;
    color: var(--text-primary) !important;
    letter-spacing: 0 !important;
}

.page-header-info p,
#tab-dashboard .page-header-info p {
    font-size: 0.88rem !important;
    color: var(--text-secondary) !important;
}

.dashboard-content {
    gap: 12px;
}

.card,
.dashboard-plan-card-container {
    border-color: var(--border) !important;
    border-radius: 8px !important;
    box-shadow: var(--cardShadow) !important;
}

#tab-dashboard .card,
#tab-dashboard .dashboard-plan-card-container,
#tab-dashboard .dashboard-devices-card,
#tab-dashboard .dashboard-graph-card {
    background: #ffffff !important;
    background-color: #ffffff !important;
}

.dashboard-plan-card-container {
    background: #ffffff !important;
    padding: 18px !important;
}

.dashboard-plan-cards {
    gap: 12px;
}

.dashboard-plan-info-card,
.dashboard-device-card {
    border-color: var(--border) !important;
    border-radius: 8px !important;
}

.dashboard-plan-info-card {
    min-height: 96px;
}

.dashboard-devices-grid {
    gap: 12px;
}

.dashboard-analytics-section {
    gap: 12px;
}

.dashboard-bar-chart-track,
.dashboard-graph-filter-btn {
    border-radius: 8px;
}

.dashboard-footer {
    position: fixed;
    left: calc(var(--sidebar-width) + 4px);
    right: 10px;
    bottom: 8px;
    height: 34px;
    z-index: 80;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 18px rgba(43, 83, 111, 0.08);
}

.dashboard-footer small {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 700;
}

@media (max-width: 1024px) {
    .topbar-search {
        width: min(300px, 30vw);
    }
}

@media (max-width: 768px) {
    .dashboard-shell {
        padding: 8px;
    }

    .sidebar {
        top: 8px;
        left: 8px;
        height: calc(100vh - 16px);
        width: calc(var(--sidebar-width) - 12px);
    }

    .main-content {
        margin-left: 0;
    }

    .topbar {
        height: auto;
        min-height: var(--topbar-height);
        flex-wrap: wrap;
        padding: 10px 12px;
        gap: 10px;
    }

    .topbar-left {
        min-width: 0;
        flex: 1;
    }

    .topbar-search {
        order: 3;
        width: 100%;
        margin: 0 !important;
    }

    .topbar-right {
        gap: 4px;
    }

    .topbar-icon-btn:nth-of-type(2),
    .topbar-icon-btn:nth-of-type(3),
    .topbar-icon-btn:nth-of-type(4) {
        display: none !important;
    }

    .topbar-user {
        min-width: 0;
        width: 44px;
        padding: 5px;
    }

    .topbar-user-copy,
    .topbar-user>svg {
        display: none;
    }

    .page-header,
    #tab-dashboard .page-header {
        padding: 18px !important;
    }

    .dashboard-footer {
        left: 8px;
        right: 8px;
        bottom: 8px;
    }
}

/* ─── Custom Scrollbar Styles ──────────────────────────────── */
.tab-section.active,
.main-content,
[style*="overflow-y: auto"],
[style*="overflow: auto"] {
    scrollbar-width: thin;
    scrollbar-color: rgba(var(--primary-rgb), 0.3) transparent;
}

/* Chrome, Edge, and Safari */
.tab-section.active::-webkit-scrollbar,
.main-content::-webkit-scrollbar,
[style*="overflow-y: auto"]::-webkit-scrollbar,
[style*="overflow: auto"]::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.tab-section.active::-webkit-scrollbar-track,
.main-content::-webkit-scrollbar-track,
[style*="overflow-y: auto"]::-webkit-scrollbar-track,
[style*="overflow: auto"]::-webkit-scrollbar-track {
    background: transparent;
}

.tab-section.active::-webkit-scrollbar-thumb,
.main-content::-webkit-scrollbar-thumb,
[style*="overflow-y: auto"]::-webkit-scrollbar-thumb,
[style*="overflow: auto"]::-webkit-scrollbar-thumb {
    background-color: rgba(var(--primary-rgb), 0.3);
    border-radius: 10px;
    border: 1px solid transparent;
    background-clip: padding-box;
}

.tab-section.active::-webkit-scrollbar-thumb:hover,
.main-content::-webkit-scrollbar-thumb:hover,
[style*="overflow-y: auto"]::-webkit-scrollbar-thumb:hover,
[style*="overflow: auto"]::-webkit-scrollbar-thumb:hover {
    background-color: rgba(var(--primary-rgb), 0.5);
}