:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --ink: #111827;
    --muted: #667085;
    --line: #d9dee7;
    --accent: #1f6f5b;
    --accent-strong: #155143;
    --accent-soft: #e8f4ef;
    --blue: #2563eb;
    --amber: #b7791f;
    --red: #b42318;
    --brand-red: #e11900;
    --shadow: 0 20px 60px rgba(15, 23, 42, .09);
    --radius: 8px;
    --font: Arial, Helvetica, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0f141b;
    --surface: #151b24;
    --surface-soft: #1b2330;
    --ink: #eef2f7;
    --muted: #a7b0be;
    --line: #2a3443;
    --accent: #63c3a6;
    --accent-strong: #8ee0c7;
    --accent-soft: #17362f;
    --blue: #79a8ff;
    --amber: #f2be62;
    --red: #ff8b7f;
    --brand-red: #ff4d3d;
    --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); font-family: var(--font); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
h1, h2, h3, p { margin-top: 0; }

/* Marca 4D: "4D" sempre vermelho + nome colado (preto no claro, branco no escuro). */
.wordmark { display: inline-flex; align-items: baseline; font-family: Arial, Helvetica, sans-serif; font-weight: 700; letter-spacing: -.01em; line-height: 1; }
.wordmark .wm-4d { color: var(--brand-red); }
.wordmark .wm-name { color: var(--ink); }
.brand-line { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
.brand-line .wordmark { font-size: 26px; }
.brand-line small { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; font-weight: 400; }

.eyebrow { margin: 0 0 10px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }

/* ---------- Login ---------- */
.auth-body { min-height: 100vh; background: var(--bg); }
.auth-shell { width: min(1160px, calc(100% - 32px)); min-height: 100vh; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) 430px; gap: 40px; align-items: center; padding: 32px 0; }
.auth-intro { display: grid; gap: 34px; }
.intro-copy h1 { max-width: 640px; margin-bottom: 16px; font-size: 40px; line-height: 1.08; }
.intro-copy p:not(.eyebrow) { max-width: 640px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.6; }
.signal-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.signal-grid article { min-height: 132px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.signal-grid span { display: inline-flex; margin-bottom: 16px; color: var(--accent); font-size: 13px; font-weight: 800; }
.signal-grid strong { display: block; margin-bottom: 8px; }
.signal-grid p { margin: 0; color: var(--muted); line-height: 1.45; font-size: 14px; }

.auth-card { padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.card-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.secure-badge { display: inline-flex; align-items: center; min-height: 28px; padding: 6px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.theme-switcher { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-soft); }
.theme-switcher button { min-height: 30px; border: 0; border-radius: 6px; padding: 0 10px; color: var(--muted); background: transparent; cursor: pointer; }
.theme-switcher button.is-active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }
.login-heading { margin: 24px 0 18px; }
.login-heading h2 { margin-bottom: 8px; font-size: 26px; line-height: 1.18; }
.login-heading p { margin: 0; color: var(--muted); }
.auth-form { display: grid; gap: 10px; }
.auth-form label:not(.check-row) { color: var(--ink); font-size: 14px; font-weight: 700; }
.auth-form input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 7px; padding: 0 12px; color: var(--ink); background: var(--surface); }
.auth-form input:focus { outline: 3px solid color-mix(in srgb, var(--accent) 20%, transparent); border-color: var(--accent); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 64px; }
.icon-button { position: absolute; top: 5px; right: 5px; display: grid; place-items: center; min-width: 50px; height: 36px; border: 0; border-radius: 6px; color: var(--accent-strong); background: var(--accent-soft); cursor: pointer; font-size: 13px; font-weight: 700; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 6px 0 4px; }
.check-row { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.check-row input { width: 16px; min-height: 16px; accent-color: var(--accent); }
.form-row a { color: var(--accent-strong); font-size: 14px; font-weight: 700; }
.submit-button, .outline-button { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; border-radius: 7px; font-weight: 800; cursor: pointer; }
.submit-button { width: 100%; border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.submit-button:hover { background: var(--accent-strong); }
.outline-button { padding: 0 14px; border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.auth-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.alert { margin: 0 0 14px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); background: var(--surface-soft); font-size: 14px; line-height: 1.4; }
.alert.err { border-color: color-mix(in srgb, var(--red) 42%, var(--line)); color: var(--red); }
.alert.info { border-color: color-mix(in srgb, var(--blue) 32%, var(--line)); }

/* ---------- App shell ---------- */
.app-body { min-height: 100vh; display: grid; grid-template-columns: 250px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar .brand-line { padding: 4px 8px 6px; }
.sidebar .wordmark { font-size: 22px; }
.side-group { margin-top: 16px; padding: 0 10px 5px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.side-nav { display: grid; gap: 3px; }
.side-nav a { display: flex; align-items: center; gap: 9px; min-height: 38px; border-radius: 7px; padding: 0 11px; color: var(--muted); font-weight: 700; font-size: 13.5px; }
.side-nav a:hover, .side-nav a.active { color: var(--accent-strong); background: var(--accent-soft); }
.side-nav .nbadge { margin-left: auto; min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 800; text-align: center; }

.app-main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 26px 0 40px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.app-topbar h1 { margin: 0; font-size: 30px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-search { display: flex; align-items: center; gap: 8px; min-width: 230px; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--muted); font-size: 13px; }
.topbar-search input { width: 100%; border: 0; background: transparent; color: var(--ink); outline: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; }

.user-strip { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px; margin-bottom: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.user-strip div { display: grid; gap: 4px; }
.user-strip span { color: var(--muted); font-size: 13px; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { min-height: 120px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.kpi-card strong { display: block; margin-bottom: 9px; color: var(--accent-strong); font-size: 30px; line-height: 1; }
.kpi-card span { display: block; margin-bottom: 6px; font-weight: 800; font-size: 13px; }
.kpi-card small { color: var(--muted); font-size: 12px; line-height: 1.4; }

.content-panel { padding: 20px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-heading h2 { margin: 2px 0 0; font-size: 20px; }
.table-prefix { display: inline-flex; align-items: center; min-height: 28px; padding: 5px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.module-card { min-height: 120px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-soft); }
.module-card span { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 11px; font-weight: 800; }
.module-card h3 { margin: 14px 0 7px; font-size: 16px; }
.module-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; background: var(--surface); }
.data-table th, .data-table td { padding: 11px 13px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; }
.data-table th { color: var(--muted); background: var(--surface-soft); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: 0; }
.loc { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.pill { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; background: var(--accent-soft); color: var(--accent-strong); }

@media (max-width: 980px) {
    .auth-shell { grid-template-columns: 1fr; align-items: start; }
    .app-body { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .signal-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 680px) {
    .auth-shell, .app-main { width: min(100% - 22px, 1180px); }
    .intro-copy h1 { font-size: 32px; }
    .signal-grid { grid-template-columns: 1fr; }
    .app-topbar, .user-strip { flex-direction: column; align-items: stretch; }
}

/* ---------- Formularios de modulo ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 14px; }
.field { display: grid; gap: 6px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 800; color: var(--ink); }
.field input, .field select { min-height: 42px; border: 1px solid var(--line); border-radius: 7px; padding: 0 11px; color: var(--ink); background: var(--surface); font: inherit; }
.field input[type=file] { padding: 9px 11px; }
.field input:focus, .field select:focus { outline: 3px solid color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }
.form-actions { display: flex; gap: 10px; align-items: center; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 16px; border-radius: 7px; font-weight: 800; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.alert.ok { border-color: color-mix(in srgb, var(--accent) 42%, var(--line)); color: var(--accent-strong); }
.pill.amber { background: color-mix(in srgb, var(--amber) 16%, var(--surface)); color: var(--amber); }
.pill.blue { background: color-mix(in srgb, var(--blue) 14%, var(--surface)); color: var(--blue); }
.pill.muted { background: var(--surface-soft); color: var(--muted); }
.empty-note { padding: 28px 8px; text-align: center; color: var(--muted); }
.foundation-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.foundation-grid .content-panel { overflow: hidden; }
.foundation-grid .data-table { min-width: 0; }
@media (max-width: 980px) { .foundation-grid { grid-template-columns: 1fr; } }
