:root {
  --bg: #f7f7f7;
  --surface: #ffffff;
  --ink: #222222;
  --ink-soft: #717171;
  --line: #ebebeb;
  --accent: #222222;
  --accent-hover: #000000;
  --success: #008a05;
  --danger: #c13515;
  --measure: #ff385c;
  --calibrate: #008a05;
  --shape: #1a73e8;
  --shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.auth-screen,
.dashboard,
.account-screen {
  min-height: 100vh;
  min-height: 100dvh;
}

.auth-screen {
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(34, 34, 34, 0.06), transparent),
    var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  padding: 2rem 1.5rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-card .lang-switch {
  margin: 1.25rem auto 0;
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  text-align: left;
  margin: 1.25rem 0 1rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.auth-form input {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
}

.auth-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--danger);
  font-size: 0.85rem;
  font-weight: 500;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.25rem 0 0.85rem;
  color: var(--muted, #6b7280);
  font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line, #e5e7eb);
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  width: 100%;
  gap: 0.65rem;
  padding: 0.8rem 1rem;
  border: 1px solid #dadce0;
  border-radius: 999px;
  background: #fff;
  color: #3c4043;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  margin: 0 0 1rem;
  box-shadow: 0 1px 2px rgba(60, 64, 67, 0.08);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.btn-google-icon {
  flex-shrink: 0;
}

.btn-google:hover:not(:disabled) {
  background: #f8f9fa;
  box-shadow: 0 1px 3px rgba(60, 64, 67, 0.16);
}

.btn-google:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-secondary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

.auth-secondary .link-btn {
  margin-bottom: 0;
}

.auth-error.ok {
  color: #1b7f4a;
}

.link-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 0.85rem;
  text-decoration: underline;
}

#btn-local-mode {
  width: 100%;
  justify-content: center;
}

.account-screen {
  background: var(--bg);
}

.account-body {
  max-width: 520px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.account-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1.25rem 1.15rem;
}

.account-card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
}

.account-email {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
  word-break: break-all;
}

.account-hint {
  margin: 0 0 0.85rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  line-height: 1.4;
}

