@import url("https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;500;600;700;800&display=swap");

:root {
    --bg-main: #0c0c0e;
    --bg-panel: #141416;
    --bg-canvas: #ffffff;
    --bg-grid: rgba(255, 255, 255, 0.045);
    --bg-toolbar: #101012;
    --text-main: #f3f0ea;
    --text-muted: #969398;
    --text-inverse: #f3f0ea;
    --primary: #5ec8c5;
    --primary-strong: #78d9d5;
    --danger: #ff8070;
    --surface-border: #2a2a2e;
    --shadow-soft: 0 12px 30px rgba(0, 0, 0, 0.28);
    --shadow-card: 0 10px 24px rgba(0, 0, 0, 0.2);
    --radius-md: 8px;
    --grid-size: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: "Manrope", "Segoe UI", sans-serif;
    color: var(--text-main);
    background: var(--bg-main);
}

button, input, select, textarea { font: inherit; }
#import-project-file { display: none; }
.hidden { display: none !important; }

.app-shell {
    display: grid;
    grid-template-rows: 62px minmax(0, 1fr);
    height: 100vh;
    min-height: 0;
    overflow: hidden;
}

.topbar {
    display: grid;
    grid-template-columns: minmax(210px, 1fr) auto;
    align-items: center;
    gap: 14px;
    padding: 0 16px 0 18px;
    color: var(--text-inverse);
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--surface-border);
    box-shadow: none;
    z-index: 20;
}

.brand-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-group { color: var(--text-inverse); text-decoration: none; }
.brand-group h1 b { color: var(--text-muted); font-weight: 500; }
.wcu-wink { width: 27px; height: 27px; border: 1px solid var(--primary); border-radius: 50%; position: relative; display: block; transform: rotate(-4deg); flex: 0 0 auto; }
.wcu-wink i { position: absolute; width: 8px; height: 4px; border-top: 1px solid var(--primary); border-radius: 50%; left: 6px; top: 7px; transform: rotate(15deg); }
.wcu-wink::after { content: ""; position: absolute; width: 3px; height: 3px; background: var(--primary); border-radius: 50%; right: 6px; top: 7px; }
.wcu-wink b { position: absolute; left: 10px; top: 9px; color: var(--primary); font: 500 10px/1 monospace; }
.gate-error { width: 100%; height: 100%; display: grid; place-content: center; gap: 10px; padding: 60px; text-align: center; color: #252529; }
.gate-error strong { font-size: 30px; }
.gate-error span { color: #77757b; }

.brand-group h1 { margin: 0; font-size: 0.95rem; letter-spacing: -0.02em; }
.brand-group p { margin: 1px 0 0; font-size: 0.66rem; color: var(--text-muted); }

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-weight: 700;
}

.topbar-controls {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.workspace {
    display: grid;
    grid-template-columns: 270px minmax(0, 1fr) 286px;
    gap: 0;
    padding: 0;
    min-height: 0;
}

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 0;
    overflow-y: auto;
    background: #121214;
}

.left-sidebar { border-right: 1px solid var(--surface-border); }
.right-sidebar { border-left: 1px solid var(--surface-border); }

.panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border: 0;
    border-bottom: 1px solid var(--surface-border);
    border-radius: 0;
    background: var(--bg-panel);
    box-shadow: none;
    overflow: hidden;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    min-height: 43px;
    padding: 0 13px;
    border-bottom: 1px solid var(--surface-border);
}

.panel-header h2 { margin: 0; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.1em; }
.panel-hint { color: var(--text-muted); font-size: 0.62rem; }

.canvas-stage {
    display: grid;
    grid-template-rows: 48px minmax(0, 1fr);
    gap: 0;
    min-height: 0;
    background: #202024;
}

.canvas-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    padding: 0 13px;
    background: #151517;
    border-bottom: 1px solid var(--surface-border);
}

.status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 9px;
    border: 1px solid var(--surface-border);
    border-radius: 999px;
    background: #171719;
    box-shadow: none;
}

.status-pill span { color: var(--text-muted); font-size: 0.76rem; }

.snap-pill {
    gap: 10px;
    padding-right: 10px;
}

.snap-pill select {
    width: auto;
    min-width: 84px;
    padding: 4px 24px 4px 8px;
    border-radius: 999px;
    border-color: rgba(147, 169, 188, 0.5);
    background: #101012;
}

.canvas-scroll {
    position: relative;
    overflow: auto;
    border: 0;
    border-radius: 0;
    background: #202024;
    box-shadow: none;
}

