:root {
    --bg: #f4f7fb;
    --surface: #fff;
    --soft: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --border: #e4e9f1;
    --primary: #3157d5;
    --primary-dark: #2646b5;
    --success: #168a62;
    --danger: #d33b4c;
    --shadow: 0 12px 32px rgba(31, 42, 68, .08);
    --radius: 16px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: Tahoma, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.7;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; }
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 68px;
    padding: 0 28px;
    color: #fff;
    background: linear-gradient(135deg, #223a8f, #3157d5);
    box-shadow: 0 8px 24px rgba(34, 58, 143, .2);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 12px;
    background: rgba(255, 255, 255, .13);
    font-size: 16px;
    font-weight: 800;
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { color: rgba(255, 255, 255, .7); font-size: 11px; }
.topbar-user { display: flex; align-items: center; gap: 14px; font-size: 12px; }
.logout-link { padding: 7px 12px; border: 1px solid rgba(255, 255, 255, .25); border-radius: 10px; }

.layout {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    min-height: calc(100vh - 68px);
}
.sidebar { padding: 24px 16px; border-left: 1px solid var(--border); background: var(--surface); }
.sidebar-label { margin: 0 10px 10px; color: #98a2b3; font-size: 11px; font-weight: 700; }
.nav-list { display: grid; gap: 6px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 11px;
    color: #475467;
    font-weight: 700;
    transition: .18s ease;
}
.nav-link:hover { color: var(--primary); background: #f1f4ff; }
.nav-link.active { color: var(--primary); background: #e9eeff; }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: #c4cad5; }
.nav-link.active .nav-dot { background: var(--primary); box-shadow: 0 0 0 4px rgba(49, 87, 213, .12); }
.main-content { width: 100%; max-width: 1440px; padding: 32px; }

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 24px;
}
.page-head h1 { margin: 0; font-size: 24px; line-height: 1.4; }
.page-head p { margin: 5px 0 0; color: var(--muted); }
.actions, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.form-actions { margin-top: 18px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 15px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-weight: 700;
    transition: .18s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { color: #344054; border-color: var(--border); background: var(--surface); }
.btn-success { color: #fff; background: var(--success); }
.btn-danger { color: var(--danger); border-color: #f4c8ce; background: #fff5f6; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 12px; }

.cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}
.stat-card, .card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.stat-card { padding: 20px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.stat-value { margin-top: 8px; font-size: 25px; font-weight: 800; line-height: 1.35; }
.stat-hint { margin-top: 5px; color: #98a2b3; font-size: 11px; }
.card { margin-bottom: 20px; overflow: hidden; }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 17px 20px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 16px; }
.card-body { padding: 20px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.form-group label { display: block; margin-bottom: 6px; color: #475467; font-size: 12px; font-weight: 700; }
.control {
    width: 100%;
    min-height: 42px;
    padding: 8px 11px;
    color: var(--text);
    border: 1px solid #d7dde7;
    border-radius: 10px;
    outline: none;
    background: #fff;
    transition: .18s ease;
}
.control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(49, 87, 213, .1); }
textarea.control { min-height: 100px; resize: vertical; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; min-width: 720px; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    vertical-align: middle;
}
.data-table th { color: #667085; background: var(--soft); font-size: 11px; white-space: nowrap; }
.data-table tbody tr:hover { background: #fbfcff; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.amount { direction: ltr; font-weight: 800; text-align: right; white-space: nowrap; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    color: #344054;
    background: #eef1f6;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.badge-primary { color: var(--primary); background: #e9eeff; }
.muted { color: var(--muted); }
.empty-state { padding: 44px 20px; color: var(--muted); text-align: center; }

.flash { margin-bottom: 18px; padding: 12px 15px; border: 1px solid; border-radius: 11px; }
.flash-success { color: #126b4d; border-color: #bfe7d8; background: #edfbf6; }
.flash-error { color: #a82938; border-color: #f4c8ce; background: #fff3f5; }
.summary-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.summary-item {
    min-width: 160px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--soft);
}
.summary-item span, .summary-item strong { display: block; }
.summary-item span { color: var(--muted); font-size: 11px; }
.summary-item strong { margin-top: 3px; direction: ltr; font-size: 16px; text-align: right; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 18px;
    border-top: 1px solid var(--border);
}
.page-link {
    display: grid;
    min-width: 34px;
    height: 34px;
    place-items: center;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: #475467;
    background: #fff;
}
.page-link.active { color: #fff; border-color: var(--primary); background: var(--primary); }
.inline-form { display: inline; }
.text-button { padding: 0; color: var(--primary); border: 0; background: transparent; font-weight: 700; }
.text-button.danger { color: var(--danger); }

.modal {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(18, 27, 48, .58);
}
.modal.open { display: flex; }
.modal-panel {
    width: 100%;
    max-width: 540px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(18, 27, 48, .24);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 24px;
    background: radial-gradient(circle at 15% 20%, rgba(91, 117, 220, .2), transparent 30%),
        linear-gradient(145deg, #eef2ff, #f7f9fc 52%, #edf7f5);
}
.login-card {
    width: 100%;
    max-width: 420px;
    padding: 32px;
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 22px;
    background: rgba(255, 255, 255, .92);
    box-shadow: 0 24px 70px rgba(31, 42, 68, .14);
}
.login-brand { margin-bottom: 25px; text-align: center; }
.login-brand .brand-mark { margin: 0 auto 12px; color: #fff; background: var(--primary); }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 5px 0 0; color: var(--muted); }

@media (max-width: 1000px) {
    .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .topbar { position: static; padding: 12px 16px; }
    .topbar-user span { display: none; }
    .layout { display: block; }
    .sidebar { padding: 10px; border-bottom: 1px solid var(--border); border-left: 0; overflow-x: auto; }
    .sidebar-label { display: none; }
    .nav-list { display: flex; width: max-content; }
    .nav-link { white-space: nowrap; }
    .main-content { padding: 22px 14px; }
    .page-head { display: block; }
    .page-head .actions { margin-top: 14px; }
    .cards, .grid-2, .grid-3, .grid-5 { grid-template-columns: 1fr; }
    .card-body { padding: 15px; }
}
