/* Floorplan Builder: app interface styles.
   UI colors live in the variables below. Drawing/export colors live in js/styles.js. */
:root {
  --dark-blue: #25408F;
  --medium-blue: #1C54F4;
  --accent: #4D93FF;
  --teal: #2AB6A9;
  --red: #ED1B34;

  --ink: #1B2333;
  --muted: #5B6578;
  --line: #DCE1EA;
  --panel: #FFFFFF;
  --canvas: #F4F6FA;
  --hover: #EEF3FF;

  --topbar-h: 48px;
  --toolbar-w: 64px;
  --panel-w: 290px;
  --lib-w: 236px;
  --status-h: 28px;
  --radius: 6px;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--font); font-size: 13px; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; color: inherit; }
kbd { font-family: var(--font); font-size: 10px; padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; background: #fff; color: var(--muted); }

#app {
  display: grid; height: 100vh;
  grid-template-columns: var(--toolbar-w) 0 1fr var(--panel-w);
  grid-template-rows: var(--topbar-h) 1fr var(--status-h);
  grid-template-areas: "top top top top" "tools lib stage panel" "status status status status";
}
#app.lib-open { grid-template-columns: var(--toolbar-w) var(--lib-w) 1fr var(--panel-w); }

/* ---------- Top bar ---------- */
#topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; background: var(--dark-blue); color: #fff; }
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: .2px; white-space: nowrap; }
.brand-file { opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 4px; }
#topbar button { background: transparent; border: 1px solid transparent; color: #fff; padding: 5px 10px; border-radius: var(--radius); cursor: pointer; }
#topbar button:hover:not(:disabled) { background: rgba(255,255,255,.12); }
#topbar button:disabled { opacity: .4; cursor: default; }
#topbar button.primary { background: var(--medium-blue); }
#topbar button.primary:hover { background: var(--accent); }
#topbar button.icon { padding: 5px 7px; font-weight: 700; min-width: 30px; }
#topbar button svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sep { width: 1px; height: 22px; background: rgba(255,255,255,.25); margin: 0 6px; }

/* ---------- Tool bar ---------- */
#toolbar { grid-area: tools; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 8px 0; gap: 4px; }
#toolbar button { width: 54px; padding: 6px 0 4px; border: 1px solid transparent; background: none; border-radius: var(--radius); cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--ink); position: relative; }
#toolbar button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#toolbar button span { font-size: 10px; }
#toolbar button kbd { position: absolute; top: 2px; right: 3px; font-size: 9px; padding: 0 2px; border: none; background: none; }
#toolbar button:hover { background: var(--hover); }
#toolbar button.active { background: var(--dark-blue); color: #fff; }
#toolbar button.active kbd { color: rgba(255,255,255,.7); }
.tool-sep { width: 36px; height: 1px; background: var(--line); margin: 4px 0; }

/* ---------- Stage ---------- */
#stage { grid-area: stage; position: relative; overflow: hidden; background: #fff; }
#canvas { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
#empty-state { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); max-width: 440px; background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; box-shadow: 0 6px 24px rgba(37,64,143,.08); pointer-events: none; }
#empty-state h2 { margin: 0 0 8px; color: var(--dark-blue); font-size: 17px; }
#empty-state ol { margin: 0 0 8px; padding-left: 20px; line-height: 1.6; }
#empty-state p { margin: 0; color: var(--muted); }
#zoombox { position: absolute; right: 12px; bottom: 12px; display: flex; align-items: center; gap: 2px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 3px; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
#zoombox button { border: none; background: none; min-width: 28px; height: 26px; border-radius: 4px; cursor: pointer; font-size: 15px; }
#zoombox button:hover { background: var(--hover); }
#zoombox button[data-action="fit"] { font-size: 12px; padding: 0 8px; }
#zoom-label { min-width: 52px; text-align: center; color: var(--muted); font-size: 12px; }

