:root {
  --color-new: #e53935;
  --color-renewed: #1e88e5;
  --color-ui-primary: #b71c1c;
  --color-ui-primary-hover: #8e0000;
  --color-ui-primary-faint: #fbe9e7;
  --color-bg: #f5f5f5;
  --color-surface: #ffffff;
  --color-border: #e0e0e0;
  --color-text: #212121;
  --color-text-muted: #6b6b6b;
  --toolbar-width: 180px;
  --app-bar-height: 48px;
  --status-bar-height: 28px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  overflow: hidden;
}

body {
  display: flex;
}

/* ---------- Toolbar ---------- */
.toolbar {
  width: var(--toolbar-width);
  height: 100vh;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  padding: 8px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.toolbar-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--color-border);
}
.toolbar-section:last-child { border-bottom: none; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-muted);
  padding: 4px 4px 2px;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--color-text);
  text-align: left;
  transition: background 0.1s, border 0.1s;
}
.tool-btn:hover {
  background: var(--color-ui-primary-faint);
}
.tool-btn.active {
  background: var(--color-ui-primary-faint);
  border-color: var(--color-ui-primary);
  color: var(--color-ui-primary);
}
.tool-btn svg { flex-shrink: 0; }

.file-btn {
  background: var(--color-ui-primary);
  color: white;
}
.file-btn:hover {
  background: var(--color-ui-primary-hover);
}

/* Variant group: sub-buttons below a tool */
.variant-group {
  display: none;
  gap: 4px;
  padding-left: 28px;
  padding-bottom: 4px;
}
.variant-group.visible { display: flex; flex-wrap: wrap; }
.variant-btn {
  padding: 2px 8px;
  font-size: 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text);
}
.variant-btn.active {
  background: var(--color-ui-primary);
  color: white;
  border-color: var(--color-ui-primary);
}

/* Color toggle */
.color-toggle {
  display: flex;
  gap: 4px;
}
.color-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--color-bg);
  border: 2px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: var(--color-text);
}
.color-btn .color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.color-new .color-dot { background: var(--color-new); }
.color-renewed .color-dot { background: var(--color-renewed); }
.color-btn.active { border-color: currentColor; font-weight: 600; }
.color-new.active { color: var(--color-new); }
.color-renewed.active { color: var(--color-renewed); }

/* ---------- Workspace ---------- */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.app-bar {
  height: var(--app-bar-height);
  background: var(--color-ui-primary);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  flex-shrink: 0;
}
.app-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.page-nav, .zoom-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}
.page-nav button, .zoom-nav button {
  width: 28px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.page-nav button:hover, .zoom-nav button:hover {
  background: rgba(255, 255, 255, 0.3);
}
.page-indicator, #zoom-indicator {
  min-width: 52px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.zoom-nav button[data-action="zoom-fit"] { width: auto; padding: 0 8px; }

/* Canvas */
.canvas-wrapper {
  flex: 1;
  overflow: auto;
  background: #888;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: white;
  pointer-events: none;
}
.empty-state p { margin: 0; font-size: 16px; }
.empty-state .hint { font-size: 12px; opacity: 0.7; }

.page-container {
  position: relative;
  display: none;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  background: white;
}
.page-container.visible { display: block; }
.page-container canvas { display: block; }
.page-container svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}
.page-container svg.tool-select { cursor: default; }

/* Annotation styles (colors driven by data-color) */
.annotation { pointer-events: all; }
.annotation[data-color="new"] { color: var(--color-new); }
.annotation[data-color="renewed"] { color: var(--color-renewed); }
.annotation.selected { outline: 2px dashed #ff9800; outline-offset: 2px; }

/* Text annotations (foreignObject inner div) */
.annotation foreignObject > div {
  font-family: sans-serif;
  font-size: 14px;
  color: inherit;
  padding: 2px 4px;
  min-width: 40px;
  min-height: 18px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px dashed transparent;
  outline: none;
  white-space: pre-wrap;
}
.annotation foreignObject > div:focus {
  border-color: currentColor;
  background: white;
}

/* Status bar */
.status-bar {
  height: var(--status-bar-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  font-size: 12px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}
#status-autosave { margin-left: auto; }

/* Drag over state */
body.drag-over .canvas-wrapper {
  outline: 3px dashed var(--color-ui-primary);
  outline-offset: -8px;
}
