/* client/style/css/main.css */
/* Общие стили: layout, переменные, базовые цвета, типографика */

:root {
    --base-font-size: 16px;
    --left-panel-width: 260px;
    --utility-toolbar-width: 44px;
    --right-panel-width: 280px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    font-family: Arial, sans-serif;
    background: #2b2b2b;
    color: #ffffff;
    overflow: hidden;
    font-size: var(--base-font-size);
    user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
    user-select: text;
}

#app {
    height: 100vh;
    display: grid;
    grid-template-rows: auto auto auto 1fr;
    grid-template-columns: var(--left-panel-width) 1fr var(--right-panel-width);
    grid-template-areas:
        "menu-bar menu-bar menu-bar"
        "ribbon ribbon ribbon"
        "stage-tabs stage-tabs stage-tabs"
        "tool-palette drawing-area properties";
    overflow: hidden;
}

/* Адаптация для экранов до 1200px */
@media (max-width: 1200px) {
    :root {
        --left-panel-width: 220px;
        --right-panel-width: 240px;
    }
}

/* Адаптация для экранов до 900px */
@media (max-width: 900px) {
    :root {
        --left-panel-width: 200px;
        --right-panel-width: 220px;
    }
}

/* Адаптация для экранов до 700px */
@media (max-width: 700px) {
    :root {
        --left-panel-width: 180px;
        --right-panel-width: 200px;
    }
}

#menu-bar {
    grid-area: menu-bar;
    background: #333;
    display: flex;
    align-items: center;
    padding: 0 0.625rem;
    border-bottom: 1px solid #444;
}

#menu-bar>div {
    padding: 0.375rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    position: relative;
}

#menu-bar>div:hover {
    background: #444;
}

#menu-account-button {
    margin-left: auto;
    border: 1px solid #5a5a5a;
    background: #3d3d3d;
    color: #ffffff;
    padding: 0.25rem 0.625rem;
    cursor: pointer;
    font-size: 0.8125rem;
}

#menu-account-button {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
    margin-right: 0.5rem;
}

#menu-account-button img {
    width: 1rem;
    height: 1rem;
    border-radius: 0.1875rem;
}

#menu-account-button.has-support-reply {
    border-color: #fbbf24;
    color: #ffffff;
}

#menu-account-button:hover {
    background: #4a4a4a;
}

#menu-bar>#command-debug-panel {
    align-items: center;
    border-left: 1px solid #555;
    color: #cfd7e6;
    cursor: default;
    display: flex;
    font-family: monospace;
    font-size: 0.75rem;
    gap: 0.75rem;
    padding: 0.25rem 0 0.25rem 0.75rem;
}

#menu-bar>#command-debug-panel:hover {
    background: transparent;
}

.debug-panel-row {
    display: inline-flex;
    gap: 0.35rem;
    white-space: nowrap;
}

.debug-panel-row span:last-child {
    color: #ffffff;
}

#account-modal-root,
#settings-modal-root {
    position: fixed;
    inset: 0;
    display: none;
    z-index: 1000;
}

#account-modal-root.visible,
#settings-modal-root.visible {
    display: block;
}

#auth-gate {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: rgba(13, 17, 23, 0.34);
}

body.app-auth-locked #auth-gate {
    display: flex;
}

body.app-auth-locked #ribbon,
body.app-auth-locked #stage-tabs,
body.app-auth-locked #tool-palette,
body.app-auth-locked #drawing-area,
body.app-auth-locked #properties {
    pointer-events: none;
    filter: blur(2px) grayscale(0.35) brightness(0.58);
}

body.app-auth-locked #menu-bar > div:not(#menu-account-button) {
    pointer-events: none;
    opacity: 0.45;
}

.auth-gate-panel {
    width: min(28rem, 92vw);
    padding: 1.25rem;
    border: 1px solid #3f4852;
    border-radius: 0.5rem;
    background: #252a31;
    color: #f4f6f8;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.42);
}

.auth-gate-panel h2 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
}

.auth-gate-panel p {
    margin: 0 0 1rem;
    color: #aeb8c4;
    font-size: 0.875rem;
    line-height: 1.45;
}

