:root {
    --color-bg-app: #f5f6f7;
    --color-bg-panel: #ffffff;
    --color-bg-sidebar-dark: #0f1722;
    --color-text-primary: #17202a;
    --color-text-secondary: #68727d;
    --color-border: #dfe3e8;
    --color-border-strong: #c9d2dc;
    --color-accent: #2563eb;
    --color-accent-dark: #1d4ed8;
    --color-route-default: #ef3b32;
    --color-success: #2f9e63;
    --color-warning: #d97706;
    --color-danger: #dc2626;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);

    --sidebar-width-left: 280px;
    --sidebar-width-right: 330px;
    --topbar-height: 60px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--color-text-primary);
    background: radial-gradient(circle at 20% 10%, #fdfefe 0%, var(--color-bg-app) 65%);
}

.site-header {
    height: var(--topbar-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1rem;
    border-bottom: 1px solid var(--color-border);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-text-primary);
    text-decoration: none;
}

nav {
    display: flex;
    gap: 0.65rem;
    align-items: center;
}

nav a {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

nav a:hover {
    color: var(--color-text-primary);
}

.page-shell {
    padding: 1rem;
    max-width: 1320px;
    margin: 0 auto;
}

.page-shell.editor-shell {
    max-width: none;
    width: 100%;
    height: calc(100vh - var(--topbar-height));
    padding: 0.55rem;
}

.editor-page {
    overflow: hidden;
}

.card {
    background: var(--color-bg-panel);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem;
}

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

.project-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width-left) 1fr var(--sidebar-width-right);
    gap: 0.6rem;
    height: 100%;
    min-height: 0;
}

.controls-column {
    max-height: 100%;
    overflow: auto;
    min-width: 0;
    padding: 0.65rem;
}

.left-column {
    background: linear-gradient(180deg, #111c29 0%, #0c1420 100%);
    border-color: #1e2c3f;
}

.left-column h1 {
    margin: 0;
    color: #f2f6fc;
    font-size: 1.12rem;
}

.left-column p {
    margin: 0.2rem 0 0;
    color: #9fb0c5;
    font-size: 0.85rem;
}

.studio-title-block {
    margin-bottom: 0.55rem;
}

.right-column {
    background: #fbfcfd;
}

.right-column .editor-panel {
    border-color: #d3dde8;
}

.right-column .editor-panel summary {
    font-size: 0.84rem;
    letter-spacing: 0.01em;
}

.right-column .stack-form {
    gap: 0.38rem;
}

.right-column .hint-text {
    font-size: 0.75rem;
}

.editor-panel {
    margin: 0 0 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    position: relative;
}

.left-column .editor-panel {
    background: #142031;
    border-color: #25364b;
}

.editor-panel summary {
    cursor: pointer;
    list-style: none;
    padding: 0.5rem 0.6rem;
    font-weight: 700;
    font-size: 0.87rem;
    color: #1f2a37;
    background: #f6f9fc;
    border-bottom: 1px solid var(--color-border);
}

.editor-panel summary::-webkit-details-marker {
    display: none;
}

.left-column .editor-panel summary {
    color: #dce8f5;
    background: #1a2a3f;
    border-bottom-color: #25364b;
}

.editor-panel > :not(summary) {
    padding: 0.5rem;
}

.hint-text {
    margin: 0.3rem 0 0;
    color: var(--color-text-secondary);
    font-size: 0.78rem;
}

.left-column .hint-text {
    color: #93a6be;
}

.stack-form {
    display: grid;
    gap: 0.45rem;
}

.stack-form p {
    margin: 0;
    display: grid;
    gap: 0.2rem;
}

.stack-form p > * {
    max-width: 100%;
}

input,
textarea,
select,
button {
    font: inherit;
    width: 100%;
    max-width: 100%;
    padding: 0.42rem 0.55rem;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: #ffffff;
}

input[type="checkbox"] {
    width: auto;
}

input[type="file"] {
    padding: 0.26rem;
    font-size: 0.82rem;
}

textarea {
    min-height: 90px;
}

button {
    cursor: pointer;
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #ffffff;
    font-weight: 600;
}

button:hover {
    background: var(--color-accent-dark);
    border-color: var(--color-accent-dark);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 2px solid #4f88ff;
    outline-offset: 1px;
}

.inline-form {
    display: inline;
}

.inline-form button {
    width: auto;
    padding: 0.32rem 0.55rem;
}

.tool-grid-mini {
    display: grid;
    gap: 0.34rem;
}

.tool-btn {
    width: 100%;
    text-align: left;
    background: #1b2b42;
    border-color: #2e4565;
    color: #eef5ff;
    font-size: 0.84rem;
    padding: 0.42rem 0.55rem;
}

.tool-btn:hover {
    background: #223650;
    border-color: #3a5c85;
}

.tool-btn.is-active {
    background: #2551b3;
    border-color: #4d78d8;
}

.map-column {
    display: grid;
    grid-template-rows: auto auto auto 1fr auto;
    gap: 0.5rem;
    min-height: 0;
    padding: 0.65rem;
    background: linear-gradient(180deg, #fdfefe 0%, #f8fafc 100%);
}

.studio-toolbar-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    padding-bottom: 0.1rem;
}

.studio-status-cluster {
    display: inline-flex;
    gap: 0.35rem;
    align-items: center;
}

.lock-status-chip {
    font-size: 0.72rem;
    border: 1px solid #d7dee8;
    background: #f6f8fb;
    color: #405063;
    border-radius: 999px;
    padding: 0.08rem 0.45rem;
    font-weight: 600;
}

.lock-status-chip.is-active {
    border-color: #9acbb1;
    background: #edf8f1;
    color: #175537;
}

.studio-toolbar-head h2 {
    margin: 0;
    font-size: 1.05rem;
}

.studio-toolbar-head p {
    margin: 0.1rem 0 0;
    font-size: 0.82rem;
    color: var(--color-text-secondary);
}

.editor-status {
    color: #2f9e63;
    font-size: 0.82rem;
    font-weight: 700;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    padding: 0.45rem;
}

.toolbar-select-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.82rem;
    color: var(--color-text-secondary);
}

