* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-color: #f4f7fb;
    --card-bg: rgba(255, 255, 255, 0.82);
    --sidebar-bg: rgba(255, 255, 255, 0.92);
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 80px;
    --header-height: 70px;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    /* CloudtoBuild-aligned blue */
    --primary-light: rgba(37, 99, 235, 0.12);
    --primary-hover: #1d4ed8;
    --danger: #ef4444;
    --success: #10b981;
    --warning: #f59e0b;

    --border: rgba(148, 163, 184, 0.22);
    --glass-border: rgba(255, 255, 255, 0.55);

    --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 24px rgba(15, 23, 42, 0.08);
    --shadow-lg: 0 20px 40px rgba(15, 23, 42, 0.10);

    --glass-blur: blur(18px);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --radius: 14px;
}

.dashboard-charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
    align-items: stretch;
}

@media (max-width: 1400px) {
    .dashboard-charts-grid {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-charts-grid> :first-child {
        grid-column: span 2;
        margin-bottom: 5px;
    }
}

@media (max-width: 1024px) {
    .dashboard-charts-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-charts-grid> :first-child {
        grid-column: span 1;
    }
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.14) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(14, 165, 233, 0.10) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(99, 102, 241, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout Structure */
.dashboard-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: var(--transition);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Center the logo container */
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
}


.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    height: 40px;
}

.logo-full {
    height: 40px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
    transition: var(--transition);
}

.logo-sm {
    height: 32px;
    width: 32px;
    object-fit: contain;
    display: none;
    /* Hidden by default */
}

/* Collapsed State Logo Logic */
.sidebar.collapsed .logo-full {
    display: none;
}

.sidebar.collapsed .logo-sm {
    display: block;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 0;
}

.sidebar.collapsed .logo-container {
    width: auto;
    margin: 0 auto;
}

#sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 5px;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    /* Float it */
    right: 10px;
}

#sidebar-toggle:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.sidebar.collapsed #sidebar-toggle {
    transform: rotate(180deg);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: 12px;
    transition: var(--transition);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
}

.mobile-logout-item {
    display: none !important;
}

.nav-item i {
    font-size: 1.25rem;
    min-width: 24px;
    display: flex;
    justify-content: center;
}

.nav-item:hover {
    background: white;
    box-shadow: var(--shadow-sm);
    color: var(--primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.nav-badge {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.25);
    flex-shrink: 0;
}

.nav-item.active .nav-badge {
    background: #fff;
    color: #ef4444;
}

.sidebar.collapsed .nav-item {
    position: relative;
    padding: 12px 0;
    justify-content: center;
}

.sidebar.collapsed .nav-badge {
    position: absolute;
    top: 4px;
    right: 8px;
    margin-left: 0;
    min-width: 16px;
    height: 16px;
    line-height: 16px;
    font-size: 0.65rem;
    padding: 0 4px;
}

.sidebar.collapsed .nav-text {
    opacity: 0;
    width: 0;
    margin-left: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar.collapsed .user-info {
    display: none;
}

.user-avatar i {
    font-size: 2.2rem;
    color: var(--text-muted);
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-logout-icon {
    color: var(--text-muted);
    font-size: 1.25rem;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
    display: flex;
    justify-content: center;
}

h1,
h2,
h3 {
    letter-spacing: -0.02em;
}

.logo-container {
    transition: var(--transition);
}

.logo-container:hover {
    transform: scale(1.05);
}

.btn-logout-icon:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    transform: rotate(90deg);
}

.sidebar.collapsed .sidebar-footer {
    justify-content: center;
    padding: 20px 0;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    transition: var(--transition);
    display: flex;
    flex-direction: column;
}

.main-content.expanded {
    margin-left: var(--sidebar-collapsed-width);
    width: calc(100% - var(--sidebar-collapsed-width));
}

.top-bar {
    height: var(--header-height);
    padding: 0 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 90;
}

@media (min-width: 1025px) {
    /* Top bar is mobile-only chrome; reclaim space on desktop */
    .top-bar {
        display: none;
    }
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.content-wrapper {
    padding: 30px 40px;
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28);
    gap: 8px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.35);
    filter: brightness(1.05);
}

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 0.85rem;
    min-height: 34px;
}

.btn-secondary {
    background: white;
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    box-shadow: var(--shadow-md);
}

/* KPI Cards */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--card-bg);
    padding: 22px;
    border-radius: 18px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--glass-blur);
    transition: var(--transition);
}

.kpi-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
    border-color: rgba(37, 99, 235, 0.2);
}