#auth-gate-login-button {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #4f87c8;
    border-radius: 0.25rem;
    background: #2f6fb3;
    color: #fff;
    cursor: pointer;
    font-size: 0.875rem;
}

#auth-gate-login-button:hover {
    background: #397dc4;
}

.app-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(8, 12, 18, 0.58);
}

.app-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    width: min(72rem, 90vw);
    height: 90vh;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid #3f4852;
    border-radius: 0.5rem;
    background: #252a31;
    color: #f4f6f8;
    box-shadow: 0 1.5rem 4rem rgba(0, 0, 0, 0.42);
}

.app-modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem 1.125rem;
    border-bottom: 1px solid #3a424c;
}

.app-modal-header h2 {
    margin: 0;
    font-size: 1rem;
    line-height: 1.2;
}

.app-modal-subtitle {
    margin-top: 0.25rem;
    color: #aeb8c4;
    font-size: 0.8125rem;
}

.app-modal-close {
    width: 2rem;
    height: 2rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #303741;
    color: #ffffff;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
}

.app-modal-close:hover {
    background: #3b4450;
}

.app-modal-body {
    display: grid;
    grid-template-columns: 9rem 1fr;
    min-height: 0;
    flex: 1;
}

.app-modal-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem;
    border-right: 1px solid #3a424c;
    background: #20252b;
}

.app-modal-tab {
    width: 100%;
    border: 0;
    border-radius: 0.375rem;
    background: transparent;
    color: #c9d1dc;
    padding: 0.625rem 0.75rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
}

.app-modal-tab:hover {
    background: #2c333c;
}

.app-modal-tab.active {
    background: #0f6fa8;
    color: #ffffff;
}

.app-modal-panel {
    padding: 1rem;
    overflow: auto;
}

.app-form {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

.app-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.app-form-grid.cols-1 {
    grid-template-columns: minmax(0, 1fr);
}

.app-form-grid.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-form-grid.cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.app-form-grid.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.app-field {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    color: #cbd4df;
    font-size: 0.8125rem;
}

.app-field input,
.app-field select,
.app-field textarea {
    width: 100%;
    border: 1px solid #4d5967;
    border-radius: 0.375rem;
    background: #171b20;
    color: #ffffff;
    padding: 0.625rem 0.6875rem;
    font-size: 0.875rem;
}

.app-field textarea {
    min-height: 7rem;
    line-height: 1.4;
    resize: vertical;
}

.app-field input:focus,
.app-field select:focus,
.app-field textarea:focus {
    border-color: #1592db;
    outline: none;
}

.app-field-compact {
    gap: 0;
}

.app-checkbox-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.625rem;
    align-items: start;
    color: #cbd4df;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.app-checkbox-field input {
    margin-top: 0.125rem;
}

.app-checkbox-field a {
    color: #8ccdf6;
    text-decoration: none;
}

.app-checkbox-field a:hover {
    text-decoration: underline;
}

.app-captcha {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 0.75rem;
}

.app-captcha-canvas {
    display: block;
    width: 100%;
    max-width: 20rem;
    height: auto;
    aspect-ratio: 1;
    align-self: center;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #0f1217;
}

.app-captcha.passed {
    border-color: rgba(34, 197, 94, 0.45);
    background: rgba(34, 197, 94, 0.12);
}

.app-captcha.passed .app-note {
    color: #8ee6a5;
}

.app-actions {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-top: 0.25rem;
}

.app-actions.wide {
    grid-column: 1 / -1;
}

.app-primary-button,
.app-secondary-button {
    border-radius: 0.375rem;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    cursor: pointer;
}

.app-primary-button {
    border: 1px solid #1580c4;
    background: #1592db;
    color: #ffffff;
}

.app-primary-button:hover {
    background: #0f7fbe;
}

.app-secondary-button {
    border: 1px solid #525d69;
    background: #303741;
    color: #e6ecf3;
}

.app-secondary-button:hover {
    background: #3b4450;
}

.account-pricing-link {
    display: inline-flex;
    align-items: center;
    min-height: 2.25rem;
    color: #d6e9ff;
    font-size: 0.8125rem;
    text-decoration: none;
}

.account-pricing-link:hover {
    text-decoration: underline;
}