.canvas-wrapper {
    position: relative;
    width: fit-content;
    min-width: 100%;
    min-height: 100%;
    padding: 56px 20px 20px 56px;
}

.canvas-grid, .canvas, .measurement-overlay {
    position: absolute;
    top: 56px;
    left: 56px;
}

.canvas-grid {
    pointer-events: none;
    border-radius: 14px;
    background-image:
        linear-gradient(var(--bg-grid) 1px, transparent 1px),
        linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
    background-size: var(--grid-size) var(--grid-size);
}

.canvas {
    overflow: hidden;
    border-radius: 14px;
    background: var(--bg-canvas);
    box-shadow: 0 16px 30px rgba(12, 28, 43, 0.14);
    transform-origin: top left;
}

.measurement-overlay {
    pointer-events: none;
    overflow: visible;
}

.ruler {
    position: absolute;
    background: rgba(243, 247, 251, 0.96);
    color: var(--text-muted);
    z-index: 2;
}

.ruler-top {
    top: 12px;
    left: 56px;
    height: 28px;
    border-radius: 10px 10px 0 0;
}

.ruler-left {
    top: 56px;
    left: 12px;
    width: 28px;
    border-radius: 10px 0 0 10px;
}

.ruler-tick, .ruler-label, .measurement-line, .measurement-label {
    position: absolute;
}

.ruler-tick { background: rgba(91, 112, 131, 0.4); }
.ruler-top .ruler-tick { bottom: 0; width: 1px; }
.ruler-left .ruler-tick { right: 0; height: 1px; }
.ruler-label { font-size: 0.7rem; }

.canvas-element {
    position: absolute;
    display: flex;
    min-width: 24px;
    min-height: 24px;
    user-select: none;
    cursor: grab;
}

.canvas-element.locked { cursor: not-allowed; }
.canvas-element.hidden-element { opacity: 0.42; filter: grayscale(0.2); }
.canvas-element.selected { outline: 2px solid rgba(15, 124, 144, 0.95); outline-offset: 1px; }

.selection-label {
    position: absolute;
    top: -24px;
    left: 0;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 124, 144, 0.92);
    color: white;
    font-size: 0.72rem;
    white-space: nowrap;
}

.element-frame { width: 100%; height: 100%; overflow: hidden; }

.element-placeholder {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    color: #52616b;
    background: linear-gradient(135deg, rgba(15, 124, 144, 0.1), rgba(255, 255, 255, 0.9));
}

.element-content-input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    padding: 10px;
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid white;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 1px rgba(15, 124, 144, 0.22);
}

.resize-handle.nw { top: -6px; left: -6px; cursor: nwse-resize; }
.resize-handle.n { top: -6px; left: calc(50% - 5px); cursor: ns-resize; }
.resize-handle.ne { top: -6px; right: -6px; cursor: nesw-resize; }
.resize-handle.e { top: calc(50% - 5px); right: -6px; cursor: ew-resize; }
.resize-handle.se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.resize-handle.s { bottom: -6px; left: calc(50% - 5px); cursor: ns-resize; }
.resize-handle.sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.resize-handle.w { top: calc(50% - 5px); left: -6px; cursor: ew-resize; }

.measurement-line { background: rgba(166, 57, 57, 0.7); }
.measurement-label {
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(166, 57, 57, 0.9);
    color: white;
    font-size: 0.68rem;
    white-space: nowrap;
}

.field, .inspector-group label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.field span, .inspector-group h3, .inspector-group label span {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--text-muted);
}

.field.compact { min-width: 82px; }

input, select, textarea {
    width: 100%;
    padding: 5px 10px;
    border: 1px solid var(--surface-border);
    border-radius: 6px;
    background: #0f0f11;
    color: var(--text-main);
}

textarea { min-height: 76px; resize: vertical; }

.btn, .icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(147, 169, 188, 0.45);
    border-radius: 7px;
    background: #232326;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    font-weight: 600;
    line-height: 1.2;
}

.btn {
    padding: 8px 12px;
}

.icon-button {
    padding: 6px 10px;
    font-size: 0.82rem;
}

.icon-only-button {
    width: 32px;
    height: 32px;
    padding: 0;
}

.button-icon {
    width: 16px;
    height: 16px;
    display: block;
    color: inherit;
}

.btn.small { padding: 6px 9px; font-size: 0.8rem; }
.btn.primary {
    border-color: rgba(11, 98, 114, 0.42);
    background: linear-gradient(180deg, rgba(26, 162, 183, 0.96), rgba(11, 98, 114, 0.96));
    color: white;
}
.btn.primary:hover {
    background: linear-gradient(180deg, rgba(20, 147, 167, 0.98), rgba(10, 88, 103, 0.98));
}
.btn.secondary, .import-button { color: var(--text-main); }
.btn.ghost, .icon-button {
    border-color: rgba(147, 169, 188, 0.4);
    background: #232326;
    color: var(--text-main);
}

