:root {
    --bg: #f4f7f1;
    --surface: #ffffff;
    --surface-2: #f8fbf6;
    --text: #1d2a21;
    --muted: #5f6d62;
    --line: #d7e0d4;
    --primary: #2e6a3f;
    --primary-strong: #245634;
    --accent: #cc9b3a;
    --danger: #b33a3a;
    --success: #217a52;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow-1: 0 8px 22px rgba(21, 52, 34, 0.08);
    --shadow-2: 0 2px 8px rgba(24, 38, 28, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at top right, #ebf3e6 0%, var(--bg) 45%);
    color: var(--text);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

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

a:hover {
    color: var(--primary-strong);
}

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 1035;
    backdrop-filter: blur(8px);
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: 0.2px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2f7a45, #245634);
    color: #fff;
    font-size: 0.9rem;
    box-shadow: var(--shadow-2);
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.top-nav a {
    text-decoration: none;
    color: var(--muted);
    font-size: 0.94rem;
    padding: 0.5rem 0.75rem;
    border-radius: 9px;
    transition: all 0.2s ease;
}

.top-nav a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.top-nav a.is-active {
    background: #e7efe4;
    color: var(--primary-strong);
    font-weight: 600;
}

.logout-btn {
    border: 1px solid #d9d0bf;
    background: #fffaf0;
    color: #7b5420;
    border-radius: 10px;
    padding: 0.45rem 0.8rem;
    line-height: 1.2;
    font-weight: 600;
}

.logout-btn:hover {
    background: #f8edda;
}

.page-main {
    padding-top: 1.2rem;
    padding-bottom: 2rem;
}

.page-panel {
    background: var(--surface);
    border: 1px solid #e5ece2;
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 1.05rem;
}

.page-title {
    margin: 0 0 0.4rem;
    font-size: clamp(1.05rem, 1.8vw, 1.35rem);
    font-weight: 700;
}

.page-lead {
    color: var(--muted);
    margin-bottom: 1rem;
}

.section-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

/* KPI summary block — background highlight for financial/operational summaries */
.kpi-summary {
    background: linear-gradient(120deg, #f7fbf3, #eef7e8);
    border: 1px solid #d9e7d2;
    border-radius: var(--radius-sm);
    padding: 0.8rem;
    color: #2f4b37;
    font-size: 0.92rem;
}

hr {
    border: none;
    border-top: 1px solid var(--line);
    margin: 1rem 0;
}

/* ---- Formulários ---- */
input,
select,
textarea {
    width: 100%;
    border: 1px solid #cfdacf;
    background: #fff;
    color: var(--text);
    border-radius: var(--radius-sm);
    padding: 0.58rem 0.7rem;
    font-size: 0.94rem;
    font-family: inherit;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #5e9e75;
    box-shadow: 0 0 0 3px rgba(94, 158, 117, 0.2);
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
}

/* Django form markup */
.helptext,
span.helptext {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.3rem;
    line-height: 1.4;
}

.helptext ul,
span.helptext ul {
    margin: 0.25rem 0 0 1.1rem;
    padding: 0;
}

.errorlist {
    list-style: none;
    margin: 0.3rem 0 0;
    padding: 0;
}

.errorlist li {
    font-size: 0.82rem;
    color: var(--danger);
    font-weight: 500;
}

/* Django as_p form rendering */
.login-card p {
    margin-bottom: 0.9rem;
}

.login-card p label {
    display: block;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.3rem;
    color: var(--text);
}

/* ---- Login ---- */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.login-card {
    width: min(440px, 100%);
    background: #fff;
    border: 1px solid #dce6d8;
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(27, 65, 43, 0.13);
    padding: 1.4rem;
}

.login-sub {
    color: var(--muted);
    margin-bottom: 0.95rem;
}

/* ---- Sessão expirada ---- */
.session-expired-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(15, 30, 20, 0.55);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: overlay-fade-in 0.2s ease;
}

@keyframes overlay-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.session-expired-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid #dce6d8;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(15, 40, 25, 0.22);
    padding: 2rem 1.8rem 1.8rem;
    text-align: center;
    animation: card-slide-up 0.25s ease;
}

@keyframes card-slide-up {
    from { transform: translateY(18px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.session-expired-icon {
    display: inline-grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e8f4ed, #d0e8d9);
    margin-bottom: 1.1rem;
    font-size: 1.5rem;
}

.session-expired-card h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    margin: 0 0 0.5rem;
}

.session-expired-card p {
    color: var(--muted);
    font-size: 0.93rem;
    line-height: 1.55;
    margin: 0 0 1.4rem;
}

.session-expired-btn {
    display: inline-block;
    width: 100%;
    padding: 0.68rem 1rem;
    background: linear-gradient(135deg, #2f7a45, var(--primary-strong));
    color: #fff;
    font-weight: 600;
    font-size: 0.95rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s ease, transform 0.1s ease;
}

.session-expired-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
    color: #fff;
}

/* ---- Offcanvas mobile nav ---- */
.offcanvas .nav-link {
    border-radius: 9px;
    color: #32503b;
    margin-bottom: 0.2rem;
}

.offcanvas .nav-link.is-active,
.offcanvas .nav-link:hover {
    background: #e8f2e5;
    color: #1f3d29;
}

@media (max-width: 992px) {
    .top-nav {
        display: none;
    }
}

@media (max-width: 640px) {
    .page-main {
        padding-top: 0.85rem;
    }

    .page-panel,
    .section-card {
        padding: 0.8rem;
    }
}
