/* Sistema de Gestão de TI — estilos */
:root {
  --bg: #f3f5f9; --surface: #fff; --surface-2: #f8fafc; --border: #e2e8f0; --border-strong: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --muted: #64748b;
  --primary: #1d4ed8; --primary-600: #1e40af; --primary-50: #eff6ff;
  --side: #0b1b36; --side-2: #12284d; --side-text: #c7d2fe; --side-muted: #8ea2c8;
  --ok: #15803d; --ok-bg: #dcfce7; --warn: #a16207; --warn-bg: #fef9c3;
  --err: #b91c1c; --err-bg: #fee2e2; --info: #1d4ed8; --info-bg: #dbeafe; --gray-bg: #e2e8f0;
  --radius: 10px; --shadow: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; } a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, transparent 60%), linear-gradient(160deg, #0b1b36, #102a52); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-card .brand { display: flex; gap: 12px; align-items: center; margin-bottom: 22px; }
.login-card .brand .logo { width: 44px; height: 44px; }
.login-card h1 { font-size: 19px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; }
.sidebar .brand small { display: block; font-weight: 400; color: var(--side-muted); font-size: 11.5px; }
.sidebar .logo { width: 34px; height: 34px; flex: none; }
.nav { padding: 6px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--side-muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); text-decoration: none; }
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 22px; position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-chip .who { line-height: 1.2; text-align: right; }
.user-chip .who b { display: block; font-size: 13px; } .user-chip .who span { font-size: 11.5px; color: var(--muted); }
.content { padding: 22px; max-width: 1400px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.backdrop { display: none; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 18px; } .card-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.accent { border-left: 4px solid var(--primary); }
.charts { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); margin-top: 16px; }
.two-col { grid-template-columns: 1fr 1fr; }
.three-col { grid-template-columns: repeat(3, 1fr); }

/* ---------- Bar chart ---------- */
.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 150px) 1fr 44px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { display: block; height: 14px; background: var(--surface-2); border-radius: 4px; position: relative; }
.bar-fill { display: block; height: 100%; background: #2a5bd7; border-radius: 0 4px 4px 0; min-width: 2px; transition: width .3s; }
.bar-row:hover .bar-fill { background: #1e40af; }
.bar-row .val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; } .btn.primary:hover { background: var(--primary-600); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; }
.icon-btn { width: 32px; height: 32px; padding: 0; justify-content: center; }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-top: 6px; font-size: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field label .req { color: var(--err); }
.input, select.input, textarea.input { width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; outline: none; }
textarea.input { height: auto; min-height: 80px; padding: 9px 11px; resize: vertical; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.15); }
.field.invalid .input { border-color: var(--err); }
.field .err-msg { color: var(--err); font-size: 12px; margin-top: 4px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- Toolbar / table ---------- */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.toolbar .search { flex: 1 1 240px; position: relative; }
.toolbar .search input { padding-left: 34px; }
.toolbar .search svg { position: absolute; left: 10px; top: 10px; width: 17px; height: 17px; color: var(--muted); }
.toolbar select.input { width: auto; min-width: 150px; max-width: 220px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); font-weight: 600; white-space: nowrap; }
table.data th.sortable { cursor: pointer; user-select: none; } table.data th.sortable:hover { color: var(--text); }
table.data tbody tr:hover { background: #f8fafc; }
table.data td.actions { text-align: right; white-space: nowrap; width: 1%; }
table.data tr.clickable { cursor: pointer; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.pager .pg { display: flex; gap: 6px; align-items: center; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); } .badge.info { background: var(--info-bg); color: var(--info); }
.badge.gray { background: var(--gray-bg); color: #334155; }

/* ---------- Detail ---------- */
.dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; margin: 0; }
.dl div { min-width: 0; } .dl dt { font-size: 12px; color: var(--muted); } .dl dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--primary); }
.timeline li:last-child { border-left-color: transparent; }
.timeline .t-head { font-weight: 600; } .timeline .t-meta { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); padding: 0 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 12px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; font-weight: 500; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Permission matrix ---------- */
.matrix th, .matrix td { text-align: center !important; }
.matrix td:first-child, .matrix th:first-child { text-align: left !important; }
.perm-cell { display: inline-flex; gap: 4px; }
.tri { border: 1px solid var(--border-strong); background: #fff; border-radius: 6px; height: 28px; min-width: 84px; padding: 0 8px; cursor: pointer; font-size: 12px; font-weight: 600; }
.tri.inherit-on { color: var(--ok); } .tri.inherit-off { color: var(--muted); }
.tri.allow { background: var(--ok-bg); border-color: #86efac; color: var(--ok); }
.tri.deny { background: var(--err-bg); border-color: #fca5a5; color: var(--err); }
.tri:disabled { cursor: not-allowed; opacity: .6; }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fade .12s; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 760px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.modal.sm { max-width: 440px; } .modal.lg { max-width: 980px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade { from { opacity: 0; } }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; max-width: calc(100vw - 32px); }
.toast { background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.25); min-width: 240px; max-width: 420px; border-left: 4px solid #60a5fa; animation: fade .15s; }
.toast.ok { border-left-color: #4ade80; } .toast.err { border-left-color: #f87171; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert.err { background: var(--err-bg); color: var(--err); } .alert.info { background: var(--info-bg); color: var(--info); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) { .dl { grid-template-columns: repeat(2, 1fr); } .three-col { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 50; }
  .menu-btn { display: inline-flex; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .content { padding: 14px; } .topbar { padding: 0 12px; }
  .form-grid, .dl, .three-col { grid-template-columns: 1fr; }
  .user-chip .who { display: none; }
  .kpi .value { font-size: 24px; } .kpis { grid-template-columns: 1fr 1fr; }
  .toolbar select.input { flex: 1 1 140px; max-width: none; }
  .charts { grid-template-columns: 1fr; }
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.data.stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 14px; text-align: right; }
  table.data.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  table.data.stack td.actions { justify-content: flex-end; width: auto; }
  table.data.stack td.actions::before { content: none; }
  .modal-body { padding: 16px; }
}
.bar-fill[data-w="0.0"] { min-width: 0; }
