:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --line: #d8e0eb;
    --line-soft: #edf1f6;
    --text: #101828;
    --muted: #667085;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --primary-soft: #e6f4f1;
    --danger: #b42318;
    --warning: #b54708;
    --success: #067647;
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

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

.auth-body {
    background:
        radial-gradient(circle at 14% 18%, rgba(15, 118, 110, 0.18), transparent 26%),
        linear-gradient(135deg, #0f172a 0%, #182235 45%, #eef2f7 45%, #f7f9fc 100%);
}

a {
    color: var(--primary-dark);
}

.shell {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: #0f172a;
    color: #fff;
    padding: 28px 22px;
    display: flex;
    flex-direction: column;
    gap: 30px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-top {
    display: grid;
    gap: 5px;
}

.sidebar-top span,
.sidebar-account span {
    color: #94a3b8;
    font-size: 13px;
}

.brand {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
}

.main-nav {
    display: grid;
    gap: 8px;
}

.main-nav a,
.link-button {
    color: #cbd5e1;
    text-decoration: none;
    background: transparent;
    border: 0;
    min-height: 38px;
    padding: 9px 11px;
    text-align: left;
    font: inherit;
    cursor: pointer;
    border-radius: 8px;
}

.main-nav a:hover,
.main-nav a.active {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.sidebar-account {
    margin-top: auto;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 18px;
}

.mobile-logout {
    display: none;
}

.sidebar-account form {
    grid-column: 1 / -1;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: #fff;
    font-weight: 800;
}

.link-button {
    width: 100%;
    min-height: 38px;
    padding: 8px 0;
}

.content {
    padding: 34px;
}

.content-inner {
    width: min(100%, 1180px);
    display: grid;
    gap: 22px;
    align-content: start;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    padding: 4px 0 2px;
}

.month-filter {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.filter-bar-panel {
    width: 100%;
}

.expense-filter {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) minmax(130px, 0.8fr) minmax(130px, 0.8fr) minmax(150px, 0.9fr) minmax(160px, 1fr) auto;
    width: 100%;
}

.month-filter label {
    min-width: 190px;
}

.expense-filter label {
    min-width: 0;
}

.month-filter button {
    white-space: nowrap;
}

.filter-actions {
    align-items: flex-end;
    display: flex;
    gap: 6px;
}

h1,
h2 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 28px;
    line-height: 1.15;
}

h2 {
    font-size: 17px;
    line-height: 1.2;
}

.muted {
    color: var(--muted);
    margin: 6px 0 0;
}

.eyebrow {
    color: var(--primary);
    display: block;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 14px;
}

.metrics article,
.panel,
.table-panel,
.auth-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metrics article {
    padding: 18px;
    display: grid;
    gap: 8px;
    min-height: 122px;
    position: relative;
    overflow: hidden;
}

.metrics article::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--primary);
}

.metrics span,
td span,
.metrics small {
    color: var(--muted);
    font-size: 13px;
}

.metrics strong {
    font-size: 21px;
    line-height: 1.1;
}

.grid {
    display: grid;
    gap: 18px;
}

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

.panel {
    padding: 22px;
}

.panel.narrow {
    max-width: 650px;
}

.panel-header,
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(360px, 0.9fr) minmax(420px, 1.1fr);
}

.auth-hero {
    color: #fff;
    padding: 42px;
    display: grid;
    align-content: space-between;
    gap: 42px;
    min-height: 100vh;
}

.auth-brand {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    text-decoration: none;
}

.auth-hero-copy {
    display: grid;
    gap: 16px;
    max-width: 480px;
}

.auth-hero-copy span,
.auth-card-header span {
    color: #5eead4;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.auth-hero-copy h1 {
    font-size: 38px;
    line-height: 1.08;
}

.auth-hero-copy p {
    color: #cbd5e1;
    font-size: 16px;
    line-height: 1.6;
    margin: 0;
}

.auth-hero-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    max-width: 460px;
}

.auth-hero-metrics div {
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.08);
}

.auth-hero-metrics strong,
.auth-hero-metrics span {
    display: block;
}

.auth-hero-metrics strong {
    font-size: 22px;
}

.auth-hero-metrics span {
    color: #cbd5e1;
    margin-top: 4px;
}

.auth-content {
    min-height: 100vh;
    display: grid;
    align-content: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 24px;
}

.auth-panel {
    width: min(100%, 460px);
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #d8e0eb;
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.16);
    padding: 34px;
}

