:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-soft: #f0f2f5;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #d8dde6;
  --accent: #2b6cb0;
  --accent-strong: #1f4e82;
  --danger: #c53030;
  --warning: #b7791f;
  --code-bg: #f8fafc;
  --code-border: #e2e8f0;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --sidebar-width: 320px;
  --line-height: 1.5em;
  --stack-offset: 120px;
  --control-offset: 60px;
}

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

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

button {
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s, background 0.12s;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(15, 23, 42, 0.08);
}

button.primary {
  background: linear-gradient(120deg, var(--accent) 0%, #3b82f6 100%);
  color: #fff;
  border-color: var(--accent);
}

button.primary.large {
  padding: 14px 20px;
  font-size: 16px;
  border-radius: 12px;
}

button.secondary {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: transparent;
}

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

button.tiny {
  padding: 6px 10px;
  font-size: 12px;
}

button.link-button {
  background: transparent;
  color: var(--accent-strong);
  border-color: transparent;
  padding: 6px 8px;
  text-decoration: underline;
}

input,
textarea {
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  color: var(--text);
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-soft);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: var(--accent-strong);
  border: 1px solid var(--border);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.control-bar {
  position: sticky;
  top: var(--control-offset);
  z-index: 15;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.control-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e2e8f0;
  color: var(--muted);
  font-weight: 600;
}

.active-indicator {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  min-width: 0;
}

.active-indicator .value {
  color: var(--text);
  font-weight: 600;
  max-width: 70%;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.app-shell {
  display: flex;
  position: relative;
  min-height: calc(100vh - var(--stack-offset));
}

.empty-panel {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 2;
  pointer-events: auto;
}

.empty-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  width: min(600px, 90vw);
  box-shadow: var(--shadow);
}

.empty-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 8px;
}

.empty-body p {
  margin: 6px 0;
}

.empty-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

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

.inline-warning {
  margin-top: 8px;
  padding: 10px 12px;
  background: #fffaf0;
  border: 1px solid #f6e05e;
  border-radius: 10px;
  color: #744210;
}

.status-banner {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  margin-bottom: 12px;
  color: var(--text);
  font-weight: 600;
}

.edge-handle {
  width: 10px;
  background: var(--surface-soft);
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s ease, opacity 0.2s ease;
  opacity: 0.7;
  flex-shrink: 0;
  height: calc(100vh - var(--stack-offset));
  position: sticky;
  top: var(--stack-offset);
}

.edge-handle:hover {
  opacity: 1;
}

.sidebar {
  position: sticky;
  top: var(--stack-offset);
  height: calc(100vh - var(--stack-offset));
  background: var(--surface);
  border-right: 1px solid var(--border);
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 8px 0 24px rgba(15, 23, 42, 0.05);
  transition: transform 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.sidebar.unpinned {
  position: fixed;
  left: 0;
  top: var(--stack-offset);
  height: calc(100vh - var(--stack-offset));
  bottom: auto;
  transform: translateX(-100%);
  opacity: 0;
  pointer-events: none;
}

.sidebar.unpinned.overlay-open {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
  z-index: 15;
}

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

.sidebar-title {
  font-weight: 700;
}

.sidebar-subtitle {
  font-size: 12px;
  color: var(--muted);
}

.sidebar-body {
  overflow: hidden;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  min-height: 0;
}

.resize-handle {
  height: 10px;
  cursor: ew-resize;
  width: 100%;
  padding: 4px 0;
  text-align: center;
  border-top: 1px dashed var(--border);
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.tree-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
}

.tree {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  background: var(--surface-soft);
  overflow: auto;
  flex: 1;
  min-height: 0;
}

.placeholder {
  padding: 10px 12px;
  background: var(--surface-soft);
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}

.tree-item[aria-current="location"],
.tree-item:hover {
  background: rgba(43, 108, 176, 0.12);
}

.tree-item.file.active {
  background: rgba(43, 108, 176, 0.15);
  border: 1px solid rgba(43, 108, 176, 0.25);
}

.caret {
  width: 14px;
  text-align: center;
  color: var(--muted);
}

.node-label {
  flex: 1;
  font-size: 13px;
}

.main-pane {
  padding: 16px;
  position: relative;
  flex: 1;
  min-width: 0;
  z-index: 1;
}

.main-pane.inactive {
  pointer-events: none;
}

.file-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.file-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.file-header {
  padding: 10px 12px;
  background: #f4f6f9;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  position: sticky;
  top: 112px;
  z-index: 5;
}

.file-path {
  font-weight: 700;
  color: var(--text);
}

.badge {
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(43, 108, 176, 0.12);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.stat {
  font-size: 12px;
  color: var(--muted);
}

.file-actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

pre {
  margin: 0;
  padding: 14px;
  background: var(--code-bg);
  color: #0f172a;
  font-family: "JetBrains Mono", "SFMono-Regular", "Consolas", monospace;
  overflow: auto;
  white-space: pre-wrap;
  line-height: var(--line-height);
  border-top: 1px solid var(--code-border);
}

pre.nowrap {
  white-space: pre;
}

.panel {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
}

.panel.hidden {
  display: none;
}

.panel-content {
  background: #fff;
  border-radius: 14px;
  width: min(900px, 90vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.panel-header,
.panel-footer {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
}

.panel-title {
  font-size: 18px;
  font-weight: 700;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--muted);
}

.panel-body {
  padding: 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--text);
}

.field textarea {
  width: 100%;
  resize: vertical;
}

.field.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.inline-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 12px;
  color: var(--muted);
}

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

.log-body {
  font-family: "JetBrains Mono", "SFMono-Regular", "Consolas", monospace;
  white-space: pre-wrap;
  background: #0f172a;
  color: #d6e7ff;
  border-radius: 10px;
  padding: 12px;
}

.hidden {
  display: none !important;
}

@media (max-width: 960px) {
  .control-bar {
    grid-template-columns: 1fr;
    justify-items: flex-start;
  }

  .control-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .active-indicator {
    justify-content: flex-start;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: absolute;
    inset: var(--stack-offset) auto 0 0;
    height: calc(100vh - var(--stack-offset));
    min-height: auto;
  }

  .edge-handle {
    width: 14px;
  }

  .file-header {
    top: calc(var(--stack-offset) + 24px);
  }
}