.app-note {
    color: #9faab7;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.app-note code {
    color: #d6e9ff;
}

.app-note a {
    color: #d6e9ff;
}

.app-note.wide {
    grid-column: 1 / -1;
}

.app-note.divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.35rem;
    color: #d6dde6;
    font-weight: 600;
}

.app-note.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(159, 170, 183, 0.28);
}

.app-inline-button {
    border: 0;
    background: transparent;
    color: #d6e9ff;
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: underline;
}

.app-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.app-summary-item {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    min-height: 4.5rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 0.75rem;
}

.app-summary-item div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.app-summary-item div:last-child {
    align-items: flex-end;
    text-align: right;
}

.app-summary-item span {
    color: #9faab7;
    font-size: 0.75rem;
}

.app-summary-item strong {
    color: #ffffff;
    font-size: 0.9375rem;
}

.app-summary-item small {
    color: #7ee787;
    font-size: 0.8125rem;
}

.app-summary-item em {
    font-style: normal;
}

.app-status {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 1.5rem;
    border-radius: 999px;
    padding: 0.125rem 0.5rem;
    font-size: 0.8125rem;
}

.app-status-green {
    background: rgba(34, 197, 94, 0.18);
    color: #7ee787;
}

.app-status-orange {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
}

.app-status-red {
    background: rgba(239, 68, 68, 0.18);
    color: #f87171;
}

.account-plan-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.account-plan-card {
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 0.75rem;
}

.account-plan-card.active {
    border-color: #1592db;
    box-shadow: inset 0 0 0 1px rgba(21, 146, 219, 0.5);
}

.account-plan-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.account-plan-name {
    color: #ffffff;
    font-size: 0.9375rem;
    font-weight: 700;
}

.account-plan-price {
    color: #d6e9ff;
    font-size: 0.8125rem;
    font-weight: 700;
    white-space: nowrap;
}

.account-plan-summary {
    min-height: 2.25rem;
    margin-top: 0.875rem;
    color: #cbd4df;
    font-size: 0.8125rem;
    line-height: 1.35;
}

.account-plan-details-button {
    width: 100%;
    margin-top: 0.875rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #303741;
    color: #e6ecf3;
    padding: 0.5rem 0.625rem;
    cursor: pointer;
    font-size: 0.8125rem;
}

.account-plan-details-button:hover {
    background: #3b4450;
}

.account-plan-details-button:disabled {
    background: #252a31;
    color: #9faab7;
    cursor: default;
}

.app-history {
    margin-bottom: 1rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    overflow: hidden;
}

.app-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    border-bottom: 1px solid #3a424c;
}

.app-history-header h3 {
    margin: 0;
    color: #ffffff;
    font-size: 0.9375rem;
}

.app-history-header span {
    color: #9faab7;
    font-size: 0.8125rem;
}

.app-history-empty {
    padding: 0.75rem;
    color: #9faab7;
    font-size: 0.8125rem;
}

.app-history-list {
    display: grid;
}

.app-history-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid #303741;
}

.app-history-row:last-child {
    border-bottom: 0;
}

.app-history-row div {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.app-history-row div:nth-child(2) {
    text-align: right;
}

.app-history-row strong {
    color: #ffffff;
    font-size: 0.875rem;
}

.app-history-row span {
    color: #9faab7;
    font-size: 0.75rem;
    line-height: 1.35;
}

.app-history-status {
    align-self: start;
    border-radius: 999px;
    padding: 0.1875rem 0.5rem;
    font-size: 0.75rem;
    font-style: normal;
    white-space: nowrap;
}

.app-history-status-green {
    background: rgba(34, 197, 94, 0.18);
    color: #7ee787;
}

.app-history-status-orange {
    background: rgba(245, 158, 11, 0.18);
    color: #fbbf24;
}

.app-history-status-red {
    background: rgba(239, 68, 68, 0.18);
    color: #f87171;
}

.app-empty-state {
    display: grid;
    gap: 0.375rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 1rem;
}

.app-empty-state strong {
    color: #ffffff;
}

.app-empty-state span {
    color: #9faab7;
    font-size: 0.8125rem;
}

.app-accordion {
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    overflow: hidden;
}

.app-accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
    min-height: 2.5rem;
    border: 0;
    background: transparent;
    color: #ffffff;
    cursor: pointer;
    padding: 0.625rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 700;
    text-align: left;
}

