@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap');

:root {
    --master-primary: #111827;
    --master-secondary: #374151;
    --master-accent: #6366f1;
    --master-success: #10b981;
    --master-warning: #f59e0b;
    --master-danger: #ef4444;
    --master-bg: #f8fafc;
    --master-card: #ffffff;
    --master-border: #e5e7eb;
    --master-text: #111827;
    --master-muted: #6b7280;
    --master-sidebar-width: 260px;
    --master-topbar-height: 60px;
    --master-radius: 12px;
    --master-shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 4px 12px rgba(17, 24, 39, 0.04);
    --bs-body-font-family: 'Montserrat', sans-serif;
    --bs-font-sans-serif: 'Montserrat', sans-serif;
    --bs-body-color: var(--master-text);
    --bs-body-bg: var(--master-bg);
    --bs-primary: var(--master-accent);
    --bs-primary-rgb: 99, 102, 241;
    --bs-secondary: var(--master-secondary);
    --bs-success: var(--master-success);
    --bs-warning: var(--master-warning);
    --bs-danger: var(--master-danger);
    --bs-border-color: var(--master-border);
    --bs-link-color: var(--master-accent);
    --bs-link-hover-color: #4f46e5;
}

*,
*::before,
*::after {
    font-family: 'Montserrat', sans-serif !important;
}

html {
    scroll-behavior: smooth;
}

body {
    background: var(--master-bg);
    color: var(--master-text);
    font-weight: 400;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.master-admin {
    overflow-x: hidden;
}

/* Shell */
.master-shell {
    display: flex;
    min-height: 100vh;
}

.master-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--master-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.2s ease;
}

/* Sidebar */
.master-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--master-sidebar-width);
    height: 100vh;
    background: var(--master-card);
    border-right: 1px solid var(--master-border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.2s ease;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--master-border);
}

.sidebar-brand-logo {
    display: block;
    text-decoration: none;
    color: var(--master-text);
}

.master-brand-mark {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.55rem;
}

.master-brand-logo {
    display: block;
    width: 100%;
    max-width: 168px;
    height: auto;
}

.master-brand-title {
    display: block;
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}

.master-brand-site-name {
    display: block;
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--master-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--master-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.sidebar-brand-title {
    font-size: 0.9375rem;
    font-weight: 600;
    line-height: 1.2;
    margin: 0;
}

.sidebar-brand-subtitle {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--master-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem 1.5rem;
}

.nav-group + .nav-group {
    margin-top: 1.25rem;
}

.nav-group-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--master-muted);
    padding: 0 0.75rem 0.5rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.125rem;
    border-radius: 8px;
    color: var(--master-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s ease, color 0.15s ease;
}

.nav-item i {
    font-size: 1rem;
    width: 1.125rem;
    text-align: center;
    opacity: 0.85;
}

.nav-item:hover {
    background: #f3f4f6;
    color: var(--master-text);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.08);
    color: var(--master-accent);
    font-weight: 600;
}

.nav-item.active i {
    color: var(--master-accent);
}

.nav-item.is-disabled {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
}

/* Collapsible submenu */
.nav-item-parent {
    width: 100%;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.nav-item-parent[aria-expanded='true'] {
    background: rgba(99, 102, 241, 0.06);
    color: var(--master-accent);
    font-weight: 600;
}

.nav-item-parent[aria-expanded='true'] .nav-chevron {
    transform: rotate(180deg);
}

.nav-chevron {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.nav-submenu {
    display: none;
    overflow: hidden;
    margin: 0.125rem 0 0.25rem 0;
    padding-left: 0.5rem;
    border-left: 2px solid rgba(99, 102, 241, 0.15);
    margin-left: 0.75rem;
}

.nav-submenu.is-open {
    display: block;
}

.nav-sub-item {
    padding: 0.45rem 0.625rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.nav-sub-item i {
    font-size: 0.875rem;
    width: 1rem;
}

.nav-item-soon {
    margin-left: auto;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--master-muted);
    background: #f3f4f6;
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, 0.45);
    z-index: 1035;
    opacity: 0;
    transition: opacity 0.2s ease;
}

body.sidebar-open {
    overflow: hidden;
}

body.sidebar-open .sidebar-backdrop {
    display: block;
    opacity: 1;
}

/* Topbar */
.master-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    height: var(--master-topbar-height);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--master-border);
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
}

