/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Ubuntu Mono', 'DejaVu Sans Mono', monospace;
  background: #1A1A2E;
  color: #CDD6F4;
  font-size: 14px;
}

/* ─── Auth pages ────────────────────────────────────────────────────────────── */
body.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
}

.auth-box {
  background: #16213E;
  border: 1px solid #2A2A4A;
  border-radius: 14px;
  padding: 40px 36px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  font-size: 40px;
  margin-bottom: 6px;
}

.auth-title {
  text-align: center;
  color: #CBA6F7;
  font-size: 22px;
  font-weight: bold;
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  color: #A6ADC8;
  font-size: 13px;
  margin-bottom: 28px;
}

.flash-msg {
  background: rgba(243, 139, 168, 0.12);
  border: 1px solid #F38BA8;
  border-radius: 6px;
  color: #F38BA8;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}

.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  color: #A6ADC8;
  font-size: 12px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  background: #1E1E2E;
  color: #CDD6F4;
  border: 1px solid #2A2A4A;
  border-radius: 6px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: #CBA6F7; }

.form-hint {
  display: block;
  color: #6C7086;
  font-size: 11px;
  margin-top: 4px;
}

.btn-auth {
  width: 100%;
  background: #CBA6F7;
  color: #11111B;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  margin-top: 6px;
  transition: filter 0.15s;
}

.btn-auth:hover { filter: brightness(1.1); }

.auth-footer {
  text-align: center;
  margin-top: 22px;
  font-size: 13px;
  color: #A6ADC8;
}

.auth-footer a { color: #89B4FA; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* ─── Impersonation banner ───────────────────────────────────────────────────── */
#impersonation-banner {
  background: rgba(249, 226, 175, 0.10);
  border-bottom: 1px solid rgba(249, 226, 175, 0.3);
  color: #F9E2AF;
  padding: 6px 16px;
  font-size: 13px;
  text-align: center;
  flex-shrink: 0;
  letter-spacing: 0.01em;
}

#impersonation-banner strong { color: #FAB387; }

#impersonation-banner a {
  color: #F38BA8;
  font-weight: bold;
  text-decoration: none;
  margin-left: 8px;
  border: 1px solid rgba(243, 139, 168, 0.4);
  padding: 2px 8px;
  border-radius: 4px;
}

#impersonation-banner a:hover { background: rgba(243, 139, 168, 0.15); }

/* ─── Main app layout ────────────────────────────────────────────────────────── */
body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #16213E;
  border-bottom: 1px solid #2A2A4A;
  padding: 6px 14px;
  flex-shrink: 0;
  gap: 10px;
  min-height: 50px;
}

#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
#sidebar {
  width: 200px;
  min-width: 160px;
  background: #11111B;
  border-right: 1px solid #2A2A4A;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  border-bottom: 1px solid #2A2A4A;
}