.account-msg {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.account-msg.ok {
  color: var(--success);
}

.account-msg.err {
  color: var(--danger);
}

.account-danger {
  border-color: #f0c7bc;
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:hover {
  filter: brightness(0.95);
}

.dashboard {
  background: var(--bg);
}

.dash-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: 56px;
  box-sizing: border-box;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.dash-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.dash-user {
  margin: 0;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.dash-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.dash-header .btn-primary,
.dash-header .btn-ghost {
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
}

.dash-body {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.dash-body h1 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
}

.dash-empty {
  color: var(--ink-soft);
}

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.project-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
}

.project-card-main {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.project-card-main strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.project-rename-input {
  width: 100%;
  max-width: 320px;
  padding: 0.4rem 0.55rem;
  border: 2px solid var(--ink);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.project-meta {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.project-card-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.project-card-actions .btn-sm {
  width: auto;
  padding: 0.45rem 0.75rem;
}

@media (max-width: 600px) {
  .project-card {
    flex-direction: column;
    align-items: stretch;
  }

  .project-card-actions {
    justify-content: stretch;
  }

  .project-card-actions .btn-sm {
    flex: 1;
    justify-content: center;
  }
}

/* ——— Welcome ——— */
.welcome {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(34, 34, 34, 0.06), transparent),
    var(--bg);
}

.lang-switch--corner {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
}

.welcome-inner {
  max-width: 520px;
  text-align: center;
}

.welcome-inner .welcome-secondary {
  display: inline-flex;
  margin-top: 0.75rem;
}

.welcome-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  justify-content: center;
  align-items: center;
  margin-top: 1.25rem;
}

/* ——— Start sheet (Airbnb / Uber Eats style) ——— */
.start-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

body.start-sheet-open {
  overflow: hidden;
}

.start-sheet.hidden {
  display: none !important;
}

.start-sheet-backdrop {
  position: absolute;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(34, 34, 34, 0.45);
  cursor: pointer;
  animation: startFadeIn 0.22s ease;
}

.start-sheet-panel {
  position: relative;
  width: min(440px, 100%);
  max-height: min(92vh, 640px);
  margin: 0;
  padding: 0.5rem 1.25rem 1.35rem;
  background: #fff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  animation: startSlideUp 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.start-sheet-handle {
  width: 40px;
  height: 4px;
  margin: 0.35rem auto 1rem;
  border-radius: 999px;
  background: #ddd;
}

.start-sheet-panel h2 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
}

.start-sheet-sub {
  margin: 0 0 1.15rem;
  font-size: 0.92rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.start-choices {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.start-choice {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  width: 100%;
  padding: 1rem 1rem;
  border: 1px solid #ebebeb;
  border-radius: 16px;
  background: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.start-choice:hover {
  border-color: #222;
  background: #fafafa;
}

.start-choice:active {
  transform: scale(0.985);
}

.start-choice-icon {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: #f2f2f2;
  color: var(--ink);
}

.start-choice-icon--maps {
  background: #e8f5e9;
  color: #1b5e20;
}

.start-choice-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.start-choice-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.start-choice-desc {
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

.start-choice-chevron {
  flex-shrink: 0;
  color: #b0b0b0;
}

.start-sheet-cancel {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0.85rem;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.start-sheet-cancel:hover {
  color: var(--ink);
  background: #f7f7f7;
}

@keyframes startFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes startSlideUp {
  from { transform: translateY(24px); opacity: 0.85; }
  to { transform: translateY(0); opacity: 1; }
}

@media (min-width: 640px) {
  .start-sheet {
    align-items: center;
    padding: 1.5rem;
  }

  .start-sheet-panel {
    border-radius: 24px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
    padding: 0.75rem 1.5rem 1.5rem;
    animation: startPopIn 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .start-sheet-handle {
    display: none;
  }
}

@keyframes startPopIn {
  from { transform: scale(0.96); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.plan-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: #eee;
  border: 1px solid var(--line);
}

.plan-badge.pro {
  color: #fff;
  background: var(--ink);
  border-color: var(--ink);
}

body.is-free .pro-only {
  display: none !important;
}

body.is-pro .free-only {
  display: none !important;
}

body.is-pro .pro-lock {
  display: none !important;
}

.pages-gallery-free-hint {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.account-plan {
  margin: 0 0 0.85rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.account-plan-row .btn-primary {
  width: 100%;
  justify-content: center;
}

.account-plan-pro-head {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 0.55rem;
}

.account-plan-active {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--success);
}

.account-plan-expiry {
  margin: 0 0 0.9rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.dash-pro-hint {
  margin: -0.5rem 0 1.25rem;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

/* Modal Pro */
.pro-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.pro-modal.hidden {
  display: none !important;
}

.pro-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.pro-modal-panel {
  position: relative;
  width: min(420px, 100%);
  padding: 1.75rem 1.5rem 1.5rem;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.pro-modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  line-height: 0;
}

.pro-modal-close svg {
  display: block;
}

.pro-modal-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.pro-gold-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5a4208;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 42%),
    linear-gradient(145deg, #f6e7a8 0%, #e4c45c 48%, #c49a2a 100%);
  border: 1px solid rgba(168, 128, 28, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.7),
    inset 0 -1px 0 rgba(140, 100, 20, 0.18),
    0 0 0 1px rgba(226, 190, 80, 0.25),
    0 0 10px rgba(228, 186, 60, 0.55),
    0 0 18px rgba(201, 154, 42, 0.35),
    0 1px 2px rgba(90, 65, 10, 0.18);
}

.pro-modal-panel .brand {
  margin-bottom: 0.75rem;
}

.pro-modal-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.45rem;
}

.pro-modal-lead {
  margin: 0 0 1rem;
  color: var(--ink-soft);
  line-height: 1.45;
  font-size: 0.95rem;
}

.pro-price {
  margin: 0 0 1rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.pro-price span {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.pro-pros {
  list-style: none;
  margin: 0 auto 1.25rem;
  padding: 0;
  width: max-content;
  max-width: 100%;
  text-align: left;
}

.pro-pros li {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.35rem 0;
  font-size: 0.92rem;
  color: var(--ink);
  text-align: left;
}

.pro-pros li::before {
  content: "";
  flex: 0 0 0.4rem;
  width: 0.4rem;
  height: 0.4rem;
  margin-top: 0.45em;
  border-radius: 50%;
  background: var(--ink);
}

.pro-lock {
  display: none;
  flex-shrink: 0;
}

body.is-free .pro-gate .pro-lock {
  display: inline-block;
  vertical-align: -0.1em;
  margin-right: 0.3rem;
  opacity: 0.75;
}

body.is-free .pro-gate.icon-btn {
  position: relative;
}

body.is-free .pro-gate.icon-btn .pro-lock {
  position: absolute;
  top: 2px;
  right: 2px;
  margin: 0;
  width: 9px;
  height: 9px;
  opacity: 0.9;
}

body.is-free .pro-gate {
  color: var(--ink-soft);
}

.pro-modal-note {
  margin: 0.85rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.brand {
  margin: 0 0 1.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--ink);
}

.welcome h1 {
  margin: 0 0 1rem;
  font-size: clamp(1.85rem, 4vw, 2.4rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.subtitle {
  margin: 0 0 2rem;
  font-size: 1.05rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.hint {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.9rem 1.6rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sm {
  width: 100%;
  padding: 0.7rem 1rem;
  font-size: 0.9rem;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.btn-ghost:hover {
  border-color: var(--ink);
  background: var(--bg);
}

.btn-ghost:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border: 1px solid #DDDDDD;
  border-radius: 8px;
  background: #fff;
  gap: 0;
}

.lang-btn {
  min-width: 34px;
  padding: 0.3rem 0.55rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.lang-btn:hover {
  color: var(--ink);
}

.lang-btn.active {
  background: var(--ink);
  color: #fff;
}

.btn-save-cloud,
#save-project-cloud {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn-save-cloud:hover,
#save-project-cloud:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-save-cloud .save-check,
#save-project-cloud .save-check {
  display: none;
  flex-shrink: 0;
}

.btn-save-cloud.has-unsaved,
#save-project-cloud.has-unsaved {
  background: var(--ink);
  color: #fff;
  border-color: transparent;
}

.btn-save-cloud.has-unsaved:hover,
#save-project-cloud.has-unsaved:hover {
  background: var(--accent-hover);
}

.btn-save-cloud.is-saved,
#save-project-cloud.is-saved {
  background: #F7F7F7;
  color: var(--ink);
  border: 1px solid #DDDDDD;
}

.btn-save-cloud.is-saved:hover,
#save-project-cloud.is-saved:hover {
  background: #EEEEEE;
  color: var(--ink);
}

.btn-save-cloud.is-saved .save-check,
#save-project-cloud.is-saved .save-check {
  display: inline-block;
}

body.is-free .btn-save-cloud.pro-gate,
body.is-free #save-project-cloud.pro-gate {
  background: #F7F7F7;
  color: var(--ink-soft);
  border: 1px solid #DDDDDD;
}

body.is-free .btn-save-cloud.pro-gate:hover,
body.is-free #save-project-cloud.pro-gate:hover {
  background: #EEEEEE;
  color: var(--ink-soft);
}

.save-status-dot {
  display: none !important;
}

.upload-btn {
  cursor: pointer;
}

/* ——— Workspace ——— */
.workspace {
  display: grid;
  grid-template-columns: 104px 1fr 280px;
  grid-template-rows: 56px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar-left,
.topbar-right,
.topbar-center {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.topbar-left {
  justify-self: start;
}

.topbar-center {
  justify-self: center;
  flex-shrink: 0;
}

.topbar-right {
  justify-self: end;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.brand-sm {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: none;
}

.doc-name {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.page-label-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.page-label-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--bg);
}

.pages-gallery {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.pages-gallery.hidden {
  display: none !important;
}

.pages-gallery-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 20, 0.45);
}

.pages-gallery-panel {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pages-gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--line);
}

.pages-gallery-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.pages-gallery-body {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.pages-gallery-source-title {
  margin: 0 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.pages-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.pages-thumb {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: border-color 0.15s ease;
  width: 100%;
}

.pages-thumb-wrap {
  position: relative;
}

.pages-thumb-wrap.active .pages-thumb,
.pages-thumb.active {
  border-color: #e85d04;
}

.pages-thumb-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  cursor: pointer;
  opacity: 0.92;
  transition: background 0.15s ease, transform 0.1s ease;
}

.pages-thumb-remove:hover {
  background: var(--danger);
  transform: scale(1.06);
}

.pages-thumb:hover {
  border-color: #ccc;
}

.pages-thumb.active {
  border-color: #e85d04;
}

.pages-thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #ddd;
}

.pages-thumb span {
  padding: 0 0.5rem 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.pages-gallery-foot {
  padding: 0.85rem 1.1rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  align-items: center;
}

.measure-name-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  background: #fff;
}

.measure-item-top .measure-type {
  flex: 1;
  min-width: 0;
  cursor: text;
  text-transform: none;
  letter-spacing: 0;
}

.measure-rename-btn {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
  flex-shrink: 0;
}

.measure-rename-btn:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.05);
}

.note-editor {
  position: absolute;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  background: #fff;
  border: 2px solid #1565c0;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  min-width: 180px;
}

.note-editor.hidden {
  display: none !important;
}

.note-editor input {
  border: none;
  outline: none;
  font: inherit;
  font-size: 0.875rem;
  width: 200px;
  color: var(--ink);
  background: transparent;
}

.measure-rename-hint {
  display: none;
}


.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: #ccc;
}

.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.unit-toggle {
  display: flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.unit-btn {
  min-width: 40px;
  padding: 0.35rem 0.7rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.unit-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.topbar-right {
  flex-wrap: wrap;
  justify-content: flex-end;
  row-gap: 0.35rem;
}

#toggle-sidebar {
  display: none;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
  padding: 0.75rem 0.4rem;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  min-width: 0;
}

.toolbar-label {
  margin: 0.4rem 0 0.25rem;
  padding: 0 0.2rem;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: normal;
  line-height: 1.25;
  text-align: center;
  overflow: visible;
  word-break: break-word;
}

.toolbar-divider {
  height: 1px;
  margin: 0.5rem 0.25rem;
  background: var(--line);
  flex-shrink: 0;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.55rem 0.2rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  min-height: 44px;
  flex-shrink: 0;
}

.tool-btn span {
  max-width: 100%;
  overflow: visible;
  white-space: normal;
  text-align: center;
  line-height: 1.15;
}

.tool-btn:hover {
  background: var(--bg);
  color: var(--ink);
}

.tool-btn.active {
  background: var(--ink);
  color: #fff;
}

.tool-btn.danger:hover {
  background: #fff0ed;
  color: var(--danger);
}

/* Canvas */
.canvas-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: #e8e8e8;
}

.canvas-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

.map-host {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #1a1a1a;
}

.map-host.hidden {
  display: none !important;
}

body.is-map-mode #main-canvas {
  visibility: hidden;
  pointer-events: none;
}

body.is-map-mode .map-host {
  display: block !important;
}

body.is-map-mode .canvas-stage {
  cursor: auto;
  touch-action: manipulation;
}

body.is-map-mode .canvas-stage.space-pan,
body.is-map-mode .canvas-stage.panning,
body.is-map-mode .canvas-stage.dragging {
  cursor: auto;
}

.map-search-bar {
  position: absolute;
  top: 0.65rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  width: min(440px, calc(100% - 1.5rem));
  pointer-events: none;
}

.map-search-bar.hidden {
  display: none !important;
}

.map-search-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
  pointer-events: auto;
}

.map-search-input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  font: inherit;
  font-size: 0.9rem;
}

.map-search-btn {
  flex-shrink: 0;
  width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  cursor: pointer;
}

.map-search-btn:hover {
  background: #f5f5f5;
}

.map-search-suggest {
  pointer-events: auto;
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0.35rem 0;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
}

.map-search-suggest.hidden {
  display: none !important;
}

.map-search-suggest li {
  margin: 0;
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--ink);
}

.map-search-suggest li:hover,
.map-search-suggest li[aria-selected="true"] {
  background: #f5f5f5;
}

.map-search-suggest li small,
.map-suggest-sub {
  display: block;
  color: var(--ink-soft);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.map-suggest-main {
  display: block;
  font-weight: 600;
}

/* Contrôle type de carte (remplace Map / Satellite natifs Google) */
.map-type-control {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  margin: 10px;
  font-family: var(--font);
}

.map-type-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  gap: 0;
}

.map-type-btn {
  appearance: none;
  margin: 0;
  padding: 0.45rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  white-space: nowrap;
  line-height: 1.2;
}

.map-type-btn:hover {
  color: var(--ink);
}

.map-type-btn.active {
  background: var(--ink);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.map-type-btn:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.map-type-labels {
  display: none;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}

.map-type-labels.is-visible {
  display: inline-flex;
}

.map-type-labels input {
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}

/* Bouton copier la vue (haut droite) */
.view-copy-btn {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 25;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.view-copy-btn:hover {
  background: var(--bg);
  border-color: var(--ink);
}

.view-copy-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

body.is-free .view-copy-btn.pro-gate {
  color: var(--ink-soft);
}

/* Masquer d’éventuels contrôles Map/Satellite natifs */
body.is-map-mode .gm-style-mtc,
body.is-map-mode .gm-style-mtc-bbw {
  display: none !important;
}

/* Zoom Google un peu plus arrondi */
body.is-map-mode .gm-bundled-control .gmnoprint > div,
body.is-map-mode .gm-bundled-control button {
  border-radius: 10px !important;
  overflow: hidden;
}

/* Dropdown natif Google Places — masqué (souvent vide / API legacy) */
.pac-container {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
  height: 0 !important;
  overflow: hidden !important;
}

.map-scale-hint {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: #e8f8e9;
  border: 1px solid rgba(0, 138, 5, 0.25);
  color: #0b5c10;
  font-size: 0.8rem;
  line-height: 1.4;
}

.map-scale-hint.hidden {
  display: none !important;
}

body.is-map-mode .cal-plan-only {
  display: none !important;
}

body.is-map-mode .map-scale-hint {
  display: block !important;
}

body.is-map-mode .tool-btn[data-tool="calibrate"],
body.is-map-mode .tool-btn[data-tool="perspective"] {
  display: none !important;
}

body.is-map-mode #page-nav {
  visibility: hidden !important;
}

.map-measure-label {
  position: absolute;
  transform: translate(-50%, -145%);
  padding: 0.28rem 0.55rem;
  border-radius: 8px;
  background: rgba(34, 34, 34, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #fff;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.25;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  user-select: none;
}

.map-measure-label.is-selected {
  background: var(--label-accent, #e85d04);
  border-color: rgba(255, 255, 255, 0.85);
}

.map-measure-label.is-movable {
  pointer-events: auto;
  cursor: grab;
  touch-action: none;
}

.map-measure-label.is-movable:active,
.map-measure-label.is-dragging {
  cursor: grabbing;
}

.label-editor {
  position: absolute;
  z-index: 5;
  display: flex;
  align-items: stretch;
  min-width: 110px;
  border-radius: 8px;
  overflow: hidden;
  background: #222;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.label-editor input {
  width: 84px;
  padding: 0.45rem 0.55rem;
  border: none;
  outline: none;
  background: transparent;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
}

.label-editor input::-webkit-outer-spin-button,
.label-editor input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.label-editor input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.label-editor span {
  display: grid;
  place-items: center;
  padding: 0 0.55rem;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: var(--ink);
  cursor: pointer;
}

.option-hint {
  margin: 0.55rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink-soft);
}

.precision-row {
  margin-top: 0.9rem;
  margin-bottom: 0;
}

.precision-toggle {
  display: flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--line);
}

.precision-btn {
  flex: 1;
  padding: 0.4rem 0.35rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.precision-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.canvas-stage.panning,
.canvas-stage.space-pan {
  cursor: grab;
}

.canvas-stage.panning.dragging,
.canvas-stage.space-pan.dragging {
  cursor: grabbing;
}

.canvas-stage.dragging-vertex {
  cursor: grabbing;
}

#main-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.status-bar {
  padding: 0.55rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.sidebar-block {
  padding: 1.1rem 1rem;
  border-bottom: 1px solid var(--line);
}

.sidebar h2 {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.sidebar-head h2 {
  margin: 0;
}

.cal-block-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin: 0 0 0.75rem;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  text-align: left;
}

.cal-block-toggle-label {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cal-block-chevron {
  flex-shrink: 0;
  transition: transform 0.18s ease;
}

#calibration-block.is-collapsed .cal-block-toggle {
  margin-bottom: 0;
}

#calibration-block.is-collapsed .cal-block-chevron {
  transform: rotate(0deg);
}

#calibration-block:not(.is-collapsed) .cal-block-chevron {
  transform: rotate(180deg);
}

#calibration-block.is-collapsed .cal-block-body {
  display: none;
}

.count {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.75rem;
  font-weight: 700;
}

.cal-status {
  margin-bottom: 0.9rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

.cal-status.pending {
  background: #fff8e6;
  color: #8a6d00;
}

.cal-status.ready {
  background: #e8f8e9;
  color: var(--success);
}

.cal-apply-hint {
  margin: 0.55rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: #e8f8e9;
  border: 1px solid rgba(0, 138, 5, 0.25);
  color: #0b5c10;
  font-size: 0.8rem;
  line-height: 1.4;
}

#apply-calibration.needs-attention {
  animation: cal-pulse 1.4s ease-in-out infinite;
  box-shadow: 0 0 0 3px rgba(0, 138, 5, 0.22);
}

.input-group:has(#ref-value.needs-attention) {
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(0, 138, 5, 0.15);
}

@keyframes cal-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
  }
}