.btn-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--master-border);
    background: var(--master-card);
    color: var(--master-secondary);
}

.btn-icon:hover {
    background: #f9fafb;
    color: var(--master-text);
}

.topbar-search {
    flex: 1;
    max-width: 420px;
    position: relative;
}

.topbar-search i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--master-muted);
    font-size: 0.9375rem;
}

.topbar-search .form-control {
    padding-left: 2.5rem;
    height: 44px;
    min-height: 44px;
    border-radius: 8px;
    border-color: var(--master-border);
    background: #f9fafb;
    font-size: 0.875rem;
}

.topbar-search .form-control:focus {
    background: var(--master-card);
    border-color: var(--master-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.topbar-action-btn {
    position: relative;
}

.notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--master-danger);
    color: #fff;
    font-size: 0.625rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.user-profile-btn {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.375rem 0.625rem 0.375rem 0.375rem;
    border: 1px solid var(--master-border);
    border-radius: 999px;
    background: var(--master-card);
    color: var(--master-text);
    text-decoration: none;
    font-size: 0.8125rem;
    font-weight: 500;
}

.user-profile-btn:hover {
    background: #f9fafb;
    color: var(--master-text);
}

.user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: var(--master-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.dropdown-menu-master {
    border: 1px solid var(--master-border);
    border-radius: var(--master-radius);
    box-shadow: var(--master-shadow);
    padding: 0.5rem;
    min-width: 280px;
}

.dropdown-menu-master .dropdown-header {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--master-muted);
}

.dropdown-menu-master .dropdown-item {
    min-height: 44px;
    display: flex;
    align-items: center;
    border-radius: 8px;
    font-size: 0.875rem;
    padding: 0.625rem 0.75rem;
}

.notification-item {
    display: block;
    padding: 0.625rem 0.75rem;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    min-height: 44px;
}

.notification-item:hover {
    background: #f9fafb;
}

.notification-item.unread {
    background: rgba(99, 102, 241, 0.04);
}

.notification-item-title {
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
}

.notification-item-text {
    font-size: 0.75rem;
    color: var(--master-muted);
    line-height: 1.4;
}

.notification-item-time {
    font-size: 0.6875rem;
    color: var(--master-muted);
    margin-top: 0.25rem;
}

/* Page */
.page-heading {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem 1.5rem 0;
    margin-bottom: 0.25rem;
}

.page-heading-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    min-width: 0;
}

.page-back-btn {
    white-space: nowrap;
}

.page-title {
    font-size: 1.375rem;
    font-weight: 600;
    margin: 0;
    letter-spacing: -0.02em;
}

.page-subtitle {
    font-size: 0.875rem;
    color: var(--master-muted);
    margin: 0.25rem 0 0;
}

.master-content {
    padding: 1.25rem 1.5rem 2rem;
    flex: 1;
}

/* Cards */
.master-card,
.card {
    background: var(--master-card);
    border: 1px solid var(--master-border);
    border-radius: var(--master-radius);
    box-shadow: var(--master-shadow);
}

.master-card .card-header,
.card .card-header {
    background: transparent;
    border-bottom: 1px solid var(--master-border);
    padding: 1rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
}

.master-card .card-body,
.card .card-body {
    padding: 1.25rem;
}

.master-card .card-footer,
.card .card-footer {
    background: transparent;
    border-top: 1px solid var(--master-border);
    padding: 0.875rem 1.25rem;
}

/* KPI */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.kpi-card {
    padding: 1.125rem 1.25rem;
    min-height: 112px;
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--master-muted);
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: -0.03em;
    color: var(--master-text);
}

.kpi-meta {
    font-size: 0.75rem;
    color: var(--master-muted);
    margin-top: 0.5rem;
}