.app-accordion-header:hover {
    background: #252b32;
}

.app-accordion-marker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid #525d69;
    border-radius: 0.25rem;
    background: #303741;
    color: #d6e9ff;
    font-size: 1rem;
    line-height: 1;
}

.app-accordion-actions {
    display: inline-flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.app-accordion-content {
    border-top: 1px solid #3a424c;
    padding: 0.75rem;
}

.app-accordion-footer {
    display: flex;
    justify-content: flex-end;
    margin-top: 0.75rem;
}

.account-support-list {
    margin-top: 1rem;
}

.account-support-ticket-list {
    display: grid;
    gap: 0.375rem;
}

.account-support-ticket {
    display: grid;
    gap: 0.75rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 0.75rem;
}

.account-support-ticket.compact {
    gap: 0;
    padding: 0;
}

.account-support-compact-button {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 3.25rem;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    padding: 0.5rem 0.625rem;
    text-align: left;
}

.account-support-compact-button:hover {
    background: #252b32;
}

.account-support-compact-button span {
    display: grid;
    gap: 0.125rem;
    min-width: 0;
}

.account-support-compact-button strong,
.account-support-compact-button small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-support-compact-button strong {
    color: #ffffff;
    font-size: 0.8125rem;
}

.account-support-compact-button small {
    color: #9faab7;
    font-size: 0.6875rem;
}

.account-support-ticket header {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.account-support-ticket header div {
    display: grid;
    gap: 0.1875rem;
    min-width: 0;
}

.account-support-ticket header strong {
    color: #ffffff;
    font-size: 0.875rem;
}

.account-support-ticket header span {
    color: #9faab7;
    font-size: 0.75rem;
    line-height: 1.35;
}

.account-support-messages {
    display: grid;
    gap: 0.5rem;
}

.account-support-message {
    display: grid;
    gap: 0.375rem;
    max-width: 88%;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #1c2127;
    padding: 0.625rem;
}

.account-support-message.user {
    justify-self: end;
    border-color: #cfe9b5;
    background: #f2ffe2;
}

.account-support-message.admin {
    justify-self: start;
    border-color: #e5e7eb;
    background: #fafafa;
}

.account-support-message div {
    display: flex;
    justify-content: space-between;
    gap: 0.625rem;
}

.account-support-message strong {
    color: #ffffff;
    font-size: 0.75rem;
}

.account-support-message span {
    color: #9faab7;
    font-size: 0.6875rem;
}

.account-support-message p {
    margin: 0;
    color: #d8dee6;
    font-size: 0.8125rem;
    line-height: 1.45;
    white-space: pre-wrap;
}

.account-support-message.admin strong,
.account-support-message.admin p,
.account-support-message.user strong,
.account-support-message.user p {
    color: #17202a;
}

.account-support-message.admin span,
.account-support-message.user span {
    color: #64748b;
}

.account-support-reply {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: end;
}

.account-support-reply textarea {
    grid-column: 1 / -1;
    width: 100%;
    min-height: 4.5rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #1c2127;
    color: #ffffff;
    padding: 0.5rem;
    font: inherit;
    resize: vertical;
}

.account-support-reply input {
    min-width: 0;
    color: #9faab7;
    font-size: 0.8125rem;
}

.account-support-reply button,
.account-support-collapse-button {
    min-height: 2rem;
    border: 1px solid #1592db;
    border-radius: 0.375rem;
    background: #1592db;
    color: #ffffff;
    padding: 0 0.75rem;
    cursor: pointer;
}

.account-support-collapse-button {
    justify-self: end;
    border-color: #525d69;
    background: #303741;
}

.account-support-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.account-support-attachments a {
    display: grid;
    gap: 0.25rem;
    width: 7.5rem;
    color: #9cc9ff;
    font-size: 0.75rem;
    text-decoration: none;
}

.account-support-attachments img {
    width: 100%;
    aspect-ratio: 4 / 3;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    object-fit: cover;
    background: #11161c;
}

.account-support-attachments span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-freeze-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 7rem auto auto;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
    border: 1px solid #3a424c;
    border-radius: 0.375rem;
    background: #20252b;
    padding: 0.75rem;
}

.account-freeze-control div,
.account-freeze-control label {
    display: grid;
    gap: 0.25rem;
    min-width: 0;
}

.account-freeze-control span {
    color: #9faab7;
    font-size: 0.75rem;
}

.account-freeze-control strong {
    color: #ffffff;
    font-size: 0.9375rem;
}

.account-freeze-control input {
    width: 100%;
    min-height: 2rem;
    border: 1px solid #525d69;
    border-radius: 0.375rem;
    background: #1c2127;
    color: #ffffff;
    padding: 0.375rem 0.5rem;
}

.account-freeze-control button {
    min-height: 2rem;
    border: 1px solid #1592db;
    border-radius: 0.375rem;
    background: #1592db;
    color: #ffffff;
    padding: 0 0.75rem;
    cursor: pointer;
}

.account-freeze-control button:disabled {
    border-color: #525d69;
    background: #303741;
    color: #9faab7;
    cursor: default;
}

.account-freeze-control .account-freeze-secondary {
    border-color: #525d69;
    background: #303741;
}

@media (max-width: 700px) {
    .app-modal-body {
        grid-template-columns: 1fr;
    }

    .app-modal-tabs {
        flex-direction: row;
        overflow-x: auto;
        border-right: 0;
        border-bottom: 1px solid #3a424c;
    }

    .app-modal-tab {
        width: auto;
        white-space: nowrap;
    }

    .app-form-grid,
    .app-summary-grid,
    .account-plan-grid,
    .account-freeze-control,
    .account-support-reply {
        grid-template-columns: 1fr;
    }

    .account-support-ticket header,
    .account-support-message div {
        flex-direction: column;
        align-items: stretch;
    }

    .account-support-message,
    .account-support-message.admin,
    .account-support-message.user {
        justify-self: stretch;
        max-width: none;
    }
}

.menu-bar-item {
    user-select: none;
}

.menu-bar-dropdown {
    position: absolute;
    top: calc(100% + 1px);
    left: 0;
    min-width: 12rem;
    display: none;
    flex-direction: column;
    background: #2f2f2f;
    border: 1px solid #4a4a4a;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.35);
    z-index: 20;
    padding: 0.25rem 0;
}

.menu-bar-item.open .menu-bar-dropdown {
    display: flex;
}

.menu-bar-action {
    width: 100%;
    border: 0;
    background: transparent;
    color: #ffffff;
    text-align: left;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.menu-bar-action:hover {
    background: #444;
}

#stage-tabs {
    grid-area: stage-tabs;
    background: #2a2a2a;
    display: flex;
    gap: 0.3125rem;
    padding: 0 0.625rem;
    align-items: flex-end;
    border-bottom: 1px solid #444;
}

.stage-tab {
    padding: 0.5rem 1rem;
    background: #444;
    border-radius: 0.25rem 0.25rem 0 0;
    cursor: pointer;
    font-size: 0.875rem;
}

.stage-tab.active {
    background: #1e1e1e;
    border-bottom: 0.1875rem solid #0078d7;
}

.stage-tab.disabled {
    background: #333;
    color: #666;
    cursor: not-allowed;
}

#drawing-area {
    grid-area: drawing-area;
    background: #1e1e1e;
    position: relative;
    min-width: 0;
    overflow: hidden;
}

