:root {
    --bg: #f0f2f5;
    --sidebar: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #1d4ed8;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --card: #ffffff;
    --radius: 16px;
    --radius-sm: 12px;
    --shadow: 0 1px 3px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.04);
    --shadow-md: 0 4px 20px rgba(15,23,42,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

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

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

.sidebar {
    width: 260px;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
}

.logo {
    padding: 28px 24px 24px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    border-bottom: 1px solid rgba(255,255,255,.06);
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    margin-bottom: 10px;
}

.logo-text {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.logo-sub {
    font-size: .7rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 500;
}

.nav { flex: 1; padding: 16px 14px; overflow-y: auto; }

.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    color: #94a3b8;
    border-radius: 10px;
    margin-bottom: 2px;
    text-decoration: none;
    transition: all .15s ease;
    font-weight: 500;
    font-size: .9rem;
}

.nav a:hover { background: var(--sidebar-hover); color: #e2e8f0; }
.nav a.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 4px 12px rgba(37,99,235,.35);
}

.nav-icon {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
    opacity: .9;
}

.sidebar-footer {
    padding: 16px 18px;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .85rem;
    flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: .85rem; font-weight: 600; color: #e2e8f0; }
.user-info .role { font-size: .72rem; color: #64748b; }

.logout-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,.06);
    color: #94a3b8;
    border-radius: 8px;
    font-size: .9rem;
    text-decoration: none;
    transition: all .15s;
}
.logout-btn:hover { background: rgba(239,68,68,.2); color: #fca5a5; }

.main {
    margin-left: 260px;
    flex: 1;
    min-width: 0;
}

.topbar {
    background: var(--card);
    padding: 16px 32px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -.02em;
}

.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 28px 32px; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow);
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
    transition: transform .15s, box-shadow .15s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    margin-bottom: 14px;
}

.stat-card .label {
    font-size: .78rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-card .value {
    font-size: 1.55rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.03em;
    line-height: 1.2;
}

.stat-card .sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 6px;
}

.stat-card .sub span { font-weight: 600; }