.kpi-title {
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Tables */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    backdrop-filter: var(--glass-blur);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

th {
    text-align: left;
    padding: 14px 20px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: rgba(248, 250, 252, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

td {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 0.95rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(37, 99, 235, 0.03);
}

/* Forms */
.form-control {
    width: 100%;
    padding: 11px 14px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: white;
    transition: var(--transition);
    font-size: 0.95rem;
    color: var(--text-main);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-card {
    background: var(--card-bg);
    padding: 18px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    display: flex;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 24px;
    flex-wrap: wrap;
    box-shadow: var(--shadow-sm);
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.alert {
    border-radius: 12px;
    padding: 12px 16px;
    margin-bottom: 16px;
    border: 1px solid transparent;
    font-size: 0.92rem;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border-color: #a7f3d0;
}

.alert-danger,
.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border-color: #fecaca;
}

.alert-warning {
    background: #fffbeb;
    color: #92400e;
    border-color: #fde68a;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    backdrop-filter: var(--glass-blur);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-main);
}

/* Badges */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-active,
.badge-paid {
    background: #d1fae5;
    color: #065f46;
}

.badge-completed {
    background: #e5e7eb;
    color: #374151;
}

.badge-paused,
.badge-due {
    background: #fef3c7;
    color: #92400e;
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-cancelled,
.badge-overdue {
    background: #fee2e2;
    color: #991b1b;
}

.badge-upcoming {
    background: #f3f4f6;
    color: #374151;
}

.badge-onetime-status {
    background: #eff6ff;
    color: #1d4ed8;
}

/* Plan Type Badges */
.badge-recurring {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    font-size: 0.65rem !important;
}

.badge-onetime {
    background: #f3f4f6;
    color: #6b7280;
    border: 1px solid #e5e7eb;
    font-size: 0.65rem !important;
}

/* Mobile */
.mobile-only {
    display: none;
}

@media (max-width: 1024px) {
    body {
        font-size: 16px;
    }

    .sidebar {
        position: fixed !important;
        transform: none !important;
        width: 100% !important;
        height: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        flex-direction: row !important;
        border-right: none !important;
        border-top: 1px solid var(--border) !important;
        background: rgba(255, 255, 255, 0.96) !important;
        backdrop-filter: var(--glass-blur) !important;
        -webkit-backdrop-filter: var(--glass-blur) !important;
        box-shadow: 0 -8px 28px rgba(15, 23, 42, 0.08) !important;
        z-index: 9999 !important;
        transition: none !important;
        overflow: hidden !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    .sidebar-header,
    .sidebar-footer {
        display: none !important;
    }

    .sidebar-nav {
        display: flex !important;
        flex-direction: row !important;
        width: 100% !important;
        height: 72px !important;
        justify-content: flex-start !important;
        align-items: stretch !important;
        padding: 0 4px !important;
        margin: 0 !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-item {
        flex: 0 0 auto !important;
        min-width: 68px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: center !important;
        padding: 8px 6px !important;
        margin: 0 !important;
        border-radius: 0 !important;
        gap: 2px !important;
        height: 100% !important;
        background: transparent !important;
        position: relative !important;
    }

    .mobile-logout-item {
        display: none !important;
    }

    .nav-item i {
        font-size: 1.45rem !important;
        margin: 0 !important;
        color: var(--text-muted);
    }

    .nav-text {
        font-size: 9px !important;
        display: block !important;
        font-weight: 600 !important;
        opacity: 1 !important;
        width: auto !important;
        margin: 0 !important;
        color: var(--text-muted);
        text-align: center !important;
        line-height: 1.1 !important;
        white-space: nowrap;
    }

    .nav-item .nav-badge {
        position: absolute !important;
        top: 6px !important;
        right: 10px !important;
        margin: 0 !important;
        min-width: 16px !important;
        height: 16px !important;
        line-height: 16px !important;
        font-size: 0.6rem !important;
        padding: 0 4px !important;
        box-shadow: 0 0 0 2px #fff !important;
    }

    .nav-item.active {
        color: var(--primary) !important;
        background: transparent !important;
        box-shadow: none !important;
    }

    .nav-item.active i,
    .nav-item.active .nav-text {
        color: var(--primary) !important;
    }

    .nav-item.active .nav-badge {
        background: #ef4444 !important;
        color: #fff !important;
    }

    .nav-item.active::before {
        content: "";
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        width: 28px;
        height: 3px;
        background: var(--primary);
        border-radius: 0 0 4px 4px;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important;
    }

    .mobile-only {
        display: flex !important;
    }

    .mobile-logo-container {
        width: auto;
        display: flex;
        justify-content: flex-start;
        align-items: center;
        flex: 1;
    }

    .top-bar {
        padding: 0 16px !important;
        height: 64px !important;
        background: rgba(255, 255, 255, 0.94) !important;
        backdrop-filter: var(--glass-blur) !important;
        -webkit-backdrop-filter: var(--glass-blur) !important;
        border-bottom: 1px solid var(--border) !important;
        position: sticky;
        top: 0;
        z-index: 1000;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 12px;
    }

    .top-bar-actions {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    .btn-top-logout {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 12px;
        border: 1px solid var(--border);
        background: white;
        color: var(--text-muted);
        text-decoration: none;
        font-size: 1.25rem;
        transition: var(--transition);
    }

    .btn-top-logout:hover,
    .btn-top-logout:focus-visible {
        color: var(--danger);
        border-color: #fecaca;
        background: #fef2f2;
    }

    .page-title {
        font-size: 1.2rem !important;
    }

    .content-wrapper {
        padding: 18px 14px !important;
    }

    .kpi-grid {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
    }

    .kpi-card {
        padding: 16px !important;
        border-radius: 14px !important;
    }

    .kpi-card:hover {
        transform: none;
    }

    .kpi-value {
        font-size: 1.45rem !important;
    }

    .kpi-title {
        font-size: 0.78rem !important;
    }

    .flex-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px;
    }

    .flex-between > div[style*="display:flex"] {
        flex-direction: column !important;
        width: 100%;
        gap: 8px !important;
    }

    .flex-between .btn,
    .flex-between > div[style*="display:flex"] .btn,
    .filter-card .btn {
        width: 100%;
    }

    .content-wrapper > .flex-between h1 {
        font-size: 1.35rem !important;
    }

    .filter-card {
        flex-direction: column;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 14px !important;
    }

    .filter-card .form-group {
        width: 100% !important;
        min-width: 0 !important;
        flex: 1 1 100% !important;
    }

    td,
    th {
        padding: 12px 14px !important;
        font-size: 0.85rem !important;
    }

    .btn {
        padding: 11px 16px !important;
        font-size: 0.9rem !important;
        min-height: 44px;
    }

    .btn-sm {
        min-height: 38px;
        padding: 8px 12px !important;
    }

    #sidebar-toggle {
        display: none !important;
    }

    /* Stack action button groups in tables */
    td .btn,
    td a.btn {
        margin-bottom: 4px;
    }
}

/* ULTRA COMPACT LOGIN - Perfected Symmetry */
.login-body {
    background: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(37, 99, 235, 0.16) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(14, 165, 233, 0.12) 0px, transparent 50%);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    margin: 0;
}

.login-card-compact {
    width: 100%;
    max-width: 360px;
    background: rgba(255, 255, 255, 0.95);
    padding: 40px 30px;
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    backdrop-filter: var(--glass-blur);
}

.login-logo-box {
    margin-bottom: 30px;
    width: 100%;
    display: flex;
    justify-content: center;
}

.login-logo-box img {
    height: 45px;
    max-width: 100%;
    object-fit: contain;
}

.login-card-compact form {
    width: 100%;
}

.login-card-compact .form-group {
    width: 100%;
    margin-bottom: 12px;
}

.login-card-compact .form-control {
    width: 100%;
    text-align: center;
    background: #f8fafc;
    border: 1px solid transparent;
    min-height: 46px;
}

.login-card-compact .form-control:focus {
    background: white;
    border-color: var(--primary);
}

.login-card-compact .btn {
    width: 100%;
    margin-top: 15px;
    height: 48px;
    font-size: 1rem;
    font-weight: 600;
}

@media (max-width: 768px) {
    [id*="Modal"] {
        align-items: flex-end !important;
        padding: 0 !important;
    }

    [id*="Modal"] > div {
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 92vh !important;
        overflow-y: auto !important;
        padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px)) !important;
        border-radius: 18px 18px 0 0 !important;
        box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.15) !important;
    }

    [id*="Modal"] > div div[style*="display:flex"] {
        flex-direction: column !important;
        gap: 0 !important;
    }

    .form-group {
        margin-bottom: 15px !important;
    }

    .table-container {
        position: relative;
        border-radius: 12px;
        border: 1px solid var(--border);
    }

    .table-container::after {
        content: "Scroll →";
        position: absolute;
        right: 10px;
        top: 12px;
        background: rgba(37, 99, 235, 0.9);
        color: white;
        padding: 4px 8px;
        border-radius: 6px;
        font-size: 10px;
        font-weight: 600;
        opacity: 0.85;
        pointer-events: none;
        animation: fadeOut 3.5s forwards;
        z-index: 2;
    }

    .kpi-grid {
        grid-template-columns: 1fr !important;
    }
}

@keyframes fadeOut {
    0% {
        opacity: 0.85;
    }

    70% {
        opacity: 0.85;
    }

    100% {
        opacity: 0;
    }
}

@media (max-width: 480px) {
    .login-card-compact {
        padding: 30px 20px;
        max-width: 100%;
    }

    .content-wrapper {
        padding: 14px 12px !important;
    }

    .nav-item {
        min-width: 62px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .kpi-card:hover,
    .btn:hover {
        transform: none;
    }
}