:root {
    color-scheme: dark;
    --page-bg: #0d0f14;
    --surface: #151820;
    --surface-alt: #1d1f24;
    --border-color: #2f323b;
    --accent: #ff6347;
    --accent-soft: rgba(255, 99, 71, 0.35);
    --text-muted: #8a8f9c;
    --success: #2aa876;
    --danger: #d64545;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--page-bg);
    color: #f0f2f7;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    padding: 24px 32px 8px;
}

h1 {
    margin: 0;
    font-weight: 600;
}

.description {
    margin-top: 6px;
    color: var(--text-muted);
}

.muted {
    color: var(--text-muted);
}

.small {
    font-size: 0.85rem;
}

.workspace {
    display: flex;
    gap: 24px;
    padding: 24px 32px 40px;
    flex-wrap: wrap;
}

.workspace.single-column {
    flex-direction: column;
}

.planner {
    flex: 1 1 320px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.camera-section {
    flex: 2 1 460px;
}

.camera-section.full-width {
    flex: 1 1 100%;
}

.forms-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.alert {
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.92rem;
    border: 1px solid transparent;
}

.alert.success {
    border-color: rgba(42, 168, 118, 0.3);
    background: rgba(42, 168, 118, 0.2);
}

.alert.danger {
    border-color: rgba(214, 69, 69, 0.3);
    background: rgba(214, 69, 69, 0.2);
}

.form-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
}

.info-card h2 {
    margin-bottom: 8px;
}

.info-card p + p {
    margin-top: 8px;
}

.form-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.form-card h2 {
    margin-top: 0;
    margin-bottom: 12px;
    font-size: 1.1rem;
}

.quick-control .primary-btn {
    width: 100%;
    margin-top: 8px;
}

.stacked-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.92rem;
    color: var(--text-muted);
}

input[type="text"],
input[type="number"],
input[type="color"],
select,
textarea {
    background: var(--surface-alt);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    color: #f0f2f7;
    font-size: 0.95rem;
}

textarea {
    resize: vertical;
}

