/* Room Planner. Follows the Rack Studio workspace: header, toolbar, catalog, canvas, inspector. */
:root {
    --color-bg: #f4f7f6;
    --color-bg-alt: #ffffff;
    --color-bg-workspace: #e9ecef;
    --color-border: #d1d5db;
    --color-text: #1f2937;
    --color-text-light: #6b7280;
    --color-accent: #3b82f6;
    --color-danger: #ef4444;
    --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "Consolas", "Menlo", "Courier New", monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; font-family: var(--font-main); font-size: 14px; color: var(--color-text); background: var(--color-bg); }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* Header */
#rp-header { flex-shrink: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: var(--color-bg-alt); border-bottom: 1px solid var(--color-border); box-shadow: 0 2px 4px rgba(0,0,0,.05); z-index: 10; }
.app-logo { display: flex; align-items: center; gap: 5px; font-size: 1.5em; font-weight: 900; color: var(--color-accent); text-decoration: none; margin-inline-end: 10px; }
.app-logo span { font-size: .8em; color: var(--color-text-light); }
.control-group { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
#rp-project-name { width: 240px; max-width: 60vw; padding: 5px 8px; border: 1px solid var(--color-border); border-radius: 4px; font: inherit; }
button, .btn { display: inline-block; padding: 5px 10px; font: inherit; font-size: .9em; background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 4px; cursor: pointer; text-decoration: none; color: var(--color-text); transition: all .1s ease; user-select: none; }
button:hover, .btn:hover { background: #e5e7eb; border-color: #9ca3af; }
button:disabled { opacity: .45; cursor: default; }
button.active, button.primary { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }
button.primary:hover { background: #2563eb; }
button.danger { color: #b91c1c; border-color: #fca5a5; background: #fef2f2; }
:focus-visible { outline: 2px solid #1d4ed8; outline-offset: 1px; }
.kpi-group { margin-inline-start: auto; display: flex; gap: 16px; font-size: .9em; align-items: center; flex-wrap: wrap; }
.kpi { text-align: start; }
.kpi .value { font-weight: bold; font-size: 1.1em; display: block; direction: ltr; unicode-bidi: isolate; }
[dir=rtl] .kpi .value { text-align: right; }
.kpi .label { font-size: .9em; color: var(--color-text-light); }
button.kpi { padding: 3px 10px; border-radius: 6px; }
button.kpi.ok { background: #ecfdf5; border-color: #6ee7b7; }
button.kpi.warn { background: #fffbeb; border-color: #fcd34d; }
button.kpi.bad { background: #fef2f2; border-color: #fca5a5; }

/* Toolbar */
#rp-toolbar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 7px 12px; border-bottom: 1px solid #cbd5e1; background: #f8fafc; flex-shrink: 0; }
#rp-toolbar button { min-height: 32px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: #243e60; padding: 5px 9px; }
#rp-toolbar button:hover { background: #edf5ff; }
#rp-toolbar button.active { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
.rp-separator { height: 22px; border-inline-start: 1px solid #cbd5e1; margin: 0 3px; }
#rp-zoom-value { min-width: 48px; text-align: center; font: 12px var(--font-mono); }
.rp-snap { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: #475569; }
.rp-snap select { min-height: 32px; border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; font: inherit; padding: 4px; }
#rp-save-status { margin-inline-start: auto; color: #52647b; font-size: 11px; max-width: 420px; }

/* Layout */
main { display: flex; flex: 1; overflow: hidden; min-height: 0; }
#rp-sidebar { width: 280px; flex-shrink: 0; background: var(--color-bg-alt); border-inline-end: 1px solid var(--color-border); overflow-y: auto; padding-bottom: 20px; z-index: 5; }
#rp-workspace { flex: 1; position: relative; min-width: 0; background: var(--color-bg-workspace); background-image: linear-gradient(var(--color-border) 1px, transparent 1px), linear-gradient(90deg, var(--color-border) 1px, transparent 1px); background-size: 20px 20px; background-position: -1px -1px; }
#rp-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; direction: ltr; cursor: default; }
#rp-hint { position: absolute; top: 10px; inset-inline: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: #fff; border: 1px solid #93c5fd; border-radius: 8px; box-shadow: 0 4px 14px rgba(15,23,42,.12); font-size: 12px; z-index: 4; }
#rp-hint span { color: #475569; flex: 1 1 260px; }
#rp-hint label { display: inline-flex; align-items: center; gap: 5px; }
#rp-hint input { width: 96px; }
#rp-hint input, #rp-hint select { padding: 5px; border: 1px solid #bccbdd; border-radius: 5px; font: inherit; }
body.rp-dragging, body.rp-dragging * { cursor: grabbing !important; user-select: none; }
body.rp-focus #rp-header, body.rp-focus #rp-sidebar { display: none; }

/* Sidebar */
.rp-section { border-bottom: 1px solid var(--color-border); }
.rp-section > summary { font-weight: 600; padding: 10px 12px; cursor: pointer; list-style-position: inside; }
.rp-section-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.rp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#rp-sidebar label, #rp-inspector label, .rp-form label { display: grid; gap: 4px; font-size: 12px; color: #475569; min-width: 0; }
#rp-sidebar input, #rp-sidebar select, #rp-inspector input, #rp-inspector select, #rp-inspector textarea, .rp-form input, .rp-form select { width: 100%; min-width: 0; padding: 7px 8px; border: 1px solid #bccbdd; border-radius: 5px; font: inherit; color: var(--color-text); background: #fff; }
input:disabled { background: #f1f5f9 !important; color: #64748b !important; }
label.rp-check { display: flex !important; align-items: center; gap: 7px; }
label.rp-check input { width: auto !important; }
.rp-note { margin: 0; font-size: 11.5px; line-height: 1.5; color: var(--color-text-light); }
.rp-shapes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.rp-shapes button { padding: 8px 6px; }
.rp-wallrow { display: grid; grid-template-columns: 64px 1fr auto; gap: 6px; align-items: center; margin-bottom: 5px; font-size: 12px; color: #64748b; }
.rp-wallrow button { padding: 6px 4px; font-family: var(--font-mono); }
.rp-wallrow.active button { background: #fef3c7; border-color: #f59e0b; }
.rp-catgroup > summary { cursor: pointer; padding: 6px 0; font-size: 12.5px; font-weight: 600; color: #334155; }
.rp-catgroup > summary small { color: #94a3b8; font-weight: 400; }
.catalog-item { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 10px; margin-bottom: 6px; border: 1px solid #e2e8f0; border-radius: 4px; background: #fff; cursor: grab; user-select: none; -webkit-user-select: none; font-size: .9em; touch-action: pan-y; }
.catalog-item:hover { background: #edf5ff; border-color: #80a9df; }
.catalog-item span { flex: 1; }
.catalog-item small { color: #64748b; font-family: var(--font-mono); font-size: 10.5px; white-space: nowrap; }
.rp-swatch { width: 26px; height: 26px; flex-shrink: 0; }

/* Inspector */
#rp-inspector { width: 310px; flex-shrink: 0; border-inline-start: 1px solid #cbd5e1; background: #fff; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 9px; }
.rp-insp-head, .rp-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.rp-insp-head h2 { font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.rp-insp-head button, .rp-dialog-head button { font-size: 18px; line-height: 1; padding: 2px 9px; }
fieldset { margin: 0; padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-weight: 600; padding: 0 6px; font-size: 12px; }
.rp-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rp-actions button, .rp-actions .btn { padding: 7px 11px; border-radius: 6px; }
.rp-issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.rp-issues li { border-inline-start: 4px solid #94a3b8; background: #f8fafc; border-radius: 4px; font-size: 12.5px; line-height: 1.45; padding: 7px 9px; }
.rp-issues li.error { border-color: #dc2626; background: #fef2f2; }
.rp-issues li.warn { border-color: #d97706; background: #fffbeb; }
.rp-issues li.info { border-color: #2563eb; background: #eff6ff; }
.rp-issues li button { all: unset; cursor: pointer; display: block; width: 100%; }
.rp-issues li button:focus-visible { outline: 2px solid #1d4ed8; }
.rp-ok { color: #047857; font-weight: 600; }

/* Dialogs */
.rp-dialog { width: min(640px, 94vw); max-height: 88vh; border: 0; border-radius: 12px; padding: 22px; box-shadow: 0 20px 90px #0f172a55; color: #172c45; }
.rp-dialog.wide { width: min(1050px, 94vw); }
.rp-dialog::backdrop { background: #0f172a80; }
.rp-dialog h2 { font-size: 21px; margin: 0 0 14px; }
.rp-dialog h3 { font-size: 15px; margin: 16px 0 6px; }
.rp-dialog > * + * { margin-top: 12px; }
.rp-form { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); align-items: end; }
.rp-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.rp-table td, .rp-table th { text-align: start; border-bottom: 1px solid #dce4ed; padding: 7px 8px; overflow-wrap: anywhere; }
.rp-table th { color: #475569; font-weight: 600; }
.rp-message { margin: 0; min-height: 1.2em; font-size: 12.5px; color: #b45309; }
.rp-export { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.rp-export button { display: grid; gap: 4px; text-align: start; padding: 12px; border-radius: 8px; background: #f8fafc; }
.rp-export button span { font-size: 11.5px; color: #64748b; line-height: 1.4; }
.rp-guide { margin: 0; padding-inline-start: 18px; font-size: 13px; line-height: 1.6; }

/* Print sheets: SVG pages sized in paper millimetres */
#rp-print { display: none; }
.rp-sheet svg { display: block; }
.rp-logo-preview { height: 34px; max-width: 140px; object-fit: contain; border: 1px solid #dce4ed; border-radius: 4px; background: #fff; }
.catalog-item [data-forget] { padding: 0 6px; border: 0; background: none; color: #94a3b8; font-size: 15px; }
.catalog-item [data-forget]:hover { color: #b91c1c; background: none; }
.rp-table button { padding: 3px 8px; }
input[type=range] { padding: 0 !important; }

@media (max-width: 900px) {
    html, body { overflow: auto; }
    #app { height: auto; min-height: 100dvh; }
    main { flex-direction: column; overflow: visible; }
    #rp-sidebar { width: auto; max-height: 260px; border-inline-end: 0; border-bottom: 1px solid var(--color-border); }
    #rp-workspace { min-height: 68vh; }
    #rp-inspector { position: fixed; inset-inline: 0; bottom: 0; width: auto; max-height: 44vh; z-index: 200; border-inline-start: 0; border-top: 1px solid #cbd5e1; border-radius: 12px 12px 0 0; box-shadow: 0 -8px 30px #0003; }
    #rp-toolbar { position: sticky; top: 0; z-index: 30; flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; }
    #rp-toolbar > * { flex-shrink: 0; }
    #rp-toolbar button, .rp-snap select { min-height: 40px; }
    .kpi-group { margin-inline-start: 0; gap: 12px; }
    .rp-dialog { padding: 15px; }
    .rp-form { grid-template-columns: 1fr; }
}
@media print {
    html, body { overflow: visible; height: auto; background: #fff; }
    #app, .rp-dialog { display: none !important; }
    #rp-print { display: block; }
    .rp-sheet { break-after: page; }
    .rp-sheet:last-child { break-after: auto; }
    .rp-issues li, .rp-table tr { break-inside: avoid; }
    .rp-issues li { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .rp-svg { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