.toolbar-select {
    width: auto;
    min-width: 160px;
    padding: 0.28rem 0.38rem;
    font-size: 0.82rem;
}

.production-legend {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.34rem 0.4rem;
}

.legend-chip {
    display: inline-flex;
    align-items: center;
    font-size: 0.74rem;
    color: #253548;
    border: 1px dashed #b8c4d2;
    border-radius: 999px;
    padding: 0.08rem 0.45rem;
    background: #fafcfe;
}

.legend-chip.bleed { border-color: #e74c3c; }
.legend-chip.trim { border-color: #2563eb; }
.legend-chip.safe { border-color: #2f9e63; }
.legend-chip.engrave { border-color: #d97706; }

.legend-chip.cut {
    border-style: solid;
    border-color: #7c3aed;
}

#atlas-map {
    width: 100%;
    height: 100%;
    min-height: 360px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: #ece9dd;
}

#atlas-map .output-frame-overlay {
    position: absolute;
    border: 2px dotted #2563eb;
    border-radius: 4px;
    background: rgba(37, 99, 235, 0.04);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.7);
    cursor: move;
    z-index: 550;
    touch-action: none;
}

#atlas-map .output-frame-overlay.frame-style-double {
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.85), inset 0 0 0 8px rgba(37, 99, 235, 0.18);
}

#atlas-map .output-frame-overlay.frame-style-vintage {
    border-style: solid;
    background: rgba(120, 90, 50, 0.06);
    box-shadow: inset 0 0 0 2px rgba(180, 133, 72, 0.45);
}

#atlas-map .output-frame-overlay.frame-style-badge {
    border-radius: 16px;
    border-style: solid;
    box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.8);
}

.canvas-element {
    position: absolute;
    min-width: 74px;
    max-width: 70%;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #d5dfeb;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
    padding: 0.32rem 0.42rem;
    z-index: 560;
    cursor: move;
    user-select: none;
}

