:root {
    --primary: #1f6f54;
    --primary-hover: #175742;
    --primary-light: #eef7f2;
    --primary-dark: #0f3629;
    --secondary: #0f172a;
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --border-color: #e2e8f0;
    --border-subtle: #edf2f7;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --warning: #f59e0b;
    --warning-light: #fffbeb;
    --info: #3b82f6;
    --info-light: #eff6ff;
    --success: #10b981;
    --success-light: #ecfdf5;
    --sidebar-width: 260px;
    --header-height: 64px;
    --radius: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: #ffffff;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transition: transform 0.25s ease-in-out;
}

.sidebar-brand {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    background: #ffffff;
}

.brand-icon {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    box-shadow: 0 2px 4px rgba(31, 111, 84, 0.25);
}

.brand-info {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.brand-sub {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    letter-spacing: 0.2px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-light);
    font-weight: 600;
    letter-spacing: 0.5px;
    padding: 8px 12px 4px;
}

/* Hierarchical Sidebar Submenu */
.nav-group {
    margin-bottom: 2px;
}

.nav-parent-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8.5px 12px;
    border-radius: var(--radius);
    color: #334155;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    user-select: none;
    transition: all 0.15s ease;
}

.nav-parent-item:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}

.nav-parent-item .chevron-icon {
    font-size: 11px;
    transition: transform 0.2s ease;
    color: #94a3b8;
}

.nav-group.open .nav-parent-item .chevron-icon {
    transform: rotate(180deg);
}

.nav-sub-menu {
    display: none;
    flex-direction: column;
    gap: 2px;
    padding-left: 12px;
    margin-top: 2px;
    margin-bottom: 4px;
    border-left: 2px solid #e2e8f0;
    margin-left: 20px;
}

.nav-group.open .nav-sub-menu {
    display: flex;
}

.nav-sub-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    color: #64748b;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.15s ease;
}

.nav-sub-link:hover {
    color: var(--primary);
    background-color: #f8fafc;
}

.nav-sub-link.active {
    color: var(--primary);
    font-weight: 700;
    background-color: var(--primary-light);
}

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: #475569;
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    transition: all 0.15s ease;
}

.nav-link-item:hover {
    background-color: #f1f5f9;
    color: var(--primary);
}

.nav-link-item.active {
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.nav-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
}

.nav-badge {
    margin-left: auto;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 9999px;
    background: #f1f5f9;
    color: #475569;
    font-weight: 600;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border-color);
    background: #fafafa;
}

.user-mini-card {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar-sm {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.user-mini-meta {
    flex: 1;
    min-width: 0;
}

.user-mini-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-mini-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* Main Content */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100vh;
}

/* Header */
.app-header {
    height: var(--header-height);
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 90;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle-btn {
    display: none;
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    font-size: 16px;
    color: var(--text-main);
}

.billing-entity-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 9999px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-clock {
    font-size: 12.5px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Content Area */
.app-content {
    padding: 24px;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
    line-height: 1.2;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13.5px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    color: #ffffff;
}

.btn-outline {
    background-color: #ffffff;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
}

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-danger {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-danger:hover {
    background-color: #dc2626;
}

/* Cards */
.card {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-main);
}

.card-body {
    padding: 20px;
}

/* Grid KPI Metrics */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.metric-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.metric-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-main);
    margin: 6px 0 4px;
}

.metric-sub {
    font-size: 12px;
    color: var(--text-muted);
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

.table th {
    background-color: #f8fafc;
    color: #475569;
    font-weight: 600;
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    color: #334155;
    vertical-align: middle;
}

.table tr:hover td {
    background-color: #fcfcfc;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 9999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-success {
    background-color: #ecfdf5;
    color: #065f46;
}

.badge-warning {
    background-color: #fffbeb;
    color: #92400e;
}

.badge-danger {
    background-color: #fef2f2;
    color: #991b1b;
}

.badge-info {
    background-color: #eff6ff;
    color: #1e40af;
}

.badge-neutral {
    background-color: #f1f5f9;
    color: #475569;
}

.badge-b2b {
    background-color: #e0e7ff;
    color: #3730a3;
}

.badge-b2c {
    background-color: #fae8ff;
    color: #86198f;
}

/* Form inputs */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    font-size: 13.5px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: #ffffff;
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s ease;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 111, 84, 0.15);
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-dialog {
    background: #ffffff;
    border-radius: 10px;
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.modal-dialog form {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.modal-dialog-lg {
    max-width: 850px;
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    background: #fafafa;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 360px;
}

.toast-item {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: flex-start;
    gap: 12px;
    animation: toastSlideIn 0.2s ease-out;
}

.toast-item.success {
    border-left: 4px solid var(--primary);
}

.toast-item.error {
    border-left: 4px solid var(--danger);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Tabs */
.nav-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    gap: 16px;
    margin-bottom: 20px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 4px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    position: relative;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Responsive */
@media (max-width: 991px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-sidebar.show {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
    .sidebar-toggle-btn {
        display: inline-block;
    }
}
