* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #1e1e2e;
  color: #cdd6f4;
}

#app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
#sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #181825;
  border-right: 1px solid #313244;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #313244;
}

.sidebar-header h1 {
  font-size: 18px;
  margin: 0;
  color: #89b4fa;
}

/* New ▾ template menu */
.new-wrap { position: relative; }

#template-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  margin: 0;
  padding: 4px;
  list-style: none;
  min-width: 200px;
  background: #11111b;
  border: 1px solid #313244;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

#template-menu.hidden { display: none; }

#template-menu .tpl-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
}

#template-menu .tpl-item:hover { background: #313244; }
.tpl-name { font-size: 13px; color: #cdd6f4; }
.tpl-desc { font-size: 11px; color: #9399b2; line-height: 1.3; }

#script-list {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  flex: 1;
}

#script-list li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#script-list li:hover { background: #313244; }
#script-list li.active { background: #45475a; color: #fff; }

/* Services panel (pinned to bottom of sidebar) */
#services {
  border-top: 1px solid #313244;
  flex-shrink: 0;
  max-height: 45%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.services-header {
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6c7086;
}

#service-list {
  list-style: none;
  margin: 0;
  padding: 0 6px 8px;
  overflow-y: auto;
}

.svc-group { padding: 6px 8px 8px; }

.svc-head { display: flex; align-items: baseline; gap: 6px; }
.svc-name { font-size: 13px; color: #a6e3a1; font-weight: 600; }
.svc-count { font-size: 10px; color: #6c7086; }
.svc-desc { font-size: 11px; color: #9399b2; line-height: 1.3; margin: 1px 0 3px; }

.rpc-list { list-style: none; margin: 0; padding: 0; }

.rpc {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 8px;
  border-radius: 5px;
}
.rpc.clickable { cursor: pointer; }
.rpc.clickable:hover { background: #313244; }

.rpc-subject {
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 12px;
  color: #cdd6f4;
}
.rpc-desc { font-size: 10px; color: #6c7086; line-height: 1.25; }

.svc-empty { padding: 4px 14px 10px; font-size: 12px; color: #6c7086; font-style: italic; }

/* Main */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid #313244;
}

#name-input {
  background: #313244;
  border: 1px solid #45475a;
  color: #cdd6f4;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 14px;
  min-width: 200px;
}

#lang-select {
  background: #313244;
  border: 1px solid #45475a;
  color: #cdd6f4;
  padding: 6px;
  border-radius: 6px;
}

.spacer { flex: 1; }

button {
  background: #313244;
  border: 1px solid #45475a;
  color: #cdd6f4;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
button:hover { background: #45475a; }
button.primary { background: #89b4fa; color: #1e1e2e; border-color: #89b4fa; font-weight: 600; }
button.primary:hover { background: #a6c8ff; }
button.danger { color: #f38ba8; }
button:disabled { opacity: 0.5; cursor: default; }

/* Editor */
#editor {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

.cm-editor { height: 100%; }
.cm-editor .cm-scroller { font-family: "SF Mono", "Fira Code", Menlo, monospace; font-size: 13px; }

/* Console */
#console {
  height: 220px;
  flex-shrink: 0;
  border-top: 1px solid #313244;
  display: flex;
  flex-direction: column;
  background: #11111b;
}

#console-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  font-size: 13px;
  color: #a6adc8;
  border-bottom: 1px solid #313244;
}

#console-header .spacer { flex: 1; }
#status { flex: 1; font-variant-numeric: tabular-nums; }
#status.ok { color: #a6e3a1; }
#status.err { color: #f38ba8; }
#status.running { color: #f9e2af; }

#console-header button {
  padding: 2px 10px;
  font-size: 12px;
}

#output {
  flex: 1;
  margin: 0;
  padding: 10px 14px;
  overflow-y: auto;
  font-family: "SF Mono", "Fira Code", Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