.kpi-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.kpi-icon.accent { background: rgba(99, 102, 241, 0.1); color: var(--master-accent); }
.kpi-icon.success { background: rgba(16, 185, 129, 0.1); color: var(--master-success); }
.kpi-icon.warning { background: rgba(245, 158, 11, 0.1); color: var(--master-warning); }
.kpi-icon.danger { background: rgba(239, 68, 68, 0.1); color: var(--master-danger); }
.kpi-icon.neutral { background: #f3f4f6; color: var(--master-secondary); }

/* Health bars */
.health-stat-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.health-stat-row:last-child {
    border-bottom: 0;
}

.health-stat-label {
    font-size: 0.875rem;
    font-weight: 500;
}

.health-stat-value {
    font-size: 0.875rem;
    font-weight: 600;
}

.health-progress {
    height: 6px;
    border-radius: 999px;
    background: #f3f4f6;
    overflow: hidden;
    margin-top: 0.375rem;
}

.health-progress-bar {
    height: 100%;
    border-radius: 999px;
}

/* Activity feed */
.activity-feed {
    list-style: none;
    margin: 0;
    padding: 0;
}

.activity-item {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid #f3f4f6;
}

.activity-item:last-child {
    border-bottom: 0;
}

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: var(--master-accent);
    margin-top: 0.375rem;
    flex-shrink: 0;
}

.activity-text {
    font-size: 0.8125rem;
    line-height: 1.45;
}

.activity-time {
    font-size: 0.6875rem;
    color: var(--master-muted);
    margin-top: 0.125rem;
}

/* Quick actions */
.quick-action-grid {
    display: grid;
    grid-template-columns: repeat(1, minmax(0, 1fr));
    gap: 1rem;
}

.quick-action-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 1.125rem;
    border: 1px solid var(--master-border);
    border-radius: var(--master-radius);
    background: var(--master-card);
    text-decoration: none;
    color: var(--master-text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.quick-action-card:hover {
    border-color: rgba(99, 102, 241, 0.35);
    box-shadow: var(--master-shadow);
    color: var(--master-text);
}

.quick-action-card i {
    font-size: 1.125rem;
    color: var(--master-accent);
}

.quick-action-card span {
    font-size: 0.875rem;
    font-weight: 600;
}

.quick-action-card small {
    font-size: 0.75rem;
    color: var(--master-muted);
}

/* Tables */
.master-table-wrap {
    width: 100%;
}

.master-table-scroll {
    overflow-x: auto;
    overflow-y: auto;
    max-height: min(70vh, 720px);
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.master-table-scroll .table > thead {
    position: sticky;
    top: 0;
    z-index: 2;
}

.table-responsive {
    border-radius: 0 0 var(--master-radius) var(--master-radius);
    -webkit-overflow-scrolling: touch;
}

.table-responsive.master-table-scroll {
    overflow-x: auto;
}

.table {
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table > thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.table > thead > tr > th {
    background: #f9fafb;
    border-bottom: 1px solid var(--master-border);
    color: var(--master-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 0.75rem 1rem;
    white-space: nowrap;
}

.table > tbody > tr > td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
    border-bottom: 1px solid #f3f4f6;
}

.table > tbody > tr:hover {
    background: #fafbfc;
}

.table > tbody > tr:last-child > td {
    border-bottom: 0;
}

/* Forms */
.form-label {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--master-secondary);
    margin-bottom: 0.375rem;
}

.form-control,
.form-select {
    border-color: var(--master-border);
    border-radius: 8px;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    min-height: 44px;
}

.form-control-sm,
.form-select-sm {
    min-height: 44px;
}

textarea.form-control {
    min-height: 88px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--master-accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-control-lg,
.form-select-lg {
    padding: 0.75rem 1rem;
}

/* Buttons */
.btn {
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
}

.btn-sm {
    min-height: 44px;
    padding: 0.375rem 0.75rem;
}

.btn-primary {
    background: var(--master-accent);
    border-color: var(--master-accent);
}

.btn-primary:hover,
.btn-primary:focus {
    background: #4f46e5;
    border-color: #4f46e5;
}

.btn-outline-primary {
    color: var(--master-accent);
    border-color: rgba(99, 102, 241, 0.35);
}

.btn-outline-primary:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--master-accent);
    color: var(--master-accent);
}

.btn-dark {
    background: var(--master-primary);
    border-color: var(--master-primary);
}

/* Badges */
.badge {
    font-weight: 600;
    font-size: 0.6875rem;
    letter-spacing: 0.02em;
    padding: 0.35em 0.65em;
    border-radius: 6px;
}

/* Alerts */
.alert {
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 0.875rem;
}

/* Sync status pills */
.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #f3f4f6;
    color: var(--master-secondary);
}

