/* ===========================================================================
   S.O.U.S. — folha de estilo da aplicação
   Tokens no :root, tema claro/escuro automático.
   =========================================================================== */

:root {
    --bg:        #f6f7f9;
    --surface:   #ffffff;
    --surface-2: #f1f3f5;
    --border:    #e2e5e9;
    --text:      #16181d;
    --text-dim:  #61666e;
    --brand:     #0f172a;
    --brand-ink: #ffffff;
    --accent:    #2563eb;
    --ok:        #16a34a;
    --warn:      #d97706;
    --danger:    #dc2626;

    --sidebar-w: 248px;
    --topbar-h:  60px;
    --radius:    10px;
    --shadow:    0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:        #0d0f13;
        --surface:   #15181e;
        --surface-2: #1c2027;
        --border:    #272c35;
        --text:      #e8eaed;
        --text-dim:  #9aa1ac;
        --brand:     #0b0d11;
        --brand-ink: #ffffff;
        --accent:    #60a5fa;
        --shadow:    0 1px 2px rgba(0, 0, 0, .4);
    }
}

* { box-sizing: border-box; }

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

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

/* ── Barra de impersonação ────────────────────────────────────────────────── */
.impersonation-bar {
    position: fixed; inset: 0 0 auto 0; z-index: 1050;
    height: 38px; display: flex; align-items: center; gap: 10px;
    padding: 0 16px; background: var(--warn); color: #fff; font-size: 13px; font-weight: 600;
}
.impersonation-bar a { color: #fff; text-decoration: underline; margin-left: auto; }

/* ── Estrutura ────────────────────────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; }
.app-shell.with-bar { padding-top: 38px; }

.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: var(--brand); color: var(--brand-ink);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}

.sidebar-brand {
    height: var(--topbar-h); display: flex; align-items: center;
    padding: 0 18px; border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-mark { font-weight: 800; letter-spacing: 2px; font-size: 15px; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }

.nav-section {
    font-size: 10px; text-transform: uppercase; letter-spacing: .9px;
    color: rgba(255, 255, 255, .42); padding: 14px 8px 6px; font-weight: 700;
}

.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; margin-bottom: 2px; border-radius: 8px;
    color: rgba(255, 255, 255, .78); font-size: 13.5px; text-decoration: none;
}
.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(255, 255, 255, .13); color: #fff; font-weight: 600; }
.nav-link i { font-size: 15px; width: 18px; text-align: center; }

.sidebar-foot {
    border-top: 1px solid rgba(255, 255, 255, .08);
    padding: 10px; display: flex; align-items: center; gap: 8px;
}
.user-chip {
    display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0;
    padding: 6px; border-radius: 8px; color: inherit; text-decoration: none;
}
.user-chip:hover, .user-chip.active { background: rgba(255, 255, 255, .08); text-decoration: none; }
.avatar {
    width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
    background: rgba(255, 255, 255, .16); color: #fff;
    display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name {
    font-size: 12.5px; font-weight: 600; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-role { font-size: 10.5px; color: rgba(255, 255, 255, .5); }

.logout-form { margin: 0; }
.btn-logout {
    background: none; border: 0; color: rgba(255, 255, 255, .6);
    padding: 6px 8px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.btn-logout:hover { background: rgba(255, 255, 255, .1); color: #fff; }

/* ── Coluna principal ─────────────────────────────────────────────────────── */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h); display: flex; align-items: center; gap: 12px;
    padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.tenant-pill {
    background: var(--surface-2); border: 1px solid var(--border);
    padding: 4px 11px; border-radius: 999px; font-size: 12px;
    color: var(--text-dim); font-weight: 600;
    max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.btn-icon {
    background: none; border: 0; color: var(--text-dim); cursor: pointer;
    width: 34px; height: 34px; border-radius: 8px; font-size: 16px;
    display: grid; place-items: center; position: relative;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* ── Notificações ─────────────────────────────────────────────────────────── */
.notif-wrap { position: relative; }
.notif-badge {
    position: absolute; top: 3px; right: 3px; min-width: 15px; height: 15px;
    padding: 0 4px; border-radius: 999px; background: var(--danger); color: #fff;
    font-size: 9.5px; font-weight: 700; display: grid; place-items: center;
}
.notif-panel {
    position: absolute; right: 0; top: calc(100% + 8px); width: 330px; max-height: 380px;
    overflow-y: auto; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); z-index: 40; padding: 6px;
}
.notif-empty { color: var(--text-dim); text-align: center; padding: 22px 0; margin: 0; font-size: 13px; }
.notif-item {
    display: grid; grid-template-columns: 20px 1fr; gap: 4px 10px;
    padding: 9px 10px; border-radius: 8px; color: var(--text); text-decoration: none;
}
.notif-item:hover { background: var(--surface-2); text-decoration: none; }
.notif-item i { color: var(--accent); grid-row: span 2; }
.notif-item time { font-size: 11px; color: var(--text-dim); }

/* ── Conteúdo ─────────────────────────────────────────────────────────────── */
.content { padding: 22px; flex: 1; }

.card-s {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card-s + .card-s { margin-top: 16px; }

.stat-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px; margin-bottom: 18px;
}
.stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.stat-label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; }

/* Tabelas: nunca deixar a página fazer scroll horizontal */
.table-wrap { overflow-x: auto; }
.table-s { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table-s th {
    text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
    color: var(--text-dim); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
}
.table-s td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
.table-s tr:last-child td { border-bottom: 0; }
.table-s tbody tr:hover { background: var(--surface-2); }

.badge-s {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 11px; font-weight: 700;
    background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border);
}
.badge-ok     { background: rgba(22, 163, 74, .12);  color: var(--ok);     border-color: transparent; }
.badge-warn   { background: rgba(217, 119, 6, .12);  color: var(--warn);   border-color: transparent; }
.badge-danger { background: rgba(220, 38, 38, .12);  color: var(--danger); border-color: transparent; }

/* ── Páginas de autenticação ──────────────────────────────────────────────── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow); padding: 30px;
}
.auth-brand { text-align: center; font-weight: 800; letter-spacing: 3px; font-size: 19px; margin-bottom: 6px; }
.auth-sub { text-align: center; color: var(--text-dim); margin-bottom: 22px; font-size: 13px; }

.form-label { font-size: 12.5px; font-weight: 600; margin-bottom: 5px; display: block; }
.form-control, .form-select {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border);
    border-radius: 8px; background: var(--surface); color: var(--text); font-size: 14px;
}
.form-control:focus, .form-select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
.form-group { margin-bottom: 14px; }

.btn-primary-s {
    width: 100%; padding: 10px; border: 0; border-radius: 8px;
    background: var(--brand); color: var(--brand-ink);
    font-weight: 700; font-size: 14px; cursor: pointer;
}
.btn-primary-s:hover { opacity: .9; }
.btn-s {
    padding: 7px 14px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface); color: var(--text); font-size: 13px;
    font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn-s:hover { background: var(--surface-2); text-decoration: none; }
.btn-danger-s { border-color: transparent; background: var(--danger); color: #fff; }

/* ── Responsivo ───────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed; z-index: 1040; left: 0; top: 0;
        transform: translateX(-100%); transition: transform .2s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 16px; }
    .topbar-title { font-size: 15px; }
    .tenant-pill { display: none; }
}
