:root {
    --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --sidebar-width: 260px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e2e8f0;
    --sidebar-text: #64748b;
    --sidebar-text-hover: #0f172a;
    --sidebar-active-bg: #eff6ff;
    --sidebar-active-text: #2563eb;
    --body-bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --table-head-bg: #1d4ed8;
    --table-head-color: #ffffff;
    --table-head-border: #1e3a8a;
    --radius: 0.75rem;
    --radius-sm: 0.5rem;
    --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.05);
    --shadow: 0 1px 3px 0 rgb(15 23 42 / 0.08), 0 1px 2px -1px rgb(15 23 42 / 0.08);
    --header-height: 64px;
    --header-bg: #e0f2fe;
}

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

body {
    font-family: var(--font-sans);
    color: var(--text-primary);
    background: var(--body-bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Bootstrap overrides */
.btn-primary {
    --bs-btn-bg: var(--primary);
    --bs-btn-border-color: var(--primary);
    --bs-btn-hover-bg: var(--primary-hover);
    --bs-btn-hover-border-color: var(--primary-hover);
    --bs-btn-active-bg: var(--primary-hover);
    --bs-btn-active-border-color: var(--primary-hover);
    font-weight: 500;
    border-radius: var(--radius-sm);
}

.form-control,
.form-select {
    border-color: var(--border);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.875rem;
    font-size: 0.9375rem;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.12);
}

/* App layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-width);
}

/* Sidebar */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform 0.25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    height: var(--header-height);
    min-height: var(--header-height);
    padding: 0 1rem;
    text-decoration: none;
    color: var(--text-primary);
    background: var(--header-bg);
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    min-width: 0;
}

.sidebar-brand-tagline {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    line-height: 1.15;
    font-size: 0.6875rem;
    font-weight: 600;
    color: #0369a1;
    letter-spacing: -0.01em;
    min-width: 0;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
}

.brand-logo {
    display: inline-flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
}

.brand-logo__image {
    display: block;
    height: auto;
    object-fit: contain;
}

.brand-logo--sidebar .brand-logo__image {
    width: auto;
    height: 36px;
    max-width: 100%;
    flex-shrink: 0;
}

.brand-logo--login {
    margin-bottom: 1rem;
}

.brand-logo--login .brand-logo__image {
    width: 168px;
    max-width: 100%;
}

.brand-logo--landing .brand-logo__image {
    width: 148px;
    max-width: 100%;
}

.brand-logo--landing.brand-logo--header .brand-logo__image {
    width: 120px;
}

.brand-logo__text {
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: -0.01em;
}

.sidebar-brand-text {
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: -0.01em;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.sidebar-label {
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem 0.375rem;
    margin-top: 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    margin-bottom: 2px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.9375rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link i {
    font-size: 1.125rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: #f1f5f9;
    color: var(--sidebar-text-hover);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

.sidebar-group {
    margin-bottom: 0.125rem;
}

.sidebar-group-toggle {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    text-align: left;
}

.sidebar-group-chevron {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}

.sidebar-group.is-open .sidebar-group-chevron {
    transform: rotate(180deg);
}

.sidebar-submenu {
    display: none;
    margin-bottom: 0.25rem;
}

.sidebar-group.is-open .sidebar-submenu {
    display: block;
}

.sidebar-sublink {
    padding-left: 2.35rem;
    font-size: 0.875rem;
}

.sidebar-sublink i {
    display: none;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--sidebar-border);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-sm);
}

.sidebar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #e2e8f0;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 0.875rem;
}

/* Top header */
.app-header {
    height: var(--header-height);
    min-height: var(--header-height);
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    flex-shrink: 0;
}

.app-header-title {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
    color: var(--text-primary);
}

.app-header-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0;
}

.app-header-toolbar {
    min-width: 0;
}

.app-header-toolbar .navbar-notifications {
    flex-shrink: 0;
    margin-left: auto;
}

.navbar-notifications-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease;
}

.navbar-notifications-btn:hover,
.navbar-notifications-btn.show {
    background: #fff;
    color: var(--primary);
}

.navbar-notifications-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    border: 2px solid var(--header-bg);
}

.navbar-notifications-menu {
    width: min(360px, calc(100vw - 2rem));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.navbar-notifications-header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.9375rem;
    border-bottom: 1px solid var(--border);
    background: #fafbfc;
}

