/* ============ Peterson Interior Designer — styles ============ */
:root {
  --bg: #0e1014;
  --panel: #15181f;
  --panel-2: #1b1f28;
  --line: #262b36;
  --text: #e7eaf0;
  --text-dim: #8b93a3;
  --accent: #f5a623;
  --accent-2: #ffd97a;
  --danger: #e5484d;
  --ok: #46a758;
  --blue: #4ea8ff;
  --canvas: #f4f1ea;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0,0,0,.45);
  --font: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

#app { display: flex; flex-direction: column; height: 100vh; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #191d25, #13161c);
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 210px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #d9811a);
  color: #14100a; font-weight: 800; font-size: 18px;
  display: grid; place-items: center;
  box-shadow: 0 2px 10px rgba(245,166,35,.35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 13px; letter-spacing: .2px; }
.brand-text small { color: var(--text-dim); font-size: 10.5px; }

.toolbar { display: flex; align-items: center; gap: 4px; flex: 1; flex-wrap: wrap; }
.tool {
  display: flex; align-items: center; gap: 6px;
  background: transparent; border: 1px solid transparent;
  color: var(--text-dim); padding: 6px 9px; border-radius: 8px;
  cursor: pointer; font-family: var(--font); font-size: 12px;
  transition: all .15s ease;
}
.tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool:hover { background: var(--panel-2); color: var(--text); }
.tool.active { background: rgba(245,166,35,.14); color: var(--accent-2); border-color: rgba(245,166,35,.35); }
.tool:disabled { opacity: .35; cursor: default; }
.tool:disabled:hover { background: transparent; color: var(--text-dim); }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

.viewswitch { display: flex; background: var(--panel-2); border-radius: 9px; padding: 3px; border: 1px solid var(--line); }
.viewswitch button {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 5px 12px; border-radius: 7px; cursor: pointer;
  font-family: var(--font); font-size: 12px; font-weight: 600;
  transition: all .15s ease;
}
.viewswitch button.active { background: var(--accent); color: #171207; box-shadow: 0 1px 6px rgba(245,166,35,.4); }

.top-right { margin-left: auto; }
.save-indicator { color: var(--ok); font-size: 11px; opacity: .9; transition: opacity .3s; }

/* ---------- main ---------- */
#main { display: flex; flex: 1; min-height: 0; }

#sidebar {
  width: 238px; flex: none; overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
}
.panel h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--text-dim); margin-bottom: 8px;
  display: flex; align-items: baseline; gap: 6px;
}
.panel h3 small { text-transform: none; letter-spacing: 0; color: var(--text-dim); opacity: .8; }
#room-count { color: var(--accent); }

#room-list { list-style: none; max-height: 210px; overflow-y: auto; }
#room-list li {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 7px; border-radius: 7px; cursor: pointer;
  color: var(--text-dim); font-size: 12px;
  transition: background .12s;
}
#room-list li:hover { background: rgba(255,255,255,.05); color: var(--text); }
#room-list li.active { background: rgba(245,166,35,.12); color: var(--accent-2); }
#room-list .dot { width: 8px; height: 8px; border-radius: 3px; flex: none; }
#room-list .area { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--text-dim); }

#furniture-list {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  max-height: 260px; overflow-y: auto;
}
.fitem {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 7px 2px; border-radius: 8px; cursor: grab;
  border: 1px solid var(--line); background: var(--panel);
  transition: all .12s;
}
.fitem:hover { border-color: var(--accent); transform: translateY(-1px); background: #20242e; }
.fitem .glyph { width: 26px; height: 20px; }
.fitem span { font-size: 9.5px; color: var(--text-dim); text-align: center; line-height: 1.1; }

#material-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.mitem {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 7px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--panel);
  font-size: 11px; color: var(--text-dim);
  transition: all .12s;
}
.mitem:hover { border-color: var(--accent); color: var(--text); }
.mitem.active { border-color: var(--accent); background: rgba(245,166,35,.12); color: var(--accent-2); }
.mitem .swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; border: 1px solid rgba(0,0,0,.35); }

.hint { font-size: 10.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.4; }

