.draw-app {
    min-height: calc(100vh - 128px);
}

.draw-workspace {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 18px;
    min-height: calc(100vh - 172px);
}

.draw-sidebar,
.draw-main {
    border: 1px solid rgba(var(--site-primary-rgb), 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 14px 34px rgba(30, 41, 59, 0.08);
}

.draw-sidebar {
    align-self: start;
    padding: 16px;
}

.tool-section + .tool-section {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid #e2e8f0;
}

.tool-section-title {
    display: block;
    margin-bottom: 10px;
    color: #0f172a;
    font-size: 0.85rem;
    font-weight: 800;
}

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

.tool-button,
.icon-button,
.text-button {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #1e293b;
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
}

.tool-button {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: left;
}

.tool-button svg,
.icon-button svg,
.text-button svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.tool-button span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tool-button:hover,
.icon-button:hover,
.text-button:hover {
    border-color: var(--site-primary);
    color: var(--site-primary);
    background: #eef2ff;
}

.tool-button.is-active {
    border-color: var(--site-primary);
    background: var(--site-primary);
    color: #ffffff;
    box-shadow: 0 8px 18px rgba(var(--site-primary-rgb), 0.24);
}

.control-row,
.check-row,
.range-row {
    display: grid;
    gap: 8px;
    margin: 0 0 12px;
    color: #334155;
    font-size: 0.9rem;
    font-weight: 700;
}

.control-row {
    grid-template-columns: minmax(0, 1fr) 48px;
    align-items: center;
}

.control-row input[type="color"] {
    width: 48px;
    height: 32px;
    margin: 0;
    padding: 2px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
}

.check-row {
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: center;
}

.check-row input {
    width: 18px;
    height: 18px;
    margin: 0;
}

.range-row span {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.range-row output {
    color: var(--site-primary);
    font-variant-numeric: tabular-nums;
}

.range-row input[type="range"] {
    width: 100%;
    margin: 0;
    padding: 0;
    accent-color: var(--site-primary);
}

.draw-main {
    display: grid;
    grid-template-rows: auto minmax(420px, 1fr);
    min-width: 0;
    overflow: hidden;
}

.draw-topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    min-height: 64px;
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.topbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-status {
    min-width: 0;
    overflow: hidden;
    color: #64748b;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-button,
.text-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border-radius: 8px;
    font-weight: 800;
}

.icon-button {
    width: 42px;
    padding: 0;
}

.text-button {
    gap: 6px;
    min-width: 84px;
    padding: 0 12px;
}

.text-button.primary {
    border-color: var(--site-primary);
    background: var(--site-primary);
    color: #ffffff;
}

.text-button.primary:hover {
    border-color: var(--site-primary-deep);
    background: var(--site-primary-deep);
    color: #ffffff;
}

.canvas-shell {
    position: relative;
    min-height: 420px;
    overflow: hidden;
    background:
        linear-gradient(45deg, #f8fafc 25%, transparent 25%),
        linear-gradient(-45deg, #f8fafc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f8fafc 75%),
        linear-gradient(-45deg, transparent 75%, #f8fafc 75%);
    background-color: #eef2f7;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    background-size: 20px 20px;
}

.drawing-canvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 420px;
    touch-action: none;
    cursor: crosshair;
}

.text-entry {
    position: absolute;
    z-index: 20;
    display: none;
    width: min(280px, calc(100% - 24px));
    min-height: 38px;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid var(--site-primary);
    border-radius: 8px;
    background: #ffffff;
    color: #0f172a;
    caret-color: var(--site-primary);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
    font: 18px/1.3 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    pointer-events: auto;
}

.text-entry.is-visible {
    display: block !important;
}

@media (max-width: 980px) {
    .draw-workspace {
        grid-template-columns: 1fr;
    }

    .draw-sidebar {
        position: static;
    }

    .tool-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .draw-main {
        grid-template-rows: auto minmax(520px, 62vh);
    }
}

@media (max-width: 680px) {
    .draw-workspace {
        gap: 12px;
    }

    .draw-sidebar,
    .draw-main {
        border-radius: 8px;
    }

    .draw-sidebar {
        padding: 12px;
    }

    .tool-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .draw-topbar {
        grid-template-columns: 1fr;
        justify-items: stretch;
    }

    .topbar-group {
        justify-content: center;
    }

    .topbar-status {
        order: -1;
    }

    .draw-main {
        grid-template-rows: auto minmax(420px, 62vh);
    }
}
