:root {
  --ink: #1d2528;
  --muted: #617074;
  --line: #d8e0df;
  --surface: #ffffff;
  --soft: #eef4f1;
  --accent: #16735f;
  --accent-strong: #0f5747;
  --warn: #b86713;
  --danger: #a63d3d;
  --blue: #2f6f9f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: #f6f8f7;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
img, canvas { max-width: 100%; }
a { color: inherit; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 32px);
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 22px;
  font-weight: 800;
  text-decoration: none;
}
.brand img {
  width: 154px;
  height: 56px;
  object-fit: contain;
}
.topbar nav { display: flex; align-items: center; gap: 12px; font-size: 14px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--accent-strong); font-weight: 700; }
.nav-form { margin: 0; }
.link-button {
  min-height: auto;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent-strong);
  font: inherit;
  font-weight: 700;
}
.shell { width: min(1180px, calc(100% - 28px)); margin: 24px auto 48px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head.compact { align-items: center; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(28px, 5vw, 44px); line-height: 1; margin-bottom: 8px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.messages { display: grid; gap: 8px; margin-bottom: 16px; }
.message { margin: 0; padding: 10px 12px; border-radius: 8px; background: var(--soft); border: 1px solid var(--line); }
.message.error { border-color: #e1a7a7; background: #fff1f1; }
.message.success { border-color: #a7d9c6; background: #effaf5; }
.offline-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid #e3c78e;
  border-radius: 8px;
  background: #fff8e9;
  color: #5d4219;
  font-weight: 800;
}
.offline-banner[hidden] { display: none; }
.offline-banner small {
  color: var(--muted);
  font-weight: 700;
}
.sync-button {
  margin-left: auto;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--warn);
}
.offline-action.is-loading {
  opacity: .75;
  cursor: progress;
}
.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}
.button.secondary { background: var(--ink); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.auth-panel {
  max-width: 460px;
  margin: 8vh auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.auth-logo {
  width: 180px;
  height: 66px;
  margin-bottom: 14px;
  object-fit: contain;
}
.form { display: grid; gap: 12px; }
.form.wide { max-width: 680px; }
label, legend { font-weight: 750; font-size: 14px; }
input, select, textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
textarea { resize: vertical; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.check { display: block; margin: 8px 0; font-weight: 600; }
.check input { width: auto; margin-right: 8px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.stats span, .status-strip span {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}
.status-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.status-strip strong { display: block; color: var(--ink); font-size: 18px; }
.inline-form, .filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: end;
}
.list { display: grid; gap: 14px; }
.floor-row { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.plans { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.plan-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.plan-link {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--soft);
  text-decoration: none;
  font-weight: 800;
}
.plan-edit {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 72px minmax(160px, 1fr) auto;
  gap: 8px;
  align-items: end;
}
.plan-edit input { margin-top: 0; }
.danger-button {
  background: var(--danger);
}
.danger-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}
.plan-shell {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.viewer-toolbar {
  position: sticky;
  top: 63px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(8px);
}
.tool-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  background: var(--ink);
}
.tool-button:disabled {
  cursor: not-allowed;
  opacity: .35;
}
.page-indicator,
.zoom-indicator {
  min-width: 56px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.plan-stage {
  position: relative;
  min-height: 70vh;
  overflow: auto;
  padding: 16px;
  background: #c8d0ce;
  cursor: grab;
  touch-action: none;
}
.plan-stage:active { cursor: grabbing; }
.plan-canvas-wrap {
  position: relative;
  margin: 0 auto;
  background: #fff;
  box-shadow: 0 14px 34px rgba(0,0,0,.18);
}
.plan-canvas-wrap canvas,
.plan-canvas-wrap img {
  display: block;
  background: #fff;
  user-select: none;
}
.annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
}
.viewer-error {
  padding: 24px;
  color: var(--danger);
  font-weight: 800;
}
.pin {
  position: absolute;
  width: 34px;
  height: 34px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 3px solid #fff;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  box-shadow: 0 8px 20px rgba(0,0,0,.24);
}
.pin.preview { background: var(--blue); pointer-events: none; }
.point-drawer { position: sticky; top: 82px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.tap-hint { padding: 10px; background: var(--soft); border-radius: 8px; color: var(--muted); font-weight: 700; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: var(--soft); font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 14px; align-items: start; }
.photos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }
.photos img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.comment { padding: 10px 0; border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  body { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  .topbar { align-items: flex-start; padding: 8px 14px; }
  .brand img { width: 140px; height: 50px; }
  .topbar nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px rgba(0,0,0,.08);
  }
  .topbar nav span { display: none; }
  .topbar nav a,
  .topbar nav .link-button {
    width: 100%;
    min-height: 48px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--ink);
    text-align: center;
  }
  .nav-form { display: contents; }
  .shell { width: min(100% - 18px, 1180px); margin-top: 14px; }
  .offline-banner {
    position: sticky;
    top: 66px;
    z-index: 8;
  }
  .page-head, .workspace, .detail-grid { grid-template-columns: 1fr; display: grid; }
  .page-head { gap: 10px; }
  .page-head .actions,
  .page-head > .button,
  .page-head > a.button { width: 100%; }
  .actions .button { flex: 1 1 150px; }
  .button, button { min-height: 46px; }
  .point-drawer { position: static; }
  .viewer-toolbar { top: 67px; overflow-x: auto; }
  .plan-stage { min-height: 58vh; padding: 10px; }
  .inline-form, .filters { grid-template-columns: 1fr; }
  .plan-edit { grid-template-columns: 1fr; }
  .auth-panel { margin: 18px auto; padding: 18px; }
  h1 { font-size: 30px; line-height: 1.05; }
  .card, .panel { padding: 14px; }
  .photos { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .status-strip {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .status-strip span { min-height: 64px; }
  .table-wrap {
    overflow: visible;
    background: transparent;
    border: 0;
  }
  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
    min-width: 0;
  }
  thead { display: none; }
  tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
  }
  td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }
  td:last-child { border-bottom: 0; }
  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
  }
  td[colspan] {
    display: block;
  }
  td[colspan]::before { content: ""; }
}