#panel-legend ul { list-style: none; display: flex; flex-direction: column; gap: 5px; }
#panel-legend li { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--text-dim); }
.sw { width: 22px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,.4); }
.sw-load { background: #3a3f4a; }
.sw-part { background: #e8e4da; }
.sw-demo { background: repeating-linear-gradient(45deg, #e5484d 0 4px, #ffe 4px 8px); }
.sw-sel { background: var(--accent); }

/* ---------- viewport ---------- */
#viewport { flex: 1; position: relative; min-width: 0; background: #20242e; }
#canvas2d {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  cursor: default;
  transition: opacity .45s ease, transform .45s ease;
}
#canvas2d.hidden { opacity: 0; pointer-events: none; transform: scale(.96); }

#view3d {
  position: absolute; inset: 0;
  transition: opacity .45s ease, transform .45s ease;
}
#view3d.hidden { opacity: 0; pointer-events: none; transform: scale(1.04); }
#three-container, #three-container canvas { width: 100%; height: 100%; display: block; }

#three-ui {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; align-items: center;
  background: rgba(21,24,31,.92); border: 1px solid var(--line);
  border-radius: 12px; padding: 5px;
  box-shadow: var(--shadow);
}
#three-ui button {
  background: transparent; border: 0; color: var(--text-dim);
  padding: 6px 12px; border-radius: 8px; cursor: pointer;
  font-family: var(--font); font-size: 12px; font-weight: 600;
  transition: all .15s;
}
#three-ui button:hover { color: var(--text); background: var(--panel-2); }
#three-ui button.active { background: var(--accent); color: #171207; }
#three-ui button.toggle.active { background: var(--panel-2); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#three-ui .ui-sep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
#three-ui .bright { display: flex; align-items: center; gap: 6px; padding: 0 8px 0 4px; color: var(--text-dim); }
#three-ui .bright svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
#three-ui .bright input { width: 92px; accent-color: var(--accent); }
.walk-hint {
  padding: 6px 12px; font-size: 11px; color: var(--text-dim);
  border-left: 1px solid var(--line); margin-left: 4px;
}
.walk-hint b { color: var(--text); }
.hidden { display: none !important; }

#toast {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(21,24,31,.95); border: 1px solid var(--line);
  padding: 9px 16px; border-radius: 10px; font-size: 12.5px;
  box-shadow: var(--shadow);
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(4px); }
#toast.err { border-color: rgba(229,72,77,.6); color: #ffb3b5; }
#toast.ok { border-color: rgba(70,167,88,.6); color: #a9e6b5; }

#tooltip {
  position: absolute; pointer-events: none;
  background: rgba(21,24,31,.95); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 8px; font-size: 11.5px;
  box-shadow: var(--shadow);
  opacity: 0; transition: opacity .15s;
  z-index: 20;
}

/* ---------- status bar ---------- */
#statusbar {
  display: flex; gap: 24px; align-items: center;
  padding: 5px 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  color: var(--text-dim); font-size: 11px;
  flex: none; z-index: 30;
}
#statusbar span { font-family: var(--mono); }
#st-info { flex: 1; font-family: var(--font); }

/* ---------- scrollbars ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2c323f; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- touch + small screens ---------- */
#canvas2d, #three-container canvas { touch-action: none; }
.tools-group { display: contents; }
.menu-btn, #btn-panels, .drawer-close { display: none; }
body.panels-open .drawer-close {
  display: block; align-self: flex-end; flex: none;
  background: var(--accent); color: #171207; border: 0; border-radius: 8px;
  padding: 7px 14px; font: 600 12.5px var(--font); cursor: pointer;
}
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 45; }

/* walk joystick (shown in walk mode on touch screens) */
#touch-walk { position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#joy {
  position: absolute; left: calc(18px + env(safe-area-inset-left)); bottom: calc(86px + env(safe-area-inset-bottom));
  width: 128px; height: 128px; border-radius: 50%;
  background: rgba(21,24,31,.38); border: 1px solid rgba(255,255,255,.28);
  pointer-events: auto; touch-action: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px;
  border-radius: 50%; background: rgba(245,166,35,.85); box-shadow: 0 2px 10px rgba(0,0,0,.35);
}

@media (max-width: 980px) {
  #sidebar { display: none; }
  .tool span { display: none; }
  #btn-panels { display: flex; }
  body.panels-open #sidebar {
    display: flex; position: fixed; left: 0; top: 0; bottom: 0; z-index: 50;
    width: min(86vw, 300px); box-shadow: var(--shadow);
    padding-top: calc(10px + env(safe-area-inset-top));
  }
}

@media (max-width: 700px) {
  body { font-size: 12px; }
  #app { height: 100dvh; }
  #topbar {
    flex-wrap: wrap; gap: 6px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }
  .brand { min-width: 0; }
  .brand-mark { width: 30px; height: 30px; font-size: 16px; }
  .brand-text, .top-right, .sep, .long, #statusbar { display: none; }
  .toolbar { display: contents; }          /* its children sit directly in the top bar */
  #levelswitch { margin-left: auto; }
  .viewswitch button { padding: 6px 11px; font-size: 12.5px; }
  .menu-btn { display: flex; padding: 7px 8px; }
  .menu-btn svg { fill: currentColor; stroke: none; }
  .tools-group { display: none; }
  #topbar.menu-open .tools-group {
    display: flex; order: 10; width: 100%; gap: 2px;
    overflow-x: auto; padding-top: 4px; border-top: 1px solid var(--line);
  }
  .tool { padding: 8px 9px; }
  .tool svg { width: 18px; height: 18px; }

  #three-ui {
    left: 8px; right: 8px; transform: none;
    bottom: calc(10px + env(safe-area-inset-bottom));
    justify-content: center; gap: 2px; padding: 4px; border-radius: 12px;
  }
  #three-ui button { padding: 8px 9px; font-size: 12px; }
  #three-ui .opt, #three-ui .walk-hint { display: none !important; }
  #three-ui .ui-sep { margin: 2px; }
  #three-ui .bright { padding: 0 2px 0 4px; gap: 4px; }
  #three-ui .bright input { width: 56px; }
  #toast { top: 8px; max-width: calc(100vw - 24px); }
}