.canvas-element.selected {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.element-style-popover {
    position: absolute;
    width: 240px;
    border: 1px solid #cfd9e5;
    border-radius: 10px;
    background: #ffffff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
    padding: 0.5rem;
    z-index: 700;
    display: grid;
    gap: 0.32rem;
}

.element-style-popover-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.1rem;
}

.element-style-popover-head strong {
    font-size: 0.78rem;
    color: #233042;
}

.element-style-popover-head button {
    width: auto;
    border: 0;
    background: transparent;
    color: #5b6675;
    padding: 0;
    font-size: 0.78rem;
}

.element-style-popover label {
    display: grid;
    gap: 0.15rem;
    font-size: 0.76rem;
    color: #3f4b5d;
}

.element-style-popover select,
.element-style-popover input {
    font-size: 0.78rem;
    padding: 0.22rem 0.3rem;
}

#element-style-delete {
    margin-top: 0.1rem;
    background: #8f1d28;
    border-color: #8f1d28;
}

.canvas-element-title {
    font-weight: 700;
    font-size: 0.84rem;
    color: #1e293b;
}

.canvas-element-subtitle {
    margin-top: 0.1rem;
    font-size: 0.74rem;
    color: #5b6675;
}

.canvas-element-stats {
    font-size: 0.74rem;
    color: #334155;
    line-height: 1.35;
}

.canvas-element-compass {
    display: inline-flex;
    align-items: center;
    gap: 0.28rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #1e3a8a;
}

.canvas-element-compass-arrow {
    font-size: 0.9rem;
}

.canvas-element-elevation {
    width: 152px;
}

.canvas-element-elevation svg {
    width: 100%;
    height: 34px;
    display: block;
}

.canvas-element-elevation path {
    fill: none;
    stroke: #0f766e;
    stroke-width: 2;
}

.editor-history-bar {
    display: flex;
    gap: 0.45rem;
    justify-content: flex-end;
}

.editor-history-bar button {
    width: auto;
    min-width: 88px;
    padding: 0.3rem 0.65rem;
}

.editor-history-bar button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#atlas-map .output-frame-overlay::after {
    content: "Output";
    position: absolute;
    top: -1.4rem;
    right: 0;
    font-size: 0.7rem;
    color: #1d4ed8;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 0.05rem 0.38rem;
}

#frame-lock-toggle.frame-lock-active {
    background: #1f7a4d;
    border-color: #1f7a4d;
}

#frame-position-lock-toggle.frame-position-lock-active {
    background: #374151;
    border-color: #374151;
}

.split-mini {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
}

.split-mini section {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #ffffff;
    padding: 0.5rem;
    min-height: 100px;
}

.split-mini h3 {
    margin: 0 0 0.3rem;
    font-size: 0.87rem;
}

.compact-list,
.project-list,
.flash-list {
    margin: 0;
    padding-left: 1rem;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
}

.product-grid article {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    background: #ffffff;
}

.auth-card {
    max-width: 440px;
    margin: 4rem auto;
}

/* Map Objects layer panel */
.map-objects-card {
    border: 1px solid #2d4562;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #152238;
}

.map-objects-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #223653;
    color: #f0f5fc;
    padding: 0.35rem 0.45rem;
}

.map-objects-head h4 {
    margin: 0;
    font-size: 0.86rem;
}

.map-objects-shortcut {
    font-size: 0.68rem;
    border: 1px solid #56769a;
    border-radius: 3px;
    color: #d7e5f6;
    padding: 0 0.22rem;
}

.map-objects-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.32rem 0.4rem;
    border-bottom: 1px solid #2c425f;
}

.text-action-btn {
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: #c8d8eb;
    font-size: 0.79rem;
    text-decoration: underline;
}

.add-action-btn {
    width: auto;
    margin-left: auto;
    padding: 0.22rem 0.58rem;
    border-radius: 999px;
    background: #2e5ec6;
    border: 1px solid #3f74e6;
    font-size: 0.77rem;
}

.layer-drop-root {
    max-height: 320px;
    overflow: auto;
    padding: 0.2rem;
}

.layer-tree,
.layer-tree ul,
.layer-tree li,
.layer-section,
.layer-node,
.layer-children {
    list-style: none;
    margin: 0;
    padding: 0;
}

