:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-light: #14b8a6;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #dc2626;
  --blue: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15,23,42,.08), 0 1px 2px rgba(15,23,42,.06);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.15);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ============ Login ============ */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #0f172a 0%, #0f766e 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 18px; padding: 40px 36px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.login-logo { display: flex; gap: 14px; align-items: center; margin-bottom: 26px; }
.login-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 18px; }
.login-logo h1 { font-size: 20px; letter-spacing: .5px; }
.login-logo p { color: var(--muted); font-size: 12px; }
.login-card label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 14px 0 6px; }
.login-card input { width: 100%; }
.login-hint { margin-top: 18px; padding: 12px; border-radius: 10px; background: #f1f5f9; border: 1px dashed #cbd5e1; color: var(--muted); font-size: 12.5px; text-align: center; }
.login-hint b { color: var(--primary); }

/* ============ Layout ============ */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 260px; background: var(--sidebar); color: #cbd5e1; display: flex; flex-direction: column; flex-shrink: 0; transition: margin-left .25s; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-mark { width: 40px; height: 40px; border-radius: 10px; background: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; font-size: 14px; }
.sidebar-brand b { display: block; font-size: 15px; color: #fff; }
.sidebar-brand small { font-size: 10px; color: #94a3b8; }
#sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-group { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #64748b; padding: 16px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #cbd5e1; cursor: pointer; font-size: 13px; margin-bottom: 2px; transition: background .15s; }
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item .nav-ico { width: 20px; text-align: center; }
.nav-badge { margin-left: auto; font-size: 10px; background: var(--red); color: #fff; border-radius: 20px; padding: 1px 7px; }
.sidebar-footer { padding: 14px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-light); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.user-meta { flex: 1; min-width: 0; }
.user-meta b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: #94a3b8; font-size: 11px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 22px; gap: 14px; }
.topbar-title h2 { font-size: 17px; }
.topbar-title small { color: var(--muted); }
.topbar-actions { margin-left: auto; position: relative; display: flex; align-items: center; gap: 8px; }
.company-badge { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; color: var(--primary); background: var(--primary-soft, #eef2ff); border: 1px solid var(--border); border-radius: 20px; padding: 4px 12px; }
#page { flex: 1; overflow-y: auto; padding: 24px; }
.menu-btn { display: none; }

@media (max-width: 900px) {
  .sidebar { margin-left: -260px; position: fixed; z-index: 40; height: 100vh; box-shadow: var(--shadow-lg); }
  .sidebar.open { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  #page { padding: 14px; }
}

/* ============ Componentes ============ */
input, select, textarea { font-family: inherit; font-size: 13px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); outline: none; transition: border-color .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }
textarea { resize: vertical; min-height: 60px; }

.btn { display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 15px; border-radius: 8px; font-size: 13px; font-weight: 600; transition: all .15s; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-danger { color: var(--red); border-color: #fecaca; }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }

.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; color: var(--muted); position: relative; }
.icon-btn:hover { background: var(--bg); color: var(--text); }
.badge-dot { position: absolute; top: -4px; right: -4px; background: var(--red); color: #fff; font-size: 9px; border-radius: 20px; padding: 1px 5px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }
.page-head .page-desc { color: var(--muted); margin-top: 2px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-title { font-size: 13px; font-weight: 700; color: var(--text); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.card-title .spacer { flex: 1; }
.card-title small { font-weight: 400; color: var(--muted); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat-card .stat-icon { position: absolute; right: 14px; top: 14px; width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 17px; }
.stat-card .stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-card .stat-sub { color: var(--muted); font-size: 11px; margin-top: 4px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-teal { background: #ccfbf1; color: #115e59; }
.badge-purple { background: #ede9fe; color: #5b21b6; }

.semaforo { display: inline-flex; gap: 3px; }
.semaforo i { width: 22px; height: 22px; border-radius: 50%; display: inline-block; }
.semaforo .green { background: var(--green); box-shadow: 0 0 0 4px rgba(22,163,74,.18); }
.semaforo .yellow { background: var(--yellow); }
.semaforo .red { background: var(--red); }
.semaforo .off { background: #e2e8f0; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th { text-align: left; padding: 10px 12px; background: #f8fafc; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tbl tr:hover td { background: #f8fafc; }
.table-wrap { overflow-x: auto; }
.row-link { color: var(--primary); font-weight: 600; cursor: pointer; }
.row-link:hover { text-decoration: underline; }

.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #f8fafc; border-radius: var(--radius) var(--radius) 0 0; }
.filter-bar select, .filter-bar input { background: #fff; }
.filter-bar .spacer { flex: 1; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .empty-ico { font-size: 34px; margin-bottom: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.form-field label .req { color: var(--red); }
.form-field input, .form-field select, .form-field textarea { width: 100%; }
.form-field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.modal-mask { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 60; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px 16px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 720px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal-lg { max-width: 980px; }
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 16px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
@keyframes pop { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast { position: fixed; bottom: 22px; right: 22px; z-index: 90; background: var(--text); color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: 13px; display: flex; align-items: center; gap: 10px; animation: slidein .2s ease; max-width: 360px; }
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert-red { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-green { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-yellow { background: #fef9c3; color: #854d0e; border: 1px solid #fde047; }

/* ============ Kanban ============ */
.kanban { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kanban-col { background: #e2e8f0; border-radius: 12px; min-width: 250px; width: 250px; flex-shrink: 0; }
.kanban-col-head { padding: 10px 14px; font-weight: 700; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kanban-col-head .count { background: #fff; border-radius: 20px; padding: 1px 8px; font-size: 11px; color: var(--muted); }
.kanban-list { padding: 4px 8px 10px; min-height: 80px; }
.kanban-card { background: #fff; border-radius: 10px; padding: 12px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; border-left: 4px solid var(--border); transition: box-shadow .15s; }
.kanban-card:hover { box-shadow: var(--shadow-lg); }
.kanban-card .kb-title { font-weight: 600; font-size: 12.5px; margin-bottom: 6px; }
.kanban-card .kb-meta { display: flex; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.kanban-card.p-alta { border-left-color: var(--red); }
.kanban-card.p-media { border-left-color: var(--yellow); }
.kanban-card.p-baixa { border-left-color: var(--green); }
.kanban-card.late { background: #fef2f2; }

/* ============ ISO map ============ */
.iso-tree { padding: 4px 0; }
.iso-node { border-left: 3px solid var(--border); padding: 10px 14px; margin: 8px 0 8px 10px; border-radius: 0 10px 10px 0; background: #fff; box-shadow: var(--shadow); cursor: pointer; transition: border-color .15s; }
.iso-node:hover { border-left-color: var(--primary); }
.iso-node.row-0 { margin-left: 0; border-left-width: 5px; border-left-color: var(--primary); }
.iso-node .iso-code { font-weight: 800; color: var(--primary); font-size: 13px; }
.iso-node .iso-title { font-weight: 600; }
.iso-node .iso-text { color: var(--muted); font-size: 12px; margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ============ Matriz risco / SWOT ============ */
.risk-matrix { display: grid; grid-template-columns: 70px repeat(5, 1fr); gap: 4px; max-width: 560px; }
.risk-matrix .rm-head { font-size: 11px; color: var(--muted); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.risk-matrix .rm-cell { border-radius: 8px; min-height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: #fff; padding: 4px; text-align: center; cursor: pointer; }
.risk-matrix .rm-cell:hover { filter: brightness(1.1); }
.swot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.swot-box { border-radius: 12px; padding: 14px; min-height: 120px; }
.swot-box h4 { font-size: 13px; margin-bottom: 8px; }
.swot-item { background: rgba(255,255,255,.7); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; font-size: 12.5px; }

/* ============ Calendário ============ */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day { border: 1px solid var(--border); border-radius: 8px; min-height: 78px; padding: 4px 6px; font-size: 11px; background: #fff; }
.cal-day.today { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(15,118,110,.2); }
.cal-day .cal-num { font-weight: 700; }
.cal-day .cal-event { margin-top: 3px; padding: 2px 5px; border-radius: 4px; font-size: 9.5px; color: #fff; cursor: pointer; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ============ Timeline / workflow ============ */
.flow-step { display: flex; align-items: center; gap: 10px; padding: 10px 0; }
.flow-step .dot { width: 30px; height: 30px; border-radius: 50%; background: #e2e8f0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--muted); flex-shrink: 0; }
.flow-step.active .dot { background: var(--primary); color: #fff; }
.flow-step.done .dot { background: var(--green); color: #fff; }
.flow-step .flow-label { font-weight: 600; font-size: 13px; }
.flow-step.active .flow-label { color: var(--primary); }

/* ============ Detalhe / tabs ============ */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab { padding: 9px 16px; font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.kv { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.kv .kv-label { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.kv .kv-value { font-size: 13.5px; font-weight: 600; margin-top: 3px; white-space: pre-wrap; word-break: break-word; }

/* ============ Chat IA ============ */
.chat-box { display: flex; flex-direction: column; height: calc(100vh - 200px); max-height: 640px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; background: #f8fafc; }
.chat-msg { max-width: 80%; padding: 11px 14px; border-radius: 12px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; }
.quick-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 14px 12px; }
.chip { background: #e2e8f0; border-radius: 20px; padding: 5px 12px; font-size: 11.5px; font-weight: 600; cursor: pointer; }
.chip:hover { background: var(--primary); color: #fff; }

/* ============ Progresso ============ */
.progress { height: 8px; background: #e2e8f0; border-radius: 20px; overflow: hidden; }
.progress .bar { height: 100%; border-radius: 20px; transition: width .4s; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }

/* ============ Notificação ============ */
.notif-panel { position: absolute; right: 0; top: 46px; width: 340px; background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); z-index: 50; max-height: 480px; overflow-y: auto; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 12.5px; cursor: pointer; }
.notif-item:hover { background: #f8fafc; }
.notif-item b { display: block; margin-bottom: 2px; }
.notif-item small { color: var(--muted); }

/* Barra impressão / util */
.print-only { display: none; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.text-muted { color: var(--muted); } .text-red { color: var(--red); } .text-green { color: var(--green); } .text-yellow { color: var(--yellow); }
.flex { display: flex; } .items-center { align-items: center; } .gap { gap: 10px; } .wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
canvas.chart { max-width: 100%; }

/* ============ Treinamento / Guia ============ */
.guide { padding: 20px; }
.guide-sec { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; overflow: hidden; background: #fff; }
.guide-sec summary { list-style: none; cursor: pointer; padding: 14px 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; background: var(--surface); }
.guide-sec summary::-webkit-details-marker { display: none; }
.guide-sec[open] summary { border-bottom: 1px solid var(--border); }
.guide-num { display: inline-flex; width: 26px; height: 26px; border-radius: 50%; background: var(--primary, #0f766e); color: #fff; font-size: 13px; align-items: center; justify-content: center; flex-shrink: 0; }
.guide-body { padding: 16px 20px; font-size: 13.5px; line-height: 1.7; color: var(--text); }
.guide-body p { margin: 0 0 10px; }
.guide-body b { color: var(--text); }
.guide-body code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; }
.guide-body .tbl { margin: 10px 0 14px; }
.guide-flow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; padding: 12px 16px; border-radius: 10px; font-weight: 700; margin: 10px 0 14px; }

/* ============ IA Auditora ISO 9001 ============ */
.page-head-sm { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.page-head-sm .page-desc { color: var(--muted); font-size: 13px; }
.ai-alert { border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 13px; background: #fff; }
.ai-alert-red { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.ai-alert-yellow { border-color: #fde68a; background: #fffbeb; color: #92400e; }
.ai-alert-green { border-color: #a7f3d0; background: #ecfdf5; color: #065f46; }
.ai-iso { display: inline-block; background: #e0f2fe; color: #075985; border-radius: 6px; padding: 2px 8px; margin: 2px; font-size: 11.5px; font-weight: 700; cursor: pointer; border: 1px solid #bae6fd; }
.ai-iso:hover { background: #bae6fd; }
.ai-item { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin: 12px; background: #fff; }
.ai-item-head { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-bottom: 8px; flex-wrap: wrap; }
.ai-item-row { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.ai-just { white-space: pre-wrap; background: #f8fafc; padding: 8px 10px; border-radius: 6px; color: var(--text); }
.ai-nc { border-left: 3px solid var(--red); background: #fef2f2; border-radius: 0 8px 8px 0; padding: 10px 14px; margin: 10px 16px; font-size: 12.5px; }
.chat-box { height: auto; display: flex; flex-direction: column; }
