:root {
  --bg: #e8edf0;
  --panel: #fbfcfd;
  --ink: #182026;
  --muted: #68727d;
  --line: #cfd7de;
  --accent: #2f6f73;
  --accent-ink: #ffffff;
  --danger: #9f3a38;
  --focus: #d99a2b;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  display: grid;
  grid-template-columns: 320px 1fr 1fr;
  gap: 12px;
  height: 100%;
  padding: 12px;
}

.shell.collapsed-sidebar {
  grid-template-columns: 1fr 1fr;
}

.panel {
  min-width: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.control {
  display: flex;
  flex-direction: column;
  padding: 14px;
  overflow: auto;
}

.shell.collapsed-sidebar .control {
  display: none !important;
}

.editor {
  display: flex;
  flex-direction: column;
}

.editor header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.editor-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1e293b;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
}

.editor-body textarea {
  flex: 1;
  width: 100%;
  height: 100%;
  padding: 14px;
  border: none;
  outline: none;
  resize: none;
  font-family: "JetBrains Mono", Consolas, Menlo, Courier, monospace;
  font-size: 13px;
  line-height: 1.6;
  background: transparent;
  color: #f8fafc;
  white-space: pre-wrap;
  word-break: break-all;
  transition: background 0.2s ease;
}

.editor-body textarea.drag-over {
  background: rgba(14, 165, 233, 0.1) !important;
  outline: 2px dashed var(--accent) !important;
  outline-offset: -4px;
}

.toggle-sidebar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 4px;
  cursor: pointer;
}

.toggle-sidebar-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.download-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  color: #fff !important;
  border-radius: 4px;
  text-decoration: none;
  transition: opacity 0.2s;
}

.download-link-btn:hover {
  opacity: 0.9;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.editor header {
  margin-bottom: 0;
}

h1,
h2 {
  margin: 0;
  font-size: 14px;
  line-height: 1.2;
}

#serverState {
  max-width: 120px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropzone {
  display: grid;
  gap: 6px;
  min-height: 90px;
  margin-bottom: 14px;
  padding: 12px;
  place-content: center;
  text-align: center;
  border: 1px dashed #8fa2ae;
  border-radius: 8px;
  background: #f2f6f7;
  cursor: pointer;
}

.dropzone input {
  display: none;
}

.dropzone strong {
  font-size: 14px;
}

.dropzone small,
.field span {
  color: var(--muted);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

select,
input[type="text"],
button {
  height: 34px;
  border-radius: 6px;
  font: inherit;
}

select,
input[type="text"] {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

input[type="text"] {
  padding: 0 10px;
}

.toggles {
  display: grid;
  gap: 8px;
  margin: 4px 0 16px;
}

.toggles.compact {
  margin: 0 0 10px;
}

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 4px;
}

.format-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.format-panel h2 {
  color: var(--ink);
}

.margin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
}

button:disabled {
  border-color: var(--line);
  background: #d7dee3;
  color: #73808c;
  cursor: not-allowed;
}

.preview {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.preview-tab {
  flex: 1;
  height: 34px;
  border: none;
  border-radius: 0;
  background: #f2f6f7;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.preview-tab:first-child {
  border-top-left-radius: 8px;
}

.preview-tab:last-child {
  border-top-right-radius: 8px;
}

.preview-tab.active {
  background: var(--panel);
  color: var(--ink);
}

.preview-tab:hover:not(.active) {
  background: #e2e8f0;
  color: var(--ink);
}

.preview-body {
  flex: 1;
  position: relative;
}

.preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #f7f8f9;
  display: none;
}

.preview-frame.active {
  display: block;
}

.saved-indicator {
  font-size: 11px;
  color: #10b981;
  background: rgba(16, 185, 129, 0.1);
  padding: 3px 8px;
  border-radius: 4px;
  font-weight: 500;
  pointer-events: none;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(300px, 1fr) minmax(300px, 1fr);
  }
  .shell.collapsed-sidebar {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(300px, 1fr) minmax(300px, 1fr);
  }
}
