:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --bg-pattern: rgba(17, 24, 39, 0.06);
  --panel: #ffffff;
  --panel-strong: #f0f5f7;
  --ink: #111827;
  --muted: #5d6678;
  --soft: #e2e8f0;
  --line: #d7dde8;
  --accent: #047857;
  --accent-strong: #065f46;
  --accent-soft: #d1fae5;
  --gold: #b45309;
  --coral: #be3b3b;
  --shadow: 0 22px 70px rgba(17, 24, 39, 0.12);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315;
  --bg-pattern: rgba(255, 255, 255, 0.07);
  --panel: #191d20;
  --panel-strong: #22282b;
  --ink: #f7fafc;
  --muted: #a8b1bd;
  --soft: #2f373c;
  --line: #3a444b;
  --accent: #34d399;
  --accent-strong: #6ee7b7;
  --accent-soft: #133d32;
  --gold: #f7b955;
  --coral: #f87171;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, transparent 31px, var(--bg-pattern) 32px),
    linear-gradient(transparent 31px, var(--bg-pattern) 32px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--font);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.app-shell {
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: var(--shadow);
}

.brand,
.topbar-actions,
.toolbar-group,
.sidebar-header,
.status-strip,
.panel-heading,
.split-actions,
.wide-button,
.tool-button,
.icon-button,
.primary-action,
.square-button,
.search-field,
.storage-note,
.toggle-row,
.status-pill {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--accent);
}

.brand-mark svg {
  width: 25px;
  height: 25px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.15rem, 1rem + 0.55vw, 1.65rem);
  letter-spacing: 0;
  line-height: 1.1;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.topbar-actions {
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-action,
.icon-button,
.tool-button,
.wide-button,
.square-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease;
}

.primary-action:hover,
.icon-button:hover,
.tool-button:hover,
.wide-button:hover,
.square-button:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.primary-action {
  gap: 8px;
  padding: 0 16px;
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.primary-action.recording {
  border-color: var(--coral);
  background: var(--coral);
}

.icon-button,
.tool-button,
.wide-button {
  gap: 8px;
  padding: 0 12px;
}

.square-button {
  justify-content: center;
  width: 40px;
  padding: 0;
}

.danger {
  color: var(--coral);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(0, 1fr) minmax(260px, 330px);
  gap: 16px;
  margin-top: 16px;
}

.sidebar,
.editor-pane,
.inspector {
  min-width: 0;
}

.sidebar,
.inspector {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar,
.editor-pane,
.tool-panel,
.metric-grid {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: var(--shadow);
}

.sidebar {
  min-height: calc(100vh - 124px);
  padding: 14px;
}

.sidebar-header {
  justify-content: space-between;
  gap: 10px;
}

.search-field {
  gap: 8px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.search-field input,
.stack input,
.dictation-controls select,
.title-input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.session-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.session-item {
  display: grid;
  gap: 6px;
  width: 100%;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.session-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.session-title {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.storage-note {
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.editor-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: calc(100vh - 124px);
  padding: 14px;
}

.status-strip {
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.status-pill {
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.82rem;
  font-weight: 800;
}

.save-state {
  color: var(--muted);
  font-size: 0.82rem;
}

.document-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.title-input {
  min-height: 48px;
  padding: 0 2px;
  font-size: clamp(1.45rem, 1.2rem + 1vw, 2.35rem);
  font-weight: 850;
  letter-spacing: 0;
}

.toolbar-group {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.dictation-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(200px, 250px);
  gap: 12px;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  overflow: hidden;
}

.dictation-left {
  position: relative;
  min-height: 180px;
}

#voiceCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 180px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent-soft) 58%, transparent), transparent),
    var(--panel);
}

.live-buffer {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px);
}

.buffer-label {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
}

.live-buffer p {
  display: -webkit-box;
  overflow: hidden;
  min-height: 2.8em;
  margin: 0;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-height: 1.4;
}

.dictation-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.field-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.dictation-controls select,
.stack input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.toggle-row {
  gap: 9px;
  color: var(--muted);
  font-size: 0.88rem;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

#editor {
  flex: 1;
  width: 100%;
  min-height: 380px;
  resize: none;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.05rem;
  line-height: 1.75;
  box-shadow: inset 0 0 0 1px transparent;
}

#editor:focus,
.title-input:focus,
.stack input:focus,
.dictation-controls select:focus,
.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  padding: 0;
  background: var(--line);
}

.metric {
  min-width: 0;
  padding: 15px;
  background: var(--panel);
}

.metric span {
  display: block;
  overflow: hidden;
  font-size: 1.65rem;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
}

.metric p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.tool-panel {
  padding: 14px;
}

.panel-heading {
  gap: 8px;
  margin-bottom: 12px;
}

.panel-heading svg {
  color: var(--accent);
}

.stack {
  display: grid;
  gap: 9px;
}

.split-actions {
  gap: 8px;
}

.split-actions > * {
  flex: 1;
  justify-content: center;
}

.command-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.command-grid button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink);
}

.command-grid button:hover {
  border-color: var(--accent);
}

.wide-button {
  justify-content: center;
  width: 100%;
  text-align: center;
}

.file-input-label {
  cursor: pointer;
}

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

.toast-region {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  z-index: 20;
}

.toast {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--panel);
  box-shadow: var(--shadow);
}

body.printing .topbar,
body.printing .sidebar,
body.printing .inspector,
body.printing .status-strip,
body.printing .dictation-panel,
body.printing .document-toolbar .toolbar-group {
  display: none;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .inspector {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 840px) {
  .app-shell {
    padding: 10px;
  }

  .topbar,
  .document-toolbar,
  .dictation-panel,
  .workspace,
  .inspector {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions,
  .toolbar-group {
    justify-content: stretch;
  }

  .topbar-actions > *,
  .toolbar-group > * {
    flex: 1;
    justify-content: center;
  }

  .sidebar,
  .editor-pane {
    min-height: auto;
  }

  .session-list {
    max-height: 260px;
  }

  .dictation-controls {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .brand {
    align-items: flex-start;
  }

  .topbar-actions,
  .toolbar-group,
  .split-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .primary-action {
    grid-column: 1 / -1;
  }

  .title-input {
    font-size: 1.35rem;
  }

  #editor {
    min-height: 420px;
    padding: 16px;
    font-size: 1rem;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .sidebar,
  .inspector,
  .status-strip,
  .dictation-panel,
  .document-toolbar .toolbar-group {
    display: none !important;
  }

  .app-shell,
  .workspace,
  .editor-pane {
    display: block;
    width: 100%;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  #editor {
    min-height: 0;
    border: 0;
    color: #000000;
  }
}
