/* Everhall Plan editor */
:root {
  --bg: #f6f4ef; --panel: #ffffff; --ink: #1d2321; --muted: #69706d; --line: #e3e0d8; --line2: #d4d0c6;
  --accent: #1f3a34; --accent-ink: #ffffff; --accent-soft: #e5ece9; --brass: #b08d4f;
  --err: #b0261c; --err-soft: #fbeceb; --warn: #94600c; --warn-soft: #fbf3e2; --info: #2a6f97; --info-soft: #e8f1f6;
  --canvas: #fbfaf7; --grid1: #ecebe6; --grid2: #dcdad2; --sel: #2a7de1;
  --r: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; font-size: 14px; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); } .small { font-size: 12px; }
h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px; flex-wrap: nowrap; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand img { border-radius: 6px; }
.title-input { min-width: 120px; flex: 0 1 260px; border: 1px solid transparent; border-radius: 6px; padding: 6px 8px; background: transparent; font-weight: 600; }
.title-input:hover { border-color: var(--line); } .title-input:focus { border-color: var(--accent); outline: none; background: #fff; }
.tb { display: flex; gap: 4px; align-items: center; }
.tb.grow-end { margin-left: auto; }
.tb > button, .btn, .menu > button { border: 1px solid var(--line2); background: #fff; border-radius: 7px; padding: 6px 11px; white-space: nowrap; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; line-height: 1.3; }
.tb > button:hover, .btn:hover, .menu > button:hover { background: #f3f2ee; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #2b4d45; }
button:disabled { opacity: .4; cursor: default; }
button.icon { padding: 5px 7px; }
button.icon svg, .tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu { position: relative; }
.menu-list { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line2); border-radius: var(--r); box-shadow: var(--shadow); padding: 4px; z-index: 30; min-width: 210px; }
.menu.open .menu-list { display: block; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; }
.menu-list button:hover { background: var(--accent-soft); }

/* layout */
.layout { flex: 1; display: grid; grid-template-columns: 228px 1fr 330px; min-height: 0; }
.left, .right { background: var(--panel); overflow-y: auto; min-height: 0; }
.left { border-right: 1px solid var(--line); padding: 14px 12px; }
.left section + section { margin-top: 18px; }
.right { border-left: 1px solid var(--line); display: flex; flex-direction: column; }
.preset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.preset-grid button, .furn-list button { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 7px; text-align: left; font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.preset-grid button:hover, .furn-list button:hover { border-color: var(--accent); background: var(--accent-soft); }
.preset-grid i { width: 10px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.18); flex: none; }
.furn-list { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

/* stage */
.stage { position: relative; min-width: 0; min-height: 0; background: var(--canvas); overflow: hidden; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; outline: none; font-family: Arial, Helvetica, sans-serif; }
#cv.tool-door, #cv.tool-window, #cv.tool-open { cursor: crosshair; }
#cv.panning { cursor: grabbing; }
.grid-minor { stroke: var(--grid1); stroke-width: 1; fill: none; }
.grid-major { stroke: var(--grid2); stroke-width: 1; fill: none; }
.toolbar { position: absolute; left: 12px; top: 12px; z-index: 5; display: flex; gap: 3px; align-items: center; background: #fff; border: 1px solid var(--line2); border-radius: 10px; padding: 4px; box-shadow: var(--shadow); flex-wrap: wrap; max-width: calc(100% - 24px); }
.tool { border: 0; background: none; border-radius: 7px; padding: 6px 9px; display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.tool:hover { background: #f1f0ec; }
.tool.on { background: var(--accent); color: #fff; }
.tool.small { padding: 6px 9px; min-width: 30px; justify-content: center; font-weight: 600; }
.toolbar .sep { width: 1px; height: 22px; background: var(--line2); margin: 0 3px; }
.only-narrow { display: none !important; }
.hint { position: absolute; left: 50%; bottom: 44px; transform: translateX(-50%); background: rgba(29,35,33,.88); color: #fff; padding: 7px 12px; border-radius: 8px; font-size: 12.5px; pointer-events: none; max-width: min(560px, 90%); text-align: center; z-index: 4; }
.hint:empty { display: none; }
.status { position: absolute; left: 0; right: 0; bottom: 0; display: flex; gap: 14px; align-items: center; padding: 6px 12px; font-size: 12px; background: rgba(255,255,255,.92); border-top: 1px solid var(--line); flex-wrap: wrap; z-index: 3; }
.status b { font-weight: 600; }
.status .disc { margin-left: auto; color: var(--err); font-weight: 600; }
.status .pill { padding: 1px 7px; border-radius: 10px; background: var(--err-soft); color: var(--err); font-weight: 600; cursor: pointer; }
.empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; padding: 20px; }
.empty > * { pointer-events: auto; }
.empty h2 { margin: 0 0 6px; font-size: 22px; } .empty p { margin: 0 0 14px; color: var(--muted); }
.empty[hidden] { display: none; }

/* right panel */
.tabs { display: flex; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.tabs button { flex: 1; border: 0; background: none; padding: 11px 4px; font-size: 13px; border-bottom: 2px solid transparent; color: var(--muted); white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 17px; background: var(--line); color: var(--ink); }
.badge.err { background: var(--err); color: #fff; } .badge.warn { background: #e8b44c; color: #2a1d00; }
.pane { padding: 14px; overflow-y: auto; }
.pane[hidden] { display: none; }
.pane h2 { font-size: 16px; margin: 0 0 4px; }
.field { display: grid; grid-template-columns: 104px 1fr; align-items: center; gap: 6px 10px; margin: 8px 0; }
.field label { font-size: 12.5px; color: var(--muted); }
.field input[type=text], .field input[type=number], .field select { width: 100%; border: 1px solid var(--line2); border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0; }
.field input:focus, .field select:focus { outline: 2px solid rgba(31,58,52,.25); border-color: var(--accent); }
.field .unit { font-size: 12px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
.field .row { display: flex; align-items: center; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.btn-row button { border: 1px solid var(--line2); background: #fff; border-radius: 7px; padding: 6px 10px; }
.btn-row button:hover { background: #f3f2ee; }
.btn-row button.danger { color: var(--err); border-color: #e7c3bf; }
.btn-row button.danger:hover { background: var(--err-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line2); border-radius: 14px; padding: 3px 9px 3px 6px; font-size: 12.5px; background: #fff; cursor: pointer; }
.chip input { margin: 0; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); }
.divider { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; font-size: 13px; }
.kv b { font-weight: 600; text-align: right; }
.room-list { list-style: none; margin: 0; padding: 0; }
.room-list li { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 7px 6px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.room-list li:hover { background: #f4f3ef; } .room-list li.on { background: var(--accent-soft); }
.room-list li i { width: 10px; height: 10px; border-radius: 3px; border: 1px solid rgba(0,0,0,.18); }
.room-list .dim { color: var(--muted); font-size: 12px; }
.totals { background: #f7f6f2; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 12px; }
.totals .big { font-size: 20px; font-weight: 700; }
.check { display: grid; grid-template-columns: 18px 1fr; gap: 8px; padding: 9px 10px; border-radius: var(--r); margin-bottom: 6px; font-size: 13px; line-height: 1.4; border: 1px solid transparent; }
.check[data-rooms] { cursor: pointer; }
.check.error { background: var(--err-soft); border-color: #f0cdc9; } .check.warn { background: var(--warn-soft); border-color: #f0dfb7; } .check.info { background: var(--info-soft); border-color: #cfe2ee; }
.check .ic { font-weight: 800; text-align: center; }
.check.error .ic { color: var(--err); } .check.warn .ic { color: var(--warn); } .check.info .ic { color: var(--info); }
.note { font-size: 12px; color: var(--muted); line-height: 1.45; }
.note.box { background: #f7f6f2; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; }
.cost-out { background: var(--accent); color: #fff; border-radius: var(--r); padding: 12px 14px; margin: 12px 0; }
.cost-out .big { font-size: 22px; font-weight: 700; margin: 2px 0; }
.cost-out .kv { color: rgba(255,255,255,.88); }
.seg { display: flex; border: 1px solid var(--line2); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: #fff; padding: 7px 4px; font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line2); }
.seg button.on { background: var(--accent); color: #fff; font-weight: 600; }
.help-list { margin: 8px 0 0; padding-left: 18px; font-size: 13px; line-height: 1.55; color: #333; }
kbd { font-family: inherit; font-size: 11px; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }

/* dialog */
dialog { border: 0; border-radius: 14px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-width: min(920px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(20,24,22,.45); }
.dlg { padding: 18px 20px 20px; }
.dlg-head { display: flex; align-items: center; justify-content: space-between; }
.dlg-head h2 { margin: 0; font-size: 19px; }
.dlg-head button { border: 0; background: none; font-size: 24px; line-height: 1; padding: 4px 8px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.tpl { border: 1px solid var(--line2); border-radius: 10px; background: #fff; padding: 10px; text-align: left; display: flex; flex-direction: column; gap: 6px; }
.tpl:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.tpl svg { width: 100%; height: 120px; background: var(--canvas); border-radius: 6px; }
.tpl b { font-size: 14px; } .tpl span { font-size: 12px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%) translateY(-10px); background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 50; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--err); }

/* tablet */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 200px 1fr 300px; }
  .brand span { display: none; }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; position: relative; overflow: hidden; }
  .left, .right { position: absolute; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow); transition: transform .2s; width: min(320px, 88vw); }
  .left { left: 0; transform: translateX(-105%); } .right { right: 0; transform: translateX(105%); }
  .left.open, .right.open { transform: none; }
  .only-narrow { display: inline-flex !important; }
  .toolbar .sep.only-narrow { display: block !important; }
  .tool span { display: none; }
  .title-input { flex-basis: 160px; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 6px; padding: 6px 8px; }
  .title-input { order: 9; flex: 1 1 100%; }
  .tb > button, .btn, .menu > button { padding: 6px 8px; font-size: 13px; }
  .status .disc { margin-left: 0; }
  .hint { bottom: 64px; }
}
@media print { body { display: none; } }