.auth-card-header {
    display: grid;
    gap: 8px;
    margin-bottom: 24px;
}

.auth-card-header h1 {
    color: #0f172a;
    font-size: 27px;
}

.auth-card-header p {
    color: var(--muted);
    line-height: 1.5;
    margin: 0;
}

.auth-panel .form {
    gap: 16px;
}

.auth-panel input {
    min-height: 48px;
}

.auth-panel button {
    min-height: 48px;
    margin-top: 4px;
}

.auth-switch {
    color: var(--muted);
    margin: 20px 0 0;
    text-align: center;
}

.auth-switch a {
    font-weight: 800;
    text-decoration: none;
}

.alerts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.alert,
.flash {
    border-radius: 8px;
    padding: 14px 16px;
    display: grid;
    gap: 4px;
    border: 1px solid transparent;
}

.alert.warning,
.flash.warning {
    background: #fff8ed;
    border-color: #fedf89;
    color: var(--warning);
}

.alert.danger,
.flash.danger {
    background: #fff1f0;
    border-color: #fecdca;
    color: var(--danger);
}

.alert.success,
.flash.success {
    background: #ecfdf3;
    border-color: #abefc6;
    color: var(--success);
}

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

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

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

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 14px;
}

label.is-disabled {
    opacity: 0.45;
}

