/* Floor Plan Drawing Tool */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #22263a;
  --border: rgba(255,255,255,0.08);
  --text: #e8eaf0;
  --text-muted: #7b82a0;
  --accent: #c8f060;
  --accent-dark: #a8d040;
  --blue: #3b82f6;
  --danger: #ef4444;
  --radius: 8px;
}

body {
  font-family: 'DM Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ─── HEADER ─────────────────────────────────── */
#fp-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}

#fp-back-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}
#fp-back-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }

#fp-title-wrap {
  flex: 1;
  min-width: 0;
}
#fp-title {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 340px;
  transition: border-color 0.15s, background 0.15s;
}
#fp-title:hover { border-color: var(--border); }
#fp-title:focus { outline: none; border-color: var(--accent); background: var(--surface-2); }

#fp-stats {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

#fp-save-status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
#fp-save-status.saved { color: var(--accent); }
#fp-save-status.error { color: var(--danger); }

.fp-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.fp-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}
.fp-btn:hover { background: #2a2e45; border-color: rgba(255,255,255,0.15); }
.fp-btn.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.fp-btn.primary:hover { background: var(--accent-dark); }
.fp-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ─── TOOLBAR ────────────────────────────────── */
#fp-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  height: 44px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.tool-sep {
  width: 1px;
  height: 22px;
  background: var(--border);
  flex-shrink: 0;
  margin: 0 4px;
}

.tool-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.tool-btn:hover { background: var(--surface-2); color: var(--text); }
.tool-btn.active { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.tool-btn.active-accent { background: rgba(200,240,96,0.15); color: var(--accent); border-color: rgba(200,240,96,0.3); }

.zoom-label {
  font-size: 11px;
  color: var(--text-muted);
  min-width: 38px;
  text-align: center;
  flex-shrink: 0;
}

.toolbar-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── MAIN AREA ──────────────────────────────── */
#fp-main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ─── CANVAS WRAP ────────────────────────────── */
#fp-canvas-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  overflow: hidden;
  cursor: crosshair;
}
#fp-canvas-wrap.tool-select { cursor: default; }
#fp-canvas-wrap.cursor-move { cursor: move; }
#fp-canvas-wrap.cursor-grab { cursor: grab; }
#fp-canvas-wrap.cursor-grabbing { cursor: grabbing; }
#fp-canvas-wrap.cursor-nw-resize { cursor: nw-resize; }
#fp-canvas-wrap.cursor-ne-resize { cursor: ne-resize; }
#fp-canvas-wrap.cursor-se-resize { cursor: se-resize; }
#fp-canvas-wrap.cursor-sw-resize { cursor: sw-resize; }
#fp-canvas-wrap.cursor-n-resize { cursor: n-resize; }
#fp-canvas-wrap.cursor-e-resize { cursor: e-resize; }
#fp-canvas-wrap.cursor-s-resize { cursor: s-resize; }
#fp-canvas-wrap.cursor-w-resize { cursor: w-resize; }

#fp-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Coord display */
#fp-coords {
  position: absolute;
  bottom: 10px;
  left: 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: rgba(15,17,23,0.7);
  padding: 3px 8px;
  border-radius: 4px;
  pointer-events: none;
  backdrop-filter: blur(4px);
}

/* ─── ROOMS PANEL ────────────────────────────── */
#fp-rooms-panel {
  width: 230px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fp-panel-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.fp-panel-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

#fp-room-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.fp-room-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.1s;
}
.fp-room-item:hover { background: var(--surface-2); }
.fp-room-item.selected { background: rgba(59,130,246,0.08); border-left-color: var(--blue); }

.fp-room-color {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}
.fp-room-info { flex: 1; min-width: 0; }
.fp-room-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fp-room-dims { font-size: 11px; color: var(--text-muted); }
.fp-room-note { font-size: 10px; color: #5a6070; line-height: 1.4; margin-top: 2px; font-style: italic; }

.fp-room-name-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  padding: 1px 0;
  width: 100%;
  outline: none;
}
.fp-room-name-input:focus { border-bottom-color: var(--accent); }

.fp-room-notes-ta {
  display: block;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  font-family: inherit;
  padding: 4px 0 2px;
  width: 100%;
  outline: none;
  resize: none;
  line-height: 1.4;
  font-style: italic;
  margin-top: 4px;
}
.fp-room-notes-ta:focus { border-top-color: rgba(200,240,96,0.4); color: var(--text); font-style: normal; }
.fp-room-notes-ta::placeholder { color: #5a6070; }

.fp-room-resize-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 9px;
  font-family: inherit;
  padding: 1px 5px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
}
.fp-room-resize-btn:hover { color: var(--text); border-color: rgba(255,255,255,0.2); }

.fp-room-edit-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.1s;
}
.fp-room-item:hover .fp-room-edit-btn { opacity: 1; }
.fp-room-edit-btn:hover { color: var(--text); }

.fp-panel-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.fp-panel-total-label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.fp-panel-total-value { font-size: 14px; font-weight: 700; color: var(--accent); }

.fp-notes-wrap {
  padding: 10px 14px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.fp-notes-wrap textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  padding: 7px 9px;
  resize: none;
  line-height: 1.5;
}
.fp-notes-wrap textarea::placeholder { color: var(--text-muted); }
.fp-notes-wrap textarea:focus { outline: none; border-color: rgba(200,240,96,0.4); }

/* ─── MODALS ─────────────────────────────────── */
.fp-modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.fp-modal-bg[hidden] { display: none; }

.fp-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  width: 340px;
  max-width: calc(100vw - 32px);
}
.fp-modal h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 18px;
}

.fp-modal .fg {
  margin-bottom: 14px;
}
.fp-modal label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.fp-modal input[type="text"],
.fp-modal input[type="number"] {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 10px;
  transition: border-color 0.15s;
}
.fp-modal input:focus { outline: none; border-color: rgba(200,240,96,0.5); }

.fp-modal .two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.fp-modal-preview {
  font-size: 13px;
  color: var(--accent);
  margin: 4px 0 14px;
  font-weight: 500;
  min-height: 20px;
}

.fp-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}
.fp-modal-actions .fp-btn { padding: 8px 18px; }

/* ─── EMPTY STATE ────────────────────────────── */
.fp-empty-hint {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
  color: var(--text-muted);
}
.fp-empty-hint svg { opacity: 0.25; margin-bottom: 12px; }
.fp-empty-hint p { font-size: 14px; line-height: 1.5; }
.fp-empty-hint small { font-size: 12px; opacity: 0.7; }

/* ─── MOBILE ─────────────────────────────────── */
@media (max-width: 640px) {
  #fp-stats, .toolbar-hint { display: none; }
  #fp-rooms-panel { display: none; }
  #fp-title { max-width: 180px; font-size: 14px; }
}