.materials-stage-view[hidden] {
    display: none;
}

body.materials-stage-active #utility-toolbar,
#drawing-area.materials-stage-active>canvas,
#drawing-area.materials-stage-active>#canvas-overlay-root {
    display: none !important;
}

.materials-stage-view {
    position: absolute;
    inset: 0;
    z-index: 50;
    overflow: hidden;
    background: #f6f7f9;
    color: #343f52;
}

.materials-stage-shell {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    min-height: 0;
}

.materials-stage-section-tabs {
    display: flex;
    align-items: flex-end;
    gap: 0.3125rem;
    padding: 0.5rem 0.75rem 0;
}

.materials-stage-section-tab {
    min-height: 2.25rem;
    border: 1px solid #e9ecef;
    border-bottom: 0;
    border-radius: 0.375rem 0.375rem 0 0;
    background: #edf2fc;
    color: #60697b;
    cursor: pointer;
    padding: 0 0.875rem;
    font-size: 0.8125rem;
}

.materials-stage-section-tab:hover {
    color: #343f52;
    background: #e3eaf8;
}

.materials-stage-section-tab.active {
    position: relative;
    z-index: 1;
    margin-bottom: -1px;
    background: #ffffff;
    border-color: #e9ecef;
    color: #343f52;
    font-weight: 700;
}