label.is-hidden {
    display: none;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

input,
select,
button {
    min-height: 42px;
    border-radius: 8px;
    border: 1px solid #cfd8e6;
    padding: 0 12px;
    font: inherit;
}

input,
select {
    background: #fff;
    color: var(--text);
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
    outline: 0;
}

button {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    cursor: pointer;
    font-weight: 800;
}

.secondary-link-button {
    align-items: center;
    background: #eef2f7;
    border: 1px solid #d8e0eb;
    border-radius: 8px;
    color: #344054;
    display: inline-flex;
    font-weight: 800;
    min-height: 42px;
    padding: 0 12px;
    text-decoration: none;
    white-space: nowrap;
}

.secondary-link-button.icon-only-action {
    padding: 0;
}

.panel-link-button {
    margin-top: 14px;
    width: fit-content;
}

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

.table-panel {
    overflow-x: visible;
}

.table-header {
    padding: 20px 22px 0;
}

.empty-state {
    display: grid;
    gap: 5px;
    margin: 0 22px 22px;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.empty-state span {
    color: var(--muted);
}

.compact-empty {
    margin: 0;
}

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

thead {
    background: var(--surface-soft);
}

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

.expenses-table {
    table-layout: fixed;
}

.expenses-table th:nth-child(1),
.expenses-table td:nth-child(1) {
    width: 24%;
}

.expenses-table th:nth-child(2),
.expenses-table td:nth-child(2) {
    width: 9%;
}

.expenses-table th:nth-child(3),
.expenses-table td:nth-child(3) {
    width: 11%;
}

.expenses-table th:nth-child(4),
.expenses-table td:nth-child(4) {
    width: 10%;
}

.expenses-table th:nth-child(5),
.expenses-table td:nth-child(5) {
    width: 8%;
}

.expenses-table th:nth-child(6),
.expenses-table td:nth-child(6) {
    width: 8%;
}

.expenses-table th:nth-child(7),
.expenses-table td:nth-child(7) {
    width: 9%;
}

.expenses-table th:nth-child(8),
.expenses-table td:nth-child(8) {
    width: 12%;
}

.expenses-table th:nth-child(9),
.expenses-table td:nth-child(9) {
    width: 9%;
}

.expenses-table td:first-child {
    display: table-cell;
    min-width: 0;
}

.expenses-table td:first-child strong {
    display: block;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
}

.expenses-table td:first-child span {
    display: block;
    margin-top: 4px;
}

.expenses-table .badge {
    max-width: 100%;
    justify-content: center;
    line-height: 1.2;
    white-space: normal;
}

th {
    color: #475467;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

tbody tr:hover {
    background: #fbfcfe;
}

td:first-child {
    display: grid;
    gap: 4px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 8px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 800;
    word-break: normal;
}

.muted-badge {
    background: #eef2f7;
    color: #475467;
}

.success-badge {
    background: #ecfdf3;
    color: var(--success);
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(74px, 92px);
    gap: 6px;
    min-width: 0;
}

.inline-form input,
.inline-form button {
    min-height: 34px;
    padding: 0 8px;
}

.compact-field {
    color: var(--muted);
    font-size: 11px;
    gap: 3px;
}

.payment-form .compact-field:first-of-type {
    grid-column: 1;
}

.payment-form .compact-field input {
    width: 100%;
}

.readonly-value {
    align-items: center;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    display: inline-flex;
    min-height: 38px;
    padding: 0 10px;
    white-space: nowrap;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-items: start;
}

.secondary-button,
.icon-button {
    background: #eef2f7;
    border-color: #d8e0eb;
    color: #344054;
}

.secondary-button {
    min-height: 34px;
    padding: 0 10px;
}

.subtle-button {
    font-size: 13px;
    min-height: 32px;
}

.pay-action-button {
    min-height: 34px;
    min-width: 34px;
    padding: 0 10px;
}

.icon-only-action {
    align-items: center;
    display: inline-flex;
    justify-content: center;
    min-height: 34px;
    min-width: 34px;
    padding: 0;
    width: 34px;
}

.icon-only-action svg {
    display: block;
    fill: currentColor;
    height: 17px;
    width: 17px;
}

.icon-button {
    min-height: 34px;
}

.row-actions summary {
    color: var(--primary-dark);
    cursor: pointer;
    font-weight: 800;
    list-style: none;
}

.row-actions summary::-webkit-details-marker {
    display: none;
}

.expense-dialog {
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
    max-width: 760px;
    padding: 24px;
    width: min(92vw, 760px);
}

.compact-dialog {
    max-width: 620px;
    width: min(92vw, 620px);
}

.expense-dialog::backdrop {
    background: rgba(15, 23, 42, 0.38);
}

.dialog-header {
    align-items: flex-start;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 18px;
    margin-bottom: 18px;
}

.edit-expense-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.delete-expense-form {
    display: grid;
    margin-top: 12px;
}

.delete-expense-form button {
    background: var(--danger);
    border-color: var(--danger);
}

.danger-button {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.confirm-dialog {
    max-width: 460px;
}

.confirm-message {
    color: var(--muted);
    line-height: 1.5;
    margin: 0 0 18px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.compact-table th,
.compact-table td {
    padding: 10px 8px;
}

.pagination {
    align-items: center;
    border-top: 1px solid var(--line-soft);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    padding: 14px 16px;
}

.pagination button {
    min-height: 34px;
    padding: 0 12px;
}

.pagination button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.pagination span {
    color: var(--muted);
    font-size: 13px;
}

.list {
    margin-top: 18px;
    display: grid;
    gap: 10px;
}

.list div {
    display: grid;
    gap: 3px;
    padding: 12px 0;
    border-top: 1px solid var(--line-soft);
}

.list span {
    color: var(--muted);
    font-size: 13px;
}

.invite-panel {
    background: linear-gradient(135deg, #ffffff 0%, #eefaf7 100%);
}

.invite-code {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 52px;
    width: fit-content;
    border: 1px dashed var(--primary);
    border-radius: 8px;
    background: #fff;
    color: var(--primary-dark);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 2px;
    padding: 0 18px;
}

.summary-line {
    display: grid;
    gap: 8px;
    padding: 18px;
    border: 1px solid var(--line-soft);
    border-radius: 8px;
    background: var(--surface-soft);
}

.summary-line strong {
    font-size: 24px;
}

.summary-line span {
    color: var(--muted);
}

canvas {
    width: 100%;
    min-height: 260px;
}

.compact-chart-panel canvas {
    min-height: 150px;
}

.compact-chart-panel {
    padding-bottom: 12px;
}

@media (max-width: 1120px) {
    .grid-form {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 980px) {
    .auth-body {
        background: #f7f9fc;
    }

    .auth-shell {
        grid-template-columns: 1fr;
    }

    .auth-hero {
        min-height: auto;
        padding: 18px 22px;
        background: #111827;
        gap: 8px;
    }

    .auth-hero-metrics {
        display: none;
    }

    .auth-hero-copy {
        display: grid;
        gap: 4px;
        max-width: none;
    }

    .auth-hero-copy span {
        display: none;
    }

    .auth-hero-copy h1 {
        font-size: 18px;
        line-height: 1.25;
    }

    .auth-hero-copy p {
        color: #cbd5e1;
        font-size: 13px;
        line-height: 1.4;
    }

    .auth-content {
        min-height: auto;
        align-content: start;
        padding: 20px 22px;
    }

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

    .sidebar {
        position: sticky;
        height: auto;
        z-index: 2;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        padding: 16px;
        gap: 16px;
    }

    .sidebar-top span {
        display: none;
    }

    .sidebar-account {
        display: none;
    }

    .mobile-logout {
        display: block;
        margin-left: auto;
    }

    .mobile-logout .link-button {
        min-height: 36px;
        padding: 8px 11px;
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
        width: auto;
    }

    .main-nav {
        display: flex;
        gap: 8px;
    }

    .main-nav a {
        min-height: 38px;
        padding: 9px 10px;
    }

    .content {
        padding: 22px;
    }

    .content-inner {
        width: 100%;
    }

    .grid.two,
    .form.compact {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .auth-panel {
        padding: 24px;
    }

    .auth-card-header h1 {
        font-size: 24px;
    }

    .sidebar {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .main-nav {
        width: 100%;
        overflow-x: auto;
    }

    .content {
        padding: 16px;
    }

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

    .month-filter {
        align-items: stretch;
        display: grid;
        width: 100%;
    }

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

    .secondary-link-button {
        justify-content: center;
        width: 100%;
    }

    .secondary-link-button.icon-only-action {
        width: 42px;
    }

    .filter-actions {
        justify-content: flex-start;
    }

    .filter-actions .icon-only-action {
        width: 42px;
    }

    .panel-link-button {
        width: 100%;
    }

    .month-filter label {
        min-width: 0;
    }

    h1 {
        font-size: 22px;
    }

    .brand {
        font-size: 19px;
    }

    .metrics article {
        min-height: 104px;
    }

    .metrics,
    .grid-form {
        grid-template-columns: 1fr;
    }

    .panel,
    .table-header {
        padding: 18px;
    }

    .empty-state {
        margin: 0 18px 18px;
    }

    .table-panel {
        overflow-x: visible;
    }

    .expenses-table {
        min-width: 0;
    }

    .expenses-table thead {
        display: none;
    }

    .expenses-table,
    .expenses-table tbody,
    .expenses-table tr,
    .expenses-table td {
        display: block;
        width: 100%;
    }

    .expenses-table td:nth-child(1),
    .expenses-table td:nth-child(2),
    .expenses-table td:nth-child(3),
    .expenses-table td:nth-child(4),
    .expenses-table td:nth-child(5),
    .expenses-table td:nth-child(6),
    .expenses-table td:nth-child(7),
    .expenses-table td:nth-child(8),
    .expenses-table td:nth-child(9) {
        width: 100%;
    }

    .expenses-table tr {
        border-bottom: 1px solid var(--line);
        padding: 12px 0;
    }

    .expenses-table td {
        align-items: flex-start;
        border-bottom: 0;
        display: grid;
        gap: 8px;
        grid-template-columns: 92px 1fr;
        padding: 7px 12px;
    }

    .expenses-table td::before {
        color: #475467;
        content: attr(data-label);
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .expenses-table td:first-child {
        display: grid;
    }

    .expenses-table td:first-child::before {
        align-self: start;
    }

    .expenses-table .badge {
        justify-self: start;
    }

    .expenses-table td > *:not(.badge) {
        min-width: 0;
    }

    .expenses-table td[data-label="Valor do mes"] strong,
    .expenses-table td[data-label="Pago"],
    .expenses-table td[data-label="Restante"] strong {
        white-space: nowrap;
    }

    .expenses-table td[data-label="Despesa"] strong,
    .expenses-table td[data-label="Despesa"] span {
        grid-column: 2;
    }

    .expenses-table td[data-label="Despesa"]::before {
        grid-row: 1 / span 2;
    }

    .expenses-table .badge {
        box-sizing: border-box;
        display: inline-flex;
        max-width: none;
        width: fit-content;
        white-space: nowrap;
    }

    .compact-table thead {
        display: none;
    }

    .compact-table,
    .compact-table tbody,
    .compact-table tr,
    .compact-table td {
        display: block;
        width: 100%;
    }

    .compact-table tr {
        border-bottom: 1px solid var(--line-soft);
        padding: 10px 0;
    }

    .compact-table td {
        border-bottom: 0;
        display: grid;
        gap: 8px;
        grid-template-columns: 96px 1fr;
        padding: 6px 0;
    }

    .compact-table td::before {
        color: #475467;
        content: attr(data-label);
        font-size: 11px;
        font-weight: 800;
        text-transform: uppercase;
    }

    .payment-form {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .row-actions {
        justify-items: start;
    }

    .edit-expense-form {
        grid-template-columns: 1fr;
    }
}
