:root {
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #111827;
    --muted: #64748b;
    --muted-strong: #475569;
    --line: #d8e0ea;
    --line-strong: #c3cedb;
    --primary: #155eef;
    --primary-dark: #0f46b8;
    --primary-soft: #eaf1ff;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --warning: #92400e;
    --warning-bg: #fff7e6;
    --success: #067647;
    --success-bg: #ecfdf3;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        linear-gradient(180deg, #f8fafc 0, var(--bg) 340px),
        var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

button,
input,
select {
    font: inherit;
}

a {
    color: inherit;
}

.app-shell {
    width: min(1320px, calc(100% - 40px));
    margin: 0 auto;
    padding: 28px 0 56px;
}

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

.login-panel {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.login-panel h1 {
    margin-bottom: 10px;
}

.login-copy {
    margin-bottom: 20px;
    color: var(--muted);
}

.login-form {
    margin-top: 18px;
}

.topbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 20px;
}

.logout-form {
    margin: 0 0 1px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 500;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(2rem, 4vw, 3.2rem);
    line-height: 0.95;
    letter-spacing: 0;
}

h2 {
    margin-bottom: 0;
    font-size: 1.15rem;
    line-height: 1.25;
}

.month-filter {
    display: grid;
    gap: 8px;
    width: min(100%, 360px);
}

.month-filter label,
.expense-form label {
    color: var(--muted-strong);
    font-size: 0.9rem;
    font-weight: 500;
}

.filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
}

input,
select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    background: #fff;
}

input:focus,
select:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(21, 94, 239, 0.16);
}

button,
.primary-button,
.secondary-button,
.icon-button,
.danger-button,
.ghost-button,
.ghost-link,
.month-links a {
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

button,
.primary-button {
    background: var(--primary);
    color: #fff;
}

button:hover,
.primary-button:hover {
    background: var(--primary-dark);
}

.secondary-button,
.ghost-button,
.ghost-link,
.month-links a {
    background: var(--primary-soft);
    color: var(--primary);
}

.secondary-button:hover,
.ghost-button:hover,
.ghost-link:hover,
.month-links a:hover {
    background: #dce8ff;
}

.notice {
    border: 1px solid transparent;
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
    font-weight: 500;
}

.notice.success {
    background: var(--success-bg);
    border-color: #abefc6;
    color: var(--success);
}

.notice.error {
    background: var(--danger-bg);
    border-color: #fecdca;
    color: var(--danger);
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.metric,
.panel,
.income-summary {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    min-height: 84px;
    padding: 12px 14px;
    display: grid;
    align-content: center;
    gap: 6px;
    border-left: 4px solid transparent;
}

.metric:nth-child(1) {
    border-left-color: var(--success);
}

.metric:nth-child(2),
.metric:nth-child(6) {
    border-left-color: var(--primary);
}

.metric:nth-child(3),
.metric:nth-child(5),
.metric:nth-child(9) {
    border-left-color: var(--danger);
}

.metric span {
    display: block;
    color: var(--muted-strong);
    font-size: 0.8rem;
    font-weight: 500;
}

.metric strong {
    display: block;
    font-size: clamp(1.18rem, 1.55vw, 1.45rem);
    font-weight: 500;
    line-height: 1.1;
    font-variant-numeric: normal;
}

.metric.negative strong,
.metric:nth-child(9) strong {
    color: var(--danger);
}

.income-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.income-summary {
    padding: 14px;
}

.income-summary.unlinked {
    border-color: #fed7aa;
}

.income-summary-heading {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.income-summary-heading span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 500;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.income-summary-heading strong {
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.25;
    font-variant-numeric: normal;
}

.income-summary-heading > strong {
    white-space: nowrap;
}

.income-summary-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 12px;
    margin: 12px 0 0;
}

.income-summary-list div {
    display: grid;
    gap: 4px;
}

.income-summary-list dt {
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 500;
}

.income-summary-list dd {
    margin: 0;
    font-size: 0.94rem;
    font-weight: 500;
    font-variant-numeric: normal;
}

.income-summary-list .negative dd {
    color: var(--danger);
}

.action-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    margin: 0 -8px 14px;
    padding: 10px 8px;
    background: rgba(238, 242, 247, 0.9);
    backdrop-filter: blur(8px);
}

.panel {
    padding: 18px;
}

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

.panel-heading.compact {
    margin-bottom: 12px;
}

.panel-divider {
    height: 1px;
    margin: 18px 0;
    background: var(--line);
}

.expense-form {
    display: grid;
    gap: 14px;
}

.expense-form label {
    display: grid;
    gap: 8px;
}

.category-list {
    display: grid;
    gap: 14px;
}

.category-item {
    display: grid;
    gap: 8px;
}

.category-item div:first-child {
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.category-item span {
    color: var(--muted);
}

.bar {
    height: 9px;
    overflow: hidden;
    border-radius: 999px;
    background: #e8edf5;
}

.bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--primary);
}