.materials-stage-content {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 1;
    gap: 0.75rem;
    min-height: 0;
    overflow: hidden;
    padding: 0.75rem;
}

.materials-stage-content.single {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
}

.materials-stage-content.single .materials-stage-section {
    width: min(100%, 82.5rem);
    height: 100%;
    max-height: 100%;
}

.materials-stage-section {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    align-self: stretch;
    min-height: 0;
    border: 1px solid #e9ecef;
    border-radius: 0.375rem;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 0.25rem 1.25rem rgba(30, 34, 40, 0.06);
}

.materials-stage-section header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 2.5rem;
    border-bottom: 1px solid #e9ecef;
    padding: 0.5rem 0.75rem;
}

.materials-stage-section h3 {
    margin: 0;
    color: #343f52;
    font-size: 0.875rem;
}

.materials-stage-section header span {
    color: #60697b;
    font-size: 0.75rem;
    white-space: nowrap;
}

.materials-stage-table-wrap {
    min-height: 0;
    overflow: auto;
}

.materials-stage-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    color: #343f52;
    font-size: 0.8125rem;
}

.materials-stage-table th,
.materials-stage-table td {
    border-bottom: 1px solid #e9ecef;
    padding: 0.4375rem 0.5rem;
    text-align: left;
    vertical-align: top;
}

.materials-stage-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #ffffff;
    color: #60697b;
    font-size: 0.75rem;
    font-weight: 700;
    height: 2.25rem;
    padding-top: 0.5625rem;
    padding-bottom: 0.5625rem;
}

.materials-stage-table th:nth-child(1),
.materials-stage-table td:nth-child(1) {
    width: 2.25rem;
    text-align: center;
}

.materials-stage-table th:nth-child(2),
.materials-stage-table td:nth-child(2) {
    width: 3rem;
    color: #60697b;
    text-align: right;
}

.materials-stage-table th:nth-child(4),
.materials-stage-table td:nth-child(4) {
    width: 10rem;
    white-space: nowrap;
}

.materials-stage-table th:nth-child(5),
.materials-stage-table td:nth-child(5) {
    width: 10rem;
    white-space: nowrap;
}

.materials-stage-table th:nth-child(6),
.materials-stage-table td:nth-child(6) {
    width: 10rem;
    white-space: nowrap;
}

.materials-stage-table th:nth-child(7),
.materials-stage-table td:nth-child(7) {
    width: 7.5rem;
    white-space: nowrap;
}

.materials-stage-table td:nth-child(3) {
    overflow-wrap: anywhere;
}

.materials-stage-checkbox {
    width: 1rem;
    height: 1rem;
    accent-color: #3f78e0;
    cursor: pointer;
}

.materials-stage-amount {
    margin-right: 0.375rem;
}

.materials-stage-row-ok {
    background: #def4ee;
}

.materials-stage-row-partial {
    background: #fff8e5;
}

.materials-stage-row-missing {
    background: #fae6e7;
}

.materials-stage-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-width: 5.5rem;
    min-height: 1.5rem;
    border-radius: 999px;
    padding: 0.125rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
}

.materials-stage-status-ok {
    background: #def4ee;
    color: #45c4a0;
}

.materials-stage-status-partial {
    background: #fff8e5;
    color: #fab758;
}

.materials-stage-status-missing {
    background: #fae6e7;
    color: #e2626b;
}

.materials-stage-empty {
    color: #60697b;
    text-align: center;
}

.materials-stage-error {
    min-height: 0;
    overflow: auto;
    color: #e2626b;
    padding: 0.75rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    user-select: text;
}