input[type="color"] {
    padding: 0;
    height: 36px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.primary-btn {
    border: none;
    border-radius: 10px;
    padding: 12px 18px;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.primary-btn:hover {
    opacity: 0.85;
}

.primary-btn.ghost {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
    padding: 10px 16px;
}

.primary-btn:disabled,
.primary-btn.ghost:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.secondary-btn {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 16px;
    background: transparent;
    color: #f0f2f7;
    cursor: pointer;
    transition: border 0.2s ease;
}

.secondary-btn:hover {
    border-color: var(--accent);
}

.danger-btn {
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    background: var(--danger);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.danger-btn:hover {
    opacity: 0.85;
}

.floating-map-btn {
    position: fixed;
    right: 32px;
    bottom: 32px;
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: #10131c;
    border: 2px solid var(--border-color);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    padding: 8px;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.floating-map-btn:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
}

.floating-map-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.map-designer,
.map-overview {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.overview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.designer-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.designer-modal-grid {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.designer-settings {
    flex: 0 0 280px;
}

.designer-workspace {
    flex: 1 1 700px;
    min-width: 680px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.designer-settings .form-card {
    height: 100%;
}

.designer-canvas-wrapper {
    display: flex;
    flex-wrap: nowrap;
    gap: 16px;
    align-items: flex-start;
}

.designer-canvas-wrapper .designer-canvas {
    flex: 1 1 640px;
    min-width: 420px;
}

.camera-editor {
    flex: 0 0 280px;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.camera-editor-header h3 {
    margin: 0 0 4px;
}

.camera-editor[data-empty="true"] {
    opacity: 0.6;
    pointer-events: none;
}

.toolbar-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    border: 1px solid var(--border-color);
    background: var(--surface-alt);
    color: #f0f2f7;
    border-radius: 24px;
    padding: 8px 16px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.tool-btn.active {
    border-color: var(--accent);
    background: rgba(255, 99, 71, 0.2);
}

.line-width-control {
    display: flex;
    flex-direction: column;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.line-width-control input {
    width: 160px;
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.designer-heading h2 {
    margin: 0;
}

.floor-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.floor-tab {
    border: 1px solid var(--border-color);
    background: var(--surface-alt);
    border-radius: 12px;
    padding: 8px 14px;
    color: #f0f2f7;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 120px;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.floor-tab.active {
    border-color: var(--accent);
    background: rgba(255, 99, 71, 0.2);
}

.designer-canvas {
    position: relative;
    border-radius: 14px;
    background: #111217;
    border: 1px solid var(--border-color);
    height: 480px;
    overflow: hidden;
    cursor: crosshair;
}

.designer-stage {
    position: absolute;
    inset: 0;
    transform-origin: top left;
}

.designer-canvas.view-only {
    cursor: default;
    height: auto;
    aspect-ratio: 3 / 2;
}

.canvas-grid {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: 0.4;
}

.designer-layout,
.camera-sectors {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.camera-sector-path {
    fill: rgba(255, 99, 71, 0.25);
    stroke: rgba(255, 99, 71, 0.6);
    stroke-width: 0.4;
}

.layout-line {
    fill: none;
    stroke-linecap: round;
}

.layout-line[data-type="wall"] {
    stroke: #f0f2f7;
}

.layout-line[data-type="window"] {
    stroke: #4cc9f0;
    stroke-dasharray: 4 4;
}

.layout-line[data-type="door"] {
    stroke: #ffb703;
}

.layout-rect {
    fill: rgba(255, 255, 255, 0.08);
    stroke: #f0f2f7;
    stroke-linecap: round;
}

.layout-status {
    min-height: 18px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.designer-hint {
    position: absolute;
    top: 12px;
    left: 16px;
    background: rgba(0, 0, 0, 0.45);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.designer-pins {
    position: absolute;
    inset: 0;
}

.designer-pin,
.camera-pin {
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-soft);
    border: 3px solid var(--accent);
    transform: translate(-50%, -50%);
    box-shadow: 0 0 18px rgba(255, 99, 71, 0.4);
    z-index: 2;
}

.designer-pin.active {
    background: rgba(255, 255, 255, 0.4);
    border-color: #fff;
}

.canvas-control {
    position: absolute;
    right: 12px;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.4);
    color: #fff;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
}

.canvas-control:hover {
    background: rgba(255, 99, 71, 0.3);
    border-color: var(--accent);
}

#canvasZoomIn {
    top: 12px;
}

#canvasZoomOut {
    top: 52px;
}

#canvasFullscreen {
    top: 92px;
    font-size: 0.9rem;
}

.designer-pin.camera-selected {
    border-color: #4cc9f0;
    box-shadow: 0 0 12px rgba(76, 201, 240, 0.8);
}

.floor-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.floor-meta-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.delete-floor-form .danger-btn.small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.camera-grid-wrapper {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.camera-grid-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
}

.camera-grid-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    grid-auto-rows: minmax(180px, auto);
    gap: 20px;
    padding: 0;
}

.camera-tile {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: border-color 0.2s ease, transform 0.2s ease;
}

.camera-tile:hover {
    border-color: var(--accent);
}

.camera-tile.size-1 {
    grid-row: span 1;
    grid-column: span 1;
}

.camera-tile.size-2 {
    grid-row: span 2;
    grid-column: span 2;
}

.camera-tile.size-3 {
    grid-row: span 3;
    grid-column: span 3;
}

.tile-header,
.tile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.camera-title {
    font-weight: 600;
    font-size: 1rem;
}

.size-controls {
    display: flex;
    gap: 6px;
}

.size-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: #15161c;
    color: #f0f2f7;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.size-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.placeholder {
    flex: 1;
    margin: 12px 0;
    border-radius: 8px;
    border: 1px dashed var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
    padding: 16px;
}

.stream-preview {
    padding: 0;
    border-style: solid;
    overflow: hidden;
}

.stream-preview video {
    width: 100%;
    height: 180px;
    object-fit: cover;
    border-radius: 8px;
    background: #000;
}

.stream-preview video.no-signal {
    object-fit: contain;
    background: var(--surface-alt);
}

.tile-footer {
    font-size: 0.85rem;
    color: var(--text-muted);
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
}

.tile-footer .secondary-btn {
    padding: 6px 12px;
}

.tile-actions {
    display: none;
    gap: 8px;
}

.camera-grid-wrapper.show-actions .tile-actions {
    display: flex;
}

.tile-actions .secondary-btn,
.tile-actions .danger-btn {
    padding: 6px 12px;
}

.map-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 20;
}

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

.map-content {
    background: #0f1118;
    border-radius: 16px;
    padding: 24px;
    width: min(640px, 90vw);
    border: 1px solid var(--border-color);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 4, 9, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 30;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-window {
    background: var(--surface);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    padding: 24px;
    width: min(520px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-window.wide {
    width: min(1120px, 95vw);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    margin-bottom: 16px;
}

.modal-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.modal-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.map-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.close-btn {
    border: none;
    background: transparent;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
}

.map-area {
    margin-top: 20px;
    background: #20232b;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: 100%;
    aspect-ratio: 3 / 2;
    position: relative;
    overflow: hidden;
}

.modal-meta {
    margin-top: 16px;
}

.modal-view-switch {
    display: flex;
    gap: 10px;
}

.modal-view-switch .secondary-btn.active {
    border-color: var(--accent);
}

.modal-panel {
    display: none;
    margin-top: 16px;
}

.modal-panel.active {
    display: block;
}

.modal-stream video {
    width: 100%;
    height: 260px;
    border-radius: 8px;
    background: #000;
    display: none;
    object-fit: cover;
}

.modal-stream video.no-signal {
    object-fit: contain;
    background: var(--surface-alt);
}

@media (max-width: 900px) {
    .workspace {
        flex-direction: column;
    }

    header {
        padding: 20px;
    }

    .workspace {
        padding: 16px;
    }
}

@media (max-width: 1100px) {
    .designer-workspace {
        min-width: auto;
    }
    .designer-canvas-wrapper {
        flex-wrap: wrap;
    }
}
