:root {
  --ink: #16213a;
  --muted: #667085;
  --line: #e1e6ee;
  --soft: #f4f6fa;
  --panel: #ffffff;
  --navy: #14213d;
  --blue: #3764e8;
  --blue-soft: #edf2ff;
  --green: #15805d;
  --danger: #c33c46;
  --shadow: 0 18px 45px rgba(20, 33, 61, .13);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--soft);
}

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

.app-shell { display: flex; height: 100%; flex-direction: column; }
.topbar {
  height: 66px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--navy);
  color: white;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
  z-index: 5;
}

.brand { display: flex; gap: 11px; align-items: center; }
.brand-mark {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; background: var(--blue); font: 800 22px Georgia, serif;
}
.brand div:last-child { display: flex; flex-direction: column; line-height: 1.15; }
.brand span { margin-top: 4px; color: #aeb9d2; font-size: 11px; letter-spacing: .04em; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.privacy-pill {
  margin-right: 8px; color: #c8d1e4; font-size: 12px;
  display: inline-flex; gap: 7px; align-items: center;
}
.privacy-pill i { width: 7px; height: 7px; border-radius: 50%; background: #3dd598; box-shadow: 0 0 0 4px rgba(61,213,152,.13); }

.button {
  border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer;
  font-weight: 700; transition: .18s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary { color: white; background: var(--blue); box-shadow: 0 6px 16px rgba(55,100,232,.25); }
.button.secondary { color: white; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18); }
.button.large { padding: 13px 22px; font-size: 15px; }
.button:disabled { opacity: .45; cursor: not-allowed; }

.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: 190px minmax(420px, 1fr) 260px; }
.left-panel, .right-panel { min-height: 0; background: var(--panel); z-index: 2; }
.left-panel { border-right: 1px solid var(--line); }
.right-panel { border-left: 1px solid var(--line); }
.panel-heading {
  height: 50px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em;
}
.icon-button {
  min-width: 30px; height: 30px; padding: 0 8px; border: 0; border-radius: 6px;
  background: transparent; cursor: pointer; font-weight: 700;
}
.icon-button:hover:not(:disabled) { background: var(--blue-soft); color: var(--blue); }
.icon-button:disabled { opacity: .3; }

