/* EPlan on the web. System fonts, a light and a dark scheme, nothing fancy:
   the plan is the point. */

:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6e6e73;
  --line: #d9d9de;
  --accent: #1f6fd6;
  --accent-text: #ffffff;
  --danger: #c23b2f;
  --canvas-bg: #e9e9ee;
  --shadow: rgba(0, 0, 0, 0.15);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --text: #f2f2f7;
    --muted: #a1a1a6;
    --line: #48484a;
    --accent: #4f9cf5;
    --accent-text: #0b1a2e;
    --danger: #ff6b5e;
    --canvas-bg: #121214;
    --shadow: rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over any display rule below. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

.app { min-height: 100%; display: flex; flex-direction: column; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 36px;
}

button:disabled { cursor: default; opacity: 0.5; }

button.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

button.link {
  border: none;
  background: none;
  color: var(--accent);
  padding: 0;
  min-height: 0;
}

a { color: var(--accent); }

.loading { padding: 24px; color: var(--muted); }

/* Header bar shared by every screen */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .back { white-space: nowrap; }

.brand { font-weight: 700; letter-spacing: 0.2px; text-decoration: none; color: var(--text); }

/* Account menu */

.account { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 260px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px var(--shadow);
  padding: 8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu[hidden] { display: none; }

.menu .who { padding: 6px 8px; }
.menu .who .email { font-weight: 600; word-break: break-all; }
.menu .who .tier { color: var(--muted); font-size: 13px; }
.menu hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.menu label { display: flex; flex-direction: column; gap: 4px; padding: 4px 8px; font-size: 13px; color: var(--muted); }
.menu select { padding: 6px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); }
.menu button { text-align: left; border: none; background: none; padding: 8px; border-radius: 8px; }
.menu button:hover { background: var(--bg); }

/* Lists (projects, plans) */

.content {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 16px;
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.list li a, .list li .row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
}

.list li a:hover { border-color: var(--accent); }

.list .name { flex: 1; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.list .detail { color: var(--muted); font-size: 13px; white-space: nowrap; }

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}

.badge.premium { color: var(--accent); border-color: var(--accent); }

.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.error { color: var(--danger); padding: 12px 0; }

h2 { font-size: 20px; margin: 8px 0 12px; }

.subtitle { color: var(--muted); margin: -8px 0 16px; font-size: 14px; }

/* Sign-in */

