/* Tokens de UX do zzportal (coezzion) — ver .zcode/skills/zzportal-ui/resources/zzportal-tokens.md */
:root {
  --bg: #f4f5f7;
  --paper: #ffffff;
  --ink: #2a2e36;
  --muted: #6b7280;
  --text: #42464d;
  --line: #e4e6ea;
  --field: #d5d8de;
  --primary: #3859ff;
  --primary-soft: #eef1ff;
  --success: #1b7a45;
  --success-soft: #e7f6ee;
  --attention: #8a5a00;
  --attention-soft: #fff4d6;
  --danger: #c24132;
  --danger-soft: #fdeeee;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 8px;
  --radius-lg: 12px;
  --mono: 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Montserrat', 'Segoe UI', sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: var(--radius); }

/* ---- casco (Layout + Menu + Header do portal) ---- */
.shell {
  display: grid;
  grid-template-columns: 90px 1fr;
  grid-template-areas:
    'menu header'
    'menu main';
  grid-template-rows: auto 1fr;
  gap: 10px;
  height: 100dvh;
  padding: 10px;
}

.menu {
  grid-area: menu;
  background: var(--paper);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 10px 6px;
  gap: 4px;
  overflow-y: auto;
}

.menu-logo {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  text-align: center;
  padding: 8px 0 12px;
  letter-spacing: 0.04em;
}

.menu-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: 0;
  background: transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}
.menu-item svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.menu-item:hover { background: var(--bg); }
.menu-item.active { background: var(--bg); color: var(--primary); font-weight: 600; }

.header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0 10px;
  min-height: 52px;
}
.header h1 { margin: 0; font-size: 16px; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 8px; }

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 2px 10px 10px 2px;
}

/* ---- componentes ---- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
}

.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grid { display: grid; gap: 10px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.grid-metrics { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }

.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
}
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #2c47d9; }
.btn-secondary { background: #fff; border-color: var(--primary); color: var(--primary); }
.btn-secondary:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  border-radius: 500px;
  padding: 2px 10px;
  background: var(--bg);
  color: var(--muted);
}
.chip-ok { background: var(--success-soft); color: var(--success); }
.chip-warn { background: var(--attention-soft); color: var(--attention); }
.chip-err { background: var(--danger-soft); color: var(--danger); }
.chip-info { background: var(--primary-soft); color: var(--primary); }
.chip-btn { border: 0; font-family: inherit; cursor: pointer; }
.chip-btn:hover { filter: brightness(0.95); }

.metric .metric-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.metric .metric-value { font-size: 14px; font-weight: 600; color: var(--ink); margin-top: 2px; }
.metric .metric-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

label.field-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}

.field, select.field, textarea.field {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--field);
  border-radius: var(--radius);
  padding: 8px 12px;
}
.field:focus { outline: 2px solid #d6defe; border-color: var(--primary); }
textarea.field { resize: vertical; min-height: 70px; font-family: var(--mono); font-size: 12px; }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text); cursor: pointer; }
.check input { accent-color: var(--primary); }

.table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table th {
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}
.table td { padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.table tr:last-child td { border-bottom: 0; }

.codeblock {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  padding: 10px 12px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.clickable { cursor: pointer; }
.clickable:hover { color: var(--primary); }

/* ---- views ---- */
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 10px; flex-wrap: wrap; }
.view-head h2 { margin: 0; font-size: 14px; font-weight: 600; }

.log-panel {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  padding: 10px 12px;
  height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-line-err { color: var(--danger); }
.log-line-sys { color: var(--muted); font-style: italic; }

.subtabs { display: flex; gap: 6px; margin-bottom: 10px; }
.subtab {
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 6px 14px; border-radius: 500px; border: 1px solid var(--line);
  background: var(--paper); color: var(--text); cursor: pointer;
}
.subtab.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.split { display: grid; grid-template-columns: 400px 1fr; gap: 10px; align-items: start; }
.result-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); cursor: pointer; }
.result-item:hover { border-color: var(--primary); }
.result-item.active { border-color: var(--primary); background: var(--primary-soft); }
.result-item mark { background: var(--attention-soft); color: var(--attention); padding: 0 1px; border-radius: 2px; }