.sync-pill.success { background: rgba(16, 185, 129, 0.1); color: var(--master-success); }
.sync-pill.danger { background: rgba(239, 68, 68, 0.1); color: var(--master-danger); }
.sync-pill.warning { background: rgba(245, 158, 11, 0.1); color: var(--master-warning); }

.sync-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.625rem 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.8125rem;
}

.sync-list-item:last-child {
    border-bottom: 0;
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    background: var(--master-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border: 1px solid var(--master-border);
    border-radius: var(--master-radius);
    box-shadow: var(--master-shadow);
    background: var(--master-card);
}

.auth-brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-brand .master-brand-mark {
    align-items: center;
    margin-bottom: 0.75rem;
}

.auth-brand .master-brand-logo {
    max-width: 220px;
    margin: 0 auto;
}

/* Utilities */
.text-muted {
    color: var(--master-muted) !important;
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--master-muted);
    font-size: 0.875rem;
}

code {
    word-break: break-all;
    font-size: 0.8125rem;
    color: var(--master-secondary);
}

.user-profile-btn.dropdown-toggle::after {
    display: none;
}

.dropdown-toggle.btn-icon::after {
    display: none;
}

/* Modals */
.modal-content {
    border: 1px solid var(--master-border);
    border-radius: var(--master-radius);
    box-shadow: var(--master-shadow);
}

.modal-header,
.modal-footer {
    border-color: var(--master-border);
}

/* Charts */
.master-chart-wrap {
    position: relative;
    width: 100%;
    min-height: 220px;
}

.master-chart-wrap canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 360px;
}

.master-content .card .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.master-content .card .table-responsive .table > thead > tr > th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #f9fafb;
}

/* Mobile stacked table cards */
.master-table-stack .master-data-table tbody tr.master-mobile-card-row,
.master-table-stack .master-data-table tbody tr:not(.master-table-empty) {
    transition: none;
}