.danger-button {
    border-color: rgba(201, 108, 108, 0.42);
    background: rgba(255, 128, 112, 0.1);
    color: var(--danger);
}

.btn:hover, .icon-button:hover {
    border-color: #4a4a50;
    background: #2d2d31;
    box-shadow: none;
}

.toolbar-button-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-label {
    min-width: 42px;
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
}

.library-grid, .project-list, .image-list, .layer-list, .inspector-form { padding: 10px; }

.library-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.library-item {
    padding: 7px 8px;
    border: 1px solid rgba(147, 169, 188, 0.45);
    border-radius: 7px;
    background: #1c1c1f;
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
}

.project-list, .image-list, .layer-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
}

#project-list {
    flex: 1 1 auto;
    min-height: 180px;
    max-height: 320px;
    overflow-y: auto;
}

#image-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    flex: 1 1 auto;
    min-height: 180px;
    max-height: 320px;
    overflow-y: auto;
}

#layer-list {
    flex: 1 1 auto;
    min-height: 180px;
    max-height: 320px;
    overflow-y: auto;
}

.project-card, .layer-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(147, 169, 188, 0.4);
    border-radius: 7px;
    background: #1a1a1d;
}

.image-card {
    display: block;
    padding: 8px;
    border: 1px solid rgba(147, 169, 188, 0.4);
    border-radius: 7px;
    background: #1a1a1d;
}

.image-card-preview {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    height: 72px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: #0f0f11;
    overflow: hidden;
    cursor: pointer;
}

.image-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.project-card-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.project-title {
    margin: 0 0 2px;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.2;
}
.project-meta { margin: 0; color: var(--text-muted); font-size: 0.74rem; }
.project-actions, .layer-actions { display: flex; align-items: center; gap: 6px; }
.layer-main {
    flex: 1;
    padding: 0;
    text-align: left;
    border: none;
    background: transparent;
    color: inherit;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.2;
}
.layer-item.selected { border-color: rgba(15, 124, 144, 0.8); background: rgba(15, 124, 144, 0.08); }

.right-sidebar .panel:first-child {
    flex: 1 1 auto;
}

.inspector-form {
    flex: 1 1 auto;
    min-height: 220px;
    max-height: 100%;
    overflow-y: auto;
}
.inspector-fields { display: flex; flex-direction: column; gap: 10px; }

.inspector-group {
    display: grid;
    gap: 8px;
    padding: 10px;
    border: 1px solid rgba(147, 169, 188, 0.3);
    border-radius: 7px;
    background: #1a1a1d;
}

.inspector-group h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.1;
}

.inspector-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.empty-state {
    padding: 14px;
    border: 1px dashed rgba(147, 169, 188, 0.7);
    border-radius: 12px;
    color: var(--text-muted);
    background: #101012;
    font-size: 0.88rem;
}

.shortcut-list {
    margin: 0;
    padding: 12px 12px 14px 28px;
    font-size: 0.88rem;
}

kbd {
    padding: 2px 6px;
    border-radius: 6px;
    background: #252529;
    border: 1px solid rgba(147, 169, 188, 0.5);
    font-size: 0.8rem;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: 320px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(23, 48, 66, 0.96);
    color: white;
    box-shadow: var(--shadow-soft);
    z-index: 30;
}

.toast.error { background: rgba(166, 57, 57, 0.96); }

@media (max-width: 1200px) {
    .workspace {
        grid-template-columns: 240px minmax(0, 1fr);
        grid-template-areas: "left center" "right center";
    }
    .left-sidebar { grid-area: left; }
    .canvas-stage { grid-area: center; }
    .right-sidebar { grid-area: right; }
}

@media (max-width: 980px) {
    .app-shell { grid-template-rows: auto minmax(0, 1fr); overflow: auto; }
    .topbar { grid-template-columns: 1fr; height: auto; padding-block: 10px; }
    .topbar-controls { justify-content: flex-start; }
    .workspace { display: block; overflow: visible; }
    .sidebar { max-height: none; border: 0; }
    .canvas-stage { min-height: 720px; }
    .canvas-wrapper { padding: 52px 16px 16px 52px; }
    .canvas-grid, .canvas, .measurement-overlay { top: 52px; left: 52px; }
    .ruler-top { left: 52px; }
    .ruler-left { top: 52px; }
}
