:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef2f7;
  --text: #162033;
  --muted: #64748b;
  --border: #d8e0ea;
  --primary: #1d4ed8;
  --primary-2: #1e40af;
  --danger: #b91c1c;
  --warning: #b45309;
  --success: #047857;
  --shadow: 0 8px 24px rgba(15, 23, 42, .08);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.layout { display: grid; grid-template-columns: 260px minmax(0,1fr); min-height: 100vh; }
.sidebar {
  background: #111827;
  color: #e5e7eb;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: #2563eb; border-radius: 10px; font-weight: 800;
}
.brand small { color: #9ca3af; display: block; }
.nav { display: grid; gap: 4px; }
.nav a {
  color: #d1d5db; padding: 9px 11px; border-radius: 8px; display: block;
}
.nav a:hover, .nav a.active { background: #1f2937; color: #fff; text-decoration: none; }
.sidebar-footer { margin-top: 20px; padding-top: 14px; border-top: 1px solid #374151; }
.main { min-width: 0; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 14px 24px; background: var(--panel);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content { padding: 24px; max-width: 1600px; margin-inline: auto; }
.page-title { margin: 0 0 18px; font-size: 1.55rem; }
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.panel, .card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow);
}
.panel { padding: 18px; margin-bottom: 16px; }
.card { padding: 16px; }
.card h3, .panel h2, .panel h3 { margin-top: 0; }
.metric { font-size: 1.75rem; font-weight: 700; margin: 6px 0; }
.muted { color: var(--muted); }
.badge {
  display: inline-flex; align-items: center; border-radius: 999px;
  padding: 2px 8px; font-size: .8rem; background: var(--panel-2);
}
.badge.success { color: var(--success); background: #d1fae5; }
.badge.warning { color: var(--warning); background: #fef3c7; }
.badge.danger { color: var(--danger); background: #fee2e2; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 9px 10px; border-bottom: 1px solid var(--border);
  text-align: start; vertical-align: top;
}
th { background: var(--panel-2); font-weight: 600; }
.table-wrap { overflow-x: auto; }
form.stack { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: minmax(140px, .4fr) 1fr; gap: 12px; align-items: center; }
label { font-weight: 600; }
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; background: #fff; color: var(--text);
}
textarea { min-height: 120px; resize: vertical; }
button, .button {
  border: 0; border-radius: 8px; padding: 9px 13px; cursor: pointer;
  background: var(--primary); color: #fff; display: inline-flex; align-items: center;
  justify-content: center; gap: 6px;
}
button:hover, .button:hover { background: var(--primary-2); text-decoration: none; }
button.secondary, .button.secondary { background: #475569; }
button.danger, .button.danger { background: var(--danger); }
button.warning, .button.warning { background: var(--warning); }
button:disabled { opacity: .55; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
pre, code, .ltr, .technical {
  direction: ltr !important; unicode-bidi: plaintext; text-align: left;
  font-family: Consolas, "Cascadia Code", monospace;
}
pre {
  white-space: pre-wrap; overflow-wrap: anywhere; background: #0f172a; color: #e2e8f0;
  border-radius: 9px; padding: 14px; max-height: 620px; overflow: auto;
}
.message { padding: 12px 14px; border-radius: 8px; margin-bottom: 12px; background: #dbeafe; }
.message.error, .error-box { background: #fee2e2; color: #7f1d1d; padding: 12px; border-radius: 8px; }
.message.success { background: #d1fae5; color: #065f46; }
.file-tree { max-height: 620px; overflow: auto; }
.file-tree a { display: block; padding: 5px 8px; border-radius: 6px; }
.file-tree a:hover { background: var(--panel-2); text-decoration: none; }
.editor-layout { display: grid; grid-template-columns: 280px minmax(0,1fr); gap: 14px; }
#editor-container { min-height: 65vh; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
#editor-textarea { min-height: 65vh; border: 0; border-radius: 0; direction: ltr; text-align: left; font-family: Consolas, monospace; }
.result-box { margin-top: 12px; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(440px, 100%); background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); }
dialog { border: 0; border-radius: 12px; width: min(560px, 92vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15,23,42,.55); }
.progress { height: 8px; border-radius: 999px; background: #e2e8f0; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

.grid.four { grid-template-columns: repeat(4, minmax(0,1fr)); }
.page-head, .row, .between {
  display: flex; align-items: center; gap: 12px;
}
.page-head, .between { justify-content: space-between; }
.page-head { margin-bottom: 18px; flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.grow { flex: 1 1 280px; }
.mt-16 { margin-top: 16px; }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.notice, .warning-box {
  padding: 13px 15px; border-radius: 9px; background: #eff6ff;
  border-inline-start: 4px solid var(--primary); margin-block: 12px;
}
.warning-box { background: #fff7ed; border-inline-start-color: var(--warning); }
.field-error { display: block; color: var(--danger); font-weight: 400; }
.feature-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
.toggle { display: flex; align-items: center; gap: 8px; background: var(--panel-2); padding: 9px; border-radius: 8px; }
.toggle input, label input[type="checkbox"] { width: auto; }
.definition-list { display: grid; grid-template-columns: minmax(110px,.35fr) 1fr; gap: 8px 14px; }
.definition-list dt { font-weight: 700; }
.definition-list dd { margin: 0; color: var(--muted); }
.vault-card, .subpanel { border: 1px solid var(--border); border-radius: 10px; padding: 13px; }
.secret-output { background: #0f172a; color: #e2e8f0; padding: 10px; border-radius: 7px; margin-block: 10px; min-height: 42px; }
.status { display: inline-flex; border-radius: 999px; padding: 3px 8px; background: var(--panel-2); }
.status.success { background:#d1fae5;color:var(--success); }
.status.failed { background:#fee2e2;color:var(--danger); }
.status.running, .status.queued { background:#fef3c7;color:var(--warning); }
.alert.critical { border-inline-start: 5px solid var(--danger); }
.alert.warning { border-inline-start: 5px solid var(--warning); }
.alert.info { border-inline-start: 5px solid var(--primary); }
.metric > span { display:block; color:var(--muted); font-size:.9rem; font-weight:500; }
.metric > strong { display:block; font-size:1.6rem; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .topbar { position: static; }
  .grid.two, .grid.three, .grid.four, .editor-layout { grid-template-columns: 1fr; }
}


.terminal-panel { background: #0b1020; color: #e5e7eb; }
.terminal-output {
  min-height: 420px;
  max-height: 65vh;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #050814;
  color: #d1fae5;
  border: 1px solid #26324f;
  border-radius: .55rem;
  padding: 1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  line-height: 1.45;
}
#terminal-input {
  background: #050814;
  color: #f8fafc;
  border-color: #334155;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.danger-text { color: #ef4444; }
#terminal-status[data-kind="ok"] { background: #14532d; }
#terminal-status[data-kind="error"] { background: #7f1d1d; }
#terminal-status[data-kind="pending"] { background: #78350f; }


/* Workspace IDE (CP-330 core) */
.workspace-ide {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) minmax(260px, 360px);
  gap: 14px;
  align-items: stretch;
}
.workspace-ide .ide-sidebar,
.workspace-ide .ide-main,
.workspace-ide .ide-panels {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.ide-sidebar,
.ide-panels { padding: 14px; overflow: auto; }
.ide-main { display: flex; flex-direction: column; min-height: 680px; overflow: hidden; }
.ide-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.ide-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  padding: 6px 8px 0;
}
.ide-tab {
  border: 1px solid var(--border);
  border-bottom: 0;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 8px 8px 0 0;
  padding: 7px 10px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ide-tab.active { background: var(--panel); font-weight: 700; }
.ide-editor-host { min-height: 460px; flex: 1; border: 0; }
.ide-editor-textarea {
  width: 100%;
  min-height: 460px;
  flex: 1;
  border: 0;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  resize: vertical;
  background: #0f172a;
  color: #e5e7eb;
}
.ide-status {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  color: var(--muted);
}
.ide-status[data-kind="error"],
.ide-init-error { color: var(--danger); }
.ide-status[data-kind="ok"] { color: var(--success); }
.ide-tree { display: grid; gap: 2px; }
.ide-tree-item button,
.search-match,
#quick-open-results button,
#draft-revisions-panel button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--text);
  cursor: pointer;
}
.ide-tree-item button:hover,
.search-match:hover,
#quick-open-results button:hover,
#draft-revisions-panel button:hover { background: var(--panel-2); }
.ide-tree-item.depth-1 { padding-left: 12px; }
.ide-tree-item.depth-2 { padding-left: 24px; }
.ide-tree-item.depth-3 { padding-left: 36px; }
.ide-panel {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}
.ide-panel:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}
.ide-panel pre,
.ide-dialog pre {
  white-space: pre-wrap;
  overflow: auto;
  max-height: 260px;
  background: var(--panel-2);
  border-radius: 10px;
  padding: 10px;
}
.ide-dialog {
  width: min(900px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.ide-dialog::backdrop { background: rgba(15, 23, 42, .35); }
.ide-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.ide-dialog input[type="search"],
.ide-dialog input[type="text"] {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.ide-search-options {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0;
  color: var(--muted);
}
.ide-terminal {
  margin: 0;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: #111827;
  color: #e5e7eb;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (max-width: 1100px) {
  .workspace-ide { grid-template-columns: 1fr; }
  .ide-main { min-height: 560px; }
}