.navbar-notifications-section + .navbar-notifications-section {
    border-top: 1px solid var(--border);
}

.navbar-notifications-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

.navbar-notifications-item {
    padding: 0.625rem 1rem;
    white-space: normal;
}

.navbar-notifications-item:hover {
    background: #f8fafc;
}

.navbar-notifications-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.125rem;
}

.navbar-notifications-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.navbar-notifications-more {
    font-size: 0.8125rem;
    color: var(--primary);
    padding: 0.5rem 1rem 0.75rem;
}

.navbar-notifications-empty {
    padding: 1.5rem 1rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.sidebar-toggle {
    display: none;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-primary);
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: #fff;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgb(15 23 42 / 0.4);
    z-index: 1035;
    backdrop-filter: blur(2px);
}

/* Content */
.app-content {
    flex: 1;
    padding: 1.5rem;
}

/* Cards & surfaces */
.surface-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.surface-card .card-header {
    background: #fafbfc;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

/* Stat cards */
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    height: 100%;
    transition: box-shadow 0.2s, border-color 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow);
    border-color: #cbd5e1;
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    margin-bottom: 0.875rem;
}

.stat-card-icon.blue {
    background: #eff6ff;
    color: #2563eb;
}

.stat-card-icon.green {
    background: #ecfdf5;
    color: #16a34a;
}

.stat-card-icon.amber {
    background: #fffbeb;
    color: #d97706;
}

.stat-card-icon.teal {
    background: #f0fdfa;
    color: #0d9488;
}

.stat-card-metric .stat-card-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--text-primary, #0f172a);
    margin-bottom: 0.375rem;
}

.stat-card-value-rp {
    font-size: 1.375rem !important;
}

.stat-card-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-top: 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--primary, #2563eb);
    text-decoration: none;
}

.stat-card-link:hover {
    text-decoration: underline;
}

.stat-card-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.stat-card-text {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* Table */
.table {
    --bs-table-hover-bg: #f8fafc;
    font-size: 0.9375rem;
}

.table > :not(caption) > thead > tr > th,
.table > :not(caption) > thead > tr > td,
.table > :not(caption) > thead.table-light > tr > th {
    --bs-table-bg: var(--table-head-bg);
    --bs-table-color: var(--table-head-color);
    --bs-table-bg-state: var(--table-head-bg);
    --bs-table-color-state: var(--table-head-color);
    background-color: var(--table-head-bg) !important;
    color: var(--table-head-color) !important;
    box-shadow: none !important;
    border-color: rgba(255, 255, 255, 0.18);
    vertical-align: middle;
}

.table thead th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--table-head-color) !important;
    border-bottom-width: 2px;
    border-bottom-color: var(--table-head-border);
    padding: 0.875rem 1rem;
}

.table-light > :not(caption) > thead > tr > th,
thead.table-light > tr > th {
    --bs-table-bg: var(--table-head-bg);
    --bs-table-color: var(--table-head-color);
    --bs-table-bg-state: var(--table-head-bg);
    --bs-table-color-state: var(--table-head-color);
    background-color: var(--table-head-bg) !important;
    color: var(--table-head-color) !important;
    box-shadow: none !important;
}

.login-demo-table thead th {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-secondary);
    background: transparent !important;
    color: var(--text-secondary) !important;
    box-shadow: none !important;
    border: none !important;
    font-size: inherit;
    text-transform: none;
    letter-spacing: normal;
    font-weight: 500;
    padding: 0.25rem 0.5rem;
}

.table tbody td {
    padding: 0.875rem 1rem;
    vertical-align: middle;
    border-color: var(--border);
}

/* Alerts */
.alert {
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.9375rem;
}

.alert-success {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

.alert-danger {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

/* Badges */
.badge {
    font-weight: 500;
    border-radius: 9999px;
    padding: 0.35em 0.65em;
}

/* Guest / login layout */
.guest-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse at 20% 50%, rgb(37 99 235 / 0.08), transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgb(99 102 241 / 0.06), transparent 50%),
        var(--body-bg);
}

.login-card {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.login-card-header {
    padding: 2rem 2rem 0;
    text-align: center;
}

.login-brand {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, #2563eb, #3b82f6);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 1rem;
}

.login-card-body {
    padding: 1.5rem 2rem 2rem;
}

.login-honeypot {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

.login-demo-table tbody tr:hover {
    background: rgb(37 99 235 / 0.06);
}

.login-demo-table code {
    font-size: 0.75rem;
    color: var(--text);
    background: var(--body-bg);
    padding: 0.1rem 0.35rem;
    border-radius: 0.25rem;
}

/* Profil warga */
.profil-warga-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1.25rem;
}

.profil-warga-avatar img,
.profil-warga-avatar-placeholder {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border);
}

