/* ============================================================
   MXM Layout Spec (Sakai + identidade MXM) — design system
   ============================================================ */
:root {
  /* Azuis */
  --black-blue: #000C17;
  --mxm-blue: #092947;
  --primary: #03629C;       /* MXM Blue WM — cor primária */
  --primary-1: #234B74;
  --menu-active: #E7EBFF;    /* MXM Blue -2 */
  --menu-hover: #E2E9ED;     /* MXM Blue -3 */
  /* Cinzas */
  --gray-3: #6A6C72;         /* texto tabela/labels/menu */
  --gray-2: #8C9AA9;         /* secundário/headers */
  --gray-1: #A5A8B0;
  --gray:   #DFDFDF;         /* bordas input/sidebar */
  --gray-m1:#F0EFED;         /* bordas card/separador tabela */
  --page-bg:#F5F5F5;
  --surface:#FFFFFF;
  /* Status */
  --info:#1184E1; --warning:#FFC107; --success:#09AB02; --error:#E70B0B; --orange:#F14B38;
  /* Tokens */
  --topbar-bg: var(--mxm-blue);
  --text-title: var(--black-blue);
  --text: var(--gray-3);
  --text-2: var(--gray-2);
  --card-border: var(--gray-m1);
  --input-border: var(--gray);
  --sidebar-bg: var(--surface);
  --sidebar-border: var(--gray);
  --row-hover: var(--page-bg);
  --topbar-h: 64px;
  --sidebar-w: 256px;
}

/* Dark mode */
body.dark {
  --page-bg: #1e1e2e;
  --surface: #181825;
  --topbar-bg: #11111b;
  --card-border: #313244;
  --input-border: #45475a;
  --sidebar-bg: #181825;
  --sidebar-border: #313244;
  --menu-active: rgba(3,98,156,.30);
  --menu-hover: #313244;
  --text-title: #cdd6f4;
  --text: #bac2de;
  --text-2: #9399b2;
  --gray-m1: #313244;
  --row-hover: #1e1e2e;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Poppins, system-ui, -apple-system, sans-serif;
  background: var(--page-bg); color: var(--text); font-size: 14px;
  padding-top: var(--topbar-h);
}

/* ---------- Topbar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 40;
  background: var(--topbar-bg); display: flex; align-items: center; gap: 14px; padding: 0 18px;
  box-shadow: 0 2px 8px rgba(0,12,23,.15);
}
.topbar-logo { color: #fff; font-size: 19px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.logo-badge { background: rgba(255,255,255,.12); color: #fff; font-weight: 700; letter-spacing: 1px; padding: 5px 9px; border-radius: 8px; font-size: 15px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar .user { color: rgba(255,255,255,.85); font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: none; background: transparent; color: rgba(255,255,255,.85); cursor: pointer; font-size: 16px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: rgba(255,255,255,.12); }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--sidebar-w); z-index: 30;
  background: var(--sidebar-bg); border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column; transition: transform .25s;
}
.menu { padding: 8px 0 12px; overflow-y: auto; flex: 1; }
.menu-group { display: block; color: var(--primary); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 24px 24px 8px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 24px; color: var(--gray-3);
  cursor: pointer; font-size: 14px; font-weight: 500; text-decoration: none;
  border-left: 3px solid transparent;
}
.menu-item i { width: 18px; text-align: center; color: var(--gray-2); }
.menu-item:hover { background: var(--menu-hover); }
.menu-item.active { background: var(--menu-active); color: var(--primary); font-weight: 600; border-left-color: var(--primary); }
.menu-item.active i { color: var(--primary); }

/* Skills > módulos > habilidades */
.skills-menu { display: flex; flex-direction: column; }
.skill-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 24px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--text); text-decoration: none; border-left: 3px solid transparent; }
.skill-head:hover { background: var(--menu-hover); }
.skill-head i { width: 18px; text-align: center; color: var(--gray-2); transition: transform .15s; }
.skill-head.open { color: var(--primary); }
.skill-head.open i { color: var(--primary); }
.skill-count { font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--menu-hover); border-radius: 10px; padding: 1px 8px; min-width: 18px; text-align: center; }
.skill-panel { display: flex; flex-direction: column; padding-bottom: 4px; }
.skill-modulo { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); padding: 8px 24px 2px 30px; font-weight: 600; }
.skill-hab { display: flex; align-items: center; gap: 6px; padding: 7px 24px 7px 36px; font-size: 13px; color: var(--text); text-decoration: none; cursor: pointer; border-left: 3px solid transparent; }
.skill-hab i { width: 14px; text-align: center; color: var(--gray-2); font-size: 12px; }
.skill-hab:hover { background: var(--menu-hover); border-left-color: var(--primary); color: var(--primary); }
.skill-hab:hover i { color: var(--primary); }
.skill-empty { font-size: 12px; color: var(--text-2); font-style: italic; padding: 4px 24px 8px 30px; }
.sidebar-foot { padding: 12px 24px; border-top: 1px solid var(--card-border); }
.status { display: inline-flex; align-items: center; gap: 7px; color: var(--text-2); font-size: 12px; }
.status i { font-size: 8px; color: var(--success); }
.status.warn i { color: var(--warning); }

