* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    background: #f4f6f8;
    color: #1f2937;
    font-family: "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    width: 220px;
    min-height: 100vh;
    background: #172033;
    color: #dbe4f0;
    padding: 22px 16px;
    position: sticky;
    top: 0;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 28px;
}

.brand-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-mark {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #14b8a6;
    color: #fff;
    border-radius: 8px;
}

.menu-toggle {
    display: none;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid #3b4b68;
    border-radius: 6px;
    background: #24314a;
    color: #fff;
    font: inherit;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a {
    padding: 11px 12px;
    border-radius: 8px;
    color: #aebbd0;
}

.nav a:hover,
.nav a.active {
    background: #24314a;
    color: #fff;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar h1 {
    margin: 0 0 6px;
    font-size: 24px;
}

.topbar p {
    margin: 0;
    color: #64748b;
}

.userbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    white-space: nowrap;
}

.userbar span {
    font-weight: 700;
}

.userbar em {
    font-style: normal;
    color: #64748b;
}

.company-chip {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #0369a1;
    font-weight: 700;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    background: #e8fff7;
    color: #047857;
    border: 1px solid #abecd6;
}

.alert.error {
    background: #fff1f2;
    color: #be123c;
    border-color: #fecdd3;
}

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

.monthly-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card,
.panel {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .04);
}

.stat-card {
    padding: 20px;
}

.stat-card span {
    color: #64748b;
}

.stat-card strong {
    display: block;
    margin-top: 10px;
    font-size: 26px;
}

.stat-card.income strong,
.text-income {
    color: #059669;
}

.stat-card.expense strong,
.text-expense {
    color: #dc2626;
}

.stat-card.balance strong {
    color: #2563eb;
}

.panel {
    padding: 18px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.dashboard-panel {
    margin-bottom: 18px;
}

.range-form {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}

.range-form label {
    min-width: 150px;
}

.range-form input {
    padding: 8px 10px;
}

.range-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.range-cards div {
    padding: 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
}

.range-cards span {
    display: block;
    color: #64748b;
    margin-bottom: 8px;
}

.range-cards strong {
    font-size: 22px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 16px;
    align-items: start;
}

.bar-stack {
    display: grid;
    gap: 5px;
    min-width: 140px;
}

.bar {
    display: block;
    height: 8px;
    border-radius: 999px;
}

.bar.income {
    background: #10b981;
}

.bar.expense {
    background: #ef4444;
}

.category-box {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.category-box h3 {
    margin: 0 0 12px;
    font-size: 16px;
}

.category-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #edf2f7;
}

.category-row:last-child {
    border-bottom: 0;
}

.category-row em {
    font-style: normal;
    font-weight: 700;
    white-space: nowrap;
}

.panel h2,
.panel-head h2 {
    margin: 0;
    font-size: 18px;
}

.form-grid {
    display: grid;
    grid-template-columns: 360px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
    margin-bottom: 18px;
}

.form-panel,
.filter-form {
    display: grid;
    gap: 14px;
}

label {
    display: grid;
    gap: 7px;
}

label span {
    color: #475569;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px 11px;
    font: inherit;
    background: #fff;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(37, 99, 235, .18);
    border-color: #2563eb;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
    border: 1px solid #2563eb;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    font: inherit;
}

.btn.ghost {
    background: #fff;
    color: #2563eb;
}

.btn.danger {
    background: #dc2626;
    border-color: #dc2626;
}

.btn.small {
    min-height: 30px;
    padding: 0 10px;
    font-size: 13px;
}

.actions,
.row-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.inline-form {
    margin: 0;
}

.inline-form select {
    min-width: 110px;
    padding: 6px 8px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
    vertical-align: top;
}

th {
    color: #475569;
    background: #f8fafc;
    font-weight: 600;
}

.empty,
.muted {
    color: #94a3b8;
}

.tag {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: #e0f2fe;
    color: #0369a1;
}

.tag.income {
    background: #dcfce7;
    color: #047857;
}

.tag.expense {
    background: #fee2e2;
    color: #b91c1c;
}

.summary-list {
    display: grid;
    gap: 12px;
    margin: 14px 0 0;
}

.summary-list div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #edf2f7;
}

.summary-list dt,
.summary-list dd {
    margin: 0;
}

.summary-list dt {
    color: #64748b;
}

.summary-list dd {
    font-weight: 700;
}

.preview-list,
.thumb-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.preview-list img,
.thumb-list img {
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

.pagination {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 16px;
}

.pagination a {
    min-width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
}

.pagination a.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #eef6ff 0%, #f6f8fb 45%, #effaf6 100%);
}

.login-shell {
    width: min(420px, calc(100vw - 32px));
}

.login-panel {
    display: grid;
    gap: 16px;
    padding: 28px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 18px 60px rgba(15, 23, 42, .12);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
}

.login-brand h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

.login-brand p,
.login-tip {
    margin: 0;
    color: #64748b;
}

.login-tip {
    font-size: 12px;
}

@media (max-width: 980px) {
    body {
        display: block;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .sidebar {
        width: auto;
        min-height: auto;
        position: static;
        padding: 14px 16px;
    }

    .brand {
        margin-bottom: 0;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .nav {
        display: none;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        margin-top: 14px;
    }

    .sidebar.nav-open .nav {
        display: grid;
    }

    .stats-grid,
    .monthly-grid,
    .form-grid,
    .range-cards,
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .range-form {
        width: 100%;
    }

    .userbar {
        white-space: normal;
    }
}

@media (max-width: 560px) {
    .main {
        padding: 16px;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .stats-grid {
        gap: 10px;
    }

    .panel {
        padding: 14px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card strong {
        font-size: 22px;
    }

    .panel-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .range-form label,
    .range-form .btn {
        width: 100%;
    }

    .table-wrap {
        overflow: visible;
    }

    table,
    thead,
    tbody,
    tr,
    th,
    td {
        display: block;
    }

    thead {
        display: none;
    }

    table {
        border-collapse: separate;
    }

    tbody {
        display: grid;
        gap: 12px;
    }

    tr {
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        background: #fff;
        padding: 10px 12px;
    }

    td {
        display: flex;
        justify-content: space-between;
        gap: 14px;
        padding: 9px 0;
        border-bottom: 1px solid #edf2f7;
        text-align: right;
    }

    td:last-child {
        border-bottom: 0;
    }

    td::before {
        content: attr(data-label);
        color: #64748b;
        font-weight: 700;
        text-align: left;
        flex: 0 0 86px;
    }

    td.empty {
        display: block;
        text-align: left;
    }

    td.empty::before {
        content: "";
        display: none;
    }

    .row-actions,
    td .row-actions {
        justify-content: flex-end;
    }

    .thumb-list,
    .preview-list {
        justify-content: flex-end;
    }

    .bar-stack {
        min-width: 120px;
        flex: 1;
    }

    .pagination {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}
