:root {
    --header-height: 64px;
    --bg-color: #f5f7fb;
    --panel-bg: #ffffff;
    --surface: #ffffff;
    --border: #d8dee9;
    --border-strong: #aeb8c7;
    --text-primary: #162033;
    --text-secondary: #667085;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --grid-line: #e7ecf4;
    --room-fill: #dbeafe;
    --nested-fill: #eef2ff;
    --shadow: 0 10px 35px rgba(16, 24, 40, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg-color);
    color: var(--text-primary);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
    font: inherit;
}

:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.42);
    outline-offset: 3px;
}

header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
}

.header-content {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: 1.45rem;
    font-weight: 800;
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 0.35rem;
}

h3 {
    font-size: 0.9rem;
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

main {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.5rem;
}

body.editor-active {
    overflow: hidden;
}

body.editor-active main {
    max-width: none;
    height: calc(100vh - var(--header-height));
    margin: 0;
    padding: 0;
}

.back-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 600;
}

.back-link:hover {
    color: var(--text-primary);
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.gallery-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.gallery-heading p,
.hint,
.shortcut-hint,
.save-status,
#canvasMeta {
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.floorplan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

.floorplan-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.floorplan-preview {
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    height: 180px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
    cursor: pointer;
}

.floorplan-preview svg {
    width: 100%;
    height: 100%;
    display: block;
}

.floorplan-info {
    padding: 1rem;
}

.floorplan-info h3 {
    color: var(--text-primary);
    font-size: 1rem;
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 0.35rem;
}

.floorplan-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.empty-state,
.empty-panel {
    color: var(--text-secondary);
    text-align: center;
    padding: 3rem 1rem;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: 8px;
}

.editor-shell {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 1rem;
    min-height: calc(100vh - 112px);
}

body.editor-active .editor-shell {
    display: block;
    height: calc(100vh - var(--header-height));
    min-height: 0;
    position: relative;
}

.sidebar {
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
}

body.editor-active .sidebar {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    bottom: 1rem;
    left: 1rem;
    z-index: 40;
    width: 340px;
    max-width: calc(100vw - 2rem);
    min-height: 0;
    overflow: auto;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 70px rgba(16, 24, 40, 0.22);
    backdrop-filter: blur(14px);
}

.editor-title {
    display: grid;
    gap: 0.75rem;
}

.title-input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    font-size: 1.05rem;
    font-weight: 800;
}

.panel {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    background: #fbfcfe;
}

.panel h3 {
    margin-bottom: 0.75rem;
}

.tool-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.tool-btn,
.btn-primary,
.btn-secondary,
.btn-danger {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.68rem 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.tool-btn,
.btn-secondary {
    background: #ffffff;
    border-color: var(--border);
    color: var(--text-primary);
}

.tool-btn:hover,
.btn-secondary:hover {
    border-color: var(--border-strong);
}

.tool-btn.active,
.btn-primary {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

.btn-primary:hover {
    background: var(--accent-dark);
}

.btn-danger {
    background: var(--danger-soft);
    color: var(--danger);
    border-color: #fecaca;
}

.btn-danger:disabled,
.btn-secondary:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.form-control {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.65rem 0.7rem;
    background: #ffffff;
    color: var(--text-primary);
}

label {
    display: grid;
    gap: 0.35rem;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 700;
}

.split-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.property-grid {
    display: grid;
    gap: 0.75rem;
}

.property-grid .wide {
    grid-column: 1 / -1;
}

.sidebar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: auto;
}

.sidebar-actions #savePlanBtn {
    grid-column: 1 / -1;
}

.save-status {
    min-height: 1.2rem;
}

.canvas-wrap {
    min-width: 0;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface);
}

body.editor-active .canvas-wrap {
    height: calc(100vh - var(--header-height));
    border: 0;
    border-radius: 0;
    background: transparent;
}

.canvas-toolbar {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.canvas-toolbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

.zoom-controls {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem;
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.zoom-controls .btn-secondary {
    min-width: 2.25rem;
    padding: 0.4rem 0.55rem;
}

.zoom-controls .zoom-level {
    min-width: 4.25rem;
}

body.editor-active .canvas-toolbar {
    position: fixed;
    top: calc(var(--header-height) + 1rem);
    right: 1rem;
    left: calc(340px + 2rem);
    z-index: 35;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 35px rgba(16, 24, 40, 0.12);
    backdrop-filter: blur(12px);
}

.canvas-frame {
    flex: 1;
    min-height: 560px;
    overflow: auto;
    background:
        linear-gradient(90deg, rgba(216, 222, 233, 0.4) 1px, transparent 1px),
        linear-gradient(rgba(216, 222, 233, 0.4) 1px, transparent 1px);
    background-size: 24px 24px;
    padding: 1.5rem;
}

body.editor-active .canvas-frame {
    height: 100%;
    min-height: 0;
    padding: 1.5rem;
    padding-left: calc(340px + 3rem);
    padding-top: 5.25rem;
}

#floorplanCanvas {
    display: block;
    min-width: 100%;
    min-height: 100%;
    background: #ffffff;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    touch-action: none;
}

body.editor-active #floorplanCanvas {
    min-width: 100%;
    min-height: 100%;
}

.svg-room {
    stroke: #1d4ed8;
    stroke-width: 2;
}

.svg-note {
    stroke: #f59e0b;
    stroke-width: 2;
}

.svg-nested {
    fill: var(--nested-fill);
    stroke: #4f46e5;
    stroke-width: 2;
    stroke-dasharray: 8 6;
}

.svg-selected {
    filter: drop-shadow(0 0 0.35rem rgba(37, 99, 235, 0.45));
}

.resize-handle {
    fill: #ffffff;
    stroke: var(--accent);
    stroke-width: 2;
    cursor: nwse-resize;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.45);
    z-index: 100;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    width: min(460px, 100%);
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid var(--border);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.modal h3 {
    color: var(--text-primary);
    font-size: 1.2rem;
    text-transform: none;
    letter-spacing: 0;
    margin-bottom: 1rem;
}

.modal form {
    display: grid;
    gap: 1rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

@media (max-width: 900px) {
    .header-content {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    .editor-shell {
        grid-template-columns: 1fr;
    }

    body.editor-active {
        overflow: auto;
    }

    body.editor-active main,
    body.editor-active .editor-shell,
    body.editor-active .canvas-wrap {
        height: auto;
        min-height: calc(100vh - var(--header-height));
    }

    body.editor-active .sidebar {
        position: relative;
        top: auto;
        bottom: auto;
        left: auto;
        width: auto;
        margin: 1rem;
    }

    body.editor-active .canvas-toolbar {
        position: relative;
        top: auto;
        right: auto;
        left: auto;
        margin: 0 1rem;
    }

    body.editor-active .canvas-frame {
        min-height: 560px;
        padding: 1rem;
    }

    .canvas-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .canvas-toolbar-actions {
        align-items: flex-start;
        flex-direction: column;
    }
}
