:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-muted: #f6f8fb;
  --border: #d7dee8;
  --border-strong: #c4cedb;
  --text: #172033;
  --muted: #667085;
  --soft: #8a95a6;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #dff5f1;
  --blue: #2357a4;
  --blue-soft: #e8f0fb;
  --danger-bg: #fff5eb;
  --danger: #9a3412;
  --shadow: 0 18px 48px rgb(23 32 51 / 10%);
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  overflow-x: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, #f8fafc 0%, var(--bg) 48%, #e7edf4 100%);
}

h1,
h2,
h3,
p {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: 19px; }
h2 { font-size: 16px; }
h3 { font-size: 13px; }
p { color: var(--muted); font-size: 13px; margin-top: 3px; }

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 9px 13px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
  white-space: nowrap;
}

button:hover { background: var(--accent-strong); }
button:disabled { opacity: .48; cursor: not-allowed; }

.app-header {
  height: 64px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 0 20px;
  background: rgb(255 255 255 / 86%);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand,
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.status-pill {
  min-width: 0;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
}

.primary-action {
  background: var(--text);
}

.primary-action:hover {
  background: #2b3448;
}

.workspace {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(290px, 360px) minmax(330px, 35vw) minmax(420px, 1fr);
  gap: 14px;
  padding: 14px;
  min-height: 0;
}

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-title {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-muted);
}

.panel-title > div {
  min-width: 0;
}

.panel-title p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field,
#markdownMode,
#docxMode {
  display: grid;
  gap: 8px;
}

#markdownMode,
#docxMode {
  min-height: 0;
  flex: 1;
  padding: 14px 16px 16px;
}

#markdownMode {
  grid-template-rows: auto minmax(0, 1fr) auto;
}

#docxMode {
  align-content: start;
}

label {
  font-size: 12px;
  font-weight: 750;
  color: var(--muted);
}

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

select {
  height: 40px;
  padding: 0 10px;
}

textarea {
  min-height: 0;
  height: 100%;
  resize: none;
  padding: 12px;
  line-height: 1.52;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

textarea:focus,
select:focus,
input[type="file"]:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.tab {
  min-height: 30px;
  padding: 6px 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

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

.tab.active {
  background: var(--blue);
  color: #fff;
}

.action-row {
  display: flex;
  justify-content: flex-end;
}

.file-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

input[type="file"] {
  padding: 8px;
  font-size: 13px;
}

.hidden { display: none !important; }

.issues {
  flex: 0 0 auto;
  display: grid;
  gap: 8px;
  padding: 0 16px;
}

.issues:not(:empty) {
  padding-top: 12px;
}

.issue {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 10px;
  border-radius: 7px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 13px;
}

.issue span {
  flex: 0 0 7px;
  width: 7px;
  height: 7px;
  margin-top: 6px;
  border-radius: 50%;
  background: currentColor;
}

#preview {
  min-height: 0;
  overflow: auto;
  padding: 4px 16px 16px;
}

.preview-empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.block {
  display: grid;
  gap: 5px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}

.block:last-child { border-bottom: 0; }

.block-type {
  color: var(--soft);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.block h3 {
  font-size: 16px;
  line-height: 1.35;
}

.block p,
.block li {
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.block ol,
.block ul {
  margin: 0;
  padding-left: 22px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  border: 1px solid var(--border);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

th { background: #eef3f8; }

pre {
  overflow: auto;
  margin: 0;
  padding: 12px;
  background: #f6f8fa;
  border-radius: 7px;
}

.template-panel {
  padding-bottom: 4px;
}

.template-panel .field {
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
}

.template-spec {
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 16px;
}

.template-spec-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.template-spec-heading h3 {
  font-size: 15px;
}

.secondary-action {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  background: #fff;
  color: var(--text);
  font-size: 12px;
}

.secondary-action:hover {
  background: var(--blue-soft);
  color: var(--blue);
}

.style-controls {
  display: grid;
  gap: 14px;
  padding-top: 14px;
}

.style-group {
  display: grid;
  gap: 8px;
}

.style-group h3 {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

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

.style-control {
  display: grid;
  gap: 4px;
}

.style-control span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.style-control input {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0 9px;
  background: #fff;
  color: var(--text);
}

.unit-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
}

.unit-field input {
  border: 0;
}

.unit-field em {
  color: var(--soft);
  font-size: 12px;
  font-style: normal;
  text-align: center;
}

.color-control {
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
}

.color-control input {
  width: 44px;
  padding: 4px;
}

.spec-details {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.spec-details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.spec-groups {
  display: grid;
  gap: 14px;
  padding-top: 14px;
}

.spec-group {
  display: grid;
  gap: 7px;
}

.spec-group h3 {
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.spec-group ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 17px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 64px);
    grid-template-columns: 1fr 1fr;
  }

  .preview-panel {
    grid-column: 1 / -1;
  }

  #markdownMode {
    min-height: 430px;
  }
}

@media (max-width: 760px) {
  .app-header {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 14px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
  }

  .status-pill {
    width: 100%;
    max-width: none;
  }

  .primary-action {
    width: 100%;
  }

  .workspace {
    height: auto;
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-title > div {
    width: 100%;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .file-control {
    grid-template-columns: 1fr;
  }

  .action-row button,
  .file-control button {
    width: 100%;
  }

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