/* ==========================================================================
   4DEsqueleto — folha de estilo base (claro/escuro).
   Rebrand: troque os tokens --accent* abaixo. Tudo mais herda daí.
   ========================================================================== */

:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --ink: #111827;
    --muted: #667085;
    --line: #d9dee7;

    /* Cor de destaque da aplicação (rebrand aqui) */
    --accent: #1f6f5b;
    --accent-strong: #155143;
    --accent-soft: #e8f4ef;

    --blue: #2563eb;
    --amber: #b7791f;
    --red: #b42318;
    --green: #1f9d55;
    --brand-red: #e11900;      /* o "4D" da marca é sempre vermelho */

    --shadow: 0 20px 60px rgba(15, 23, 42, .09);
    --radius: 10px;
    --font: Arial, Helvetica, sans-serif;
    --sidebar-w: 250px;
}

: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;
    --green: #58d68d;
    --brand-red: #ff4d3d;

    --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); font-family: var(--font); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
h1, h2, h3, p { margin-top: 0; }
i[class^="ti-"], i[class*=" ti-"] { line-height: 1; }

/* ---------- Marca ---------- */
.wordmark { display: inline-flex; align-items: baseline; font-family: Arial, Helvetica, sans-serif; font-weight: 700; letter-spacing: -.01em; line-height: 1; }
.wm-badge { align-self: center; flex: none; display: inline-flex; width: 1.5em; height: 1.5em; margin-right: .42em; border-radius: .34em; background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.wm-badge img { width: 80%; height: 80%; margin: auto; object-fit: contain; display: block; }
.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; }
.hide-sm { }
.muted { color: var(--muted); }

/* ==========================================================================
   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 article i { display: inline-flex; margin-bottom: 14px; color: var(--accent); font-size: 22px; }
.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; gap: 6px; min-height: 28px; padding: 6px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.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: 56px; }
.icon-button { display: grid; place-items: center; min-width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 7px; color: var(--ink); background: var(--surface); cursor: pointer; }
.password-wrap .icon-button { position: absolute; top: 4px; right: 4px; height: 38px; border: 0; color: var(--accent-strong); background: var(--accent-soft); }
.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; cursor: pointer; }
.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; }
.form-row a:hover { text-decoration: underline; }
.submit-button, .outline-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; 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); }
.outline-button:hover { border-color: var(--accent); color: var(--accent-strong); }
.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)); }
.alert.ok { border-color: color-mix(in srgb, var(--accent) 42%, var(--line)); color: var(--accent-strong); }

/* Faixa de modo demonstração no login */
.dev-login-strip { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 16px; padding: 12px 14px; border: 1px dashed color-mix(in srgb, var(--amber) 50%, var(--line)); border-radius: 8px; background: color-mix(in srgb, var(--amber) 8%, var(--surface)); }
.dev-login-strip span { display: inline-flex; align-items: center; gap: 6px; color: var(--amber); font-size: 13px; font-weight: 700; }

/* Botões de tema */
.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 { display: grid; place-items: center; min-width: 32px; min-height: 30px; border: 0; border-radius: 6px; color: var(--muted); background: transparent; cursor: pointer; font-size: 15px; }
.theme-switcher button.is-active { color: var(--ink); background: var(--surface); box-shadow: 0 1px 4px rgba(15, 23, 42, .12); }

/* ==========================================================================
   Shell da aplicação (sidebar + main)
   ========================================================================== */
.app-body { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }

.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.sidebar .brand-link { padding: 4px 8px 10px; }
.sidebar .wordmark { font-size: 22px; }
.side-group { margin-top: 14px; padding: 0 10px 5px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.side-nav { display: grid; gap: 3px; }
.side-nav a { display: flex; align-items: center; gap: 10px; min-height: 38px; border-radius: 8px; padding: 0 11px; color: var(--muted); font-weight: 700; font-size: 13.5px; }
.side-nav a i { font-size: 18px; flex: none; }
.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; }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }
.side-user { display: flex; align-items: center; gap: 10px; padding: 8px 6px; }
.side-user-info { min-width: 0; }
.side-user-info strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-info span { display: block; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; }
.icon-link { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); font-size: 17px; }
.icon-link:hover { border-color: var(--red); color: var(--red); }

.avatar { width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 14px; }

/* Main */
.app-main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 22px 0 44px; }
.app-topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.topbar-title { display: flex; align-items: center; gap: 12px; }
.app-topbar h1 { margin: 0; font-size: 28px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.topbar-search { display: flex; align-items: center; gap: 8px; min-width: 220px; 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; }
.sidebar-toggle { display: none; }

/* Faixa de usuário / tenant */
.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; }

/* KPIs */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-card { min-height: 118px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.kpi-card .kpi-ico { display: inline-grid; place-items: center; width: 34px; height: 34px; margin-bottom: 10px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-strong); font-size: 18px; }
.kpi-card strong { display: block; margin-bottom: 6px; color: var(--accent-strong); font-size: 28px; line-height: 1; }
.kpi-card span { display: block; margin-bottom: 4px; font-weight: 800; font-size: 13px; }
.kpi-card small { color: var(--muted); font-size: 12px; line-height: 1.4; }

/* Painéis / seções */
.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; gap: 6px; min-height: 28px; padding: 5px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }

/* Grid de módulos / cards */
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.module-card { display: block; min-height: 118px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-soft); }
a.module-card:hover { border-color: var(--accent); }
.module-card span.tag { display: inline-flex; align-items: center; gap: 6px; 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 .m-ico { color: var(--accent); font-size: 22px; }
.module-card h3 { margin: 12px 0 7px; font-size: 16px; }
.module-card p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

/* Tabelas */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; min-width: 560px; 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; }
.data-table tbody tr:hover { background: var(--surface-soft); }