/* ---------- Content ---------- */
.content { margin-left: var(--sidebar-w); padding: 2rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 1.25rem; }
.page-title { font-size: 24px; font-weight: 600; color: var(--text-title); margin: 0; }
.mask { display: none; position: fixed; inset: 0; background: rgba(0,12,23,.45); z-index: 25; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--card-border); border-radius: 10px; box-shadow: 0 1px 4px rgba(0,12,23,.06); padding: 20px; margin-bottom: 20px; }
.form-label { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 10px; }
.form-label i { color: var(--primary); }

/* ---------- Inputs ---------- */
.ask textarea {
  width: 100%; background: var(--surface); color: var(--text); font-family: inherit; font-size: 14px;
  border: 1px solid var(--input-border); border-radius: 6px; padding: 10px 14px; resize: vertical;
}
.ask textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(3,98,156,.15); }
.ask-bar { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; }
.chip { background: transparent; border: 1px solid var(--input-border); color: var(--text-2); padding: 5px 12px; border-radius: 20px; cursor: pointer; font-size: 12px; }
.chip:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Buttons (pill) ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 22px; border-radius: 35px; border: 1px solid transparent; background: var(--surface); color: var(--text); font-family: inherit; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap; flex-shrink: 0; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(3,98,156,.2); }
.btn-primary:hover { box-shadow: 0 4px 12px rgba(3,98,156,.3); }
.btn-primary:disabled { opacity: .55; cursor: progress; box-shadow: none; }
.btn-outline { background: transparent; border-color: var(--primary); color: var(--primary); }
.btn-icon-outline { width: 40px; height: 40px; padding: 0; border-radius: 50%; border: 1px solid var(--input-border); background: var(--surface); color: var(--primary); }
.btn-icon-outline:hover { border-color: var(--primary); }
.btn-icon-outline.mic.listening { background: var(--error); border-color: var(--error); color: #fff; animation: micpulse 1.1s infinite; }
#speaker.muted { opacity: .45; }
#speaker.muted:hover { opacity: .7; }
.btn.disabled, .btn:disabled.mic { opacity: .4; cursor: not-allowed; }
@keyframes micpulse { 0% { box-shadow: 0 0 0 0 rgba(231,11,11,.5); } 70% { box-shadow: 0 0 0 9px rgba(231,11,11,0); } 100% { box-shadow: 0 0 0 0 rgba(231,11,11,0); } }

/* ---------- Result ---------- */
.hidden { display: none !important; }
.loading { color: var(--text-2); padding: 28px; text-align: center; }
.result-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.result-head h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; color: var(--text-title); }
.muted { color: var(--text-2); margin: 0; }

