/* ---------------------------------------------------------------------------
   LOGO Emulator — professional dark theme
   --------------------------------------------------------------------------- */

:root {
  --bg: #0d1017;
  --bg-2: #12161f;
  --bg-3: #171c27;
  --border: #232a3a;
  --text: #c8d0e0;
  --text-dim: #77839c;
  --accent: #e0442e;
  --accent-2: #7aa2f7;
  --ok: #73d08c;
  --err: #f2555a;
  --warn: #f5a05a;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

/* ---- top bar -------------------------------------------------------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  min-height: 52px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 8px; user-select: none; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.4px; }
.brand-sub { color: var(--text-dim); font-size: 12px; margin-left: 6px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  flex-wrap: wrap;
}

.tool-group { display: flex; align-items: center; gap: 6px; }
.tool-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-dim); }

select {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font-ui);
  outline: none;
  min-width: 130px;
}
select:focus { border-color: var(--accent-2); }

.btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #1d2330; border-color: #2f3850; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #ef553c; border-color: #ef553c; }

.btn-danger {
  background: transparent;
  border-color: var(--err);
  color: var(--err);
}
.btn-danger:hover:not(:disabled) { background: rgba(242, 85, 90, 0.12); }

.status {
  font-size: 12px;
  font-family: var(--font-mono);
  padding: 4px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-3);
}
.status.ready { color: var(--ok); }
.status.running { color: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ---- main layout ----------------------------------------------------------- */

#layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

#left-pane {
  flex: 1 1 45%;
  min-width: 280px;
  display: flex;
  min-height: 0;
}

.editor-host { flex: 1; min-width: 0; overflow: hidden; }
.editor-host .cm-editor { height: 100%; }

#divider {
  flex: 0 0 4px;
  background: var(--border);
  cursor: col-resize;
  transition: background 0.15s;
}
#divider:hover { background: var(--accent-2); }

#right-pane {
  flex: 1 1 55%;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#stage-wrap {
  flex: 1 1 65%;
  min-height: 200px;
  position: relative;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
#stage { position: absolute; inset: 0; }

#console-wrap {
  flex: 1 1 35%;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
}

.console {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.55;
}

.console-line { display: flex; gap: 8px; white-space: pre-wrap; word-break: break-word; }
.console-prefix { flex: 0 0 auto; color: var(--text-dim); user-select: none; }
.console-print .console-text { color: var(--text); }
.console-type .console-text { color: var(--text-dim); }
.console-error { color: var(--err); }
.console-error .console-prefix { color: var(--err); }
.console-info { color: var(--accent-2); opacity: 0.9; }

.console-empty { color: var(--text-dim); font-style: italic; }

/* ---- status bar -------------------------------------------------------------- */

#statusbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  padding: 4px 14px;
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

.hint { user-select: none; }
.hint a { color: var(--accent-2); text-decoration: none; }
.hint a:hover { text-decoration: underline; }

/* ---- account toolbar buttons ------------------------------------------------- */

.account-group { margin-left: auto; }
#btn-account { font-weight: 600; }
.btn.active { border-color: var(--accent); color: var(--text); }

/* ---- modals ------------------------------------------------------------------ */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(4, 6, 10, 0.72);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: min(440px, 100%);
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 10px;
  font-weight: 700; font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.modal-head .x {
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.modal-head .x:hover { color: var(--text); }

.auth-form { padding: 14px 18px 18px; display: flex; flex-direction: column; gap: 10px; }
.auth-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-dim); font-weight: 600;
}
.auth-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
  font-family: var(--font-ui);
}
.auth-form input:focus { outline: none; border-color: var(--accent-2); }
.auth-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auth-form .dim { font-weight: 400; font-size: 11px; }
.form-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form-actions .err { color: var(--err); font-size: 12px; margin-right: auto; }
.hidden { display: none !important; }

.tabs { display: flex; gap: 4px; padding: 12px 18px 0; }
.tab {
  background: none; border: 1px solid transparent; border-bottom: none;
  color: var(--text-dim); font-size: 13px; font-weight: 600;
  padding: 6px 12px; cursor: pointer; border-radius: 6px 6px 0 0;
}
.tab.active { color: var(--text); border-color: var(--border); background: var(--bg); }

/* ---- saved programs list ----------------------------------------------------- */
.prog-list { max-height: 52vh; overflow: auto; padding: 6px 10px; display: flex; flex-direction: column; gap: 4px; }
.prog-empty { color: var(--text-dim); font-size: 13px; padding: 14px 8px; }
.prog-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
}
.prog-open { flex: 1; text-align: left; }
.prog-meta { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.prog-del { padding: 2px 8px; }

/* ---- reference panel --------------------------------------------------------- */

#ref-panel {
  position: fixed;
  top: 52px; right: 12px; bottom: 28px;
  width: min(420px, 92vw);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  z-index: 900;
  display: flex; flex-direction: column;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
}
.ref-head {
  display: flex; flex-direction: column; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.ref-title { font-weight: 700; font-size: 14px; display: flex; justify-content: space-between; }
.ref-search {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); padding: 8px 10px; font-size: 13px; font-family: var(--font-ui);
}
.ref-search:focus { outline: none; border-color: var(--accent-2); }
.ref-close { background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }
.ref-close:hover { color: var(--text); }
.ref-body { flex: 1; overflow: auto; padding: 8px 14px 14px; }
.ref-cat {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--accent-2); font-weight: 700; margin: 14px 4px 6px;
  border-bottom: 1px solid var(--border); padding-bottom: 3px;
}
.ref-cat:first-child { margin-top: 2px; }
.ref-item { padding: 6px 4px; border-radius: 6px; }
.ref-item:hover { background: var(--bg-3); }
.ref-cmd { font-family: var(--font-mono); font-size: 13px; color: var(--accent); font-weight: 700; }
.ref-desc { font-size: 12px; color: var(--text-dim); margin-top: 2px; line-height: 1.4; }
.ref-empty { color: var(--text-dim); font-size: 13px; padding: 20px; text-align: center; }
.ref-foot {
  padding: 8px 14px; border-top: 1px solid var(--border);
  font-size: 10px; color: var(--text-dim); line-height: 1.4;
}

/* ---- scrollbars (webkit) ------------------------------------------------------ */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a3145; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a4360; }

/* ---- responsive: stack panes vertically on narrow screens --------------------- */

@media (max-width: 860px) {
  #layout { flex-direction: column; }
  #left-pane { flex: 1 1 45%; }
  #right-pane { flex: 1 1 55%; }
  #divider { flex: 0 0 4px; cursor: row-resize; }
}