.signin {
  width: min(100%, 420px);
  margin: 48px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.signin h2 { margin: 0; }
.signin p { margin: 0; color: var(--muted); }
.signin .note { font-size: 13px; }

.google, .apple {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  font-weight: 600;
}
/* Sign in with Apple: black on a light page, white on a dark one, as Apple's
   guidelines ask of a button in a single colour. */
.apple { background: #000; color: #fff; border: 1px solid #000; border-radius: 10px; }
.apple:hover { background: #222; }
@media (prefers-color-scheme: dark) {
  .apple { background: #fff; color: #000; border-color: #fff; }
  .apple:hover { background: #e6e6e6; }
}

.field { display: flex; flex-direction: column; gap: 4px; }
.field input {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
}

.devform { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.devform h3 { margin: 0; font-size: 14px; color: var(--muted); }

/* Viewer */

.viewer { flex: 1; display: flex; flex-direction: column; min-height: 100vh; height: 100vh; }
.viewer .topbar { flex: none; }
.viewer .stage { flex: 1; position: relative; min-height: 0; min-width: 0; background: var(--canvas-bg); overflow: hidden; }
.viewer .stage > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
.viewer .stage > canvas.dragging { cursor: grabbing; }
.viewer .stage > canvas.moving { cursor: move; }

/* The editor's workspace: the stage with the palette beside it (the iPad layout) or under it (the iPhone's bar). */

.workspace { flex: 1; display: flex; min-height: 0; }
.workspace.side-layout { flex-direction: row; }
.workspace.bar-layout { flex-direction: column; }

.tools .sync-status { color: var(--muted); font-size: 12px; white-space: nowrap; }

.tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.tools button { min-width: 36px; padding: 6px 10px; }
.tools .zoom { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; font-size: 13px; }

.standard { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.standard button { border: none; border-radius: 0; min-height: 34px; }
.standard button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }

.notice {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  box-shadow: 0 4px 16px var(--shadow);
  max-width: min(90%, 520px);
  font-size: 14px;
}

.notice[hidden] { display: none; }

/* Export dialog */

dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  padding: 20px;
  width: min(92vw, 360px);
  box-shadow: 0 12px 40px var(--shadow);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h2 { margin: 0 0 12px; font-size: 18px; }
dialog .switch { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
dialog .switch input { width: 18px; height: 18px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
dialog .status { color: var(--muted); font-size: 13px; min-height: 1.4em; margin: 8px 0 0; }

@media (max-width: 600px) {
  /* The title and the account button keep the first row; the tools wrap under them. */
  .topbar { flex-wrap: wrap; }
  .tools { order: 1; width: 100%; justify-content: flex-start; }
  .account { margin-left: auto; }
}

/* ---- Editor: the palette ---- */

.palette { flex: none; background: var(--surface); user-select: none; -webkit-user-select: none; }
.palette.locked { opacity: 0.45; pointer-events: none; }
.palette .cell {
  width: 68px;
  height: 66px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  padding: 4px 2px 0;
  border-radius: 8px;
  position: relative;
  touch-action: none;
  cursor: grab;
}
.palette .cell:hover { background: var(--bg); }
.palette .cell.dragging-out { opacity: 0.4; }
.palette .cell .glyph { display: block; }
.palette .cell .name {
  font-size: 10px;
  line-height: 1.15;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
  color: var(--text);
  width: 100%;
}
.palette .drag-hint {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 4px);
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 5;
  pointer-events: none;
}
.palette .recent-empty { color: var(--muted); font-size: 13px; text-align: center; margin: 12px 8px; grid-column: 1 / -1; }
.palette .size-toggle { min-height: 34px; padding: 4px 10px; }

/* The side panel: the controls on top, the ten group buttons down the leading edge, the group's symbols beside them. */

.palette.side-panel { border-left: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 6px; overflow: hidden; }
.palette.side-panel .controls { display: flex; justify-content: flex-end; height: 34px; }
.palette.side-panel .body { display: flex; gap: 8px; align-items: flex-start; }
.palette.side-panel .groups { display: flex; flex-direction: column; gap: 2px; flex: none; }
.palette.side-panel .group {
  width: 38px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  min-height: 0;
}
.palette.side-panel .group[aria-selected="true"] { background: var(--accent); color: var(--accent-text); }
.palette.side-panel .group svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.palette.side-panel .section { display: flex; flex-direction: column; min-width: 0; }
.palette.side-panel .group-name { height: 20px; font-size: 12px; font-weight: 600; color: var(--muted); line-height: 20px; }
.palette.side-panel .grid { display: grid; column-gap: 4px; row-gap: 2px; }

/* The bottom bar: the group menu, the paged strip, the size button. */

.palette.bottom-bar { border-top: 1px solid var(--line); padding: 6px 10px; }
.palette.bottom-bar .bar-row { display: flex; align-items: center; gap: 8px; }
.palette.bottom-bar .group-menu { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--text); max-width: 150px; min-height: 36px; }
.palette.bottom-bar .strip { flex: 1; display: flex; align-items: center; gap: 4px; min-width: 0; height: 70px; }
.palette.bottom-bar .cells { flex: 1; display: flex; gap: 4px; justify-content: center; min-width: 0; }
.palette.bottom-bar .chevron { width: 28px; min-width: 28px; padding: 0; min-height: 36px; }

/* ---- Editor: overlays on the stage ---- */

.canvas-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  box-shadow: 0 4px 16px var(--shadow);
  max-width: min(92%, 640px);
  font-size: 13px;
  font-weight: 500;
  z-index: 6;
}
.canvas-banner .banner-note { color: var(--muted); font-weight: 400; font-size: 12px; }

.drag-prompt {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: 0 4px 16px var(--shadow);
  font-size: 13px;
  color: var(--muted);
  pointer-events: none;
  z-index: 6;
}

.mini-toolbar {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 4px 16px var(--shadow);
  padding: 2px;
  z-index: 8;
}
.mini-toolbar button {
  width: 44px;
  height: 40px;
  min-height: 0;
  padding: 0;
  border: none;
  background: none;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.mini-toolbar button + button { border-left: 1px solid var(--line); border-radius: 0; }
.mini-toolbar button:last-child { border-top-right-radius: 999px; border-bottom-right-radius: 999px; }
.mini-toolbar button:hover { background: var(--bg); }
.mini-toolbar button.danger { color: var(--danger); }
.mini-toolbar svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

.drag-ghost { position: fixed; pointer-events: none; z-index: 50; opacity: 0.85; }

.size-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(360px, calc(100% - 24px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 28px var(--shadow);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 7;
}
.size-panel .size-row { display: flex; align-items: center; gap: 12px; }
.size-panel .size-caption { font-size: 13px; color: var(--muted); }
.size-panel input[type="range"] { flex: 1; min-width: 0; }
.size-panel .size-value { font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; font-size: 14px; color: var(--muted); }

/* The inspector: a panel docked at the stage's top-right corner, the canvas still usable beside it. */

dialog.inspector {
  position: absolute;
  inset: 12px 12px auto auto;
  margin: 0;
  width: min(320px, calc(100% - 24px));
  z-index: 9;
  max-height: calc(100% - 24px);
  overflow: auto;
}
.inspector-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.inspector-glyph { flex: none; }
.inspector-title { font-weight: 600; }
.inspector-subtitle { color: var(--muted); font-size: 13px; }
dialog .field { margin-bottom: 10px; font-size: 13px; color: var(--muted); }
dialog .field input, dialog .field textarea {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  margin-top: 4px;
  resize: vertical;
}
dialog .field .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 20px; letter-spacing: 2px; text-transform: uppercase; }
dialog .field .hint { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
dialog .description { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.inspector .footnote { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
button.danger { color: var(--danger); border-color: var(--danger); background: var(--surface); }

/* The start card of a plan with no floorplan, over the blank grid. */

.start-card {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(360px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 40px var(--shadow);
  padding: 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 5;
}
.start-card h2 { margin: 0; font-size: 18px; }
.start-card p { margin: 0; color: var(--muted); font-size: 14px; }
.start-card .note { font-size: 12px; }
.start-card .status { min-height: 1.2em; font-size: 13px; }
.start-card .status.error { color: var(--danger); }
.start-card button { min-height: 44px; font-weight: 600; }

/* ---- Projects and plans: edit mode, rows, sections ---- */

.list li .row.editing { padding: 6px 8px; gap: 8px; }
.list li .row.editing .rename {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: none;
  text-align: left;
  padding: 6px 4px;
  min-width: 0;
}
.list li .row.editing .rename .name { color: var(--text); }
.list li .row.editing .pencil { color: var(--muted); }
.list li .minus, .list li .minus-space { width: 32px; height: 32px; min-height: 0; padding: 0; border-radius: 50%; flex: none; }
.list li .minus { color: #fff; background: var(--danger); border: none; font-size: 20px; line-height: 1; }
.list li .row.action { width: 100%; text-align: left; color: var(--accent); font-weight: 600; cursor: pointer; }
.list li .row.action:hover { border-color: var(--accent); }
.list li .name .email { display: block; font-weight: 400; }
.list li.empty { color: var(--muted); padding: 8px 0; }
.list-section { margin-top: 20px; }
.list-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 0 0 8px; }
.list-section .muted { color: var(--muted); font-size: 14px; margin: 6px 0; }
.sharing .invite { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.sharing .invite .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 24px; letter-spacing: 3px; font-weight: 600; }
.empty-state { text-align: center; padding: 48px 0; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.empty-state h2 { margin: 0; }
.empty-state p { color: var(--muted); margin: 0; max-width: 360px; }
.empty-state .actions { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
dialog form .actions { margin-top: 14px; }
dialog .error[hidden] { display: none; }
