:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee7;
  --panel: #ffffff;
  --paper: #f5f2ec;
  --bg: #eef1f5;
  --accent: #7a4f2f;
  --accent-dark: #55341d;
  --focus: #1f6feb;
  --danger: #b42318;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #18212b;
  color: #f7f7f2;
  padding: 24px;
  border-right: 1px solid #101821;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: #26313d;
  font-weight: 800;
}

.brand small,
.eyebrow,
.panel-header p {
  display: block;
  color: var(--muted);
  margin: 0;
  font-size: 13px;
}

.brand small {
  color: #aeb8c4;
}

.template-list {
  display: grid;
  gap: 10px;
}

.template-item {
  width: 100%;
  text-align: left;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: #f7f7f2;
  padding: 14px;
  cursor: pointer;
}

.template-item:hover,
.template-item.active {
  border-color: rgba(255, 255, 255, 0.35);
  background: #26313d;
}

.template-item span {
  display: block;
  margin-top: 4px;
  color: #aeb8c4;
  font-size: 12px;
}

.workspace {
  padding: 24px;
  display: grid;
  gap: 20px;
  align-content: start;
}

.topbar,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

h1 {
  font-size: 28px;
}

h2 {
  font-size: 16px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  min-height: 40px;
  border: 1px solid transparent;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 700;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

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

.content-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.85fr) minmax(420px, 1.15fr);
  gap: 20px;
  align-items: start;
}

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

.form-panel,
.preview-panel,
.history-panel {
  padding: 20px;
}

.form-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  font-size: 13px;
  font-weight: 750;
}

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

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 10px 11px;
  min-height: 40px;
  border-radius: 6px;
}

input[type="file"] {
  padding: 8px;
}

textarea {
  min-height: 104px;
  resize: vertical;
}

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

.error {
  color: var(--danger);
  font-size: 12px;
  min-height: 16px;
}

.attachments-box {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.attachments-box h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.attachments-box p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fbfcfd;
}

.attachment-item span {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 750;
}

.document-preview {
  margin-top: 18px;
  min-height: 520px;
  max-height: 720px;
  overflow: auto;
  background: var(--paper);
  border: 1px solid #e3dccf;
  padding: 34px;
  line-height: 1.62;
  white-space: pre-wrap;
}

.document-preview h3 {
  margin: 0 0 18px;
  font-size: 18px;
}

.history-panel {
  margin-bottom: 24px;
}

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfd;
}

.history-item strong,
.history-item span {
  display: block;
  overflow-wrap: anywhere;
}

.history-item span {
  color: var(--muted);
  font-size: 13px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #17202a;
  color: #fff;
  padding: 12px 14px;
  border-radius: 6px;
  box-shadow: 0 14px 38px rgba(17, 24, 39, 0.2);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
  }

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

@media (max-width: 640px) {
  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .form-fields {
    grid-template-columns: 1fr;
  }

  .document-preview {
    padding: 20px;
    min-height: 380px;
  }
}