.sidebar-templates {
  margin-top: auto;
  border-bottom: none;
  border-top: 1px solid #2A2A4A;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: bold;
  color: #A6ADC8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.btn-icon {
  background: #2A2A4A;
  color: #CDD6F4;
  border: none;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.btn-icon:hover { background: #3a3a5a; }

.files-actions { display: flex; gap: 6px; }

.file-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  max-height: 350px;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  color: #CDD6F4;
  transition: background 0.12s;
  user-select: none;
}

.file-item:hover { background: #1E1E2E; }

.file-item.active { background: #2A2A4A; color: #CBA6F7; }

.file-item .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-item .file-delete {
  opacity: 0;
  background: none;
  border: none;
  color: #F38BA8;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  line-height: 1;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.file-item:hover .file-delete { opacity: 1; }

.template-select {
  width: 100%;
  background: #1E1E2E;
  color: #CDD6F4;
  border: 1px solid #2A2A4A;
  border-radius: 5px;
  padding: 5px 6px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  outline: none;
}

.template-select:focus { border-color: #CBA6F7; }
.template-select option { background: #1E1E2E; color: #CDD6F4; }

/* ─── Editor area ────────────────────────────────────────────────────────────── */
#editor-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

/* ─── Tab bar ────────────────────────────────────────────────────────────────── */
#tab-bar {
  background: #11111B;
  border-bottom: 1px solid #2A2A4A;
  display: flex;
  align-items: flex-end;
  flex-shrink: 0;
  min-height: 36px;
  overflow-x: auto;
  overflow-y: hidden;
}

#tabs-container { display: flex; align-items: flex-end; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #1A1A2E;
  border: 1px solid #2A2A4A;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  font-size: 13px;
  color: #A6ADC8;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  user-select: none;
  max-width: 200px;
}

.tab:hover        { background: #1E1E2E; color: #CDD6F4; }
.tab.active       { background: #1E1E2E; color: #CDD6F4; border-bottom-color: #1E1E2E; }
.tab .tab-name    { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab .tab-close   { font-size: 15px; color: #6C7086; line-height: 1; border-radius: 3px; padding: 0 2px; flex-shrink: 0; transition: color 0.12s, background 0.12s; }
.tab .tab-close:hover { color: #F38BA8; background: #2A2A4A; }

/* ─── CodeMirror wrapper ─────────────────────────────────────────────────────── */
#editor-wrapper {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.CodeMirror {
  height: 100% !important;
  font-family: 'Ubuntu Mono', 'DejaVu Sans Mono', monospace !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
}

.CodeMirror-scroll { height: 100%; }

/* ─── CodeMirror Holberton theme ─────────────────────────────────────────────── */
.cm-s-holberton.CodeMirror           { background: #1E1E2E; color: #CDD6F4; }
.cm-s-holberton .CodeMirror-gutters  { background: #181825; border-right: 1px solid #2A2A4A; }
.cm-s-holberton .CodeMirror-linenumber          { color: #6C7086; }
.cm-s-holberton .CodeMirror-activeline-background { background: #252535; }
.cm-s-holberton .CodeMirror-cursor   { border-left: 2px solid #CDD6F4; }
.cm-s-holberton .CodeMirror-selected,
.cm-s-holberton .CodeMirror-selectedtext         { background: #45475A !important; }
.cm-s-holberton .CodeMirror-focused .CodeMirror-selected { background: #45475A !important; }
.cm-s-holberton span.cm-keyword      { color: #CBA6F7; font-weight: bold; }
.cm-s-holberton span.cm-def          { color: #89B4FA; }
.cm-s-holberton span.cm-variable     { color: #CDD6F4; }
.cm-s-holberton span.cm-variable-2   { color: #CDD6F4; }
.cm-s-holberton span.cm-string       { color: #A6E3A1; }
.cm-s-holberton span.cm-string-2     { color: #F9E2AF; }
.cm-s-holberton span.cm-number       { color: #FAB387; }
.cm-s-holberton span.cm-comment      { color: #6C7086; font-style: italic; }
.cm-s-holberton span.cm-operator     { color: #89DCEB; }
.cm-s-holberton span.cm-builtin      { color: #89B4FA; }
.cm-s-holberton span.cm-meta         { color: #F38BA8; }
.cm-s-holberton span.cm-error        { background: transparent; color: #F38BA8; }
.cm-s-holberton span.cm-atom         { color: #FAB387; }
.cm-s-holberton span.cm-bracket      { color: #89DCEB; }
.cm-s-holberton span.cm-tag          { color: #F38BA8; }
.cm-s-holberton span.cm-attribute    { color: #89B4FA; }
.cm-s-holberton span.cm-property     { color: #89DCEB; }

/* ─── Output resize handle ───────────────────────────────────────────────────── */
#output-resizer {
  height: 7px;
  flex-shrink: 0;
  cursor: ns-resize;
  background: #11111B;
  border-top: 1px solid #2A2A4A;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s;
  touch-action: none;          /* let pointer drag work on touch devices */
}

#output-resizer:hover,
#output-resizer.resizing { background: #2A2A4A; }

.output-resizer-grip {
  width: 36px;
  height: 3px;
  border-radius: 2px;
  background: #45475A;
  transition: background 0.12s;
}

#output-resizer:hover .output-resizer-grip,
#output-resizer.resizing .output-resizer-grip { background: #89B4FA; }

/* While dragging, suppress text selection and force the resize cursor everywhere */
body.is-resizing-output,
body.is-resizing-output * {
  cursor: ns-resize !important;
  user-select: none !important;
}

/* ─── Output panel ───────────────────────────────────────────────────────────── */
#output-panel {
  height: 220px;
  min-height: 80px;
  display: flex;
  flex-direction: column;
  background: #11111B;
  flex-shrink: 0;
}

#output-label {
  background: #16213E;
  border-bottom: 1px solid #2A2A4A;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: bold;
  color: #A6ADC8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

#terminal {
  flex: 1;
  overflow: hidden;
  padding: 4px;
  background: #11111B;
  min-height: 0;
}

.xterm            { height: 100%; }
.xterm-viewport   { background-color: #11111B !important; }
.xterm-screen     { overflow: hidden; }

/* ─── Toolbar ────────────────────────────────────────────────────────────────── */
.toolbar-left  { display: flex; align-items: center; gap: 8px; }
.toolbar-right { display: flex; align-items: center; gap: 10px; }

.app-title {
  font-size: 15px;
  font-weight: bold;
  color: #CBA6F7;
  margin-right: 6px;
  white-space: nowrap;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  padding: 8px 18px;
  cursor: pointer;
  font-family: inherit;
  transition: filter 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { filter: brightness(0.9); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-run   { background: #2ECC71; color: #11111B; }
.btn-stop  { background: #E74C3C; color: #fff; }
.btn-save  { background: #3498DB; color: #fff; }
.btn-download { background: #2A2A4A; color: #94E2D5; border: 1px solid #94E2D540; }
.btn-download:hover:not(:disabled) { background: #3a3a5a; filter: none; }
.btn-clear { background: #2A2A4A; color: #CDD6F4; border: 1px solid #3a3a6a; }
.btn-ai    { background: #2A2A4A; color: #CBA6F7; border: 1px solid #CBA6F740; }
.btn-ai:hover:not(:disabled) { background: #3a3a5a; filter: none; }

/* ─── Status bar ─────────────────────────────────────────────────────────────── */
#status-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 20px;
  background: #1A1A2E;
  border: 1px solid #2A2A4A;
  transition: border-color 0.2s;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #A6ADC8;
  transition: background 0.2s;
  flex-shrink: 0;
}

#status-bar.status-ready   .status-dot { background: #A6ADC8; }
#status-bar.status-running .status-dot { background: #2ECC71; animation: pulse 1s infinite; }
#status-bar.status-error   .status-dot { background: #F38BA8; }
#status-bar.status-ok      .status-dot { background: #2ECC71; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ─── Language toggle ────────────────────────────────────────────────────────── */
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 2px;
  background: #1A1A2E;
  border: 1px solid #2A2A4A;
  border-radius: 6px;
  padding: 2px 4px;
}

.lang-btn {
  background: none;
  border: none;
  color: #6C7086;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.lang-btn.lang-active { color: #CBA6F7; background: #2A2A4A; }
.lang-btn:hover:not(.lang-active) { color: #CDD6F4; }
.lang-sep { color: #2A2A4A; font-size: 12px; }

/* ─── User bar ───────────────────────────────────────────────────────────────── */
.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.user-name {
  color: #CDD6F4;
  font-weight: bold;
}

.user-admin-link {
  color: #F9E2AF;
  text-decoration: none;
  font-size: 12px;
  background: #2A2A4A;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid #F9E2AF40;
}

.user-admin-link:hover { background: #3a3a5a; }

/* Forms wrapping a single action button (logout / stop-impersonate) so they can
   carry a CSRF token while still looking like the inline links they replaced. */
.inline-form { display: inline; margin: 0; }

.user-logout {
  color: #A6ADC8;
  text-decoration: none;
  font-size: 12px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font-family: inherit;
}

.user-logout:hover { color: #F38BA8; }

/* Stop-impersonate button, styled to match the old banner link. */
#impersonation-banner button.linklike {
  color: #F38BA8;
  font-weight: bold;
  font-size: 13px;
  font-family: inherit;
  text-decoration: none;
  margin-left: 8px;
  border: 1px solid rgba(243, 139, 168, 0.4);
  background: none;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
}

#impersonation-banner button.linklike:hover { background: rgba(243, 139, 168, 0.15); }

/* ─── AI panel ───────────────────────────────────────────────────────────────── */
#ai-panel {
  width: 420px;
  min-width: 340px;
  background: #11111B;
  border-left: 1px solid #2A2A4A;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.ai-panel-hidden { display: none !important; }

.ai-header {
  background: #16213E;
  border-bottom: 1px solid #2A2A4A;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: bold;
  color: #CBA6F7;
  font-size: 13px;
  flex-shrink: 0;
}

.ai-close-btn {
  background: none;
  border: none;
  color: #6C7086;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  transition: color 0.15s;
}

.ai-close-btn:hover { color: #F38BA8; }

.ai-header-title { white-space: nowrap; }

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ai-icon-btn {
  background: #2A2A4A;
  color: #CDD6F4;
  border: none;
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-icon-btn:hover { background: #3a3a5a; }

.ai-hidden { display: none !important; }

/* Conversation = messages (scroll) + input (pinned) */
.ai-conversation {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Chat history list */
.ai-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ai-chat-new {
  background: #CBA6F7;
  color: #11111B;
  border: none;
  border-radius: 6px;
  padding: 9px;
  font-weight: bold;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: filter 0.15s;
  margin-bottom: 4px;
}

.ai-chat-new:hover { filter: brightness(1.1); }

.ai-chat-empty {
  color: #6C7086;
  font-size: 12px;
  text-align: center;
  padding: 16px 8px;
}

.ai-chat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1E1E2E;
  border: 1px solid #2A2A4A;
  border-radius: 8px;
  padding: 8px 10px;
  transition: background 0.12s, border-color 0.12s;
}

.ai-chat-item:hover { background: #252535; }
.ai-chat-item.active { border-color: #CBA6F7; }

.ai-chat-info { flex: 1; cursor: pointer; overflow: hidden; }

.ai-chat-item-title {
  color: #CDD6F4;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chat-item-date {
  color: #6C7086;
  font-size: 11px;
  margin-top: 2px;
}

.ai-chat-del {
  background: none;
  border: none;
  color: #6C7086;
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.ai-chat-item:hover .ai-chat-del { opacity: 1; }
.ai-chat-del:hover { color: #F38BA8; }

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Row = avatar + bubble */
.ai-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 100%;
}

.ai-row.user {
  flex-direction: row-reverse;
}

.ai-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  background: #2A2A4A;
  border: 1px solid #3a3a5a;
  margin-top: 2px;
}

.ai-row.assistant .ai-avatar { background: #2a2440; border-color: #CBA6F740; }

.ai-message {
  border-radius: 12px;
  padding: 9px 13px;
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.ai-message.user {
  background: linear-gradient(135deg, #3a3a5a, #2A2A4A);
  color: #CDD6F4;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}

.ai-message.assistant {
  background: #1E1E2E;
  color: #CDD6F4;
  border: 1px solid #2A2A4A;
  border-bottom-left-radius: 4px;
  max-width: 88%;
}

.ai-message.ai-error {
  color: #F38BA8;
  border-color: #F38BA840;
}

/* Markdown bits */
.ai-message strong { color: #F9E2AF; font-weight: bold; }
.ai-message em     { color: #CBA6F7; font-style: italic; }

.ai-inline-code {
  font-family: 'Ubuntu Mono', monospace;
  background: #11111B;
  color: #A6E3A1;
  border: 1px solid #2A2A4A;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
}

/* Fenced code blocks */
.ai-code-block {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #2A2A4A;
  background: #11111B;
}

.ai-code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: #181825;
  border-bottom: 1px solid #2A2A4A;
}

.ai-code-lang {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6C7086;
  font-weight: bold;
}

.ai-code-copy {
  background: #2A2A4A;
  color: #CDD6F4;
  border: none;
  border-radius: 4px;
  padding: 2px 9px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s;
}

.ai-code-copy:hover  { background: #3a3a5a; }
.ai-code-copy.copied { background: #2ECC71; color: #11111B; }

.ai-code-pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  font-family: 'Ubuntu Mono', 'DejaVu Sans Mono', monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.ai-code-pre code { font-family: inherit; white-space: pre; }

/* Syntax tokens (match the editor's Holberton theme) */
.tok-keyword { color: #CBA6F7; font-weight: bold; }
.tok-string  { color: #A6E3A1; }
.tok-number  { color: #FAB387; }
.tok-comment { color: #6C7086; font-style: italic; }
.tok-builtin { color: #89B4FA; }

/* Typing indicator */
.ai-typing { display: inline-flex; gap: 4px; padding: 2px 0; }
.ai-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #6C7086;
  animation: ai-bounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ai-bounce {
  0%, 80%, 100% { transform: translateY(0);   opacity: 0.4; }
  40%           { transform: translateY(-4px); opacity: 1;   }
}

.ai-input-area {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid #2A2A4A;
  flex-shrink: 0;
}

.ai-input {
  flex: 1;
  background: #1E1E2E;
  color: #CDD6F4;
  border: 1px solid #2A2A4A;
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.ai-input:focus { border-color: #CBA6F7; }

.btn-ai-send {
  background: #CBA6F7;
  color: #11111B;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: filter 0.15s;
  flex-shrink: 0;
}

.btn-ai-send:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ai-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Admin pages ────────────────────────────────────────────────────────────── */
body.admin-body {
  display: block;
  overflow: auto;
  min-height: 100vh;
}

.admin-topbar {
  background: #16213E;
  border-bottom: 1px solid #2A2A4A;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-title { font-size: 16px; font-weight: bold; color: #CBA6F7; }

.admin-topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.admin-badge {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: bold;
}

.badge-ok   { background: rgba(166, 227, 161, 0.12); color: #A6E3A1; border: 1px solid #A6E3A140; }
.badge-warn { background: rgba(249, 226, 175, 0.12); color: #F9E2AF; border: 1px solid #F9E2AF40; }
.badge-info { background: rgba(137, 180, 250, 0.12); color: #89B4FA; border: 1px solid #89B4FA40; }

.admin-link-btn {
  background: #2A2A4A;
  color: #CDD6F4;
  text-decoration: none;
  font-size: 12px;
  font-family: inherit;
  padding: 5px 12px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.admin-link-btn:hover:not(:disabled) { background: #3a3a5a; }
.admin-link-btn:disabled { opacity: 0.5; cursor: default; }

.refresh-status {
  font-size: 11px;
  color: #A6ADC8;
  white-space: nowrap;
}
.refresh-status #refresh-next { color: #CDD6F4; font-variant-numeric: tabular-nums; }
.refresh-sep { margin: 0 4px; color: #6C7086; }

.admin-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.admin-card {
  background: #16213E;
  border: 1px solid #2A2A4A;
  border-radius: 10px;
  overflow: hidden;
}

.admin-card-header {
  background: #11111B;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: bold;
  color: #A6ADC8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-count {
  background: #2A2A4A;
  color: #CDD6F4;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
}
.card-count.count-warn   { background: rgba(250,179,135,.2); color: #FAB387; }
.card-count.count-danger { background: rgba(243,139,168,.2); color: #F38BA8; }

/* Storage card */
.storage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.storage-stat {
  background: #2A2A4A;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: center;
}
.storage-num   { font-size: 20px; font-weight: bold; color: #CDD6F4; }
.storage-label { font-size: 11px; color: #A6ADC8; margin-top: 4px; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  background: #11111B;
  color: #6C7086;
  padding: 8px 16px;
  text-align: left;
  font-weight: bold;
  font-size: 11px;
  text-transform: uppercase;
  border-bottom: 1px solid #2A2A4A;
}

.admin-table td {
  padding: 8px 16px;
  border-bottom: 1px solid #1E1E2E;
  color: #CDD6F4;
  vertical-align: middle;
}

.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #1a1a2e; }

.admin-empty { padding: 20px 16px; color: #6C7086; font-size: 13px; }

.mono { font-family: 'Ubuntu Mono', monospace; }
.ts   { color: #A6ADC8; font-size: 12px; }
.text-muted { color: #6C7086; }

.role-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: bold;
}

.role-admin   { background: rgba(249, 226, 175, 0.15); color: #F9E2AF; }
.role-student { background: rgba(137, 180, 250, 0.15); color: #89B4FA; }
.role-master  { background: rgba(203, 166, 247, 0.18); color: #CBA6F7; }

/* ─── Admin: flash messages & account management ─────────────────────────────── */
.admin-flashes { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }

.admin-flash {
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  border: 1px solid;
}
.flash-success {
  background: rgba(166, 227, 161, 0.12);
  border-color: rgba(166, 227, 161, 0.5);
  color: #A6E3A1;
}
.flash-error {
  background: rgba(243, 139, 168, 0.12);
  border-color: rgba(243, 139, 168, 0.5);
  color: #F38BA8;
}

.admin-manage-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.admin-input {
  background: #11111b;
  border: 1px solid #313244;
  border-radius: 6px;
  color: #CDD6F4;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 13px;
  min-width: 180px;
}
.admin-input:focus { outline: none; border-color: #CBA6F7; }

.btn-create-admin {
  background: rgba(203, 166, 247, 0.15);
  color: #CBA6F7;
  border: 1px solid rgba(203, 166, 247, 0.4);
  border-radius: 6px;
  padding: 6px 14px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  transition: background 0.15s;
}
.btn-create-admin:hover { background: rgba(203, 166, 247, 0.3); }

.exit-ok      { color: #A6E3A1; font-weight: bold; }
.exit-err     { color: #F38BA8; font-weight: bold; }
.exit-stop    { color: #F9E2AF; }
.exit-running { color: #89B4FA; animation: pulse 1s infinite; }

.btn-kill {
  background: rgba(243, 139, 168, 0.15);
  color: #F38BA8;
  border: 1px solid #F38BA840;
  border-radius: 5px;
  padding: 3px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: background 0.15s;
}

.btn-kill:hover { background: rgba(243, 139, 168, 0.3); }

.action-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.btn-view-as {
  background: rgba(137, 180, 250, 0.12);
  color: #89B4FA;
  border: 1px solid rgba(137, 180, 250, 0.3);
  border-radius: 5px;
  padding: 3px 8px;
  text-decoration: none;
  font-size: 12px;
  display: inline-block;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-view-as:hover { background: rgba(137, 180, 250, 0.25); }

.btn-delete {
  background: rgba(243, 139, 168, 0.1);
  color: #F38BA8;
  border: 1px solid #F38BA830;
  border-radius: 5px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: background 0.15s;
}

.btn-delete:hover { background: rgba(243, 139, 168, 0.25); }

/* ─── Admin: helpers, day tabs, rate reset ───────────────────────────────────── */
.admin-hidden { display: none !important; }

.admin-subheader {
  padding: 10px 16px 6px;
  font-size: 12px;
  font-weight: bold;
  color: #FAB387;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-top: 1px solid #2A2A4A;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-note {
  padding: 8px 16px 0;
  margin: 0;
  font-size: 12px;
  color: #6C7086;
}

.day-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid #2A2A4A;
}

.day-tab {
  background: #1E1E2E;
  color: #A6ADC8;
  border: 1px solid #2A2A4A;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
}

.day-tab:hover { background: #26263c; }

.day-tab-active {
  background: rgba(137, 180, 250, 0.15);
  color: #89B4FA;
  border-color: rgba(137, 180, 250, 0.4);
}

.day-tab-count {
  background: #11111B;
  color: #CDD6F4;
  font-size: 10px;
  padding: 0 6px;
  border-radius: 8px;
}

.day-tab-active .day-tab-count {
  background: rgba(137, 180, 250, 0.25);
  color: #CDD6F4;
}

.btn-reset-rate {
  margin-left: auto;
  background: rgba(166, 227, 161, 0.12);
  color: #A6E3A1;
  border: 1px solid rgba(166, 227, 161, 0.3);
  border-radius: 5px;
  padding: 3px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: background 0.15s;
}

.btn-reset-rate:hover { background: rgba(166, 227, 161, 0.25); }

/* Long-running process highlight */
.row-long td { background: rgba(243, 139, 168, 0.07); }
.long-flag {
  margin-left: 6px;
  color: #F38BA8;
  font-size: 11px;
  font-weight: bold;
}

/* Per-day toolbar (clear buttons live here) */
.day-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid #1E1E2E;
  font-size: 12px;
}

.btn-clear-day {
  background: rgba(243, 139, 168, 0.1);
  color: #F38BA8;
  border: 1px solid #F38BA830;
  border-radius: 5px;
  padding: 3px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: background 0.15s;
}

.btn-clear-day:hover { background: rgba(243, 139, 168, 0.25); }

/* Copy button feedback */
.ai-code-copy.copied      { color: #A6E3A1 !important; }
.ai-code-copy.copy-failed { color: #F38BA8 !important; }

/* ─── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #11111B; }
::-webkit-scrollbar-thumb { background: #2A2A4A; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #3a3a5a; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  #sidebar { width: 140px; min-width: 100px; }
  .btn { padding: 6px 10px; font-size: 12px; }
  .app-title { display: none; }
  #ai-panel { width: 260px; min-width: 220px; }
  .user-name { display: none; }
}

/* ─── Game preview window (pygame) ───────────────────────────────────────────── */
.hidden { display: none !important; }

.game-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 8, 18, 0.78);
  backdrop-filter: blur(2px);
}

.game-modal-box {
  display: flex;
  flex-direction: column;
  width: min(92vw, 760px);
  max-height: 92vh;
  background: #1E1E2E;
  border: 1px solid #313150;
  border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.game-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: #181825;
  border-bottom: 1px solid #313150;
}

.game-modal-title {
  font-weight: 600;
  color: #CDD6F4;
  font-size: 15px;
}

.game-modal-actions { display: flex; gap: 8px; }

.game-btn {
  border: 1px solid #45475A;
  background: #313150;
  color: #CDD6F4;
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s;
}
.game-btn:hover { background: #3a3a5a; border-color: #585B70; }
.game-btn-close { background: #45233a; border-color: #6e3450; }
.game-btn-close:hover { background: #5a2c49; border-color: #8a3f63; }

.game-modal-body {
  position: relative;
  flex: 1;
  min-height: 380px;
  background: #11111B;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game-frame {
  width: 100%;
  height: 100%;
  min-height: 380px;
  border: 0;
  background: #11111B;
  display: block;
}

.game-status {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #BAC2DE;
  font-size: 15px;
  text-align: center;
  padding: 24px;
  background: #11111B;
}
.game-status.with-spinner .game-spinner { display: block; }
.game-spinner { display: none; }

#game-status-text {
  max-width: 460px;
  line-height: 1.55;
}
/* Multi-line tips/errors (shown without the spinner) read better left-aligned. */
.game-status:not(.with-spinner) #game-status-text { text-align: left; }
#game-status-text code {
  background: #313150;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.92em;
}

.game-spinner {
  width: 34px;
  height: 34px;
  border: 4px solid #313150;
  border-top-color: #89B4FA;
  border-radius: 50%;
  animation: game-spin 0.8s linear infinite;
}
@keyframes game-spin { to { transform: rotate(360deg); } }

.game-modal-foot {
  padding: 8px 14px;
  background: #181825;
  border-top: 1px solid #313150;
  color: #9399B2;
  font-size: 12px;
  text-align: center;
}
