:root {
    --color-bg: #f4f6f9;
    --color-surface: #ffffff;
    --color-border: #e3e8ef;
    --color-text: #1c2431;
    --color-text-muted: #6b7686;
    --color-primary: #0d6e6e;
    --color-primary-dark: #095454;
    --color-primary-soft: #e3f2f1;
    --color-accent: #2f8f7f;
    --color-success: #1b8a5a;
    --color-success-soft: #e4f6ec;
    --color-warning: #b7791f;
    --color-warning-soft: #fdf3dc;
    --color-danger: #c0392b;
    --color-danger-soft: #fbe7e4;
    --color-info: #2563a8;
    --color-info-soft: #e5eefb;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --sidebar-width: 250px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; }
p { margin: 0 0 1rem; }

.app-shell { display: flex; min-height: 100vh; }

/* ---------------- Sidebar ---------------- */
.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--color-primary-dark), #073f3f);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
}

.sidebar .brand {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 2rem;
    padding: 0 .5rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.sidebar .brand small {
    display: block;
    font-weight: 400;
    font-size: .7rem;
    opacity: .75;
}

.sidebar nav { display: flex; flex-direction: column; gap: .2rem; flex: 1; }

.sidebar nav a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .6rem .8rem;
    border-radius: var(--radius-sm);
    font-size: .92rem;
    display: flex;
    align-items: center;
    gap: .6rem;
}

.sidebar nav a:hover { background: rgba(255,255,255,.08); }
.sidebar nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }

.sidebar .sidebar-footer {
    border-top: 1px solid rgba(255,255,255,.15);
    padding-top: 1rem;
    font-size: .85rem;
}

.sidebar .sidebar-footer form button {
    background: none; border: none; color: rgba(255,255,255,.75); cursor: pointer; padding: 0; font-size: .85rem;
}
.sidebar .sidebar-footer form button:hover { color: #fff; text-decoration: underline; }

/* ---------------- Main content ---------------- */
.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar h1 { font-size: 1.3rem; }

.content { padding: 2rem; flex: 1; }

/* ---------------- Cards ---------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card > h2, .card > h3 { margin-bottom: 1rem; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
}

.stat-card .stat-label {
    font-size: .8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: .35rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
}

.stat-card.accent-primary { border-top: 3px solid var(--color-primary); }
.stat-card.accent-success { border-top: 3px solid var(--color-success); }
.stat-card.accent-warning { border-top: 3px solid var(--color-warning); }
.stat-card.accent-danger { border-top: 3px solid var(--color-danger); }
.stat-card.accent-info { border-top: 3px solid var(--color-info); }

.two-col {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 960px) {
    .two-col { grid-template-columns: 1fr; }
    .sidebar { display: none; }
}

/* ---------------- Tables ---------------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .75rem; border-bottom: 1px solid var(--color-border); font-size: .9rem; }
th { color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; font-size: .72rem; letter-spacing: .04em; }
tbody tr:hover { background: #fafbfc; }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}
.badge-receita { background: var(--color-success-soft); color: var(--color-success); }
.badge-despesa { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-inactive { background: var(--color-border); color: var(--color-text-muted); }
.badge-pendente { background: var(--color-warning-soft); color: var(--color-warning); }
.badge-pago { background: var(--color-success-soft); color: var(--color-success); }
.badge-cancelado { background: var(--color-border); color: var(--color-text-muted); }
.badge-atrasado { background: var(--color-danger-soft); color: var(--color-danger); }

tr.overdue { background: var(--color-danger-soft); }
tr.overdue:hover { background: #f8d7d1; }
tr.overdue td { color: var(--color-danger); font-weight: 600; }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; margin-bottom: 1rem; }
.form-group label { font-size: .82rem; font-weight: 600; color: var(--color-text-muted); }
.form-group.full { grid-column: 1 / -1; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="time"], input[type="number"], input[type="tel"], input[type="search"],
input[type="month"], select, textarea {
    padding: .55rem .7rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: .92rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.field-error { color: var(--color-danger); font-size: .8rem; }

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .55rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: #fff; color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: #f3f5f7; }
.btn-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.btn-danger:hover { background: #f6d5d0; }
.btn-sm { padding: .35rem .7rem; font-size: .78rem; }

.actions-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.5rem; align-items: center; justify-content: space-between; }

/* ---------------- Alerts ---------------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.25rem; font-size: .9rem; }
.alert-error { background: var(--color-danger-soft); color: var(--color-danger); }
.alert-success { background: var(--color-success-soft); color: var(--color-success); }
.alert-info { background: var(--color-info-soft); color: var(--color-info); }

/* ---------------- Auth pages ---------------- */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top left, #0f7d7d, #073f3f 65%);
    padding: 1rem;
}

.auth-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 380px;
}

.auth-card .brand {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-card .brand strong { font-size: 1.3rem; color: var(--color-primary-dark); display: block; }
.auth-card .brand span { font-size: .82rem; color: var(--color-text-muted); }

.auth-card .btn { width: 100%; justify-content: center; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-muted); }

.tag-list { display: flex; flex-wrap: wrap; gap: .4rem; }

.filters-bar { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; margin-bottom: 1.5rem; }
.filters-bar form { display: flex; gap: .75rem; flex-wrap: wrap; align-items: end; }

.text-success { color: var(--color-success); }
.text-danger { color: var(--color-danger); }
.text-muted { color: var(--color-text-muted); }
.text-right { text-align: right; }

.month-nav { display: flex; align-items: center; gap: .75rem; }
.month-nav .current-month { font-weight: 600; min-width: 110px; text-align: center; }

/* ---------------- Simple bar chart (dashboard trend) ---------------- */
.bar-chart { display: flex; align-items: flex-end; gap: .75rem; height: 160px; margin-top: 1rem; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: .3rem; }
.bar-chart .bar-track { width: 100%; max-width: 34px; height: 100%; display: flex; flex-direction: column-reverse; justify-content: flex-start; gap: 2px; }
.bar-chart .bar-segment.receita { background: var(--color-success); border-radius: 3px 3px 0 0; }
.bar-chart .bar-segment.despesa { background: var(--color-danger); border-radius: 3px 3px 0 0; }
.bar-chart .bar-label { font-size: .72rem; color: var(--color-text-muted); }
