* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 13px;
  color: #1a1a1a;
  overflow: hidden;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- Shared footer ---------- */
.app-footer {
  flex-shrink: 0; height: 22px; display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; color: #9a9aa4; background: #fafafb; border-top: 1px solid #ececf0;
  letter-spacing: .2px; user-select: none;
}

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex; align-items: center; gap: 4px;
  height: 52px; padding: 0 12px;
  background: #fff; border-bottom: 1px solid #e2e2e6;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(20,20,40,.03);
}
.app-title {
  font-weight: 600; font-size: 14px; margin-right: 16px; white-space: nowrap;
  color: #1a1a2e;
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; background: transparent; cursor: pointer;
  color: #3c3c46;
  height: 34px; padding: 0 10px; border-radius: 7px;
  font-size: 12.5px; font-weight: 500; font-family: inherit;
  white-space: nowrap; text-decoration: none;
  transition: background .12s;
}
.tb-btn svg { width: 17px; height: 17px; flex-shrink: 0; display: block; }
.tb-btn.icon-only { padding: 0; width: 34px; justify-content: center; }
.tb-btn:hover { background: #f0f0f5; }
.tb-btn:active { background: #e6e6ee; }
.tb-btn:disabled { opacity: 0.32; cursor: default; }
.tb-btn:disabled:hover { background: transparent; }
.tb-btn.primary { background: #4f46e5; color: #fff; font-weight: 600; }
.tb-btn.primary:hover { background: #4338ca; }
.tb-sep { width: 1px; height: 24px; background: #e5e5ea; margin: 0 8px; flex-shrink: 0; }
.tb-spacer, #main .spacer, #dataPanelHeader .spacer { flex: 1; }
#zoomLabel { width: 40px; text-align: center; display: inline-block; font-size: 12px; color: #666; }

.user-menu { display: flex; align-items: center; gap: 8px; margin-left: 2px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f3f3f8; color: #3c3c46; font-size: 12.5px; font-weight: 500;
  padding: 6px 12px 6px 8px; border-radius: 20px;
}
.user-chip svg { width: 15px; height: 15px; opacity: .7; }

/* ---------- Main layout ---------- */
#main { flex: 1; display: flex; min-height: 0; }

#toolbox {
  width: 216px; flex-shrink: 0; background: #f7f7fa;
  overflow-y: auto; border-right: 1px solid #e2e2e6;
  padding: 4px 8px 16px;
}
.panel-section-title {
  font-size: 10.5px; font-weight: 700; color: #8a8a96;
  letter-spacing: .6px; padding: 16px 6px 6px;
}
.tool-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  border: none; background: transparent; cursor: pointer;
  padding: 7px 8px; font-size: 12.8px; font-weight: 500; color: #2c2c36;
  border-radius: 7px; font-family: inherit;
  transition: background .12s;
}
.tool-btn svg { width: 17px; height: 17px; flex-shrink: 0; color: #6b6b78; }
.tool-btn:hover { background: #eaeaf1; }
.tool-btn:hover svg { color: #4f46e5; }

#canvasArea {
  flex: 1; background: #3a3d45; overflow: auto;
  display: flex; align-items: center; justify-content: center;
}
#canvasScroll { padding: 48px; }
#labelCanvas {
  position: relative; background: #fff;
  box-shadow: 0 4px 18px rgba(0,0,0,.5);
  outline: none;
}
#grid { position: absolute; inset: 0; pointer-events: none; }

#bottomAndProps { display: contents; }
#properties {
  width: 300px; flex-shrink: 0; background: #f3f3f5;
  overflow-y: auto; border-left: 1px solid #ddd;
}

/* ---------- Elements on canvas ---------- */
.lbl-el {
  position: absolute;
  border: 1.4px solid transparent;
  cursor: move;
  user-select: none;
}
.lbl-el.selected { border-color: #3b82f6; }
.lbl-el.locked { cursor: default; }
.lbl-el-content { width: 100%; height: 100%; overflow: hidden; pointer-events: none; }
.lbl-el-content canvas, .lbl-el-content img { width: 100%; height: 100%; display: block; }
.lbl-el-content.text-content {
  display: flex; white-space: pre-wrap; word-break: break-word;
  line-height: 1;
}
.lbl-el-shape-rect { width: 100%; height: 100%; }
.lbl-el-shape-ellipse { width: 100%; height: 100%; border-radius: 50%; }
.lbl-el-shape-line { width: 100%; height: 100%; display: flex; align-items: center; }
.lbl-el-shape-line .line-inner { width: 100%; }
.lbl-el-image-placeholder {
  width: 100%; height: 100%; background: #e0e0e0;
  display: flex; align-items: center; justify-content: center;
  color: #999; font-size: 22px;
}

.resize-handle {
  position: absolute; width: 9px; height: 9px;
  background: #fff; border: 1.2px solid #3b82f6;
  transform: translate(-50%, -50%);
}
.resize-handle.tl { left: 0; top: 0; cursor: nwse-resize; }
.resize-handle.tm { left: 50%; top: 0; cursor: ns-resize; }
.resize-handle.tr { left: 100%; top: 0; cursor: nesw-resize; }
.resize-handle.ml { left: 0; top: 50%; cursor: ew-resize; }
.resize-handle.mr { left: 100%; top: 50%; cursor: ew-resize; }
.resize-handle.bl { left: 0; top: 100%; cursor: nesw-resize; }
.resize-handle.bm { left: 50%; top: 100%; cursor: ns-resize; }
.resize-handle.br { left: 100%; top: 100%; cursor: nwse-resize; }

/* ---------- Properties panel ---------- */
.prop-row { display: flex; align-items: center; padding: 4px 14px; gap: 8px; }
.prop-row label { width: 76px; flex-shrink: 0; font-size: 12px; color: #333; }
.prop-row input[type=text], .prop-row input[type=number], .prop-row select, .prop-row textarea {
  flex: 1; padding: 6px 8px; font-size: 12px;
  border: 1px solid #ccc; border-radius: 4px; background: #fff; min-width: 0;
}
.prop-row textarea { resize: vertical; min-height: 46px; font-family: inherit; }
.prop-row input[type=checkbox] { width: 16px; height: 16px; }
.prop-hint { padding: 4px 14px; font-size: 11px; color: #999; }
.prop-error { padding: 4px 14px; font-size: 11px; color: #c62828; }
.color-swatches { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.color-swatch {
  width: 18px; height: 18px; border: 1px solid rgba(0,0,0,.2); cursor: pointer;
}
.color-swatch.active { outline: 2px solid #3b82f6; outline-offset: 1px; }
.style-toggle-row { display: flex; gap: 4px; }
.style-toggle {
  border: 1px solid #ccc; background: #fff; border-radius: 4px;
  width: 28px; height: 26px; cursor: pointer; font-size: 13px;
}
.style-toggle.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }

/* ---------- Data panel ---------- */
#dataPanel {
  height: 190px; flex-shrink: 0; border-top: 1px solid #ddd;
  background: #fafafb; display: flex; flex-direction: column;
}
#dataPanelHeader {
  height: 38px; flex-shrink: 0; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; border-bottom: 1px solid #e2e2e6; font-size: 12px;
}
.dp-title { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: #2c2c36; }
.dp-title svg { opacity: .65; }
#dataRowNav { display: inline-flex; align-items: center; gap: 2px; }
#dataInfo { color: #888; }
#dataPanelBody { flex: 1; overflow: auto; }
#dataEmptyMsg {
  height: 100%; display: flex; align-items: center; justify-content: center;
  color: #888; font-size: 12px; text-align: center; padding: 0 40px;
}
#dataTable { border-collapse: collapse; font-size: 11px; width: 100%; }
#dataTable th, #dataTable td {
  border: 1px solid #e2e2e2; padding: 4px 8px; text-align: left; white-space: nowrap;
}
#dataTable th { background: #eee; position: sticky; top: 0; }
#dataTable tr.preview-row { background: #dbeafe; }
#dataTable tr:hover { background: #f0f4ff; cursor: pointer; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-box {
  background: #fff; border-radius: 8px; padding: 20px 22px;
  width: 400px; max-width: 92vw; max-height: 86vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal-box h2 { margin: 0 0 14px; font-size: 16px; }
.modal-row { margin-bottom: 12px; }
.modal-row label { display: block; font-size: 12px; margin-bottom: 4px; color: #444; }
.modal-row input, .modal-row select {
  width: 100%; padding: 7px 9px; font-size: 13px;
  border: 1px solid #ccc; border-radius: 5px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button {
  padding: 8px 16px; border-radius: 5px; border: 1px solid #ccc;
  background: #fff; cursor: pointer; font-size: 13px;
}
.modal-actions button.primary { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.template-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 6px; border-bottom: 1px solid #eee; cursor: pointer; font-size: 13px;
}
.template-list-item:hover { background: #f2f2f7; }
.template-list-item .del-btn {
  display: inline-flex; align-items: center; gap: 4px;
  color: #c62828; font-size: 12px;
}
.template-list-item .del-btn svg { width: 14px; height: 14px; }
.segmented { display: flex; border: 1px solid #ccc; border-radius: 6px; overflow: hidden; }
.segmented button {
  flex: 1; border: none; background: #fff; padding: 8px; cursor: pointer; font-size: 13px;
  border-right: 1px solid #ccc;
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: #4f46e5; color: #fff; }
.status-line { font-size: 12px; margin-top: 10px; color: #333; }

/* ---------- Print ---------- */
@media print {
  body * { visibility: hidden; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  background: #1a1a2e; color: #fff; font-size: 12.5px; font-weight: 500;
  padding: 11px 18px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 0; transition: opacity .25s, transform .25s; z-index: 2000; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.toast-error { background: #c62828; }

/* ---------- User menu dropdown ---------- */
.user-menu { position: relative; }
.user-chip { cursor: pointer; user-select: none; }
.user-chip:hover { background: #eaeaf1; }
.user-chip .chev { width: 12px; height: 12px; opacity: .5; margin-left: -2px; }
.user-dropdown {
  position: absolute; top: 42px; right: 0; width: 190px;
  background: #fff; border: 1px solid #e2e2e6; border-radius: 9px;
  box-shadow: 0 10px 30px rgba(20,20,40,.14); padding: 6px; z-index: 500;
}
.user-dropdown button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  border: none; background: transparent; cursor: pointer; text-align: left;
  padding: 8px 10px; border-radius: 6px; font-size: 12.8px; color: #2c2c36; font-family: inherit;
}
.user-dropdown button:hover { background: #f0f0f5; }
.user-dropdown button svg { width: 16px; height: 16px; color: #6b6b78; }
.user-dropdown button.danger { color: #c62828; }
.user-dropdown button.danger svg { color: #c62828; }
.user-dropdown hr { border: none; border-top: 1px solid #eee; margin: 5px 2px; }
