:root {
  --navy: #0d355d;
  --navy-dark: #082642;
  --teal: #087f78;
  --ink: #172531;
  --muted: #64717c;
  --line: #d6dde2;
  --panel: #ffffff;
  --surface: #edf1f3;
  --paper-shadow: 0 12px 35px rgba(15, 35, 50, 0.18);
  --danger: #b42318;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--surface);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button, select, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.42; }

.app-header {
  height: 70px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(420px, 2fr) minmax(170px, 1fr);
  align-items: center;
  gap: 20px;
  padding: 0 22px;
  color: #fff;
  background: var(--navy-dark);
  border-bottom: 4px solid var(--teal);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
  width: max-content;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid #63d1c8;
  color: #63d1c8;
  font-family: Georgia, serif;
  font-weight: 700;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 2px; color: #b8c8d4; font-size: 12px; }

.document-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}

.select-label { font-size: 12px; color: #b8c8d4; }

select, input[type="number"], textarea {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
}

select { min-width: 250px; height: 38px; padding: 0 34px 0 11px; }

.button, .tool-button, .icon-button {
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border-radius: 4px;
}

.button { padding: 0 15px; font-weight: 700; }
.button.primary { justify-self: end; background: #f1b640; color: #222; }
.button.primary:hover:not(:disabled) { background: #ffd06c; }
.button.secondary { border-color: #698198; background: transparent; color: #fff; }
.button.secondary:hover { background: #17466f; }
.button svg, .tool-button svg { width: 17px; }

.satisfaction-dialog {
  width: min(520px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 24px 70px rgba(8, 38, 66, .28);
}
.satisfaction-dialog::backdrop { background: rgba(8, 38, 66, .62); }
.satisfaction-dialog form { padding: 28px; text-align: center; }
.satisfaction-icon {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin: 0 auto 14px;
  border-radius: 50%;
  color: #fff;
  background: var(--teal);
}
.satisfaction-icon svg { width: 25px; }
.satisfaction-dialog h2 { margin: 0; color: var(--navy); font-family: Georgia, serif; font-size: 24px; }
.satisfaction-dialog p { margin: 12px auto 20px; color: var(--muted); line-height: 1.5; }
.satisfaction-dialog small { display: block; margin-top: 14px; color: var(--muted); line-height: 1.4; }
.satisfaction-actions { display: flex; justify-content: center; gap: 9px; }
.dialog-secondary { border-color: var(--line); color: var(--navy); background: #fff; }
.dialog-primary { color: #fff; background: var(--teal); }
.dialog-primary:hover { background: #066a65; }

.app-shell {
  height: calc(100vh - 70px);
  height: calc(100dvh - 70px);
  display: grid;
  grid-template-columns: 158px minmax(420px, 1fr) 250px;
  overflow: hidden;
}

.page-panel, .properties-panel {
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
.properties-panel { border-right: 0; border-left: 1px solid var(--line); }

.panel-heading {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--navy);
}

.count {
  min-width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--teal);
  font-size: 11px;
}

.page-list { height: calc(100% - 48px); overflow-y: auto; padding: 12px; }

.page-item {
  width: 100%;
  height: 82px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8fafb;
  color: var(--muted);
}
.page-item:hover { border-color: var(--teal); }
.page-item.active { border: 2px solid var(--teal); color: var(--navy); background: #eaf6f4; }

.editor-area { position: relative; min-width: 0; min-height: 0; display: grid; grid-template-rows: 52px minmax(0, 1fr) 28px; }

.tool-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 7px 14px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.tool-group { display: flex; gap: 5px; padding-right: 14px; border-right: 1px solid var(--line); }
.tool-button, .icon-button { background: #fff; color: var(--navy); border-color: var(--line); }
.tool-button { padding: 0 11px; }
.icon-button { width: 36px; padding: 0; }
.tool-button:hover:not(:disabled), .icon-button:hover:not(:disabled) { border-color: var(--teal); background: #eaf6f4; }
.tool-button.active { color: #fff; border-color: var(--teal); background: var(--teal); }
.icon-button.danger { color: var(--danger); }
.icon-button svg { width: 17px; }

.zoom-control { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.zoom-control output { width: 58px; text-align: center; color: var(--muted); font-size: 12px; }

.ai-draft-banner {
  position: absolute;
  z-index: 8;
  top: 64px;
  left: 18px;
  right: 18px;
  min-height: 66px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto 36px;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid #b7cbd7;
  border-left: 4px solid var(--teal);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 24px rgba(8, 38, 66, .18);
}
.ai-draft-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--navy);
}
.ai-draft-icon svg { width: 19px; }
.ai-draft-copy { min-width: 0; }
.ai-draft-copy strong, .ai-draft-copy small { display: block; }
.ai-draft-copy strong { color: var(--navy); font-size: 14px; }
.ai-draft-copy small { margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.ai-logo-button { min-height: 38px; color: #fff; background: var(--teal); }
.ai-logo-button:hover { background: #066a65; }
.ai-banner-close { border-color: transparent; }

.workspace {
  position: relative;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 34px;
  background-color: #dfe5e8;
  background-image: linear-gradient(45deg, rgba(255,255,255,.28) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.28) 75%), linear-gradient(45deg, rgba(255,255,255,.28) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.28) 75%);
  background-position: 0 0, 12px 12px;
  background-size: 24px 24px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: #75838d;
}
.empty-state svg { width: 52px; height: 52px; stroke-width: 1.3; }
.empty-state .empty-upload { border-color: var(--teal); background: var(--teal); color: #fff; }
.empty-state .empty-upload:hover { background: #066a65; }
.empty-state .empty-upload svg { width: 17px; height: 17px; stroke-width: 2; }

.page-stage {
  position: relative;
  width: max-content;
  margin: 0 auto;
  background: white;
  box-shadow: var(--paper-shadow);
}

#pdf-canvas { display: block; }

.overlay-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: pan-x pan-y;
}
.overlay-layer.drawing { cursor: crosshair; touch-action: none; }

.workspace::-webkit-scrollbar { width: 14px; height: 14px; }
.workspace::-webkit-scrollbar-track { background: #cbd4d9; }
.workspace::-webkit-scrollbar-thumb { border: 3px solid #cbd4d9; border-radius: 7px; background: #657681; }
.workspace::-webkit-scrollbar-thumb:hover { background: #41545f; }

.editor-element {
  position: absolute;
  min-width: 10px;
  min-height: 10px;
  border: 1px dashed transparent;
  cursor: move;
  user-select: none;
  touch-action: none;
}
.editor-element:hover { border-color: rgba(8, 127, 120, 0.65); }
.editor-element.selected { border: 2px solid var(--teal); }
.editor-element.text-element { white-space: pre-wrap; overflow: hidden; line-height: 1.2; }
.editor-element.source-text { cursor: text; }
.editor-element.source-text:hover { background: rgba(8, 127, 120, 0.08); }
.editor-element.source-text.modified { background: #fff; }
.editor-element.source-image { cursor: pointer; }
.editor-element.source-image:hover { background: rgba(8, 127, 120, 0.12); }
.source-text-cover {
  position: absolute;
  z-index: 0;
  display: block;
  background: #fff;
  pointer-events: none;
}
.editor-element img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.editor-element svg { display: block; overflow: visible; width: 100%; height: 100%; }

.resize-handle {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 13px;
  height: 13px;
  border: 2px solid #fff;
  background: var(--teal);
  cursor: nwse-resize;
}

.status { padding: 6px 14px; border-top: 1px solid var(--line); background: #fff; color: var(--muted); font-size: 11px; }
.status.error { color: var(--danger); }

.no-selection { padding: 22px 16px; color: var(--muted); font-size: 13px; }
#properties-form { padding: 16px; }
#properties-form label { display: block; margin-bottom: 16px; }
#properties-form label > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
#properties-form textarea { width: 100%; resize: vertical; padding: 9px; line-height: 1.4; }
#properties-form input[type="number"] { width: 100%; height: 36px; padding: 0 8px; }
#properties-form input[type="color"] { width: 100%; height: 36px; padding: 3px; border: 1px solid var(--line); background: #fff; }
#properties-form input[type="range"] { width: 100%; accent-color: var(--teal); }
.property-button {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--teal);
  border-radius: 4px;
  color: var(--teal);
  background: #fff;
  font-weight: 700;
}
.property-button:hover { color: #fff; background: var(--teal); }
.property-button svg { width: 17px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

@media (max-width: 900px) {
  .app-header { grid-template-columns: 1fr auto; height: auto; min-height: 70px; padding: 10px 14px; }
  .document-controls { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; }
  .app-shell { height: calc(100vh - 124px); grid-template-columns: 90px minmax(320px, 1fr); }
  .properties-panel { position: fixed; right: 0; top: 124px; bottom: 0; width: 250px; z-index: 10; transform: translateX(100%); }
  .page-list { padding: 7px; }
  .page-item { height: 60px; }
  .workspace { padding: 20px; }
}

@media (max-width: 620px) {
  .brand small, .select-label, .tool-button span { display: none; }
  .app-header { grid-template-columns: 1fr auto; }
  select { min-width: 180px; max-width: 55vw; }
  .button { padding: 0 10px; }
  .app-shell { grid-template-columns: 1fr; }
  .page-panel { display: none; }
  .tool-row { gap: 6px; padding-inline: 7px; max-width: 100vw; overflow-x: auto; }
  .tool-group { padding-right: 7px; }
  .zoom-control { margin-left: 0; }
  .ai-draft-banner { left: 8px; right: 8px; grid-template-columns: 32px minmax(0, 1fr) 32px; }
  .ai-draft-icon { width: 32px; height: 32px; }
  .ai-logo-button { grid-column: 1 / -1; grid-row: 2; }
  .ai-banner-close { grid-column: 3; grid-row: 1; }
  .satisfaction-actions { align-items: stretch; flex-direction: column; }
  .satisfaction-actions .button { min-height: 42px; }
}