/* Tool options bar (top of the drawing) */
#tool-options { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; width: max-content; max-width: calc(100% - 20px); background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; box-shadow: 0 2px 10px rgba(0,0,0,.08); z-index: 5; }
#tool-options[hidden] { display: none; }
.opt-label { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.opt-label input { width: 80px; padding: 3px 6px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); }
.opt-note { color: var(--muted); font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 4px 10px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button:hover { background: var(--hover); }
.seg button.on { background: var(--dark-blue); color: #fff; }

/* Fixtures library (left side of the drawing) */
#library { grid-area: lib; background: #fff; border-right: 1px solid var(--line); overflow-y: auto; min-width: 0; }
#library[hidden] { display: none; }
.lib-head { padding: 10px 12px; font-weight: 600; color: var(--dark-blue); border-bottom: 1px solid var(--line); }
.lib-cat { padding: 10px 12px 4px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.lib-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 0 8px; }
.lib-item { border: 1px solid transparent; background: none; border-radius: 6px; padding: 6px 2px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.lib-item svg { width: 44px; height: 38px; }
.lib-item span { font-size: 10px; line-height: 1.15; text-align: center; color: var(--ink); }
.lib-item:hover { background: var(--hover); }
.lib-item.on { border-color: var(--medium-blue); background: #EEF3FF; }
.lib-note { padding: 10px 12px; }

/* ---------- Side panel ---------- */
#panel { grid-area: panel; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; }
#panel details { border-bottom: 1px solid var(--line); }
#panel summary { padding: 10px 14px; font-weight: 600; color: var(--dark-blue); cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
#panel summary::after { content: "\25BE"; color: var(--muted); }
#panel details:not([open]) summary::after { content: "\25B8"; }
#panel summary::-webkit-details-marker { display: none; }
.sec-body { padding: 0 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row.stack { flex-direction: column; align-items: stretch; gap: 3px; }
.row input[type=color] { width: 140px; height: 26px; padding: 1px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.row input[type=text], .row select, .row input[type=number] { width: 140px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.row.stack input { width: 100%; }
.row input:focus, .row select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.note { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: var(--radius); padding: 5px 10px; cursor: pointer; }
.btn:hover:not(:disabled) { background: var(--hover); border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--medium-blue); color: #fff; border-color: var(--medium-blue); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #FFF0F2; border-color: var(--red); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.pill.ok { background: #E3F6F4; color: #157A71; }
.pill.warn { background: #FFF1E0; color: #9A5B00; }
input[type=range] { width: 140px; accent-color: var(--medium-blue); }
.bg-name { font-weight: 600; word-break: break-all; }

/* ---------- Status bar ---------- */
#statusbar { grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 12px; background: #fff; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; }
#hint { overflow: hidden; text-overflow: ellipsis; }
.grow { flex: 1; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(27,35,51,.45); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 10px; width: min(520px, 92vw); max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.wide { width: min(860px, 94vw); }
.modal h3 { margin: 0; padding: 14px 18px; border-bottom: 1px solid var(--line); color: var(--dark-blue); font-size: 15px; }
.modal .modal-body { padding: 16px 18px; overflow-y: auto; line-height: 1.5; }
.modal .modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal input[type=text] { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 5px; font-size: 15px; }
.modal input[type=text]:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
.modal .error { color: var(--red); font-size: 12px; min-height: 16px; margin-top: 4px; }
.page-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.page-thumb { border: 2px solid var(--line); border-radius: 6px; padding: 6px; background: #fff; cursor: pointer; text-align: center; }
.page-thumb:hover { border-color: var(--accent); }
.page-thumb canvas { max-width: 100%; height: auto; display: block; margin: 0 auto 4px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.help-table { border-collapse: collapse; width: 100%; }
.help-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.help-table td:first-child { white-space: nowrap; width: 1%; }
.modal h4 { margin: 14px 0 6px; color: var(--dark-blue); }
.modal h4:first-child { margin-top: 0; }

/* ---------- Toasts and busy ---------- */
#toasts { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 60; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 9px 14px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.2); max-width: 560px; border-left: 4px solid var(--accent); animation: toastIn .15s ease-out; }
.toast.ok { border-left-color: var(--teal); }
.toast.error { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }
#busy { position: fixed; inset: 0; background: rgba(255,255,255,.6); display: flex; align-items: center; justify-content: center; z-index: 70; }
#busy[hidden] { display: none; }
.busy-box { background: #fff; padding: 14px 18px; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.15); display: flex; gap: 10px; align-items: center; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--medium-blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Smaller screens: narrower side panel */
@media (max-width: 1100px) { :root { --panel-w: 250px; } .brand-file { display: none; } }
.prop-title { font-weight: 600; }

/* Export dialog */
.xp { display: flex; flex-direction: column; gap: 10px; }
.xp-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.xp-label { width: 84px; color: var(--muted); }
.xp input[type=number] { width: 70px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; }
.xp select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 4px; }
.xp-fmt-note { margin-left: 94px; }
.xp-out { background: #F4F6FA; border-radius: 6px; padding: 8px 10px; font-weight: 600; color: var(--dark-blue); }
.xp-out.err { color: var(--red); background: #FFF0F2; }

/* Size slider with presets (tool bar and Selection panel) */
.opt-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; white-space: nowrap; }
.size-ctl { display: flex; flex-direction: column; gap: 6px; }
.opt-row .size-ctl { flex-direction: row; align-items: center; flex-wrap: wrap; }
.size-top { display: flex; align-items: center; gap: 8px; }
.size-top input[type=range] { width: 150px; accent-color: var(--medium-blue); }
.size-val { color: var(--muted); font-size: 12px; white-space: nowrap; }
.size-val:empty { display: none; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 2px 9px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--accent); background: var(--hover); }
.chip.on { background: var(--dark-blue); border-color: var(--dark-blue); color: #fff; }
.sec-body .size-top { flex-wrap: wrap; }
.sec-body .size-top input[type=range] { width: 100%; }
