@import url("https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;500;600;700;800&display=swap");

:root {
    font-family: "Be Vietnam Pro", "SVN-Gilroy", "Inter", "Segoe UI", Roboto, Arial, sans-serif;
    --green: #00A86B;
    --green-dark: #007A52;
    --blue: #2F80ED;
    --red: #EB5757;
    --amber: #F2C94C;
    --text: #1F2933;
    --muted: #6B7280;
    --bg: #F6F8FA;
    --surface: #FFFFFF;
    --border: #E5E7EB;
    --shadow: rgba(31, 41, 51, .035);
    --soft-green: #EAF8F1;
    --control-bg: #EEF2F3;
}

:root[data-theme="dark"] {
    --green: #18C98A;
    --green-dark: #6EE7B7;
    --blue: #60A5FA;
    --red: #F87171;
    --amber: #FBBF24;
    --text: #E5E7EB;
    --muted: #9CA3AF;
    --bg: #101418;
    --surface: #171D22;
    --border: #2A343D;
    --shadow: rgba(0, 0, 0, .28);
    --soft-green: rgba(24, 201, 138, .13);
    --control-bg: #222B33;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Be Vietnam Pro", "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
a { color: var(--green-dark); text-decoration: none; }
button, input, select { font: inherit; }
button { border: 0; border-radius: 8px; padding: 10px 14px; cursor: pointer; background: var(--control-bg); color: var(--text); min-height: 42px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(0, 168, 107, .22); outline-offset: 2px; }
.primary { background: var(--green); color: #fff; font-weight: 700; }
.danger { background: var(--red); color: #fff; }
.shell { min-height: 100vh; display: grid; grid-template-columns: 240px 1fr; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 22px; display: flex; flex-direction: column; gap: 24px; }
.mobile-menu-row { display: grid; gap: 14px; }
.brand, .login-brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 20px; }
.brand-mark, .login-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 8px; color: #fff; background: var(--green); position: relative; flex: 0 0 auto; }
.brand-mark::before, .login-mark::before { content: ""; width: 15px; height: 20px; border: 3px solid #fff; border-top: 0; border-radius: 0 0 10px 10px; transform: translateY(2px); }
.brand-mark::after, .login-mark::after { content: ""; position: absolute; width: 18px; height: 3px; background: #fff; border-radius: 99px; top: 13px; left: 10px; }
.nav { display: grid; gap: 8px; }
.nav a { padding: 11px 12px; border-radius: 8px; color: var(--muted); font-weight: 650; display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.nav-icon { width: 20px; height: 20px; display: inline-grid; place-items: center; color: inherit; }
.nav a:hover, .nav a.active { color: var(--green-dark); background: var(--soft-green); }
.logout { margin-top: auto; }
.logout button { width: 100%; }
.theme-toggle { width: 42px; min-height: 42px; padding: 0; display: inline-grid; place-items: center; font-size: 18px; }
.main { padding: 24px; max-width: 1440px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.user-pill { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 9px 13px; color: var(--muted); }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: 26px; letter-spacing: 0; }
.metric-balance { border-color: rgba(0, 168, 107, .32); background: linear-gradient(180deg, var(--surface), var(--soft-green)); }
.income { color: var(--blue); }
.expense { color: var(--red); }
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.chart-grid { display: grid; grid-template-columns: minmax(280px, .85fr) minmax(0, 1.35fr); gap: 16px; align-items: stretch; margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px; margin-bottom: 16px; box-shadow: 0 10px 30px var(--shadow); }
.chart-panel { margin-bottom: 0; min-height: 360px; }
.chart-wrap { position: relative; height: 286px; min-height: 286px; }
.chart-wide { height: 286px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { font-size: 17px; margin: 0; }
.category-list, .transaction-list, .plain-list { display: grid; gap: 10px; }
.category-row, .transaction-row, .plain-list div { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.dot, .category-icon { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.category-icon { width: 36px; height: 36px; border-radius: 8px; }
.transaction-row strong { display: block; }
.transaction-row small, .plain-list small, .muted { color: var(--muted); }
.transaction-row em { display: inline-block; margin-top: 4px; color: #8A6100; background: #FFF7D6; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-style: normal; }
.amount { font-weight: 800; white-space: nowrap; }
.icon-link { font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.form-grid label, .form-stack label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
input, select { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; background: var(--surface); color: var(--text); min-height: 42px; }
.form-actions { display: flex; align-items: end; }
.filter-form, .compact-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.compact-form input, .compact-form select { width: auto; min-width: 140px; }
.security-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-items: start; }
.security-form { display: grid; gap: 10px; min-width: 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.security-form h3 { margin: 0 0 2px; font-size: 14px; }
.security-form button { width: 100%; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; margin-top: 4px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pagination a { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; padding: 0 12px; border-radius: 8px; background: var(--soft-green); font-weight: 700; }
.pagination a.disabled { color: #A0A7AF; background: var(--control-bg); pointer-events: none; }
.pagination-note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }
.delete-form { margin-top: 16px; }
.guest-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top left, var(--soft-green), transparent 38%), var(--bg); }
.login-panel { width: min(430px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; box-shadow: 0 20px 70px var(--shadow); }
.login-brand { align-items: flex-start; margin-bottom: 18px; min-width: 0; }
.login-copy { min-width: 0; }
.login-brand h1 { font-size: 24px; margin: 0 0 4px; line-height: 1.25; overflow-wrap: anywhere; }
.login-brand p { margin: 0; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.form-stack { display: grid; gap: 14px; }
.alert { padding: 10px 12px; color: #842029; background: #F8D7DA; border-radius: 8px; margin-bottom: 12px; }
.notice { padding: 10px 12px; color: #0F5132; background: #D1E7DD; border-radius: 8px; margin-bottom: 12px; }

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: sticky; top: 0; z-index: 10; padding: 7px 8px; border-right: 0; border-bottom: 1px solid var(--border); flex-direction: column; align-items: stretch; gap: 0; box-shadow: 0 10px 30px rgba(31, 41, 51, .06); }
    .mobile-menu-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 5px; min-width: 0; }
    .brand { font-size: 0; min-width: 0; gap: 0; }
    .brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .brand-mark { width: 28px; height: 28px; border-radius: 7px; }
    .brand-mark::before { width: 10px; height: 14px; border-width: 2px; }
    .brand-mark::after { width: 13px; height: 2px; top: 10px; left: 7.5px; }
    .nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; overflow: visible; padding-bottom: 0; scrollbar-width: none; }
    .nav::-webkit-scrollbar { display: none; }
    .nav a { min-width: 0; justify-content: center; padding: 7px 4px; font-size: 11px; line-height: 1; background: var(--control-bg); border: 1px solid transparent; text-align: center; }
    .nav a.active { border-color: rgba(0, 168, 107, .22); }
    .nav-icon { display: none; }
    .logout { display: flex; justify-content: flex-end; margin: 0; flex: 0 0 auto; }
    .logout button { width: auto; min-height: 30px; padding: 6px 6px; font-size: 0; }
    .logout button::before { content: "Thoát"; font-size: 11px; }
    .theme-toggle { width: 30px; min-height: 30px; font-size: 14px; }
    .main { padding: 14px 12px 22px; }
    .topbar { margin-bottom: 14px; align-items: flex-start; gap: 10px; }
    .topbar h1 { font-size: 22px; line-height: 1.25; }
    .eyebrow { font-size: 12px; }
    .user-pill { padding: 7px 10px; font-size: 12px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
    .metric { min-height: 92px; padding: 13px; }
    .metric span { font-size: 12px; }
    .metric strong { font-size: 20px; line-height: 1.2; overflow-wrap: anywhere; }
    .content-grid, .chart-grid, .form-grid { grid-template-columns: 1fr; gap: 12px; }
    .panel { padding: 13px; margin-bottom: 12px; border-radius: 8px; }
    .chart-panel { min-height: 310px; }
    .chart-wrap { height: 236px; min-height: 236px; }
    .panel-head { align-items: flex-start; flex-direction: column; }
    .panel-head h2 { font-size: 16px; }
    .category-row, .plain-list div { grid-template-columns: auto 1fr auto; gap: 8px; }
    .transaction-row { grid-template-columns: auto 1fr; gap: 9px; padding: 11px 0; }
    .transaction-row small { display: block; margin-top: 3px; line-height: 1.45; }
    .amount, .icon-link { grid-column: 2; }
    .amount { justify-self: start; font-size: 15px; }
    .icon-link { display: inline-flex; align-items: center; min-height: 32px; width: fit-content; padding: 0 10px; border-radius: 8px; background: var(--soft-green); }
    .filter-form, .compact-form { display: grid; grid-template-columns: 1fr; width: 100%; }
    .compact-form input, .compact-form select { width: 100%; min-width: 0; }
    .security-grid { grid-template-columns: 1fr; gap: 10px; }
    .security-form { padding: 10px; }
    .pagination { align-items: stretch; display: grid; grid-template-columns: 1fr; text-align: center; }
    .pagination a { width: 100%; }
    .form-actions { align-items: stretch; }
    .form-actions button, .primary, .danger { width: 100%; }
    .login-panel { padding: 18px; width: min(390px, calc(100vw - 24px)); }
    .login-brand { gap: 10px; }
    .login-mark { width: 34px; height: 34px; border-radius: 8px; }
    .login-mark::before { width: 12px; height: 16px; border-width: 2.5px; }
    .login-mark::after { width: 15px; height: 2.5px; top: 11px; left: 8.5px; }
    .login-brand h1 { font-size: 20px; }
    .login-brand p { font-size: 13px; }
}

@media (max-width: 430px) {
    .main { padding-left: 10px; padding-right: 10px; }
    .summary-grid { gap: 8px; }
    .metric { padding: 12px; min-height: 88px; }
    .metric strong { font-size: 18px; }
    .chart-wrap { height: 220px; min-height: 220px; }
    .mobile-menu-row { gap: 5px; }
    .nav { gap: 4px; }
    .nav a { padding: 7px 2px; font-size: 10px; }
    .theme-toggle { width: 28px; min-height: 30px; }
    .logout button { padding-left: 6px; padding-right: 6px; }
    .logout button::before { font-size: 10px; }
    .topbar { flex-direction: column; }
    .user-pill { max-width: 100%; }
}
