/* LiveAgent Lab — Obsidian-like dark UI, zero build deps */

:root {
  --bg-0: #1e1e1e;
  --bg-1: #252525;
  --bg-2: #2b2b2b;
  --bg-3: #333333;
  --bg-hover: #323232;
  --bg-active: #3a3a3a;
  --border: #3f3f3f;
  --border-soft: #353535;
  --text: #dcddde;
  --text-muted: #9a9a9a;
  --text-faint: #6e6e6e;
  --accent: #7f6df2;
  --accent-hover: #9585f5;
  --accent-soft: rgba(127, 109, 242, 0.15);
  --danger: #e35d6a;
  --danger-hover: #f0707c;
  --success: #4caf82;
  --warning: #d4a017;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  --radius: 8px;
  --radius-sm: 6px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", "SF Mono", ui-monospace, monospace;
  --topbar-h: 52px;
  --left-w: 240px;
  --right-w: 280px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
}

input,
select,
textarea {
  background: var(--bg-0);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

textarea {
  resize: vertical;
  min-height: 72px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.muted {
  color: var(--text-muted);
}

.sm-text {
  font-size: 12px;
}

.view {
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-3);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-ghost.danger:hover:not(:disabled),
.btn-danger {
  color: #fff;
  background: var(--danger);
}

.btn-ghost.danger {
  color: var(--danger);
  background: transparent;
}

.btn-ghost.danger:hover:not(:disabled) {
  background: rgba(227, 93, 106, 0.15);
  color: var(--danger-hover);
}

.btn-block {
  width: 100%;
}

.btn.sm {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* Login */
.login-view {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top, rgba(127, 109, 242, 0.12), transparent 50%),
    var(--bg-0);
}

.login-card {
  width: min(400px, 100%);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 24px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

.login-brand p {
  margin: 4px 0 0;
  font-size: 13px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, var(--accent), #5b8def);
  color: #fff;
  flex-shrink: 0;
}

.brand-mark.sm {
  width: 28px;
  height: 28px;
  font-size: 11px;
  border-radius: 7px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field > span {
  font-size: 12px;
  color: var(--text-muted);
}

.form-error {
  color: var(--danger);
  font-size: 13px;
  margin: 10px 0 0;
}

/* App shell */
.app-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 14px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.topbar-left {
  flex: 1;
  overflow: hidden;
}

.brand-name {
  font-size: 14px;
}

.divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}

.chip {
  display: inline-flex;
  align-items: center;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 12px;
}

.chip-muted {
  background: var(--bg-3);
  color: var(--text-muted);
}

.model-select select {
  min-width: 160px;
  max-width: 240px;
  padding: 6px 8px;
  background: var(--bg-2);
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Workspace 3-col */
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
}

.pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
}

.pane-right {
  border-right: none;
  border-left: 1px solid var(--border);
  background: var(--bg-1);
}

.pane-center {
  background: var(--bg-0);
  border-right: none;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}

.pane-header.sub {
  border-top: 1px solid var(--border-soft);
  margin-top: auto;
}

.pane-header h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pane-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 6px;
}

.pane-body.compact {
  flex: 0 0 auto;
  max-height: 36%;
}

.empty-hint {
  margin: 12px 8px;
  color: var(--text-faint);
  font-size: 12px;
}

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

.tree-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  user-select: none;
}

.tree-list li:hover {
  background: var(--bg-hover);
}

.tree-list li.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.tree-list .item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-list .item-meta {
  font-size: 11px;
  color: var(--text-faint);
}

.tree-list .item-actions {
  display: none;
  gap: 2px;
}

.tree-list li:hover .item-actions {
  display: inline-flex;
}

.tree-list .item-actions button {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.tree-list .item-actions button:hover {
  background: var(--bg-3);
  color: var(--text);
}

/* Center panels */
.center-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}

.tab {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
}

.tab:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.center-tabs-spacer {
  flex: 1;
}

.save-status {
  font-size: 12px;
}

.center-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-1);
}

.doc-title {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  padding: 6px 8px;
  font-weight: 600;
}

.doc-title:focus {
  border-color: var(--border);
  background: var(--bg-0);
}

.editor-actions {
  display: flex;
  gap: 4px;
}

.editor-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
}

.editor-body.split {
  grid-template-columns: 1fr 1fr;
}

.doc-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: none;
  border-radius: 0;
  resize: none;
  padding: 16px 18px;
  background: var(--bg-0);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.6;
  tab-size: 2;
}