.profil-warga-avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    color: #94a3b8;
    font-size: 2.25rem;
}

.profil-warga-avatar--editable {
    position: relative;
}

.profil-warga-avatar-edit {
    position: absolute;
    right: -2px;
    bottom: -2px;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #2563eb;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 2px 6px rgb(15 23 42 / 0.15);
    transition: background 0.15s ease;
}

.profil-warga-avatar-edit:hover {
    background: #1d4ed8;
}

.profil-warga-name {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.profil-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--bs-secondary);
    margin-bottom: 0.875rem;
}

.profil-detail-list {
    margin-bottom: 0;
}

.profil-detail-list dt {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--bs-secondary);
    margin-bottom: 0.125rem;
}

.profil-detail-list dd {
    font-size: 0.9375rem;
    margin-bottom: 0.875rem;
}

.profil-detail-list dd:last-child {
    margin-bottom: 0;
}

.profil-anggota-card--readonly .profil-detail-list dd {
    margin-bottom: 0.5rem;
}

.profil-anggota-card--readonly .profil-detail-list dd:last-child {
    margin-bottom: 0;
}

.identity-value__text,
.identity-input {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

.input-group-identity .identity-toggle-btn {
    flex-shrink: 0;
}

.profil-kategori-usia {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: #f8fafc;
    flex-shrink: 0;
    font-size: 1.05rem;
}

.profil-anggota-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
}

.profil-anggota-item-body {
    min-width: 0;
    flex: 1;
}

.kk-member-card {
    position: relative;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.85rem;
    padding: 1rem 1rem 1.1rem 1.15rem;
    background: #fff;
    border-left-width: 5px;
    box-shadow: 0 1px 2px rgb(15 23 42 / 0.04);
}

.kk-member-card--tone-1 { border-left-color: #2563eb; background: linear-gradient(90deg, #eff6ff 0%, #fff 22%); }
.kk-member-card--tone-2 { border-left-color: #059669; background: linear-gradient(90deg, #ecfdf5 0%, #fff 22%); }
.kk-member-card--tone-3 { border-left-color: #d97706; background: linear-gradient(90deg, #fffbeb 0%, #fff 22%); }
.kk-member-card--tone-4 { border-left-color: #7c3aed; background: linear-gradient(90deg, #f5f3ff 0%, #fff 22%); }
.kk-member-card--tone-5 { border-left-color: #e11d48; background: linear-gradient(90deg, #fff1f2 0%, #fff 22%); }
.kk-member-card--tone-6 { border-left-color: #0891b2; background: linear-gradient(90deg, #ecfeff 0%, #fff 22%); }

.kk-member-card__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed rgb(15 23 42 / 0.12);
    flex-wrap: wrap;
}

.kk-member-card__badge {
    flex-shrink: 0;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.05rem;
    line-height: 1;
    color: #fff;
}

.kk-member-card--tone-1 .kk-member-card__badge { background: #2563eb; }
.kk-member-card--tone-2 .kk-member-card__badge { background: #059669; }
.kk-member-card--tone-3 .kk-member-card__badge { background: #d97706; }
.kk-member-card--tone-4 .kk-member-card__badge { background: #7c3aed; }
.kk-member-card--tone-5 .kk-member-card__badge { background: #e11d48; }
.kk-member-card--tone-6 .kk-member-card__badge { background: #0891b2; }

.kk-member-card__title {
    flex: 1;
    min-width: 160px;
}

.kk-member-card__subtitle {
    font-size: 0.8125rem;
    color: var(--bs-secondary);
}

.warga-riwayat-item {
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.65rem;
    background: #f8fafc;
}

.warga-riwayat-link:hover .warga-riwayat-item {
    border-color: #93c5fd;
    background: #eff6ff;
}

/* Mobile */
@media (max-width: 991.98px) {
    .app-main {
        margin-left: 0;
    }

    .sidebar {
        transform: translateX(-100%);
    }

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

    .sidebar-backdrop.show {
        display: block;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    .app-content {
        padding: 1rem;
    }
}
