:root {
  --window-bg: #ece9d8;
  --panel-bg: #ffffff;
  --line: #b6b6b6;
  --text: #111111;
  --muted: #555555;
  --tab: #f1f1f1;
  --tab-active: #ffffff;
  --button: #f3f3f3;
  --button-border: #8e8e8e;
  --status: #f6f6f6;
  --chat-width: 360px;
  --mono: Consolas, "Courier New", monospace;
  --ui: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--window-bg);
  color: var(--text);
  font-family: var(--ui);
}

body.setup-required {
  overflow: hidden;
}

button,
select,
textarea {
  font: inherit;
}

.window {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.titlebar {
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfbfb 0%, #e8e8e8 100%);
  font-size: 0.9rem;
}

.menubar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
  background: #f7f7f7;
}

.menubar button,
.menubar select,
.chat-header button,
.chat-form button {
  height: 30px;
  border: 1px solid var(--button-border);
  background: var(--button);
  color: var(--text);
  padding: 0 0.75rem;
}

.menubar select {
  min-width: 220px;
}

.notepad {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--panel-bg);
  min-height: 0;
  height: 100%;
}

.workspace {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.editor-shell {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #ffffff;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem 0.45rem 0;
  border-bottom: 1px solid var(--line);
  background: #f5f5f5;
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.65rem;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: var(--tab);
  cursor: pointer;
}

.tab.active {
  background: var(--tab-active);
}

.tab-close {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
}

.editor-shell #editor,
.editor-shell .editor-preview {
  padding-right: 1rem;
  padding-bottom: 8.5rem;
}

.voice-dock {
  position: absolute;
  left: 50%;
  bottom: 1rem;
  transform: translateX(-50%);
  width: min(640px, calc(100% - 2rem));
  z-index: 4;
  pointer-events: none;
}

.voice-dock-panel {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: min(100%, 240px);
  margin: 0 auto;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.14);
}

.voice-dock.is-recording .voice-dock-panel,
.voice-dock.has-transcript .voice-dock-panel {
  width: 100%;
  max-width: 100%;
}

.voice-dock-transcript {
  width: 100%;
  min-height: 120px;
  max-height: 180px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #ffffff;
  color: var(--text);
  padding: 0.85rem 0.95rem;
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.45;
}

.voice-dock:not(.is-recording):not(.has-transcript) .voice-dock-transcript {
  display: none;
}

.voice-dock-toggle {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  background: #f7f7f7;
  color: var(--text);
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.voice-dock-toggle:disabled {
  cursor: wait;
  opacity: 0.72;
}

.voice-dock-meta {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fcfcfc;
  padding: 0.7rem 0.8rem;
  font-size: 0.82rem;
}

.voice-dock-meta.is-hidden {
  display: none;
}

.voice-dock-meta-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--muted);
}

.voice-dock-task-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.voice-dock-task {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  padding: 0.5rem 0.65rem;
  white-space: pre-wrap;
  line-height: 1.35;
}

.voice-dock-debug {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.voice-dock-debug-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.voice-dock-debug-filters.is-hidden {
  display: none;
}

.voice-dock-debug-toggle {
  align-self: flex-start;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.voice-dock-debug-filter {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  cursor: pointer;
}

.voice-dock-debug-filter.is-active {
  background: #0f1720;
  border-color: #0f1720;
  color: #d7e6f5;
}

.voice-dock-debug-output {
  margin: 0;
  min-height: 120px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0f1720;
  color: #d7e6f5;
  padding: 0.75rem 0.85rem;
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.voice-dock-debug-output.is-hidden {
  display: none;
}

#editor {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  resize: none;
  border: 0;
  background: #ffffff;
  color: var(--text);
  padding: 0.9rem;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.45;
}

#editor.is-hidden {
  display: none;
}

#editor:focus {
  outline: none;
}

.editor-preview {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 0.9rem;
  background: #ffffff;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.55;
  cursor: text;
}

.editor-preview.is-hidden {
  display: none;
}

.editor-preview:focus {
  outline: none;
}

.editor-line {
  white-space: pre-wrap;
  min-height: 1.45em;
  margin: 0;
}

.editor-line + .editor-line {
  margin-top: 0.15rem;
}

.editor-line.h1 {
  font-family: var(--ui);
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 0.15rem;
  margin-bottom: 0.45rem;
}

.editor-line.h2 {
  font-family: var(--ui);
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 0.65rem;
  margin-bottom: 0.25rem;
}

.editor-line.h3 {
  font-family: var(--ui);
  font-size: 1.08rem;
  font-weight: 700;
  line-height: 1.3;
  margin-top: 0.45rem;
  margin-bottom: 0.1rem;
}

.editor-line.empty {
  min-height: 0.9rem;
}

.editor-line.meta {
  color: var(--muted);
}

.preview-block {
  position: relative;
}

.preview-block + .preview-block {
  margin-top: 0.55rem;
}

.preview-block.active {
  outline: 1px solid #d9d9d9;
  outline-offset: 0.15rem;
}

.setup-overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(233, 233, 233, 0.82);
  z-index: 10;
  padding: 1.25rem;
}

.setup-overlay.is-hidden {
  display: none;
}

.setup-card {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: 0 14px 42px rgba(0, 0, 0, 0.14);
  padding: 1rem 1rem 0.9rem;
}

.setup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.setup-card h1 {
  margin: 0;
  font-size: 1.15rem;
}

.setup-close {
  height: 30px;
  border: 1px solid var(--button-border);
  background: var(--button);
  padding: 0 0.7rem;
}

.setup-copy {
  margin: 0.55rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.9rem;
}

.setup-meta {
  margin: 0.5rem 0 0.9rem;
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.85rem;
}

.setup-form {
  display: grid;
  gap: 0.8rem;
}

.setup-field {
  display: grid;
  gap: 0.3rem;
}

.setup-field.is-hidden {
  display: none;
}

.setup-field input,
.setup-field select {
  height: 34px;
  border: 1px solid var(--button-border);
  padding: 0 0.65rem;
  background: #ffffff;
}

.setup-actions {
  display: flex;
  gap: 0.5rem;
}

.setup-actions button {
  height: 34px;
  border: 1px solid var(--button-border);
  background: var(--button);
  padding: 0 0.85rem;
}

.setup-status {
  margin-top: 0.85rem;
  border: 1px solid var(--line);
  background: #f7f7f7;
  padding: 0.7rem;
  white-space: pre-wrap;
  min-height: 76px;
  font-size: 0.84rem;
  line-height: 1.42;
}

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.3rem 0.6rem;
  border-top: 1px solid var(--line);
  background: var(--status);
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
}

.statusbar span {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 900px) {
  :root {
    --chat-width: min(100vw, 340px);
  }

  .editor-shell #editor,
  .editor-shell .editor-preview {
    padding-right: 1rem;
  }
}
