/* ===== APP RESET ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  font-family: var(--font);
  background: #f4f4f4;
}

body {
  min-width: 0;
  height: 100vh;
  margin: 0;
  overflow: hidden;
  color: #171717;
  background: #f4f4f4;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

/* ===== TOOLBAR ===== */
.toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 18px;
  border-bottom: 1px solid #dedede;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toolbar-title {
  margin-right: 12px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #f7f7f7;
}

.segmented button {
  min-width: 42px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  color: #5c5c5c;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
}

.segmented button.is-active {
  color: #111;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 148px;
  font-size: 12px;
  color: #5c5c5c;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #2f8f4e;
}

.status.is-unsaved .status-dot {
  background: #b26a00;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #d4d4d4;
  border-radius: 8px;
  color: #171717;
  background: #fff;
  font-size: 12px;
  font-weight: 650;
}

.button:hover {
  border-color: #a8a8a8;
}

.button:disabled,
.small-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.button.primary {
  color: #fff;
  border-color: #111;
  background: #111;
}

.button.warning {
  color: #7a4a00;
  border-color: #e0b35d;
  background: #fff8ea;
}

.button.danger {
  color: #8f1d1d;
  border-color: #e0b5b5;
  background: #fff5f5;
}

.button-icon {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

.editor-notice {
  position: fixed;
  top: 68px;
  right: 18px;
  z-index: 25;
  max-width: 390px;
  padding: 12px 14px;
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  color: #202020;
  background: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
  font-size: 12px;
  line-height: 1.45;
}

.editor-notice.is-info {
  border-color: #cfd6e4;
}

.editor-notice.is-warning {
  border-color: #e0b35d;
  color: #6f4400;
  background: #fff9ec;
}

.editor-notice.is-error {
  border-color: #dfb0b0;
  color: #831f1f;
  background: #fff5f5;
}

/* ===== LAYOUT ===== */
.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 390px) minmax(0, 1fr);
  height: 100vh;
  padding-top: 56px;
}

.panel-editor {
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
  overflow-y: auto;
  border-right: 1px solid #dedede;
  background: #fff;
}

.panel-editor-inner {
  padding: 18px 18px 28px;
}

.panel-preview {
  --preview-gutter: clamp(24px, 3vw, 40px);
  min-height: calc(100vh - 56px);
  overflow: auto;
  padding: var(--preview-gutter) var(--preview-gutter) calc(var(--preview-gutter) + 16px);
  background: #f4f4f4;
}

.preview-frame {
  width: max-content;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.16);
}

/* ===== EDITOR FORM ===== */
.editor-empty {
  padding: 16px;
  border: 1px dashed #cfcfcf;
  border-radius: 8px;
  color: #6a6a6a;
  font-size: 13px;
  line-height: 1.45;
}

.editor-section {
  border-bottom: 1px solid #ececec;
}

.editor-section:first-child {
  border-top: 1px solid #ececec;
}

.editor-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  list-style: none;
  color: #1c1c1c;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.editor-section summary::-webkit-details-marker {
  display: none;
}

.summary-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.summary-caret {
  width: 16px;
  color: #8a8a8a;
  font-size: 12px;
}

.editor-section[open] .summary-caret {
  transform: rotate(90deg);
}

.section-body {
  display: grid;
  gap: 14px;
  padding-bottom: 18px;
}

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

.field label {
  color: #5e5e5e;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid #d7d7d7;
  border-radius: 7px;
  color: #171717;
  background: #fff;
  font-size: 13px;
  line-height: 1.45;
}

.field input {
  height: 36px;
  padding: 0 10px;
}

.field textarea {
  min-height: 88px;
  padding: 9px 10px;
  resize: vertical;
}

.field textarea.field-textarea-inline {
  min-height: 36px;
  padding: 7px 10px;
  line-height: 1.4;
}

.field input:focus,
.field textarea:focus {
  border-color: #111;
  outline: 2px solid rgba(17, 17, 17, 0.08);
}

.field.is-invalid input,
.field.is-invalid textarea,
.bullet-entry.is-invalid textarea {
  border-color: #b44242;
  background: #fffafa;
}

.field-error {
  color: #9b1c1c;
  font-size: 11px;
  line-height: 1.35;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.item-card {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  background: #fafafa;
}

.item-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.item-title {
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-actions {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 6px;
}

.order-actions {
  display: inline-flex;
  gap: 4px;
}

.small-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #d4d4d4;
  border-radius: 7px;
  color: #282828;
  background: #fff;
  font-size: 12px;
  font-weight: 750;
}

.small-button:hover {
  border-color: #9e9e9e;
}

.small-button.danger {
  color: #9b1c1c;
}

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

.bullet-entry {
  display: grid;
  gap: 5px;
}

.bullet-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  align-items: start;
}

.role-list {
  gap: 7px;
}

.role-entry {
  display: grid;
  gap: 5px;
}

.role-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px;
  align-items: start;
}

.role-actions {
  display: inline-flex;
  gap: 4px;
}

.bullet-actions {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.bullet-row textarea {
  min-height: 64px;
}

.print-hint {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: 310px;
  padding: 14px 16px;
  border: 1px solid #d6d6d6;
  border-radius: 8px;
  color: #202020;
  background: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.16);
  font-size: 12px;
  line-height: 1.45;
}

.print-hint strong {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
}

/* ===== PRINT ===== */
@media print {
  html,
  body {
    width: 210mm;
    height: 297mm;
    min-width: 0;
    overflow: visible;
    background: white;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .toolbar,
  .panel-editor,
  .editor-notice,
  .print-hint {
    display: none !important;
  }

  .app-shell {
    display: block;
    min-height: 0;
    padding-top: 0;
  }

  .panel-preview {
    display: block;
    width: 210mm;
    min-height: 297mm;
    overflow: visible;
    padding: 0;
    background: white;
  }

  .preview-frame {
    width: 210mm;
    margin: 0;
    box-shadow: none;
  }

  .cv {
    box-shadow: none;
  }
}

@media screen and (max-width: 980px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .toolbar {
    position: sticky;
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 14px;
  }

  .toolbar-group {
    min-width: 0;
    overflow-x: auto;
  }

  .app-shell {
    display: block;
    height: auto;
    padding-top: 0;
  }

  .panel-editor {
    position: relative;
    top: auto;
    height: auto;
    max-height: 52vh;
    border-right: 0;
    border-bottom: 1px solid #dedede;
  }

  .panel-preview {
    min-height: 0;
  }
}