.md-body { line-height: 1.5; }.md-body h1, .md-body h2, .md-body h3 { font-weight: 600; margin: 14px 0 6px; }
.md-body h1 { font-size: 16px; } .md-body h2 { font-size: 14px; } .md-body h3 { font-size: 13px; }
.md-body p { margin: 6px 0; }
.md-body ul, .md-body ol { margin: 6px 0; padding-left: 20px; }
.md-body code { font-family: var(--mono); font-size: 12px; background: #f7f8fa; border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.md-body pre { background: #f7f8fa; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; overflow-x: auto; }
.md-body pre code { border: 0; background: transparent; padding: 0; }
.md-body a { color: var(--primary); }
.md-body blockquote { margin: 6px 0; padding: 4px 12px; border-left: 3px solid var(--field); color: var(--muted); }
.md-body table { border-collapse: collapse; }
.md-body th, .md-body td { border: 1px solid var(--line); padding: 4px 8px; font-size: 12px; }

/* terminais — janelas flutuantes, arrastáveis e redimensionáveis */
#term-host { display: none; }
.term-pane { height: 100%; width: 100%; }
.term-pane .xterm { padding: 6px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }

.term-window {
  position: fixed;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
  resize: both;              /* grip nativo no canto inferior direito */
  overflow: hidden;
  min-width: 460px;
  min-height: 280px;
  max-width: 98vw;
  max-height: 96vh;
}
.term-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--primary-soft);
  cursor: grab;
  user-select: none;
  flex: 0 0 auto;
}
.term-window-head.dragging { cursor: grabbing; }
.term-window-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.term-window-body { flex: 1 1 auto; min-height: 0; padding: 6px; }
.term-window-body .term-pane { height: 100%; }

/* modal e toast */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(42, 46, 54, 0.4);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--paper); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  width: min(640px, calc(100vw - 40px)); max-height: 80vh; display: flex; flex-direction: column;
  padding: 18px; gap: 12px;
}
.modal h3 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-wide { width: min(980px, calc(100vw - 40px)); }
.card.clickable { cursor: pointer; transition: border-color 0.12s ease-out; }
.card.clickable:hover { border-color: var(--primary); }
.modal-body { overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

#toast-root { position: fixed; bottom: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 500;
  border-radius: var(--radius); padding: 10px 16px; box-shadow: var(--shadow);
  animation: toast-in 0.15s ease-out;
}
.toast-err { background: var(--danger); }
.toast-ok { background: var(--success); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 0; }

/* ---- diff de cópias de skill ---- */
.diff {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 12px;
  max-height: 46vh;
  overflow: auto;
  padding: 6px 0;
}
.diff-line { display: flex; gap: 8px; padding: 0 10px; white-space: pre-wrap; word-break: break-word; }
.diff-line.add { background: var(--success-soft); color: var(--success); }
.diff-line.del { background: var(--danger-soft); color: var(--danger); }
.diff-line.ctx { color: var(--muted); }
.diff-sign { flex: 0 0 10px; user-select: none; }
.diff-num { flex: 0 0 34px; text-align: right; color: var(--muted); user-select: none; }
.diff-text { flex: 1 1 auto; }
.diff-hunk + .diff-hunk { border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 4px; }
.diff-file { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.diff-file.add { color: var(--success); }
.diff-file.del { color: var(--danger); }

/* ---- importar memórias ---- */
.imp-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px;
  background: var(--primary-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.imp-group strong { font-size: 13px; color: var(--primary); }
.imp-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.imp-item:hover { border-color: var(--primary); }
.imp-actions {
  position: sticky;
  bottom: 8px;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: var(--paper);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-areas: 'menu' 'main';
    grid-template-rows: auto 1fr;
  }
  .header { display: none; }
  .menu { flex-direction: row; justify-content: space-around; }
  .menu-logo { display: none; }
  .menu-item span { display: none; }
  .split { grid-template-columns: 1fr; }
}

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: nowrap; }
.pager-pages { display: flex; gap: 4px; align-items: center; }
select.field.field-sm, .field.field-sm { width: auto; padding: 5px 28px 5px 10px; height: auto; line-height: 1.3; flex-shrink: 0; }
.pager label { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; flex-shrink: 0; }
.pager > span { flex-shrink: 0; }
.pager-top { margin: 0 0 8px; }