.layer-section {
    border-bottom: 1px solid #2b405d;
}

.layer-section-head {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.35rem;
    background: #1a2a41;
    color: #c9d9ec;
    font-weight: 700;
}

.layer-section-title {
    font-size: 0.82rem;
}

.layer-children {
    margin-left: 0.55rem;
    padding-left: 0.28rem;
    border-left: 1px dashed #3f5a7c;
}

.layer-row {
    display: flex;
    align-items: center;
    gap: 0.28rem;
    padding: 0.22rem 0.25rem;
    border-bottom: 1px solid #233751;
    color: #cddced;
    cursor: pointer;
}

.layer-row:hover {
    background: #1e3048;
}

.layer-row.selected {
    background: #274569;
    outline: 1px solid #4f77a9;
}

.layer-row.drop-target {
    outline: 2px dashed #7ba8ff;
    outline-offset: -2px;
}

.layer-expander {
    width: 16px;
    height: 16px;
    border: 0;
    background: transparent;
    color: #99b1cf;
    padding: 0;
    line-height: 1;
    font-size: 0.72rem;
}

.layer-expander.placeholder {
    visibility: hidden;
}

.layer-vis {
    width: 14px;
    height: 14px;
    margin: 0;
}

.layer-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8rem;
}

.layer-row-actions {
    display: inline-flex;
    gap: 0.2rem;
}

.layer-row-icon {
    width: auto;
    padding: 0.1rem 0.28rem;
    border-radius: 4px;
    font-size: 0.68rem;
    border: 1px solid #43648f;
    background: #1f3551;
    color: #d6e4f8;
}

.layer-row-icon.danger {
    border-color: #87515b;
    background: #4a242c;
    color: #ffd7dd;
}

.layer-add-drawer {
    position: absolute;
    top: 2rem;
    left: calc(100% + 0.45rem);
    width: 265px;
    max-height: 430px;
    overflow: auto;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: #ffffff;
    box-shadow: var(--shadow-md);
    z-index: 80;
}

.layer-add-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.48rem;
    border-bottom: 1px solid var(--color-border);
}

.drawer-close-btn {
    width: auto;
    border: 0;
    background: transparent;
    color: var(--color-text-secondary);
    padding: 0;
    font-size: 0.82rem;
}

.layer-add-group {
    display: grid;
    gap: 0.22rem;
    padding: 0.45rem;
}

.layer-add-group h5 {
    margin: 0.1rem 0 0.35rem;
    font-size: 0.82rem;
    color: var(--color-text-secondary);
}

.drawer-item-btn {
    text-align: left;
    font-size: 0.8rem;
    color: #1f2d3c;
    background: #ffffff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.28rem 0.44rem;
}

.drawer-item-btn:hover {
    background: #f7fbff;
}

.drawer-item-btn.danger {
    color: #8f1d28;
    border-color: #efcad0;
    background: #fff7f8;
}

@media (max-width: 1360px) {
    .project-shell {
        grid-template-columns: 250px 1fr 300px;
    }
}

@media (max-width: 1180px) {
    .editor-page {
        overflow: auto;
    }

    .page-shell.editor-shell {
        height: auto;
    }

    .project-shell {
        grid-template-columns: 1fr;
        height: auto;
    }

    .controls-column,
    .map-column {
        max-height: none;
    }

    #atlas-map {
        height: 54vh;
        min-height: 320px;
    }

    .layer-add-drawer {
        position: relative;
        top: auto;
        left: auto;
        width: 100%;
        max-height: none;
        box-shadow: none;
        margin-top: 0.4rem;
    }
}

@media (max-width: 760px) {
    .site-header {
        padding: 0 0.65rem;
    }

    nav {
        gap: 0.4rem;
    }

    nav a {
        font-size: 0.82rem;
    }

    .page-shell {
        padding: 0.6rem;
    }

    .split-layout,
    .split-mini {
        grid-template-columns: 1fr;
    }

    .editor-toolbar {
        flex-wrap: wrap;
    }

    .toolbar-select {
        min-width: 130px;
    }
}
