:root {
  --primary: #182536;
  --secondary: #345bd5;
  --secondary-dark: #2548b4;
  --success: #345bd5;
  --success-dark: #2548b4;
  --warning: #a6661a;
  --warning-dark: #825014;
  --danger: #c84242;
  --danger-dark: #a52f2f;
  --light: #f0f3fa;
  --dark: #263449;
  --bg: #f5f6f8;
  --hint: #66758a;
  --border: #e2e7ef;
  --radius: 14px;
  --shadow: 0 3px 16px rgba(24, 37, 54, 0.035);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--dark);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
  background: var(--primary);
  color: #fff;
  padding: 18px 0;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.header-actions { display: flex; gap: 10px; align-items: center; }
.header h1 { font-size: 20px; font-weight: 600; }
.accent-line {
  height: 3px;
  background: linear-gradient(90deg, var(--secondary), var(--success));
}

/* Layout */
.container {
  max-width: 1440px;
  margin: 24px auto 40px;
  padding: 0 40px;
}

.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 26px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}
.section-title {
  font-size: 16px;
  color: var(--dark);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* Templates */
.templates-list label {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.templates-list label:hover { background: var(--light); }
.templates-list input[type="checkbox"] {
  width: 17px; height: 17px;
  accent-color: var(--secondary);
  cursor: pointer;
}

/* Field blocks */
.block {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 26px 0 14px;
  margin: 8px 0;
  scroll-margin-top: 24px;
}
.field-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 7px 0;
}
.field-row > label {
  flex: 0 0 215px;
  font-size: 13.5px;
  padding-top: 8px;
  color: var(--dark);
}
.field-row .field-input { flex: 1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.safety-responsibles, .safety-responsible-rows { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.safety-responsible-row { display: flex; align-items: center; gap: 10px; }
.safety-responsible-row input[type="checkbox"] { flex: 0 0 18px; width: 18px; height: 18px; }
.safety-responsible-row input[type="text"] { width: 100%; }
.safety-responsible-remove { flex: 0 0 28px; }
.safety-responsible-add { align-self: flex-start; margin-top: 2px; }
.party-field { display: flex; align-items: center; gap: 10px; width: 100%; }
.party-field input[type="checkbox"] { flex: 0 0 18px; width: 18px; height: 18px; }
.party-field input[type="text"] { flex: 1; min-width: 0; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 13.5px;
  padding: 11px 13px;
  border: 1px solid #dce2eb;
  border-radius: 8px;
  background: #fcfdff;
  color: var(--dark);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(52, 91, 213, 0.12);
}
textarea { resize: vertical; min-height: 80px; }
textarea.auto-grow { overflow-y: hidden; resize: none; box-sizing: border-box; }
input.stage-days { flex: 0 0 90px; max-width: 90px; text-align: center; }
input.narrow { flex: 0 0 70px; text-align: center; }
.sep { color: var(--hint); font-weight: 600; }

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn-warning { background: var(--warning); }
.btn-warning:hover { background: var(--warning-dark); }
.btn-secondary { background: #fff; border-color: #dce2eb; color: var(--dark); }
.btn-secondary:hover { background: var(--light); border-color: #c5cfdf; }
.btn-success { background: var(--success); }
.btn-success:hover { background: var(--success-dark); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-big {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.btn-small { padding: 6px 12px; font-size: 13px; margin-top: 10px; }
.btn-icon {
  background: none; border: none; font-size: 26px;
  cursor: pointer; color: var(--hint); line-height: 1;
}
.btn-icon:hover { color: var(--dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Service counter */
.counter { display: flex; align-items: center; gap: 10px; }
.counter button {
  width: 34px; height: 34px; border: none; border-radius: 6px;
  background: var(--secondary); color: #fff; font-size: 18px;
  font-weight: 700; cursor: pointer;
}
.counter button:hover { background: var(--secondary-dark); }
.counter button:disabled { opacity: 0.4; cursor: not-allowed; }
.counter span { min-width: 24px; text-align: center; font-weight: 700; font-size: 15px; }

/* Stages tables */
.stages-table { margin: 16px 0; }
.stages-table h4 { font-size: 14px; margin-bottom: 6px; }
.stages-table .sync-hint { color: var(--hint); font-size: 12px; font-weight: 400; }
.stage-head, .stage-row {
  display: grid;
  grid-template-columns: 125px 1fr 1fr;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.stage-head { font-size: 12px; color: var(--hint); font-weight: 600; }
.stage-row .stage-num { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--dark); }
.stage-row-controls { display: inline-flex; gap: 3px; }
.stage-row-controls button {
  width: 22px; height: 22px; padding: 0; border: none; border-radius: 4px;
  background: var(--secondary); color: #fff; font-weight: 700; cursor: pointer;
}
.stage-row-controls button:hover { background: var(--secondary-dark); }
.stage-row-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.stage-row .del-row {
  width: 30px; height: 30px; border: none; border-radius: 6px;
  background: var(--danger); color: #fff; font-size: 16px;
  cursor: pointer; line-height: 1;
}
.stage-row .del-row:hover { background: var(--danger-dark); }
.appendix-images { margin-top: 28px; }
.appendix-images-title { font-size: 15px; margin-bottom: 6px; }
.appendix-images .hint-text { margin-bottom: 12px; }
.appendix-upload-card {
  width: 100%; overflow: hidden; border: 1px solid var(--border); border-radius: 10px;
  background: #fff; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.appendix-upload-card.is-dragging { border-color: var(--secondary); box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.16); transform: translateY(-1px); }
.appendix-drop-zone {
  position: relative; height: 190px; overflow: hidden; cursor: pointer; outline: none;
  background: linear-gradient(145deg, #f8fbfd, #edf4f8); border-bottom: 1px solid var(--border);
}
.appendix-drop-zone:focus-visible { box-shadow: inset 0 0 0 3px rgba(52, 152, 219, 0.35); }
.appendix-drop-placeholder {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 5px; color: var(--hint); text-align: center; padding: 18px;
}
.appendix-drop-placeholder strong { color: var(--dark); font-size: 14px; font-weight: 600; }
.appendix-drop-placeholder span { font-size: 12px; }
.appendix-drop-placeholder kbd {
  margin-top: 5px; padding: 3px 8px; border: 1px solid #cfd8df; border-bottom-width: 2px;
  border-radius: 5px; background: #fff; color: #5d6d7e; font: 600 11px "Segoe UI", sans-serif;
}
.appendix-upload-icon {
  width: 38px; height: 32px; border: 2px solid var(--secondary); border-radius: 7px; position: relative;
}
.appendix-upload-icon::before { content: "↑"; position: absolute; inset: 3px 0 0; color: var(--secondary); font-size: 24px; font-weight: 700; }
.appendix-preview { width: 100%; height: 100%; object-fit: contain; display: none; background: #fff; }
.appendix-upload-card.has-image .appendix-preview { display: block; }
.appendix-upload-card.has-image .appendix-drop-placeholder { display: none; }
.appendix-upload-card.has-image .appendix-drop-zone::after {
  content: "Нажмите или перетащите файл, чтобы заменить"; position: absolute; left: 50%; bottom: 10px;
  transform: translateX(-50%) translateY(8px); opacity: 0; white-space: nowrap;
  padding: 6px 10px; border-radius: 6px; background: rgba(44, 62, 80, 0.82); color: #fff;
  font-size: 11px; transition: opacity 0.15s, transform 0.15s;
}
.appendix-upload-card.has-image .appendix-drop-zone:hover::after { opacity: 1; transform: translateX(-50%) translateY(0); }
.appendix-file-input { display: none; }
.appendix-image-name { color: var(--hint); font-size: 12px; overflow-wrap: anywhere; }
.appendix-image-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; }
.appendix-image-actions .btn { margin-top: 0; flex: none; }

.editor-modal-content {
  background: var(--bg); width: min(96vw, 1280px); height: 94vh;
  border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column;
}
.editor-toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: stretch; margin-bottom: 9px; }
.editor-toolbar-group {
  display: flex; gap: 5px; flex-wrap: wrap; align-items: center; padding: 6px;
  border: 1px solid #d8e0e7; border-radius: 8px; background: #fff;
  box-shadow: 0 1px 4px rgba(44, 62, 80, 0.09);
}
.navigation-tools { border-top: 3px solid #607d8b; }
.drawing-tools { border-top: 3px solid #27ae60; }
.fence-tools { border-top: 3px solid #f28c00; }
.paint-tools { border-top: 3px solid #1687d9; }
.symbol-tools { border-top: 3px solid #8e44ad; }
.history-tools { border-top: 3px solid #e67e22; }
.editor-tool, .editor-action {
  border: 1px solid transparent; border-radius: 6px; background: #f4f7f9; color: var(--dark);
  padding: 7px 10px; cursor: pointer; font: inherit; font-size: 12px;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.editor-tool::before, .editor-action::before {
  content: ""; width: 18px; height: 18px; flex: 0 0 18px; display: inline-grid;
  place-items: center; border-radius: 3px; font-size: 17px; font-weight: 700; line-height: 1;
}
.editor-tool[data-tool="select"]::before { content: "✋︎"; color: #455a64; font-size: 16px; }
.editor-tool[data-tool="zoom"]::before { content: "⌕"; color: #455a64; font-size: 21px; }
.editor-tool[data-tool="work-zone"]::before { border: 2px solid #159447; background: repeating-linear-gradient(135deg, transparent 0 5px, #159447 6px 7px); }
.editor-tool[data-tool="danger-zone"]::before { border: 2px solid #800020; background: repeating-linear-gradient(0deg, transparent 0 5px, #800020 6px 7px), repeating-linear-gradient(90deg, transparent 0 5px, #800020 6px 7px); }
.editor-tool[data-tool="fence"]::before { background: linear-gradient(transparent 7px, #f28c00 7px 11px, transparent 11px); }
.editor-tool[data-tool="polyline"]::before { background: transparent url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18"%3E%3Cpolyline points="2,14 6,10 10,13 16,4" fill="none" stroke="%23f28c00" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/%3E%3C/svg%3E') center/contain no-repeat; }
.editor-tool[data-tool="rectangle"]::before { border: 2px solid #f28c00; background: transparent; border-radius: 2px; }
.editor-tool[data-tool="passage"]::before { content: "⇄"; color: #0066cc; font-size: 20px; }
.editor-tool[data-tool="text"]::before { content: "T"; color: #222; font-family: Georgia, serif; }
.editor-tool[data-tool="extinguisher"]::before { background: #ff0000; border-radius: 0; clip-path: polygon(50% 4%, 96% 90%, 4% 90%); }
.editor-tool[data-tool="crane"]::before { border: 2px solid #3155a6; background: #fff45c; border-radius: 5px; }
.editor-tool[data-tool="lift"]::before { border: 2px solid #8e44ad; background: #8e44ad; border-radius: 5px; }
.editor-tool[data-tool="legend"]::before { content: "i"; color: #111; border: 2px solid #111; border-radius: 50%; font: 700 14px Georgia, serif; }
.editor-tool[data-tool="brush"]::before { content: "🖌"; font-size: 15px; }
.editor-tool[data-tool="draw-line"]::before { background: linear-gradient(to top right, transparent 46%, #e02424 46% 54%, transparent 54%); }
.editor-tool[data-tool="draw-rect"]::before { border: 2px solid #e02424; background: transparent; border-radius: 2px; }
.editor-tool[data-tool="draw-ellipse"]::before { border: 2px solid #e02424; background: transparent; border-radius: 50%; }
.editor-tool[data-tool="eraser"]::before, .editor-tool[data-tool="image-eraser"]::before { background: linear-gradient(135deg, #f6a5c0 0 55%, #ffffff 55%); border: 1px solid #d8e0e7; border-radius: 3px; }
.editor-tool[data-tool="image-eraser"]::before { background: linear-gradient(135deg, #f6a5c0 0 55%, #b9d7ea 55%); }
.paint-option { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dark); }
.paint-option input[type="color"] { width: 34px; height: 30px; padding: 2px; border: 1px solid #d8e0e7; border-radius: 6px; background: #fff; cursor: pointer; }
.paint-option input[type="range"] { width: 90px; accent-color: #1687d9; }
#editor-undo::before { content: "↶"; color: #d35400; }
#editor-redo::before { content: "↷"; color: #d35400; }
#editor-delete::before { content: "×"; color: #c0392b; font-size: 21px; }
#editor-clear::before { content: "□"; color: #c0392b; text-decoration: line-through; }
.editor-tool:hover, .editor-action:hover { background: #eaf3f9; border-color: #b9d7ea; }
.editor-tool.active { background: var(--secondary); border-color: var(--secondary); color: #fff; box-shadow: 0 1px 4px rgba(52, 152, 219, 0.35); }
.editor-tool:disabled, .editor-action:disabled { opacity: 0.45; cursor: not-allowed; }
.editor-action.danger { color: var(--danger); background: #fff3f2; }
.editor-hint { color: var(--hint); font-size: 12px; margin-bottom: 8px; }
#editor-canvas-wrap {
  flex: 1; min-height: 0; overflow: hidden; background: #cfd4d8; border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  position: relative;
}
.eraser-cursor {
  position: absolute; border: 1.5px solid #333; outline: 1.5px solid rgba(255,255,255,0.85);
  border-radius: 50%; pointer-events: none; display: none; z-index: 20;
  transform: translate(-50%, -50%); box-sizing: border-box;
}
#editor-canvas-wrap .canvas-container { box-shadow: 0 1px 8px rgba(0, 0, 0, 0.25); }
.editor-footer { display: flex; justify-content: flex-end; gap: 10px; padding-top: 10px; }
.editor-footer .btn { min-width: 150px; }

/* Status & downloads */
.status { text-align: center; margin-top: 12px; font-size: 14px; min-height: 20px; }
.status.ok { color: #16724e; font-weight: 600; }
.status.err { color: var(--danger); font-weight: 600; }

.downloads {
  margin-top: 16px;
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid #bce0cf;
  padding: 18px 24px;
}
.downloads h3 { font-size: 15px; margin-bottom: 10px; }
.downloads ul { list-style: none; }
.downloads li {
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.downloads li:last-child { border-bottom: none; }
.downloads .dl-name { flex: 1; font-size: 13.5px; }
.downloads li .btn { margin-top: 0; flex: none; }
.downloads > .btn { margin-top: 14px; }
.downloads a { color: var(--secondary); text-decoration: none; font-weight: 600; }
.downloads a:hover { text-decoration: underline; }

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(17, 28, 45, 0.5);
  backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-content {
  background: #fff;
  border-radius: 18px;
  width: 100%; max-width: 980px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  padding: 20px 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.modal-header h2 { font-size: 18px; }
.modal-body { overflow-y: auto; flex: 1; padding: 4px 2px 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  border: none; background: none; font: inherit; font-size: 14px;
  padding: 9px 14px; cursor: pointer; color: var(--hint);
  border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--secondary); border-bottom-color: var(--secondary); font-weight: 600; }
.tab:hover { color: var(--dark); }

.hint-text { font-size: 12.5px; color: var(--hint); margin-bottom: 12px; line-height: 1.4; }

.labels-grid, .orgs-grid {
  display: grid;
  gap: 8px;
  align-items: center;
  padding: 4px 0;
}
.labels-grid { grid-template-columns: 1.2fr 1fr 1fr; }
.labels-grid-header, .orgs-grid-header { font-size: 12px; color: var(--hint); font-weight: 600; }
.labels-grid .ph { font-size: 12px; color: var(--dark); word-break: break-all; }
.orgs-grid { grid-template-columns: 60px 1.4fr 0.8fr 1fr 0.7fr 34px; }
.move-btns { display: flex; gap: 2px; }
.move-btns button {
  width: 26px; height: 26px; border: none; border-radius: 4px;
  background: var(--secondary); color: #fff; font-size: 11px; cursor: pointer;
}
.move-btns button:disabled { opacity: 0.35; cursor: not-allowed; }
.del-mini {
  width: 28px; height: 28px; border: none; border-radius: 4px;
  background: var(--danger); color: #fff; font-size: 14px; cursor: pointer;
}
.recon-row { display: flex; gap: 8px; align-items: center; padding: 4px 0; }

.hidden { display: none !important; }

.footer { text-align: center; color: var(--hint); font-size: 12px; padding: 20px 0 30px; }

/* Spinner */
.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite;
  vertical-align: -3px; margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth overlay */
.auth-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.auth-box {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 420px;
  padding: 32px 28px;
  text-align: center;
}
.auth-box h2 { font-size: 20px; margin-bottom: 8px; color: var(--primary); }
.auth-hint { color: var(--hint); font-size: 13px; margin-bottom: 20px; }
.auth-field {
  text-align: left; margin-bottom: 14px;
}
.auth-field label {
  display: block; font-size: 13px; color: var(--dark); margin-bottom: 5px; font-weight: 600;
}
.auth-field input[type="text"], .auth-field input[type="password"] {
  width: 100%; flex: none;
}
.auth-error {
  color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 12px;
}
.auth-admin-link {
  margin-top: 18px; font-size: 13px;
}
.auth-admin-link a { color: var(--secondary); text-decoration: none; }
.auth-admin-link a:hover { text-decoration: underline; }

.user-toolbar {
  display: flex; align-items: center; gap: 12px;
}
.user-name {
  color: #fff; font-size: 14px; font-weight: 600;
}

/* Admin panel */
.admin-panel .header-inner { justify-content: space-between; }
.admin-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.admin-table th, .admin-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left;
}
.admin-table th { color: var(--hint); font-weight: 600; font-size: 12px; }
.admin-table td button { margin-right: 6px; }
.admin-form { display: grid; gap: 14px; max-width: 420px; }
.admin-form .auth-field { margin-bottom: 0; }
.admin-form label input[type="checkbox"] {
  width: auto; flex: none; margin-right: 6px;
}

/* History modal */
.history-modal-content { max-width: 900px; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--secondary);
  border-radius: 8px;
  padding: 14px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  flex-wrap: wrap;
}
.history-meta { flex: 1; min-width: 220px; }
.history-meta strong { display: block; font-size: 14px; color: var(--dark); margin-bottom: 4px; }
.history-date { font-size: 12px; color: var(--hint); }
.history-actions { display: flex; gap: 8px; align-items: center; }
.history-draft { border-left-color: var(--warning); background: #fffaf4; }
#draft-btn { margin-top: 0; }

html { scroll-behavior: smooth; scrollbar-gutter: stable; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, [tabindex]:focus-visible { outline: 3px solid #7899f1; outline-offset: 4px; }
button { touch-action: manipulation; }
input::placeholder, textarea::placeholder { color: #7c8899; opacity: 1; }
input[type="checkbox"] { accent-color: var(--secondary); }
body.modal-open { overflow: hidden; }
.icon { width: 19px; height: 19px; flex: 0 0 19px; vertical-align: middle; }
.skip-link { position: fixed; top: -80px; left: 20px; z-index: 300; padding: 12px 18px; background: #fff; color: var(--secondary); border-radius: 8px; }
.skip-link:focus { top: 12px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand-mark { width: 42px; height: 46px; display: grid; place-items: center; border: 1px solid #51627b; border-radius: 11px; background: #26364c; }
.brand-mark svg { width: 29px; height: 29px; }
.brand strong { display: block; font-size: 23px; font-weight: 650; letter-spacing: -0.8px; line-height: 1.2; }
.brand small { display: block; color: #a4b2c7; font-size: 11px; margin-top: 4px; letter-spacing: 0.4px; }
.brand-dot { color: #90aaff; }
.header-actions { margin-left: auto; }
.header .btn-secondary { background: transparent; border-color: transparent; color: #d2dbea; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-size: 13px; font-weight: 500; }
.header .btn-secondary:hover { background: #2b3a50; border-color: #3b4b62; color: #fff; }
.user-toolbar { padding-left: 22px; border-left: 1px solid #39485c; gap: 9px; }
.user-name { font-size: 13px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
.user-avatar { width: 31px; height: 31px; display: grid; place-items: center; background: #334764; color: #dce7ff; border-radius: 50%; font-size: 12px; font-weight: 700; }
.user-toolbar .btn { margin: 0; }
.workspace { margin-top: 36px; margin-bottom: 20px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 32px; }
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 1.6px; color: var(--hint); margin-bottom: 8px; }
.page-heading h1 { font-size: clamp(25px, 2.6vw, 36px); line-height: 1.25; letter-spacing: -1.2px; color: var(--primary); font-weight: 650; }
.page-description { color: var(--hint); margin-top: 10px; font-size: 14px; }
.format-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff; border: 1px solid var(--border); border-radius: 7px; font-size: 11px; color: var(--hint); white-space: nowrap; }
.format-dot { width: 6px; height: 6px; background: #368068; border-radius: 50%; }
.workspace-grid { display: grid; grid-template-columns: 290px minmax(0, 1fr); align-items: start; gap: 26px; }
.workspace-sidebar { position: sticky; top: 24px; max-height: calc(100dvh - 140px); overflow-y: auto; scrollbar-width: thin; }
.workspace-main { min-width: 0; }
.template-card { padding: 22px 18px 16px; margin-bottom: 24px; }
.section-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.section-heading .section-title { margin: 0; padding: 0; border: 0; font-weight: 650; letter-spacing: -0.2px; }
.section-heading .hint-text { margin: 4px 0 0; }
.step-number { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; font-size: 11px; font-weight: 700; color: var(--secondary); background: #edf1ff; border-radius: 9px; font-variant-numeric: tabular-nums; }
.template-card .section-title { font-size: 14px; }
.template-card > .hint-text { margin-bottom: 20px; }
.template-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 0 2px 10px; font-size: 11px; color: var(--hint); }
.text-button { border: 0; padding: 4px 0; background: transparent; color: var(--secondary); font: inherit; font-size: 11px; cursor: pointer; font-weight: 600; }
.text-button:hover { text-decoration: underline; }
.text-button:disabled { opacity: 0.5; cursor: not-allowed; }
.templates-list { display: grid; gap: 9px; }
.templates-list label { position: relative; padding: 13px 11px; gap: 10px; border: 1px solid var(--border); background: #fff; border-radius: 9px; transition: border-color 0.15s, background 0.15s; }
.templates-list label:hover { border-color: #a9bae9; background: #f8faff; }
.templates-list label:has(input:checked) { background: #f2f5ff; border-color: #bac9f5; }
.templates-list label:has(input:focus-visible) { outline: 3px solid #7899f1; outline-offset: 2px; }
.templates-list input[type="checkbox"] { flex: 0 0 16px; width: 16px; height: 16px; }
.template-copy { min-width: 0; }
.template-copy strong { display: block; font-size: 13px; font-weight: 600; line-height: 1.4; overflow-wrap: anywhere; }
.template-copy small { display: block; margin-top: 3px; color: var(--hint); font-size: 10px; }
.template-file { margin-left: auto; align-self: center; font-size: 9px; font-weight: 600; color: #7988a5; }
.sidebar-note { display: flex; gap: 9px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); color: var(--hint); font-size: 11px; line-height: 1.6; }
.note-icon { flex: 0 0 15px; height: 15px; margin-top: 2px; display: grid; place-items: center; border: 1px solid #9caac0; border-radius: 50%; font: 11px Georgia, serif; }
.form-navigation { padding: 0 12px; }
.form-navigation .eyebrow { padding-left: 10px; margin-bottom: 12px; }
#form-nav { display: grid; gap: 3px; }
#form-nav a { display: flex; align-items: center; gap: 12px; padding: 9px 11px; border-radius: 7px; text-decoration: none; color: var(--hint); font-size: 12px; }
#form-nav a span { color: #7e8da5; font-size: 10px; font-variant-numeric: tabular-nums; }
#form-nav a:hover, #form-nav a[aria-current="location"] { background: #e9edf7; color: var(--secondary); }
.draft-tip { margin: 22px 22px 8px; padding-top: 18px; border-top: 1px solid var(--border); font-size: 11px; color: var(--hint); line-height: 1.6; }
.draft-tip strong { color: #52627a; font-weight: 600; }
.draft-tip p { margin-top: 5px; }
.fields-card { padding: 26px 30px 10px; margin: 0; }
.fields-card > .section-heading { margin-bottom: 22px; }
.section-badge { margin-left: auto; color: var(--hint); border: 1px solid var(--border); border-radius: 5px; font-size: 10px; padding: 3px 7px; white-space: nowrap; }
.block-title { display: flex; align-items: baseline; gap: 10px; color: var(--primary); font-size: 14px; font-weight: 650; margin-bottom: 16px; }
.block-title span { font-size: 10px; color: #7b8ca5; font-weight: 500; }
.field-row { padding: 8px 0; }
.field-row > label { font-size: 12px; color: #53637a; padding-top: 12px; line-height: 1.5; }
.field-row .field-input { min-width: 0; }
.field-input > input:not(.narrow):not(.stage-days), .field-input > textarea, .field-input > select { width: 100%; }
.field-row:has(textarea) { align-items: flex-start; }
.empty-state { padding: 44px 24px; background: #f8f9fc; border: 1px dashed #d4dceb; border-radius: 10px; color: var(--hint); font-size: 13px; text-align: center; margin-bottom: 24px; }
.action-bar { position: sticky; bottom: 16px; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 16px; margin-top: 24px; padding: 16px 20px; border: 1px solid #dbe2ee; border-radius: 12px; background: rgba(255, 255, 255, 0.97); box-shadow: 0 6px 28px rgba(24, 37, 54, 0.1); backdrop-filter: blur(12px); }
.action-summary { display: flex; align-items: center; gap: 12px; }
.summary-icon { width: 36px; height: 40px; display: grid; place-items: center; color: var(--secondary); background: #f0f3fc; border: 1px solid #e2e8f7; border-radius: 7px; }
.action-summary strong { display: block; font-weight: 600; font-size: 13px; }
.action-summary div > span { display: block; font-size: 11px; color: var(--hint); margin-top: 3px; }
.action-buttons { display: flex; gap: 10px; }
.action-buttons .btn { min-height: 44px; font-size: 13px; padding: 11px 18px; }
.action-buttons .btn-success { box-shadow: 0 3px 8px #345bd525; }
.action-bar .status { flex: 0 0 100%; text-align: left; padding: 10px 12px; border-radius: 7px; font-size: 12px; }
.action-bar .status:empty { display: none; }
.status.ok { background: #edf8f2; }
.status.err { background: #fff0ef; }
.status.err, .auth-error, .hint-text.err { color: var(--danger); }
.downloads { scroll-margin-top: 24px; }
.downloads .step-number { background: #e6f5ed; color: #16724e; }
.downloads h3 { margin: 0; }
.downloads > .hint-text { margin-top: 12px; margin-bottom: 0; }
.dl-name { overflow-wrap: anywhere; min-width: 0; }
.btn-icon { display: grid; place-items: center; width: 36px; height: 36px; flex: 0 0 36px; border-radius: 8px; background: #f3f5f9; }
.btn-icon:hover { background: #e9edf4; }
.modal-content { padding: 26px; }
.modal-header { gap: 16px; margin-bottom: 22px; }
.modal-header .eyebrow { margin-bottom: 4px; }
.modal-header h2 { font-size: 21px; letter-spacing: -0.4px; }
.modal-body { overscroll-behavior: contain; }
.tabs { border-bottom: 1px solid var(--border); gap: 8px; }
.tab { font-size: 12px; }
.history-item { padding: 18px; border-left-width: 3px; }
.history-actions { flex-wrap: wrap; }
.history-actions .btn { margin-top: 0; font-size: 11px; }
.history-badge { display: inline-block; font-size: 10px; color: #16724e; background: #eaf6ef; border-radius: 4px; padding: 2px 6px; margin-bottom: 7px; }
.history-draft .history-badge { color: #956017; background: #fcf0db; }
.history-draft { background: #fffdf9; }
.history-filters { display: flex; gap: 10px; margin-bottom: 18px; }
.history-filters input { flex: 1; }
.history-filters select { flex: 0 0 160px; }
.counter button { background: #edf1fb; color: var(--secondary); border: 1px solid #d6dff2; }
.counter button:hover { background: #dce5fa; }
.counter span { color: var(--primary); }
.stages-table { padding: 18px 0 6px; }
.stage-head { padding: 9px 0; font-size: 10px; }
.stage-head, .stage-row { grid-template-columns: 105px minmax(0, 1fr) minmax(0, 1fr); }
.stage-head > *, .stage-row > * { min-width: 0; }
.stages-table h4 { font-size: 13px; }
.appendix-drop-zone { background: #f5f7fc; }
.appendix-upload-card { border-style: dashed; }
.editor-hint { line-height: 1.6; }
.footer { padding: 20px 16px 30px; font-size: 11px; }
.auth-overlay { background: #eef1f7; background-image: radial-gradient(ellipse at 15% 15%, #dfe7fa 0, transparent 55%), radial-gradient(ellipse at 90% 90%, #e0e8f3 0, transparent 50%); overflow-y: auto; }
.auth-layout { display: grid; grid-template-columns: 1fr 1fr; width: min(920px, 100%); border: 1px solid #dbe2ee; border-radius: 22px; overflow: hidden; box-shadow: 0 24px 80px #1b2c4812; background: #fff; }
.auth-intro { padding: 44px; background: var(--primary); color: #fff; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.auth-intro .brand { margin-bottom: 60px; }
.auth-intro h1 { font-size: 32px; font-weight: 600; line-height: 1.25; letter-spacing: -1px; max-width: 290px; margin-bottom: 18px; }
.auth-intro > p { color: #aebdd2; line-height: 1.8; font-size: 13px; }
.auth-steps { display: grid; gap: 18px; margin-top: 35px; list-style: none; font-size: 12px; color: #d0dbee; }
.auth-steps li { display: flex; align-items: center; gap: 12px; }
.auth-steps span { color: #a8bcf6; border: 1px solid #425472; border-radius: 7px; padding: 4px 7px; font-size: 10px; }
.auth-box { border: 1px solid var(--border); padding: 40px; }
.auth-layout .auth-box { max-width: none; padding: 54px 44px; border: 0; border-radius: 0; box-shadow: none; text-align: left; align-self: center; }
.auth-box h2 { font-size: 25px; letter-spacing: -0.6px; margin-bottom: 10px; }
.auth-hint { line-height: 1.7; margin-bottom: 30px; }
.auth-field { margin-bottom: 19px; }
.auth-field label { font-size: 12px; margin-bottom: 8px; }
.auth-field input { min-height: 46px; }
.auth-error:empty { min-height: 0; margin-bottom: 0; }
.auth-error:not(:empty) { background: #fff0ef; padding: 10px; border-radius: 7px; }
.auth-box .btn-big { font-size: 14px; padding: 12px; }
.auth-footnote { font-size: 11px; color: var(--hint); margin-top: 24px; line-height: 1.7; }
.admin-table { display: block; overflow-x: auto; }

@media (max-width: 1180px) {
  .header-inner, .container { padding-left: 24px; padding-right: 24px; }
  .workspace-grid { grid-template-columns: 260px minmax(0, 1fr); gap: 20px; }
  .fields-card { padding-left: 24px; padding-right: 24px; }
  .field-row { flex-direction: column; gap: 6px; }
  .field-row > label { flex: none; padding-top: 0; }
  .field-row .field-input { width: 100%; flex: auto; }
  .user-toolbar { padding-left: 12px; }
  .header-actions { gap: 2px; }
}
@media (max-width: 900px) {
  .header-actions { order: 3; width: 100%; justify-content: flex-start; margin: 0; padding-top: 10px; border-top: 1px solid #39485c; }
  .user-toolbar { margin-left: auto; }
  .page-heading { align-items: flex-start; }
  .format-badge { display: none; }
  .action-summary div > span { display: none; }
  .action-buttons .btn { padding: 10px 12px; font-size: 12px; }
  .workspace-grid { grid-template-columns: 225px minmax(0, 1fr); gap: 16px; }
  .template-card { padding: 18px 12px; }
  .template-file, .section-badge { display: none; }
  .template-card .section-heading { gap: 8px; }
  .stage-head, .stage-row { grid-template-columns: 75px minmax(0, 1fr) minmax(0, 1fr); }
  .stage-row .stage-num { flex-wrap: wrap; }
  .auth-intro { padding: 34px; }
  .auth-layout .auth-box { padding: 34px; }
}
@media (max-width: 720px) {
  .header-inner, .container { padding-left: 16px; padding-right: 16px; }
  .header { padding: 15px 0 9px; }
  .header-inner { gap: 12px; }
  .brand strong { font-size: 21px; }
  .brand small { font-size: 10px; }
  .brand-mark { width: 35px; height: 39px; }
  .header-actions .btn { font-size: 12px; padding: 8px; flex: 1; }
  .user-toolbar { border: 0; padding: 0; gap: 6px; }
  .user-name { max-width: 90px; font-size: 11px; }
  .user-avatar { display: none; }
  .user-toolbar .btn { font-size: 11px; padding: 7px; }
  .workspace { margin-top: 26px; }
  .page-heading { margin-bottom: 24px; }
  .page-heading h1 { font-size: 27px; letter-spacing: -0.8px; }
  .page-description { font-size: 12px; line-height: 1.7; }
  .workspace-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .workspace-sidebar { position: static; max-height: none; overflow: visible; }
  .template-card { padding: 20px; margin: 0; }
  .template-file { display: block; }
  .draft-tip, .form-navigation { display: none; }
  .fields-card { padding: 22px 20px 8px; }
  .block { padding-top: 22px; }
  .field-row { flex-direction: column; gap: 6px; }
  .field-row > label { flex: none; padding-top: 0; }
  input[type="text"], input[type="password"], input[type="date"], input[type="number"], select, textarea { font-size: 16px; }
  .labels-grid { grid-template-columns: 1fr; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .labels-grid-header { display: none; }
  .orgs-grid { grid-template-columns: 1fr; padding: 14px 0; border-bottom: 1px solid var(--border); }
  .orgs-grid-header { display: none; }
  .stage-head, .stage-row { grid-template-columns: 60px minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
  .stage-row textarea { padding: 8px; }
  .stage-head { font-size: 9px; overflow-wrap: anywhere; }
  .action-bar { bottom: 8px; padding: 12px; margin-top: 18px; }
  .action-summary { display: none; }
  .action-buttons { width: 100%; gap: 8px; }
  .action-buttons .btn { flex: 1; padding: 10px 8px; font-size: 11px; }
  .action-bar .status { font-size: 11px; max-height: 95px; overflow-y: auto; }
  .modal { padding: 10px; }
  .modal-content { padding: 20px 16px; max-height: 92dvh; border-radius: 14px; }
  .modal-header h2 { font-size: 19px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; flex-shrink: 0; gap: 0; }
  .tab { white-space: nowrap; padding: 10px; font-size: 11px; }
  .history-item { flex-direction: column; align-items: flex-start; }
  .history-meta { min-width: 0; }
  .history-actions { width: 100%; }
  .history-actions .btn { flex: 1; }
  .history-filters { flex-direction: column; }
  .history-filters select { flex: auto; }
  .editor-modal-content { height: 96dvh; padding: 12px; }
  .editor-toolbar { max-height: 30dvh; overflow-y: auto; flex-shrink: 0; }
  .editor-footer .btn { min-width: 0; flex: 1; }
  .editor-hint { font-size: 10px; }
  .appendix-image-actions .btn { width: 100%; }
  .downloads { padding: 20px; }
  .auth-overlay { padding: 16px; align-items: flex-start; }
  .auth-layout { grid-template-columns: 1fr; margin: auto; max-width: 440px; }
  .auth-intro { padding: 26px; }
  .auth-intro .brand { margin-bottom: 24px; }
  .auth-intro h1 { font-size: 25px; margin-bottom: 0; }
  .auth-intro > p, .auth-steps { display: none; }
  .auth-layout .auth-box { padding: 28px; }
  .auth-box { margin: auto; padding: 28px; }
  .auth-hint { margin-bottom: 22px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition: none !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Views: home / docs / images ---------- */
main[data-view] { display: none; }
body[data-view="home"] main[data-view="home"],
body[data-view="docs"] main[data-view="docs"],
body[data-view="images"] main[data-view="images"] { display: block; }
body:not([data-view="docs"]) #history-btn,
body:not([data-view="docs"]) #settings-btn { display: none; }

.home-view { min-height: calc(100dvh - 190px); }
body[data-view="home"] main.home-view { display: flex; align-items: center; justify-content: center; }
.home-inner { width: 100%; max-width: 860px; text-align: center; padding: 40px 0; }
.home-inner h1 { font-size: clamp(26px, 3vw, 38px); letter-spacing: -1.2px; color: var(--primary); font-weight: 650; }
.home-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 36px; }
.home-option {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 32px 24px;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  font: inherit; color: var(--dark); cursor: pointer; text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.home-option:hover, .home-option:focus-visible { border-color: #a9bae9; box-shadow: 0 8px 28px rgba(52, 91, 213, 0.12); transform: translateY(-2px); outline: none; }
.home-option strong { font-size: 17px; color: var(--primary); }
.home-option > span:last-child { font-size: 13px; color: var(--hint); line-height: 1.5; }
.home-option-icon { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 16px; background: #edf1ff; color: var(--secondary); }
.home-option-icon svg { width: 30px; height: 30px; }

.image-heading-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.image-heading-actions .btn { margin-top: 0; }
.image-tool-card { padding: 22px; }
.image-tool-card .appendix-drop-zone { height: min(420px, 55dvh); }
.image-tool-card .status:empty { display: none; }
.image-history-thumb { width: 84px; height: 60px; object-fit: contain; background: #f5f7fc; border: 1px solid var(--border); border-radius: 6px; flex: none; }
.history-item .image-history-thumb + .history-meta { min-width: 0; }

@media (max-width: 700px) {
  .home-options { grid-template-columns: minmax(0, 1fr); }
}