.doc-editor:focus {
  box-shadow: none;
  border: none;
}

.doc-preview {
  overflow: auto;
  padding: 16px 20px;
  border-left: 1px solid var(--border-soft);
  background: var(--bg-1);
}

/* Markdown body */
.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 1.1em 0 0.5em;
  line-height: 1.3;
  font-weight: 600;
}

.markdown-body h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.markdown-body h2 { font-size: 1.35em; }
.markdown-body h3 { font-size: 1.15em; }
.markdown-body h4 { font-size: 1.05em; color: var(--text-muted); }

.markdown-body p {
  margin: 0.7em 0;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.6em 0;
  padding-left: 1.4em;
}

.markdown-body li {
  margin: 0.25em 0;
}

.markdown-body code {
  font-family: var(--mono);
  font-size: 0.92em;
  background: var(--bg-3);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.markdown-body pre {
  background: #171717;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow: auto;
  margin: 0.9em 0;
}

.markdown-body pre code {
  background: none;
  padding: 0;
  font-size: 12.5px;
  line-height: 1.5;
}

.markdown-body blockquote {
  margin: 0.8em 0;
  padding: 0.2em 0 0.2em 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

.markdown-body a {
  color: var(--accent-hover);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
  font-size: 13px;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.markdown-body th {
  background: var(--bg-3);
}

/* Chat */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-bubble {
  max-width: min(760px, 92%);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--bg-1);
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: rgba(127, 109, 242, 0.3);
}

.chat-bubble.assistant {
  align-self: flex-start;
}

.chat-bubble .role {
  display: block;
  font-size: 11px;
  color: var(--text-faint);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-bubble.system {
  align-self: center;
  color: var(--text-muted);
  background: transparent;
  border-style: dashed;
  font-size: 12px;
}

.chat-composer {
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  padding: 10px 12px 12px;
}

.chat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 8px;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}

.check input {
  width: auto;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.chat-input-row textarea {
  min-height: 72px;
  max-height: 180px;
  background: var(--bg-0);
}

/* Export panel */
.export-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.export-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
}

.export-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  background: var(--bg-2);
}

.export-item .row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.export-item .status {
  font-size: 11px;
  color: var(--text-muted);
}

.export-item .status.done {
  color: var(--success);
}

.export-item .status.failed {
  color: var(--danger);
}

.export-item .status.running {
  color: var(--warning);
}

/* Toast */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--bg-3);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.error {
  border-color: rgba(227, 93, 106, 0.5);
  color: #ffb4bb;
}

.toast.success {
  border-color: rgba(76, 175, 130, 0.45);
}

/* Drawer */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 100vw);
  height: 100vh;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
  z-index: 41;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
  margin: 0;
  font-size: 16px;
}

.drawer-body {
  flex: 1;
  overflow: auto;
  padding: 16px;
}

.admin-section h3 {
  margin: 18px 0 10px;
  font-size: 14px;
}

.admin-section > h3:first-child {
  margin-top: 0;
}

.admin-key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.admin-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.data-table th {
  background: var(--bg-2);
  color: var(--text-muted);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.data-table tr:hover td {
  background: var(--bg-hover);
}

.admin-form {
  margin-bottom: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-bottom: 12px;
}

.form-grid .field {
  margin: 0;
}

.form-grid .field.full {
  grid-column: 1 / -1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}

.modal {
  width: min(420px, 100%);
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.modal p {
  margin: 0 0 14px;
  color: var(--text-muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

/* Responsive */
@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 200px minmax(0, 1fr) 240px;
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }

  .pane-left,
  .pane-right {
    border: none;
    border-bottom: 1px solid var(--border);
    max-height: 220px;
  }

  .pane-right {
    max-height: 280px;
    border-top: 1px solid var(--border);
  }

  .chip {
    max-width: 100px;
  }

  .brand-name {
    display: none;
  }

  .editor-body.split {
    grid-template-columns: 1fr;
  }

  .doc-preview {
    border-left: none;
    border-top: 1px solid var(--border-soft);
    min-height: 200px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--topbar-h);
    padding: 8px 10px;
  }
}

@media (max-width: 560px) {
  .topbar-right .btn-ghost {
    padding: 6px 8px;
  }

  .model-select select {
    min-width: 120px;
  }

  .chat-input-row {
    grid-template-columns: 1fr;
  }
}