/* Pílulas / status */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 800; background: var(--accent-soft); 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.red { background: color-mix(in srgb, var(--red) 14%, var(--surface)); color: var(--red); }
.pill.green { background: color-mix(in srgb, var(--green) 16%, var(--surface)); color: var(--green); }
.pill.muted { background: var(--surface-soft); color: var(--muted); }
.empty-note { padding: 28px 8px; text-align: center; color: var(--muted); }

/* Grid 2 colunas */
.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; }

/* ==========================================================================
   Formulários de módulo
   ========================================================================== */
.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, .field textarea { min-height: 42px; border: 1px solid var(--line); border-radius: 7px; padding: 9px 11px; color: var(--ink); background: var(--surface); font: inherit; }
.field textarea { min-height: 90px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea: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; gap: 8px; 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:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }

/* ==========================================================================
   Modal (efeito vidro)
   ========================================================================== */
.modal-backdrop { position: fixed; inset: 0; z-index: 60; display: none; place-items: center; padding: 20px; background: rgba(8, 12, 18, .5); backdrop-filter: blur(4px); }
.modal-backdrop.open { display: grid; }
.modal { width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-box { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; max-width: min(360px, calc(100% - 36px)); }
.toast { padding: 12px 14px; border: 1px solid var(--line); border-left-width: 4px; border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); color: var(--ink); font-size: 13.5px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.info { border-left-color: var(--blue); }
.toast.ok { border-left-color: var(--green); }
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }

/* ==========================================================================
   Console de log flutuante (abinha no canto) — sempre escuro (dev console)
   ========================================================================== */
#app-console { position: fixed; top: 80px; right: 0; z-index: 10000; font-family: 'Consolas', ui-monospace, monospace; font-size: 10.5px; display: flex; flex-direction: row-reverse; align-items: flex-start; pointer-events: none; }
#app-console .console-tab { pointer-events: auto; width: 26px; min-height: 84px; background: rgba(15,23,42,.92); border: 1px solid #334155; border-right: none; border-radius: 6px 0 0 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; writing-mode: vertical-rl; text-orientation: mixed; color: #fbbf24; font-weight: 800; letter-spacing: 1px; transition: background .2s; user-select: none; }
#app-console .console-tab:hover { background: rgba(30,41,59,.98); color: #fff; }
#app-console .console-tab .cbadge { position: absolute; top: -6px; left: -6px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 9px; font-weight: 800; display: none; align-items: center; justify-content: center; writing-mode: horizontal-tb; }
#app-console .console-tab.has-err .cbadge { display: flex; }
#app-console .console-panel { pointer-events: auto; width: min(400px, 92vw); max-height: 260px; background: rgba(2,6,23,.96); border: 1px solid #334155; border-right: none; border-radius: 6px 0 0 6px; display: none; flex-direction: column; box-shadow: -4px 4px 15px rgba(0,0,0,.5); overflow: hidden; }
#app-console.open .console-panel { display: flex; }
#app-console.open .console-tab { background: #0f172a; border-color: #fbbf24; }
#app-console .console-header { background: #0f172a; padding: 6px 10px; border-bottom: 1px solid #1e293b; display: flex; justify-content: space-between; align-items: center; color: #cbd5e1; font-weight: bold; text-transform: uppercase; letter-spacing: 1px; user-select: none; flex-shrink: 0; }
#app-console .console-actions { display: flex; gap: 8px; }
#app-console .console-btn { background: none; border: none; color: #94a3b8; cursor: pointer; padding: 2px; font: inherit; transition: color .2s; }
#app-console .console-btn:hover { color: #fff; }
#app-console .console-body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 4px; color: #e2e8f0; scrollbar-width: thin; scrollbar-color: #334155 #020617; }
#app-console .log-row { display: flex; gap: 6px; line-height: 1.4; border-bottom: 1px solid rgba(255,255,255,.05); padding-bottom: 2px; }
#app-console .log-ts { color: #64748b; min-width: 56px; flex: none; }
#app-console .log-txt { word-break: break-word; }
#app-console .log-info { color: #38bdf8; } #app-console .log-warn { color: #fbbf24; } #app-console .log-err { color: #ef4444; font-weight: bold; } #app-console .log-ok { color: #4ade80; }

/* Banner de manutenção / avisos de topo */
.top-banner { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: color-mix(in srgb, var(--amber) 16%, var(--surface)); color: var(--amber); border-bottom: 1px solid color-mix(in srgb, var(--amber) 40%, var(--line)); font-size: 13px; font-weight: 700; }

/* ==========================================================================
   Responsivo
   ========================================================================== */
@media (max-width: 980px) {
    .auth-shell { grid-template-columns: 1fr; align-items: start; }
    .foundation-grid { grid-template-columns: 1fr; }

    .app-body { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; z-index: 50; top: 0; left: 0; width: min(280px, 84%); height: 100vh;
        transform: translateX(-100%); transition: transform .22s ease;
        border-right: 1px solid var(--line); box-shadow: var(--shadow);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-toggle { display: grid; }
    .sidebar-scrim { position: fixed; inset: 0; z-index: 40; display: none; background: rgba(8, 12, 18, .45); }
    .sidebar-scrim.show { display: block; }
    .app-main { width: min(100% - 28px, 1180px); }
}
@media (max-width: 680px) {
    .auth-shell { width: min(100% - 22px, 1160px); }
    .intro-copy h1 { font-size: 32px; }
    .signal-grid { grid-template-columns: 1fr; }
    .app-topbar, .user-strip { flex-direction: column; align-items: stretch; }
    .hide-sm { display: none; }
}