#utility-toolbar {
    grid-area: drawing-area;
    position: relative;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-self: end;
    align-self: stretch;
    width: var(--utility-toolbar-width);
    gap: 0.375rem;
    padding: 0.5rem 0.25rem;
    pointer-events: none;
}

.utility-toolbar-button {
    width: 2rem;
    height: 2rem;
    border: 1px solid #505050;
    border-radius: 0.25rem;
    background: #3d3d3d;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.utility-toolbar-button:hover,
.utility-toolbar-button[aria-pressed="true"] {
    border-color: #0078d7;
    background: #454f5c;
}

.utility-toolbar-button img {
    width: 1.25rem;
    height: 1.25rem;
    object-fit: contain;
}

.utility-toolbar-panel {
    position: absolute;
    top: 0.5rem;
    right: calc(100% + 0.5rem);
    width: 16rem;
    display: none;
    color: #f5f5f5;
    background: #383838;
    border: 1px solid #555;
    border-radius: 0.375rem;
    box-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.35);
    pointer-events: auto;
}

.utility-toolbar-panel.visible {
    display: block;
}

.utility-toolbar-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid #4a4a4a;
    font-size: 0.875rem;
    font-weight: 700;
}

.utility-toolbar-panel-close {
    width: 1.5rem;
    height: 1.5rem;
    border: 0;
    border-radius: 0.25rem;
    background: transparent;
    color: #ddd;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
}

.utility-toolbar-panel-close:hover {
    background: #4a4a4a;
}

.utility-toolbar-panel-body {
    padding: 0.75rem;
    color: #d8d8d8;
    font-size: 0.8125rem;
    line-height: 1.4;
}

.utility-toolbar-panel-content {
    display: flex;
    flex-direction: column;
    gap: 0.625rem;
}

.utility-toolbar-panel-content[hidden] {
    display: none;
}

.utility-toolbar-section-title {
    align-items: center;
    display: flex;
    gap: 0.5rem;
}

.utility-toolbar-section-title::after {
    content: "";
    flex: 1;
    border-top: 1px solid #4a4a4a;
}

#utility-toolbar .utility-toolbar-wide-button {
    width: 100%;
    height: 2.25rem;
    padding: 0 0.625rem;
    justify-content: flex-start;
    gap: 0.5rem;
}

#canvas-overlay-root {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
}

.canvas-overlay-panel {
    position: absolute;
    min-width: 10rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.625rem;
    border: 1px solid rgba(32, 32, 32, 0.18);
    border-radius: 0.625rem;
    background: rgba(255, 255, 255, 0.96);
    color: #202020;
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.14);
    pointer-events: auto;
    transform: translate(0.875rem, -50%);
}

.canvas-overlay-panel.visible {
    display: flex;
}

.canvas-overlay-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.canvas-overlay-label {
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.canvas-overlay-input {
    width: 5rem;
    border: 1px solid #cfcfcf;
    border-radius: 0.4375rem;
    background: #ffffff;
    color: #202020;
    padding: 0.3125rem 0.4375rem;
    font-size: 0.875rem;
}

.canvas-overlay-button {
    border: 1px solid #1580c4;
    border-radius: 0.4375rem;
    background: #1592db;
    color: #ffffff;
    padding: 0.3125rem 0.625rem;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.canvas-overlay-button:hover,
.canvas-overlay-button:focus {
    background: #0f7fbe;
    border-color: #0f6fa8;
    outline: none;
}

.canvas-overlay-suffix {
    font-size: 0.75rem;
    color: #5a5a5a;
    white-space: nowrap;
}

.canvas-opening-anchor-marker {
    position: absolute;
    display: none;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem 0.25rem 0.3125rem;
    border: 1px solid rgba(255, 166, 64, 0.42);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: #5f3700;
    box-shadow: 0 0.375rem 0.875rem rgba(0, 0, 0, 0.16);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.canvas-opening-anchor-marker.visible {
    display: flex;
}

.canvas-opening-anchor-marker {
    gap: 0;
    padding: 0.3125rem;
}

.canvas-opening-anchor-text {
    display: none;
}

.canvas-opening-anchor-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #ffa640;
    box-shadow: 0 0 0 0.1875rem rgba(255, 166, 64, 0.22);
}

.placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 1.5rem;
    text-align: center;
}