.stat-card.blue { background: #eff6ff; }
.stat-card.blue .stat-icon { background: #dbeafe; }
.stat-card.blue .value { color: #1d4ed8; }

.stat-card.green { background: #ecfdf5; }
.stat-card.green .stat-icon { background: #d1fae5; }
.stat-card.green .value { color: #047857; }

.stat-card.red { background: #fef2f2; }
.stat-card.red .stat-icon { background: #fee2e2; }
.stat-card.red .value { color: #b91c1c; }

.stat-card.yellow { background: #fffbeb; }
.stat-card.yellow .stat-icon { background: #fef3c7; }
.stat-card.yellow .value { color: #b45309; }

.stat-card.purple { background: #f5f3ff; }
.stat-card.purple .stat-icon { background: #ede9fe; }
.stat-card.purple .value { color: #6d28d9; }

.stat-card.cyan { background: #ecfeff; }
.stat-card.cyan .stat-icon { background: #cffafe; }
.stat-card.cyan .value { color: #0e7490; }

.stat-card.white {
    background: var(--card);
    border: 1px solid var(--border);
}
.stat-card.white .stat-icon { background: #f1f5f9; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 24px;
    overflow: hidden;
}

.card-header {
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2 {
    font-size: .95rem;
    font-weight: 650;
    letter-spacing: -.01em;
}

.card-body { padding: 20px 22px; }

.card-link {
    font-size: .8rem;
    font-weight: 500;
    color: var(--primary);
}
.card-link:hover { text-decoration: underline; }

.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.dash-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

th, td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}

th {
    background: #fafbfc;
    font-weight: 600;
    color: var(--text-muted);
    font-size: .72rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.avatar-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #93c5fd, #6366f1);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: .75rem;
    flex-shrink: 0;
}

.avatar.sm { width: 28px; height: 28px; font-size: .7rem; border-radius: 8px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: .8rem;
    font-weight: 550;
    margin-bottom: 6px;
    color: #334155;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: .9rem;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    color: var(--text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-group textarea { min-height: 80px; resize: vertical; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-size: .875rem;
    font-weight: 550;
    cursor: pointer;
    text-decoration: none;
    transition: all .15s;
    line-height: 1.3;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,.25);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-secondary {
    background: #f1f5f9;
    color: var(--text);
}
.btn-secondary:hover { background: #e2e8f0; }

.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 8px; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .01em;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

.alert {
    padding: 14px 18px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: .875rem;
    font-weight: 500;
}

.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    align-items: flex-end;
}

.filters .form-group { margin-bottom: 0; min-width: 150px; }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.45);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: #fff;
    border-radius: 18px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,.2);
    animation: modalIn .2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 { font-size: 1.05rem; font-weight: 650; }

.modal-close {
    background: #f1f5f9;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .15s;
}
.modal-close:hover { background: #e2e8f0; color: var(--text); }

.modal-body { padding: 24px; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(37,99,235,.25) 0%, transparent 70%);
    top: -100px;
    right: -100px;
}

.login-box {
    background: #fff;
    padding: 44px 40px;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 25px 60px rgba(0,0,0,.3);
    position: relative;
    z-index: 1;
}

.login-box .login-logo {
    width: 56px;
    height: 56px;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    margin: 0 auto 16px;
}

.login-box h1 {
    text-align: center;
    margin-bottom: 4px;
    font-size: 1.4rem;
    font-weight: 700;
}

.login-box .subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 28px;
    font-size: .85rem;
}

.group-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.group-tag {
    background: #eff6ff;
    color: #1d4ed8;
    padding: 2px 10px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 550;
}

.checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 10px;
}

.checkbox-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 6px;
    cursor: pointer;
    font-weight: 400;
    border-radius: 6px;
    transition: background .1s;
}
.checkbox-list label:hover { background: #f8fafc; }
.checkbox-list input { width: auto; accent-color: var(--primary); }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; opacity: .5; }
.empty-state p { font-size: .9rem; }

.donut-wrap {
    display: flex;
    align-items: center;
    gap: 28px;
    padding: 8px 0;
}

.donut {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    position: relative;
    flex-shrink: 0;
}

.donut-inner {
    position: absolute;
    inset: 22px;
    background: #fff;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.donut-inner .num {
    font-size: 1.4rem;
    font-weight: 700;
    line-height: 1.1;
}

.donut-inner .lbl {
    font-size: .65rem;
    color: var(--text-muted);
    font-weight: 500;
}

.donut-legend { flex: 1; }

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: .85rem;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.legend-item .count {
    margin-left: auto;
    font-weight: 600;
    color: var(--text);
}

.status-list { list-style: none; }

.status-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: .875rem;
}
.status-list li:last-child { border-bottom: none; }

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-list .count {
    margin-left: auto;
    font-weight: 700;
    font-size: .95rem;
}

.person-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f1f5f9;
}
.person-row:last-child { border-bottom: none; }

.person-info { flex: 1; min-width: 0; }
.person-info .pname { font-weight: 600; font-size: .875rem; }
.person-info .pmeta { font-size: .75rem; color: var(--text-muted); margin-top: 1px; }

.person-right {
    text-align: right;
    flex-shrink: 0;
}
.person-right .amount { font-weight: 650; font-size: .875rem; }
.person-right .days { font-size: .72rem; color: var(--text-muted); }

@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dash-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
    .dash-grid, .dash-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
    }
    .main { margin-left: 0; }
    .nav {
        display: flex;
        flex-wrap: wrap;
        gap: 2px;
        padding: 8px;
    }
    .nav a { padding: 8px 12px; font-size: .8rem; }
    .sidebar-footer { display: none; }
    .logo { padding: 16px; flex-direction: row; align-items: center; gap: 12px; }
    .logo-icon { margin-bottom: 0; width: 32px; height: 32px; font-size: 1rem; }
    .content { padding: 16px; }
    .topbar { padding: 12px 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-card { padding: 14px 16px; }
    .stat-card .value { font-size: 1.25rem; }
}
