/* Moodle Connector dashboard — modern dark theme, fully offline (no CDNs). */

:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1c2330;
  --bg-input: #0b0e13;
  --border: #2a313c;
  --border-strong: #3a434f;
  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --muted: #6e7b89;
  --accent: #4c8dff;
  --accent-press: #3b74e0;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --approve: #d11d2c;
  --approve-press: #a6131f;
  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
}

#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
}
.brand-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7aa7ff);
  box-shadow: 0 0 12px rgba(76, 141, 255, 0.5);
  flex: none;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 14px; }
.brand-text small { color: var(--muted); font-size: 11px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  text-align: left;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13.5px;
  font-family: inherit;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-elev-2); color: var(--text); }
.nav-item.active {
  background: var(--bg-elev-2);
  color: var(--text);
  border-color: var(--border-strong);
}
.nav-ico {
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 5px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  flex: none;
}
.nav-item.active .nav-ico { color: var(--accent); border-color: var(--accent); }

.sidebar-foot {
  display: flex; flex-direction: column; gap: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.sidebar-foot .muted { font-size: 11px; }

/* ── Content ─────────────────────────────────────────────── */
.content { padding: 26px 30px 60px; max-width: 1100px; width: 100%; }
.page { display: none; animation: fade 0.15s ease; }
.page.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head .muted { margin: 0; }

.muted { color: var(--muted); }
.hidden { display: none !important; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; }
.card h3 { margin: 18px 0 10px; font-size: 14px; color: var(--text-dim); }
.card-danger { border-color: rgba(248, 81, 73, 0.35); }
.card-head-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.card-head-row h2 { margin: 0; }
.head-controls { display: flex; align-items: center; gap: 12px; }

/* ── Forms ───────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; color: var(--text-dim); }
.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 720px) { .field-grid { grid-template-columns: 1fr; } }

input[type="text"], input[type="password"], input[type="number"], textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-size: 13.5px;
  font-family: inherit;
  width: 100%;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, 0.18);
}
input[readonly] { color: var(--text-dim); background: #0a0d12; cursor: default; }
textarea { resize: vertical; font-family: var(--mono); }

.hint { font-size: 11.5px; color: var(--muted); }
.note {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.check-row { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); margin-bottom: 12px; cursor: pointer; }
.check-row.inline { margin-bottom: 0; }
.check-row input { width: auto; }

.inline-input { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-dim); }
.inline-input span { white-space: nowrap; }
.inline-input input { width: 130px; }
.inline-input.wide { flex: 1; }
.inline-input.wide input { width: 100%; min-width: 220px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 6px 0 14px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
.btn:hover { background: #232c39; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-press); border-color: var(--accent-press); }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-elev-2); }
.btn-danger-outline { background: transparent; border-color: rgba(248,81,73,0.5); color: var(--bad); }
.btn-danger-outline:hover { background: rgba(248,81,73,0.12); }

.btn-approve {
  background: var(--approve);
  border-color: var(--approve);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 13px 22px;
  letter-spacing: 0.3px;
  box-shadow: 0 0 0 1px rgba(209,29,44,0.4), 0 6px 18px rgba(209,29,44,0.25);
}
.btn-approve:hover:not(:disabled) { background: var(--approve-press); border-color: var(--approve-press); }
.btn-approve:disabled { box-shadow: none; }

/* ── Pills / badges ──────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
}
.pill-muted { color: var(--muted); background: var(--bg-elev-2); }
.pill-good { color: var(--good); background: rgba(63,185,80,0.12); border-color: rgba(63,185,80,0.4); }
.pill-warn { color: var(--warn); background: rgba(210,153,34,0.12); border-color: rgba(210,153,34,0.4); }
.pill-bad { color: var(--bad); background: rgba(248,81,73,0.12); border-color: rgba(248,81,73,0.4); }

/* ── Status grid (session) ───────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.status-grid .k { color: var(--text-dim); font-size: 13px; }
.status-grid .v { font-size: 13px; word-break: break-word; }
.status-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 13px; }

/* ── Result blocks / JSON ────────────────────────────────── */
.result-block { margin-top: 12px; }
.result-head { font-size: 11.5px; color: var(--muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.5px; }
.result-body {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  max-height: 460px;
  overflow-y: auto;
  unicode-bidi: plaintext; /* keeps Hebrew content from breaking layout */
}
.result-body .muted { font-family: var(--sans); }
.result-body.is-error { border-color: rgba(248,81,73,0.5); }

/* simple JSON syntax tint (applied via spans by the pretty printer) */
.jk { color: #79c0ff; }      /* keys */
.js { color: #a5d6a3; }      /* strings */
.jn { color: #f0a36b; }      /* numbers */
.jb { color: #d2a8ff; }      /* booleans/null */
.jp { color: var(--muted); } /* punctuation */

.json-collapse {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
}
.json-collapse > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  user-select: none;
}
.json-collapse > summary:hover { color: var(--text); }
.json-collapse[open] > summary { border-bottom: 1px solid var(--border); }
.json-collapse > .result-body {
  border: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  margin: 0;
}

/* ── Tables ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 11px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table thead th {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  position: sticky; top: 0;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(255,255,255,0.02); }
.col-rel { width: 70px; text-align: center; }
.col-rel + td, td.col-rel { text-align: center; }
.col-actions { width: 1%; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.cell-schema {
  font-family: var(--mono);
  font-size: 11.5px;
  max-width: 280px;
}
.cell-schema .result-body { max-height: 200px; padding: 8px 10px; }

.logs-wrap { max-height: 480px; overflow-y: auto; }
.logs-table td { font-family: var(--mono); font-size: 12px; }
.logs-table .msg { unicode-bidi: plaintext; white-space: pre-wrap; word-break: break-word; }

.lvl { padding: 1px 7px; border-radius: 5px; font-size: 11px; font-weight: 600; }
.lvl-info { color: var(--text-dim); background: var(--bg-elev-2); }
.lvl-warn { color: var(--warn); background: rgba(210,153,34,0.12); }
.lvl-error { color: var(--bad); background: rgba(248,81,73,0.12); }

/* ── Transcript (agent) ──────────────────────────────────── */
.transcript { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.t-msg {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  background: var(--bg-elev-2);
  unicode-bidi: plaintext;
}
.t-role { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 4px; }
.t-role.user { color: var(--accent); }
.t-role.assistant { color: var(--good); }
.t-role.tool { color: var(--warn); }
.t-body { white-space: pre-wrap; word-break: break-word; font-size: 13px; }

/* ── Pipeline ────────────────────────────────────────────── */
.pipeline-steps { display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.pstep {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-elev-2);
}
.pstep > .btn { margin-bottom: 4px; }
.approve-step { border-color: rgba(209,29,44,0.4); background: rgba(209,29,44,0.06); }
.approve-note { font-size: 11.5px; color: var(--text-dim); margin: 8px 0 4px; }
.preview-rendered {
  margin: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--bg-input);
  unicode-bidi: plaintext;
}
.preview-rendered h4 { margin: 0 0 8px; font-size: 13px; color: var(--text-dim); }
.preview-field { margin-bottom: 8px; }
.preview-field .pf-label { font-size: 11.5px; color: var(--muted); }
.preview-field .pf-val { white-space: pre-wrap; word-break: break-word; }

/* ── Progress / toast ────────────────────────────────────── */
.progress {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 22px; right: 22px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 50;
  max-width: 360px;
  unicode-bidi: plaintext;
}
.toast.toast-good { border-color: rgba(63,185,80,0.5); }
.toast.toast-bad { border-color: rgba(248,81,73,0.5); }

/* ── Chat ────────────────────────────────────────────────── */
.chat-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
}

/* The page area is a column: scrollable thread + fixed composer at the bottom.
 * Height fills the viewport minus the page header. */
.chat-shell {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 160px);
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  overflow: hidden;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-empty { text-align: center; margin: auto; padding: 30px 10px; }

.chat-row { display: flex; }
.chat-row-user { justify-content: flex-end; }
.chat-row-assistant { justify-content: flex-start; }

.chat-bubble {
  max-width: 76%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  animation: chatIn 0.22s ease;
}
@keyframes chatIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.chat-bubble-user {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-bubble-assistant {
  background: var(--bg-elev-2);
  border-color: var(--border-strong);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

/* message text — keep Hebrew/RTL rendering correct */
.chat-md { unicode-bidi: plaintext; word-break: break-word; white-space: pre-wrap; }
.chat-bubble-assistant .chat-md { white-space: normal; }
.chat-md p { margin: 0 0 8px; }
.chat-md p:last-child { margin-bottom: 0; }
.chat-md h1, .chat-md h2, .chat-md h3 { margin: 10px 0 6px; line-height: 1.3; }
.chat-md h1 { font-size: 17px; }
.chat-md h2 { font-size: 15px; }
.chat-md h3 { font-size: 14px; color: var(--text-dim); }
.chat-md ul, .chat-md ol { margin: 4px 0 8px; padding-inline-start: 22px; }
.chat-md li { margin: 2px 0; }
.chat-md a { color: #79c0ff; }
.chat-bubble-user .chat-md a { color: #cfe2ff; text-decoration: underline; }
.chat-md code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.chat-md pre {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  overflow-x: auto;
  margin: 6px 0 8px;
}
.chat-md pre code { background: none; border: none; padding: 0; font-size: 12px; }
.chat-md .md-table { border-collapse: collapse; margin: 6px 0 8px; font-size: 12.5px; width: 100%; }
.chat-md .md-table th, .chat-md .md-table td {
  border: 1px solid var(--border); padding: 5px 9px; text-align: left;
}
.chat-md .md-table thead th { background: var(--bg-input); color: var(--text-dim); }

/* attachments inside a bubble */
.chat-atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chat-att-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px;
  text-decoration: none;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}
.chat-att-link:hover { background: #232c39; border-color: var(--accent); }
.chat-bubble-user .chat-att-link { color: var(--text); }

/* pending submission card */
.chat-pending {
  margin-top: 12px;
  border: 1px solid rgba(209,29,44,0.5);
  background: rgba(209,29,44,0.08);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  unicode-bidi: plaintext;
}
.chat-pending-head { font-weight: 700; color: #ff8a8a; font-size: 13px; margin-bottom: 8px; }
.chat-pending-meta { font-size: 12.5px; color: var(--text-dim); display: flex; flex-direction: column; gap: 3px; margin-bottom: 10px; }
.chat-approve-btn { font-size: 13.5px; padding: 9px 16px; }
.chat-pending-status { margin-top: 9px; font-size: 12.5px; }
.chat-pending-status.is-error { color: var(--bad); }
.chat-pending-status.chat-pending-ok { color: var(--good); }

/* typing indicator */
.chat-typing { display: inline-flex; align-items: center; gap: 5px; padding: 14px 16px; }
.chat-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
  animation: chatBlink 1.2s infinite ease-in-out both;
}
.chat-dot:nth-child(2) { animation-delay: 0.18s; }
.chat-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes chatBlink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* composer (fixed at the bottom of the chat shell) */
.chat-composer {
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 10px 12px;
}
.chat-attach-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  margin-bottom: 8px;
  unicode-bidi: plaintext;
}
.chat-chip-x {
  background: transparent; border: none; color: var(--muted);
  cursor: pointer; font-size: 13px; line-height: 1;
  padding: 2px 6px; border-radius: 50%;
}
.chat-chip-x:hover { color: var(--bad); background: rgba(248,81,73,0.12); }

.chat-input-row { display: flex; align-items: flex-end; gap: 8px; }
.chat-attach-btn {
  flex: none; font-size: 16px; line-height: 1;
  padding: 9px 11px; height: 40px;
}
#chat-input {
  flex: 1;
  resize: none;
  font-family: var(--sans);
  max-height: 160px;
  min-height: 40px;
  overflow-y: auto;
  unicode-bidi: plaintext;
}
.chat-send-btn { flex: none; height: 40px; }

@media (max-width: 820px) {
  .chat-shell { height: calc(100vh - 230px); }
  .chat-bubble { max-width: 88%; }
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 820px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; flex-wrap: wrap; align-items: center;
    gap: 10px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1 1 100%; }
  .nav-item { flex: 1 1 auto; justify-content: center; }
  .sidebar-foot { flex-direction: row; align-items: center; border: none; padding: 0; }
  .content { padding: 20px 16px 50px; }
}