.field-row {
  margin-bottom: 0.75rem;
}

.field-row label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s ease;
}

.input-group:focus-within {
  border-color: var(--ink);
}

.input-group input {
  flex: 1;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  border: none;
  outline: none;
  font-size: 0.95rem;
  background: transparent;
}

.input-suffix {
  display: grid;
  place-items: center;
  padding: 0 0.75rem;
  background: var(--bg);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  border-left: 1px solid var(--line);
}

.input-suffix-select {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0 1.6rem 0 0.7rem;
  border: none;
  border-left: 1px solid var(--line);
  background: var(--bg)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23717171' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 0.45rem center;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  outline: none;
}

.measure-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.measure-list .empty {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.measure-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.75rem;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid transparent;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.measure-item:hover {
  border-color: #ddd;
}

.measure-item.selected {
  border-color: #e85d04;
  background: #fff7f0;
}

.measure-item.selected .measure-type {
  color: #e85d04;
}

.measure-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.measure-type {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
}

.measure-delete {
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.measure-delete:hover {
  color: var(--danger);
}

.measure-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.measure-meta {
  font-size: 0.75rem;
  color: var(--ink-soft);
}

/* Loading */
.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 1rem;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  z-index: 100;
  text-align: center;
  font-weight: 600;
  color: var(--ink-soft);
}

.spinner {
  width: 36px;
  height: 36px;
  margin: 0 auto;
  border: 3px solid var(--line);
  border-top-color: var(--ink);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Responsive */
@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto auto;
  }

  .topbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 0.45rem 0.65rem;
    gap: 0.45rem;
    min-height: 52px;
    height: auto;
  }

  .dash-header {
    height: auto;
    min-height: 52px;
    padding: 0.45rem 0.65rem;
    gap: 0.45rem;
    flex-wrap: wrap;
  }

  .dash-header .btn-primary,
  .dash-header .btn-ghost {
    padding: 0.45rem 0.65rem;
    font-size: 0.75rem;
  }

  .topbar-left {
    order: 1;
    justify-self: unset;
  }

  .topbar-center {
    order: 3;
    width: 100%;
    justify-content: center;
    justify-self: unset;
  }

  .topbar-right {
    order: 2;
    margin-left: auto;
    justify-self: unset;
  }

  #toggle-sidebar {
    display: inline-flex;
  }

  .toolbar {
    grid-column: 1;
    grid-row: 3;
    flex-direction: row;
    align-items: stretch;
    gap: 0.2rem;
    padding: 0.4rem 0.5rem;
    border-right: none;
    border-top: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .toolbar-label,
  .toolbar-divider {
    display: none;
  }

  .tool-btn {
    min-width: 64px;
    padding: 0.45rem 0.35rem;
  }

  .canvas-wrap {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
  }

  .sidebar {
    grid-column: 1;
    grid-row: 4;
    flex-direction: column;
    max-height: min(42vh, 320px);
    border-left: none;
    border-top: 1px solid var(--line);
  }

  .workspace.sidebar-collapsed .sidebar {
    display: none;
  }

  .sidebar-block {
    flex: none;
    border-bottom: 1px solid var(--line);
    border-right: none;
    overflow-y: visible;
  }

  .sidebar-block:last-child {
    border-bottom: none;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }

  .doc-name {
    max-width: 110px;
  }

  .topbar-right .btn-ghost.upload-btn[for="load-project"],
  .topbar-right .btn-ghost.upload-btn[for="file-input-add"] {
    display: none;
  }

  .pages-gallery-panel {
    width: min(960px, 100%);
    max-height: min(88dvh, 720px);
  }

  .note-editor {
    min-width: 0;
    max-width: calc(100vw - 1.5rem);
  }

  .note-editor input {
    width: min(200px, 55vw);
  }
}

@media (max-width: 600px) {
  .welcome {
    padding: 1.25rem;
  }

  .welcome h1 {
    font-size: 1.55rem;
  }

  .topbar-center .page-label-btn {
    font-size: 0.8rem;
    padding: 0.35rem 0.6rem;
  }

  .btn-ghost {
    padding: 0.45rem 0.65rem;
    font-size: 0.75rem;
  }

  .unit-toggle {
    padding: 2px;
  }

  .unit-btn {
    padding: 0.3rem 0.45rem;
    font-size: 0.75rem;
  }

  .status-bar {
    font-size: 0.75rem;
    padding: 0.45rem 0.65rem;
  }

  .tool-btn {
    min-width: 58px;
    font-size: 0.6rem;
  }

  .topbar-right .btn-ghost#save-project {
    padding: 0.45rem 0.55rem;
  }
}