.chart-box { background: var(--surface); border: 1px solid var(--card-border); border-radius: 10px; padding: 16px; margin-bottom: 18px; height: 360px; position: relative; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Consulta: chat (esquerda) + resultado (direita) ---------- */
.consulta-layout { display: flex; gap: 20px; align-items: stretch; height: calc(100vh - var(--topbar-h) - 4rem); }
.chat-panel { width: 560px; flex-shrink: 0; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.chat-history { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-empty { color: var(--text-2); font-size: 13px; text-align: center; margin: auto; max-width: 280px; }
.msg { max-width: 92%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--page-bg); border: 1px solid var(--card-border); color: var(--text); border-bottom-left-radius: 4px; }
.msg.bot.err { border-color: var(--error); color: var(--error); }
.msg-suggest { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.msg-suggest button { background: none; border: none; color: var(--primary); text-align: left; cursor: pointer; font-size: 13px; padding: 2px 0; font-family: inherit; }
.msg-suggest button:hover { text-decoration: underline; }
.confirm-box { display: flex; gap: 8px; margin-top: 10px; }
.confirm-box .btn { height: 34px; padding: 0 16px; }
.chat-input { border-top: 1px solid var(--card-border); padding: 12px; }
.chat-input .chips { margin-bottom: 8px; }
.chat-input textarea { width: 100%; min-height: 96px; background: var(--surface); color: var(--text); border: 1px solid var(--input-border); border-radius: 6px; padding: 12px 14px; font-family: inherit; font-size: 15px; resize: vertical; }
.msg.user { cursor: pointer; }
.msg.user:hover { filter: brightness(1.08); }
.chat-input textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(3,98,156,.15); }
.chat-actions { display: flex; gap: 8px; margin-top: 10px; align-items: center; }
.chat-actions #go { margin-left: auto; }

.result-panel { flex: 1; min-width: 0; overflow-y: auto; }
.result-empty, .result-exec { height: 100%; min-height: 320px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-2); text-align: center; }
.result-empty i { font-size: 34px; opacity: .5; }
.result-exec .pi-spin { font-size: 30px; color: var(--primary); }

@media (max-width: 900px) {
  .consulta-layout { flex-direction: column; height: auto; }
  .chat-panel { width: 100%; height: 360px; }
}

/* KPI */
.kpis { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 18px; }
.kpi { background: var(--surface); border: 1px solid var(--card-border); border-radius: 10px; box-shadow: 0 1px 4px rgba(0,12,23,.06); padding: 20px 26px; min-width: 170px; text-align: center; }
.kpi-val { font-size: 32px; font-weight: 700; color: var(--primary); }
.kpi-label { color: var(--text-2); font-size: 12px; font-weight: 500; margin-top: 4px; }
.kpi.percent { min-width: 220px; }
.pct-bar { height: 8px; background: var(--gray-m1); border-radius: 6px; margin: 12px 0 8px; overflow: hidden; }
.pct-bar > span { display: block; height: 100%; background: var(--primary); border-radius: 6px; }

/* ---------- Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 20px; align-items: start; }
.dash-item { min-width: 0; grid-column: span 6; }
.dash-card { margin-bottom: 0; height: 100%; position: relative; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.dash-title { min-width: 0; }
.dash-title strong { display: block; font-size: 14px; color: var(--text-title); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-actions { display: flex; gap: 4px; flex-shrink: 0; }
.dash-ico { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--input-border); background: var(--surface); color: var(--text-2); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; }
.dash-ico:hover { border-color: var(--primary); color: var(--primary); }
.dash-body .chart-box { margin-bottom: 0; }
.dash-body .kpis, .dash-body .table-wrap { margin-bottom: 0; }
.dash-resize { position: absolute; right: 4px; bottom: 4px; width: 16px; height: 16px; cursor: nwse-resize; color: var(--text-2); opacity: .45; touch-action: none; }
.dash-resize::after { content: ''; position: absolute; right: 2px; bottom: 2px; width: 9px; height: 9px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; }
.dash-resize:hover { opacity: 1; color: var(--primary); }

/* ---------- Histórico de execução ---------- */
.hist-table .hist-cmd { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-row { cursor: pointer; }
.tag { display: inline-block; border-radius: 20px; font-size: 12px; font-weight: 600; padding: 3px 10px; white-space: nowrap; }
.tag-ok { background: rgba(9,171,2,.12); color: var(--success); }
.tag-inviavel { background: rgba(255,193,7,.18); color: #9a7400; }
.tag-erro { background: rgba(231,11,11,.12); color: var(--error); }
.hist-result { margin-top: 22px; }
@media (max-width: 760px) { .dash-grid { grid-template-columns: 1fr; } .dash-item { grid-column: 1 / -1 !important; } }

/* Tabela */
.table-wrap { overflow: auto; border: 1px solid var(--card-border); border-radius: 10px; max-height: 540px; }
table.data { border-collapse: collapse; width: 100%; }
table.data th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); font-weight: 600; text-align: left; padding: 12px 16px; border-bottom: 2px solid var(--gray-m1); position: sticky; top: 0; z-index: 2; background: var(--surface); white-space: nowrap; box-shadow: 0 2px 0 var(--gray-m1); }
table.data td { font-size: 14px; color: var(--text); padding: 12px 16px; border-bottom: 1px solid var(--gray-m1); white-space: nowrap; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover td { background: var(--row-hover); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; }
.pager .btn { height: 34px; padding: 0 16px; }
.pager-info { color: var(--text-2); font-size: 13px; white-space: nowrap; }

/* SQL */
.sqlbox { margin-top: 14px; }
.sqlbox summary { cursor: pointer; color: var(--primary); font-weight: 500; }
.sqlbox pre { background: #0b1a2b; color: #cbd5e1; border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12px; white-space: pre-wrap; margin-top: 8px; }
.xml-view { background: #0b1a2b; color: #cbd5e1; border-radius: 10px; padding: 14px 16px; overflow: auto; font-size: 12px; line-height: 1.45; white-space: pre; max-height: 60vh; margin-bottom: 14px; }

/* Tela de consulta (XML amigável) */
.consulta-rec { margin-bottom: 8px; }
.consulta-titulo { font-size: 15px; font-weight: 600; color: var(--text-title); margin: 16px 0 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px 18px; background: var(--surface); border: 1px solid var(--card-border); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px; }
.detail-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-2); font-weight: 600; }
.detail-value { font-size: 14px; color: var(--text); word-break: break-word; }
.consulta-grupo { font-size: 13px; font-weight: 600; color: var(--primary); margin: 14px 0 6px; }

/* Aprovações pendentes */
.aprov-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.aprov-table th.aprov-th { text-align: center; width: 34px; padding-left: 6px; padding-right: 6px; }
.aprov-table td.aprov-cbcell { text-align: center; width: 34px; padding: 8px 6px; }
.aprov-cb { width: 17px; height: 17px; cursor: pointer; accent-color: var(--primary); }
.aprov-bot { width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer; background: var(--primary); display: inline-flex; align-items: center; justify-content: center; box-shadow: 0 1px 4px rgba(3,98,156,.35); }
.aprov-bot:hover { background: var(--topbar-bg, #092947); }
.aprov-bot-badge { color: #fff; font-size: 9px; font-weight: 800; letter-spacing: .02em; }

/* Avisos / sugestões */
.notice { background: var(--surface); border: 1px solid var(--card-border); border-left: 3px solid var(--primary); border-radius: 10px; padding: 18px 20px; }
.notice.err { border-left-color: var(--error); }
.notice.aviso { border-left-color: var(--warning); margin-bottom: 16px; padding: 12px 16px; }
.notice.sucesso { border-left-color: var(--success); }
.notice.sucesso p { display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600; color: var(--success); margin: 0; }
.notice.sucesso i { font-size: 22px; }
.notice h2 { margin: 0 0 8px; font-size: 17px; font-weight: 600; color: var(--text-title); }
.suggest { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 4px; }
.link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 14px; padding: 4px 0; text-align: left; font-family: inherit; }
.link:hover { text-decoration: underline; }

/* ---------- Responsivo ---------- */
@media (max-width: 992px) {
  .sidebar { transform: translateX(-100%); }
  .content { margin-left: 0; }
  .layout.sidebar-open .sidebar { transform: translateX(0); }
  .layout.sidebar-open .mask { display: block; }
}
@media (max-width: 768px) {
  .content { padding: 1rem; }
  .page-head { flex-direction: column; align-items: stretch; }
  .ask-bar { flex-wrap: wrap; }
  .btn-primary { flex: 1; }
}