/* Responsive layout */
@media (min-width: 768px) {
    .kpi-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .quick-action-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1366px) {
    .kpi-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

    .quick-action-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (max-width: 991.98px) {
    .master-main {
        margin-left: 0;
    }

    .master-sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    body.sidebar-open .master-sidebar {
        transform: translateX(0);
        box-shadow: 8px 0 24px rgba(17, 24, 39, 0.12);
    }

    .topbar-search {
        max-width: none;
        flex: 1;
    }

    .master-table-scroll {
        max-height: none;
    }
}

@media (max-width: 767.98px) {
    .master-content .row > [class*='col-md'],
    .master-content .row > [class*='col-lg'],
    .master-content .row > [class*='col-xl'] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .card-header.d-flex {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .card-header .btn {
        width: 100%;
    }

    .kpi-card {
        min-height: 96px;
        padding: 1rem;
    }

    .kpi-value {
        font-size: 1.5rem;
    }

    .page-title {
        font-size: 1.125rem;
    }

    .master-table-stack .master-table-scroll {
        overflow: visible;
        max-height: none;
    }

    .master-table-stack .master-data-table {
        border: 0;
    }

    .master-table-stack .master-data-table thead {
        display: none;
    }

    .master-table-stack .master-data-table tbody {
        display: block;
    }

    .master-table-stack .master-data-table tbody tr {
        display: block;
        background: var(--master-card);
        border: 1px solid var(--master-border);
        border-radius: var(--master-radius);
        box-shadow: var(--master-shadow);
        margin-bottom: 0.75rem;
        padding: 0.25rem 0;
    }

    .master-table-stack .master-data-table tbody tr:hover {
        background: var(--master-card);
    }

    .master-table-stack .master-data-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.625rem 1rem;
        border-bottom: 1px solid #f3f4f6;
        text-align: right;
    }

    .master-table-stack .master-data-table tbody td:last-child {
        border-bottom: 0;
        justify-content: flex-end;
    }

    .master-table-stack .master-data-table tbody td::before {
        content: attr(data-label);
        font-size: 0.6875rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--master-muted);
        text-align: left;
        flex: 0 0 42%;
    }

    .master-table-stack .master-data-table tbody td.master-table-actions {
        padding-top: 0.75rem;
    }

    .master-table-stack .master-data-table tbody td.master-table-actions::before {
        display: none;
    }

    .master-table-stack .master-data-table tbody td[colspan] {
        display: block;
        text-align: center;
    }

    .master-table-stack .master-data-table tbody td[colspan]::before {
        display: none;
    }

    .modal-dialog {
        margin: 0.75rem;
        max-width: calc(100% - 1.5rem);
    }

    .modal-fullscreen-sm-down {
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .modal-fullscreen-sm-down .modal-content {
        min-height: 100vh;
        border-radius: 0;
    }

    .modal-body {
        max-height: calc(100vh - 140px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 575.98px) {
    .master-topbar {
        padding: 0 0.75rem;
        gap: 0.5rem;
    }

    .page-heading,
    .master-content {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .topbar-search .form-control {
        font-size: 16px;
    }

    .user-profile-btn .user-name {
        display: none;
    }

    .kpi-grid {
        gap: 0.75rem;
    }

    .quick-action-grid {
        grid-template-columns: 1fr;
    }

    .kpi-icon {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
}

@media (min-width: 992px) {
    .master-sidebar {
        transform: translateX(0) !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
    }
}

.connection-credentials-box {
    background: var(--master-surface, #fff);
    border: 1px solid var(--master-border, #e2e8f0);
    border-radius: 12px;
    padding: 1rem;
    display: grid;
    gap: 1rem;
    min-width: 0;
    overflow: hidden;
}

.connection-credentials-grid {
    display: grid;
    gap: 0.875rem;
    grid-template-columns: minmax(0, 1fr);
}

.copy-field-row {
    display: grid;
    gap: 0.375rem;
    min-width: 0;
}

.copy-field-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--master-text-muted, #64748b);
    margin: 0;
}

.copy-field-control {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
    min-width: 0;
}

.copy-field-input {
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    border: 1px solid var(--master-border, #e2e8f0);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    background: var(--master-bg, #f8fafc);
    color: var(--master-text, #0f172a);
}

.copy-field-input--mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    word-break: break-all;
}

.copy-field-input[readonly] {
    cursor: text;
}

.copy-field-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
    flex: 0 0 auto;
}

.copy-field-btn.is-copied {
    border-color: #198754;
    color: #198754;
}

.copy-field-hint {
    font-size: 0.75rem;
    color: var(--master-text-muted, #64748b);
}

/* Sidebar credential panel — stack input and copy button */
.col-lg-4 .copy-field-control {
    flex-direction: column;
    align-items: stretch;
}

.col-lg-4 .copy-field-btn {
    width: 100%;
    justify-content: center;
}

.module-filter-card .card-header {
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
    font-weight: 600;
}

/* Filter & sort forms — prevent clipped select text in narrow columns */
.module-filter-card .card-body > form > .row,
.master-filter-form > .row,
.master-filter-form form > .row,
.master-filter-toolbar {
    --filter-field-min: 9.5rem;
    row-gap: 1rem;
}

.module-filter-card .card-body > form > .row > [class*='col-'],
.master-filter-form > .row > [class*='col-'],
.master-filter-form form > .row > [class*='col-'] {
    min-width: var(--filter-field-min);
}

.module-filter-card .form-select,
.module-filter-card .form-control,
.master-filter-form .form-select,
.master-filter-form .form-control,
.master-filter-toolbar .form-select,
.master-filter-toolbar .form-control {
    width: 100%;
    max-width: 100%;
}

.module-filter-card .form-select,
.master-filter-form .form-select,
.master-filter-toolbar .form-select {
    padding-right: 2.5rem;
    background-position: right 0.875rem center;
    background-size: 14px 10px;
}

.module-filter-card form > .row > [class*='col-']:has([name='search']),
.master-filter-form form > .row > [class*='col-']:has([name='search']) {
    min-width: 14rem;
    flex: 1 1 16rem;
}

.module-filter-card form > .row > [class*='col-']:has([name='sort_by']),
.module-filter-card form > .row > [class*='col-']:has([name='sort_metrics']),
.module-filter-card form > .row > [class*='col-']:has([name='sort_events']),
.master-filter-form form > .row > [class*='col-']:has([name='sort_by']),
.master-filter-form form > .row > [class*='col-']:has([name='sort_metrics']),
.master-filter-form form > .row > [class*='col-']:has([name='sort_events']) {
    min-width: 11.5rem;
    flex: 0 1 13rem;
}

.module-filter-card form > .row > [class*='col-']:has([name='sort_dir']),
.master-filter-form form > .row > [class*='col-']:has([name='sort_dir']) {
    min-width: 7rem;
    flex: 0 1 8.5rem;
}

.module-filter-card form > .row > [class*='col-'].d-grid:has(.btn),
.master-filter-form form > .row > [class*='col-'].d-grid:has(.btn) {
    min-width: 5.75rem;
    flex: 0 1 7.5rem;
}

.module-filter-sort-row {
    margin-top: 0.25rem !important;
    padding-top: 1rem !important;
    border-top: 1px solid var(--master-border);
}

.master-filter-toolbar {
    flex-wrap: wrap;
    align-items: center;
}

.master-filter-toolbar .form-select {
    flex: 0 1 auto;
    min-width: 9rem;
}

.master-filter-form form > .row > .col-auto,
.module-filter-card form > .row > .col-auto {
    min-width: 9rem;
    flex: 0 1 auto;
}

.report-export-actions {
    margin-left: auto;
}

.report-export-dropdown .dropdown-toggle {
    white-space: nowrap;
}

.master-data-table .col-serial {
    width: 3rem;
}

.master-data-table .col-actions {
    min-width: 8.5rem;
}

.master-data-table td.small,
.master-data-table th.small {
    font-size: 0.8125rem;
    max-width: 12rem;
    word-break: break-word;
}

@media (max-width: 767.98px) {
    .module-filter-card .card-body > form > .row > [class*='col-'],
    .master-filter-form form > .row > [class*='col-'] {
        flex: 0 0 100%;
        max-width: 100%;
        min-width: 0;
    }

    .module-filter-card form > .row > [class*='col-']:has([name='sort_dir']),
    .module-filter-card form > .row > [class*='col-'].d-grid:has(.btn),
    .master-filter-form form > .row > [class*='col-']:has([name='sort_dir']),
    .master-filter-form form > .row > [class*='col-'].d-grid:has(.btn) {
        flex: 0 0 calc(50% - 0.5rem);
        max-width: calc(50% - 0.5rem);
    }
}

@media (max-width: 575.98px) {
    .copy-field-control {
        flex-direction: column;
        align-items: stretch;
    }

    .copy-field-btn {
        width: 100%;
        justify-content: center;
    }

    .report-export-actions {
        width: 100%;
    }

    .report-export-dropdown,
    .report-export-dropdown .dropdown-toggle {
        width: 100%;
    }
}

.sync-detail-list dt {
    color: var(--master-text-muted, #64748b);
    font-size: 0.8125rem;
    font-weight: 500;
}

.sync-detail-list dd {
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}