.table-panel {
    padding: 0;
    overflow: hidden;
}

.table-panel .panel-heading {
    margin: 0;
    padding: 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.56);
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: min(560px, 100%);
    max-height: min(760px, calc(100vh - 40px));
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    padding: 18px;
}

.compact-modal {
    width: min(460px, 100%);
}

.month-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.month-links a {
    min-height: 34px;
    padding: 0 12px;
    font-size: 0.9rem;
}

.month-links a.active {
    background: var(--primary);
    color: #fff;
}

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

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 920px;
}

th,
td {
    border-top: 1px solid var(--line);
    padding: 14px 12px;
    text-align: left;
    vertical-align: middle;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    border-top: 0;
    background: var(--surface-soft);
}

th {
    color: var(--muted-strong);
    font-size: 0.78rem;
    font-weight: 500;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #f8fbff;
}

tbody td:nth-child(2) {
    font-weight: 500;
}

.amount-col {
    text-align: right;
    white-space: nowrap;
    font-weight: 500;
    font-variant-numeric: normal;
}

.actions-col {
    width: 92px;
    text-align: right;
}

.action-buttons {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    white-space: nowrap;
}

.action-buttons form {
    display: flex;
    margin: 0;
}

.icon-button {
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
}

.icon-button:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.danger-button {
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
}

.danger-button:hover {
    background: #fee4e2;
    color: var(--danger);
}

.icon-only {
    width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 0.95rem;
    line-height: 1;
}

.tag,
.payment {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 0.84rem;
    font-weight: 500;
    white-space: nowrap;
}

.status {
    display: inline;
    padding: 0;
    color: var(--success);
    font-size: 0.84rem;
    font-weight: 500;
    white-space: nowrap;
}

.tag {
    background: #f1f5f9;
    color: #334155;
}

.status {
    color: var(--success);
}

.status.late {
    color: var(--danger);
}

.status.warning {
    color: var(--warning);
}

.payment.paid {
    background: var(--success-bg);
    color: var(--success);
}

.payment.unpaid {
    background: var(--danger-bg);
    color: var(--danger);
}

.paid-row td {
    color: var(--muted);
    background: #fbfcfe;
}

.paid-row td:nth-child(2) {
    text-decoration: line-through;
    text-decoration-thickness: 2px;
    text-decoration-color: #cbd5e1;
}

.income-list {
    display: grid;
    gap: 14px;
}

.income-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 160px;
    gap: 12px;
    align-items: end;
}

.empty-state {
    margin: 0;
    padding: 22px 18px;
    color: var(--muted);
}

@media (max-width: 1100px) {
    .summary-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

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

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

@media (max-width: 900px) {
    .topbar {
        display: grid;
        align-items: stretch;
    }

    .month-filter {
        width: 100%;
    }

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

}

@media (max-width: 560px) {
    .app-shell {
        width: min(100% - 20px, 1180px);
        padding-top: 20px;
    }

    h1 {
        font-size: 2rem;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .income-summary-heading,
    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .income-summary-list {
        grid-template-columns: 1fr;
    }

    .income-summary-grid {
        grid-template-columns: 1fr;
    }

    .filter-row {
        grid-template-columns: 1fr;
    }

    .action-bar {
        justify-content: stretch;
    }

    .action-bar button {
        flex: 1 1 160px;
    }

    .income-row {
        grid-template-columns: 1fr;
    }
}