.thumbnail-list { height: calc(100% - 50px); padding: 14px; overflow-y: auto; }
.empty-mini { padding: 28px 10px; text-align: center; color: #98a2b3; font-size: 12px; }
.thumbnail {
  position: relative; margin-bottom: 14px; padding: 7px; cursor: pointer;
  border: 2px solid transparent; border-radius: 8px; background: #f7f8fb;
}
.thumbnail.active { border-color: var(--blue); background: var(--blue-soft); }
.thumbnail canvas { display: block; width: 100%; height: auto; background: white; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.thumbnail span { display: block; margin-top: 6px; text-align: center; color: var(--muted); font-size: 11px; font-weight: 700; }

.editor { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.toolbar {
  height: 58px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; background: #fff; border-bottom: 1px solid var(--line);
}
.tool-group { display: flex; align-items: center; gap: 3px; }
.tool {
  height: 44px; min-width: 52px; padding: 4px 8px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 10px; cursor: pointer;
}
.tool-icon { height: 20px; color: var(--ink); font-size: 19px; line-height: 18px; }
.tool[data-tool="editText"] .tool-icon,
.tool[data-tool="text"] .tool-icon { font-size: 14px; font-weight: 900; }
.tool:hover, .tool.active { color: var(--blue); background: var(--blue-soft); }
.tool.active .tool-icon { color: var(--blue); }
.tool-group.compact { color: var(--muted); font-size: 12px; }
.divider { width: 1px; height: 22px; margin: 0 4px; background: var(--line); }

.document-stage {
  flex: 1; min-height: 0; position: relative; overflow: auto;
  display: grid; place-items: center; padding: 36px; background-color: #e9edf3;
  background-image: radial-gradient(#cfd6e1 1px, transparent 1px);
  background-size: 18px 18px;
}
.document-stage.dragover { outline: 3px solid var(--blue); outline-offset: -8px; }
.welcome-card {
  width: min(520px, 90%); padding: 48px; text-align: center; border-radius: 18px;
  background: rgba(255,255,255,.95); box-shadow: var(--shadow); border: 1px solid rgba(255,255,255,.9);
}
.welcome-icon {
  width: 72px; height: 88px; margin: 0 auto 24px; display: grid; place-items: center;
  color: white; font-weight: 900; font-size: 16px; border-radius: 8px 8px 14px 8px; background: var(--blue);
  box-shadow: 0 13px 28px rgba(55,100,232,.28); transform: rotate(-3deg);
}
.welcome-card h1 { margin: 0 0 14px; font-family: Georgia, serif; font-size: 28px; line-height: 1.2; }
.welcome-card p { margin: 0 auto 24px; max-width: 420px; color: var(--muted); line-height: 1.65; font-size: 14px; }
.welcome-card > span { display: block; margin-top: 13px; color: #98a2b3; font-size: 11px; }
.canvas-wrap { position: relative; margin: auto; box-shadow: 0 18px 45px rgba(19,32,55,.22); background: white; }
.canvas-wrap canvas { position: absolute; top: 0; left: 0; display: block; }
#pdfCanvas { position: relative; }
#overlayCanvas { touch-action: none; }
#overlayCanvas.edit-text-mode { cursor: text !important; }
.hidden { display: none !important; }
.statusbar {
  height: 30px; flex-shrink: 0; padding: 0 12px; display: flex; justify-content: space-between; align-items: center;
  background: white; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px;
}

.properties-scroll { height: calc(100% - 50px); overflow-y: auto; }
.property-section { padding: 16px; border-bottom: 1px solid var(--line); }
.property-section h3 { margin: 0 0 13px; font-size: 12px; }
.property-section label { display: block; margin-top: 10px; color: var(--muted); font-size: 10px; font-weight: 700; }
.property-section input:not([type=checkbox]), .property-section select {
  width: 100%; height: 34px; margin-top: 5px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 6px; background: white; color: var(--ink); font-size: 12px;
}
.property-section input[type=color] { padding: 3px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { margin: 12px 0 0; padding: 9px; border-radius: 6px; color: #68758b; background: #f7f8fb; font-size: 9px; line-height: 1.45; }
.action-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.action-grid button {
  min-height: 34px; border: 1px solid var(--line); border-radius: 6px; background: white; font-size: 10px; cursor: pointer;
}
.action-grid button:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.action-grid button:disabled { opacity: .4; cursor: not-allowed; }
.action-grid .danger { grid-column: 1 / -1; color: var(--danger); }
.section-title-row { display: flex; align-items: center; justify-content: space-between; }
.section-title-row h3 { margin-bottom: 0; }
.lock-badge { padding: 3px 6px; border-radius: 10px; color: var(--green); background: #e7f7f1; font-size: 8px; font-weight: 800; text-transform: uppercase; }
.metadata-list { margin: 13px 0 0; }
.metadata-list div { display: grid; grid-template-columns: 58px 1fr; gap: 7px; margin: 8px 0; font-size: 9px; }
.metadata-list dt { color: #98a2b3; }
.metadata-list dd { margin: 0; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.integrity { background: #fbfcff; }
.switch-row { display: flex !important; align-items: center; gap: 8px; font-size: 10px !important; }
.switch-row input { accent-color: var(--blue); }

dialog { width: 420px; border: 0; border-radius: 16px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10,18,34,.55); backdrop-filter: blur(4px); }
dialog form { text-align: center; }
.dialog-icon { width: 46px; height: 46px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--blue); font-size: 24px; }
dialog h2 { margin-bottom: 5px; }
dialog p { margin-top: 0; color: var(--muted); font-size: 13px; }
.download-choice {
  width: 100%; margin-top: 10px; padding: 13px; display: flex; flex-direction: column; gap: 4px;
  text-align: left; border: 1px solid var(--line); border-radius: 9px; background: white; cursor: pointer;
}
.download-choice:hover { border-color: var(--blue); background: var(--blue-soft); }
.download-choice span { color: var(--muted); font-size: 10px; line-height: 1.4; }
.dialog-cancel { margin-top: 14px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.text-edit-dialog { width: min(520px, calc(100% - 32px)); padding: 0; }
.text-edit-dialog form { padding: 22px; text-align: left; }
.dialog-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.dialog-heading h2 { margin: 0 0 4px; }
.dialog-heading p { margin: 0 0 18px; }
.dialog-close { border: 0; background: transparent; color: var(--muted); font-size: 24px; cursor: pointer; }
.dialog-label { display: block; margin-top: 12px; color: var(--muted); font-size: 11px; font-weight: 700; }
.dialog-label input, .dialog-label textarea {
  width: 100%; margin-top: 6px; padding: 10px; border: 1px solid var(--line);
  border-radius: 8px; color: var(--ink); background: white; resize: vertical; font-family: inherit;
}
.dialog-label select {
  width: 100%; height: 39px; margin-top: 6px; padding: 0 10px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white;
}
.dialog-label input[readonly] { color: var(--muted); background: var(--soft); }
.font-preview-card { margin-top: 12px; padding: 10px 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.font-preview-card > span { display: block; margin-bottom: 8px; color: var(--muted); font: 700 9px Inter, sans-serif; text-transform: uppercase; letter-spacing: .04em; }
#replacementPreview { min-height: 22px; overflow: hidden; color: #111827; white-space: nowrap; }
.text-edit-summary { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.text-edit-summary span { padding: 5px 8px; border-radius: 12px; color: #52617a; background: var(--blue-soft); font-size: 9px; font-weight: 700; }
.text-edit-options { display: grid; grid-template-columns: minmax(150px, 1fr) 90px 100px; gap: 10px; }
.fit-text-option {
  display: flex; align-items: center; gap: 8px; margin-top: 12px;
  color: var(--muted); font-size: 10px; font-weight: 700;
}
.fit-text-option input { accent-color: var(--blue); }
.find-replace-dialog { width: min(560px, calc(100% - 32px)); }
.find-options { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 13px; }
.find-options label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 700; }
.find-options input { accent-color: var(--blue); }
.find-status {
  min-height: 48px; margin-top: 16px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px;
  border-radius: 8px; background: var(--soft); font-size: 11px;
}
.find-status span { color: var(--muted); font-size: 10px; }
.find-navigation { display: grid; grid-template-columns: auto auto 1fr 1fr; gap: 8px; margin-top: 16px; }
.find-navigation .button { padding: 9px 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.dialog-secondary { border: 1px solid var(--line); background: white; }
.toast {
  position: fixed; left: 50%; bottom: 42px; z-index: 20; padding: 10px 16px; transform: translate(-50%, 20px);
  border-radius: 8px; color: white; background: var(--navy); opacity: 0; pointer-events: none; font-size: 12px; transition: .2s ease;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 150px minmax(380px,1fr); }
  .right-panel { display: none; }
  .privacy-pill { display: none; }
}

@media (max-width: 700px) {
  .workspace { grid-template-columns: 1fr; }
  .left-panel { display: none; }
  .tool { min-width: 42px; padding: 3px; }
  .tool-group.compact #fitButton, .toolbar .divider { display: none; }
  .topbar { padding: 0 10px; }
  .brand span { display: none; }
  .document-stage { padding: 16px; }
}
