:root {
    --bg-page: #e9eef5;
    --bg-card: #ffffff;
    --teal-btn: #3f8fac;
    --teal-hover: #32758d;
    --input-bg: #f4f8fb;
    --input-border: #d7e0e8;
    --text-main: #2c3e50;
    --green: #27ae60;
    --red: #c0392b;
    --orange: #e67e22;
    --purple: #8e44ad;
    --shadow-soft: 0 6px 18px rgba(22, 37, 66, 0.08);
    --shadow-hover: 0 10px 24px rgba(22, 37, 66, 0.12);
    --transition-fast: 0.18s ease;
    --transition-slow: 0.28s ease;
}

html, body {
    min-height: 100%;
}

html {
    background: var(--bg-page);
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-main);
    padding-bottom: 40px;
    box-sizing: border-box;
}

.page-refresh-anim {
    animation: pageSoftRefresh 0.38s ease;
}

.browser-login-btn {
    position: fixed;
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    z-index: 11000;
    border: none;
    border-radius: 999px;
    padding: 10px 14px;
    background: #1f2f42;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    transition:
        transform 0.26s ease,
        opacity 0.26s ease,
        visibility 0.26s ease,
        background-color var(--transition-fast),
        box-shadow var(--transition-fast);
}

.browser-login-btn:hover:not(.browser-login-btn--scroll-hidden) {
    transform: translateY(-1px);
    background: #27425d;
    box-shadow: 0 10px 18px rgba(0, 0, 0, 0.24);
}

.browser-login-btn.browser-login-btn--scroll-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(calc(-100% - 20px));
    pointer-events: none;
}

/* «Выход» не показываем на списке стендов — не перекрывает карточки; «Вход» для гостей остаётся */
.browser-login-btn.browser-login-btn--hidden-on-stand-list {
    display: none !important;
}

.container { max-width: 600px; margin: 0 auto; padding: 20px 15px; display: none; }
.container.active { display: block; animation: pageFadeIn 0.32s ease both; }

h2 { text-align: center; color: #333; font-weight: 600; margin-bottom: 25px; margin-top: 0; font-size: 22px; }

.menu-grid { display: flex; flex-direction: column; gap: 12px; }

.main-btn {
    background: var(--bg-card);
    border: 1px solid #ddd; padding: 18px; font-size: 16px; color: #333;
    border-radius: 8px; cursor: pointer; text-align: left; font-weight: 600;
    display: flex; justify-content: space-between;
    box-shadow: var(--shadow-soft);
    transition: transform var(--transition-fast), box-shadow var(--transition-slow), background-color var(--transition-slow), border-color var(--transition-fast);
    user-select: none; align-items: center;
}
.main-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: #c8d5df; }
.main-btn:active { transform: scale(0.985); background: #f9fbfd; }
.main-btn span { color: var(--teal-btn); }
.btn-primary { background-color: var(--teal-btn); color: white; border: none; justify-content: center; }
.btn-primary:hover { background-color: var(--teal-hover); }
.btn-primary span { color: white; }

.btn-beta { border-left: 4px solid var(--orange); }
.beta-badge { background: var(--orange); color: white; font-size: 10px; padding: 2px 6px; border-radius: 4px; margin-left: 8px; vertical-align: middle; }
.btn-beta.build-on { border-left-color: var(--green); }
.btn-beta.build-off { border-left-color: var(--red); }

.admin-hidden {
    display: none;
}

.selector-group { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.radio-label {
    background: var(--bg-card); padding: 15px; border-radius: 8px;
    border: 2px solid transparent; box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    cursor: pointer; display: flex; align-items: center; gap: 10px; font-weight: 500;
    transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-slow), background-color var(--transition-fast);
}
.radio-label:hover { transform: translateY(-1px); border-color: #d6e3eb; box-shadow: var(--shadow-soft); }
.radio-label.checked { border-color: var(--teal-btn); background: #eef7fa; }
input[type="radio"] { display: none; }

.card {
    background: var(--bg-card);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 15px;
    box-shadow: var(--shadow-soft);
    position: relative;
    border: 1px solid #e6edf3;
    transition: transform var(--transition-fast), box-shadow var(--transition-slow), border-color var(--transition-fast);
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: #d3dfe8; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; border-bottom: 1px solid #eee; padding-bottom: 10px; }
.stand-title { font-size: 18px; font-weight: 700; color: #2c3e50; }

.badge { padding: 5px 10px; border-radius: 4px; font-size: 12px; font-weight: bold; color: white; text-transform: uppercase; }
.badge.free { background-color: var(--green); }
.badge.busy { background-color: var(--red); }

.links { display: flex; gap: 10px; margin-bottom: 15px; }
.link-chip {
    flex: 1; text-align: center; padding: 10px;
    background: var(--input-bg); border: 1px solid var(--input-border);
    border-radius: 6px; color: var(--teal-btn);
    text-decoration: none; font-weight: 600; font-size: 14px;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast), color var(--transition-fast);
}
.link-chip:hover { background: #eaf3f8; border-color: #bcd0dd; color: var(--teal-hover); transform: translateY(-1px); }

input[type="text"], input[type="password"], select {
    width: 100%; padding: 12px; background: var(--input-bg); border: 1px solid var(--input-border);
    border-radius: 6px; box-sizing: border-box; font-size: 16px; margin-bottom: 15px; outline: none;
    color: var(--text-main);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
    border-color: var(--teal-btn);
    box-shadow: 0 0 0 3px rgba(63, 143, 172, 0.18);
    background: #f9fcff;
}

.action-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    margin-top: 10px;
    transition: transform var(--transition-fast), filter var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
}
.action-btn:hover { transform: translateY(-1px); filter: brightness(0.98); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.12); }
.action-btn:active { transform: scale(0.985); }
.act-take { background: var(--teal-btn); color: white; }
.act-free { background: transparent; border: 2px solid var(--red); color: var(--red); }
.act-save { background: var(--teal-btn); color: white; margin-top: 5px; font-size: 14px; padding: 8px; width: auto; }
.act-build { background: var(--orange); color: white; }

.act-queue { background: var(--purple); color: white; display: flex; justify-content: center; align-items: center; gap: 8px; }
.act-queue:disabled { opacity: 0.6; cursor: not-allowed; background: #bbb; }
.act-queue:disabled:hover { transform: none; box-shadow: none; }

.act-leave { background: var(--red); color: white; display: flex; justify-content: center; align-items: center; gap: 8px; }

/* Контейнер ОБЩЕЙ очереди */
.general-queue-box {
    background: var(--bg-card);
    border: 2px solid var(--purple);
    border-radius: 8px; padding: 15px;
    margin-bottom: 20px;
    display: none;
    box-shadow: 0 4px 10px rgba(142, 68, 173, 0.2);
    transition: opacity var(--transition-slow), transform var(--transition-slow);
}
.general-queue-box.visible { display: block; animation: fadeInUp 0.28s ease both; }
.gq-title { font-weight: bold; color: var(--purple); margin-bottom: 10px; text-align: center; font-size: 15px; }

.user-info { background: #f9f9f9; padding: 10px; border-radius: 6px; display: flex; align-items: flex-start; gap: 12px; border: 1px solid #eee; position: relative; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #ddd; object-fit: cover; flex-shrink: 0; box-shadow: 0 2px 6px rgba(0,0,0,0.18); }

.user-details { display: flex; flex-direction: column; width: 100%; padding-right: 50px; }
.user-name { font-weight: bold; font-size: 14px; margin-bottom: 4px; display: flex; align-items: center; gap: 6px;}

.task-link { font-size: 13px; color: var(--teal-btn); text-decoration: none; font-weight: 500; display: inline-block; padding: 2px 0; transition: color var(--transition-fast), transform var(--transition-fast); }
.task-link:hover { color: var(--teal-hover); transform: translateY(-1px); }
.edit-icon { cursor: pointer; font-size: 14px; color: #999; margin-left: 8px; transition: color var(--transition-fast), transform var(--transition-fast); }
.edit-icon:hover { color: #666; transform: scale(1.08); }

/* Убрать чужого пользователя со стенда */
.stand-peer-kick-icon {
    position: absolute;
    bottom: 10px;
    right: 10px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    color: var(--red);
    font-weight: bold;
    padding: 5px;
    user-select: none;
}
.stand-peer-kick-icon:hover { opacity: 0.7; transform: scale(1.08); transition: transform var(--transition-fast), opacity var(--transition-fast); }

.edit-form { display: none; margin-top: 5px; }
.edit-form.active { display: block; }
.edit-input { padding: 6px; font-size: 13px; width: 70%; display: inline-block; margin-bottom: 0 !important; }

.timer-badge {
    position: absolute; top: 8px; right: 8px;
    font-size: 11px; color: #555; background: #e0e0e0;
    padding: 2px 6px; border-radius: 4px; font-family: monospace; font-weight: 600;
}

.queue-container { margin-top: 15px; padding-top: 10px; border-top: 1px dashed #ddd; }
.queue-label { font-size: 12px; color: #666; font-weight: 600; margin-bottom: 6px; }
.queue-avatars { display: flex; align-items: center; height: 32px; padding-left: 5px; flex-wrap: wrap; gap: 0; }
.q-avatar {
    width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff;
    object-fit: cover; margin-left: -10px; box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    position: relative;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.q-avatar:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 4px 10px rgba(0,0,0,0.22); }
.q-avatar:first-child { margin-left: 0; z-index: 20; }

.typing-indicator { font-size: 12px; color: var(--orange); font-style: italic; margin-bottom: 8px; height: 16px; opacity: 0; transition: opacity 0.2s; }
.typing-indicator.visible { opacity: 1; }

.back-link { color: var(--teal-btn); cursor: pointer; font-weight: 600; font-size: 16px; display: inline-block; margin-bottom: 15px; transition: color var(--transition-fast), transform var(--transition-fast); }
.back-link:hover { color: var(--teal-hover); transform: translateX(-2px); }

.auth-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 16px;
}

.auth-modal.visible {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.auth-modal-content {
    width: min(520px, 100%);
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
    animation: popIn 0.24s ease both;
}

.auth-modal-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
}

.auth-modal-text {
    margin: 0 0 14px;
    line-height: 1.45;
    color: #2c3e50;
}

.auth-id-hint {
    color: #3aa7ff;
    cursor: help;
    transition: color var(--transition-fast);
}
.auth-id-hint:hover { color: #1e8ee8; }

.auth-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.auth-error {
    min-height: 18px;
    color: #c0392b;
    font-size: 13px;
    margin-top: -6px;
    margin-bottom: 8px;
}

.auth-modal-links {
    margin-top: 2px;
    margin-bottom: 4px;
    text-align: left;
}

.auth-link-btn {
    background: transparent;
    border: none;
    color: #3f8fac;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    padding: 0;
}

.auth-link-btn:hover {
    color: #2d758f;
    text-decoration: underline;
}

.status-chip {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 12px;
}

.status-chip.status-on {
    background: rgba(39, 174, 96, 0.16);
    color: #1f8a4c;
}

.status-chip.status-off {
    background: rgba(192, 57, 43, 0.16);
    color: #9e2b1f;
}

.status-chip.status-partial {
    background: rgba(230, 161, 44, 0.18);
    color: #a56b08;
}

.main-btn-off {
    opacity: 0.55;
}

#build-disabled-text {
    white-space: pre-line;
}

.switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-weight: 600;
}

.label-text {
    font-size: 13px;
    font-weight: 600;
    color: #637a8b;
    margin-bottom: 6px;
    display: block;
}

.user-id {
    font-size: 13px;
    color: #6e7f8d;
}

.user-report-card {
    padding: 14px;
}

.admin-modal-switch-wrap {
    margin: 16px 0 8px;
    padding: 12px 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.admin-modal-switch-wrap[hidden] {
    display: none !important;
}

.gl-switch-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    margin: 0;
    color: #2c3e50;
}

.gl-switch-text {
    flex: 1;
    line-height: 1.35;
}

.gl-switch {
    position: relative;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.gl-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.gl-switch-slider {
    position: absolute;
    inset: 0;
    background: #b8c5ce;
    border-radius: 999px;
    transition: background 0.2s ease;
}

.gl-switch-slider::before {
    content: '';
    position: absolute;
    width: 22px;
    height: 22px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.gl-switch input:checked + .gl-switch-slider {
    background: #3f8fac;
}

.gl-switch input:checked + .gl-switch-slider::before {
    transform: translateX(22px);
}

.gl-switch input:focus-visible + .gl-switch-slider {
    outline: 2px solid #3f8fac;
    outline-offset: 2px;
}

.gl-switch input:disabled + .gl-switch-slider {
    opacity: 0.45;
}

/* Карточка стенда автоматизации без прав: блокируем ввод и кнопки; СУ/WEB кликабельны */
.stand-card-disabled {
    position: relative;
    opacity: 0.72;
    filter: grayscale(0.2);
}

.stand-card-disabled .stand-card-disable-shield {
    position: absolute;
    inset: 0;
    z-index: 3;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.38);
    border-radius: inherit;
}

.stand-card-disabled .links {
    position: relative;
    z-index: 4;
}

.stand-card-disabled:hover {
    transform: none;
    box-shadow: var(--shadow-soft);
    border-color: #e6edf3;
}

.user-row-clickable {
    cursor: pointer;
}

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

.user-row-top .user-info {
    flex: 1;
}

.user-row-top .status-chip {
    margin-bottom: 0;
    white-space: nowrap;
}

.save-status {
    min-height: 18px;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
}

.save-status.ok {
    color: #1f8a4c;
}

.save-status.error {
    color: #9e2b1f;
}

.build-submit-loading {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.build-submit-loading[hidden] {
    display: none !important;
}

.admin-hint {
    font-size: 13px;
    color: #6e7f8d;
    margin: 0 0 14px;
    line-height: 1.4;
}

.admin-build-company-block {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
}

.build-visual-hint {
    font-size: 13px;
    color: #5a7a8f;
    margin: 8px 0 14px;
    padding: 10px 12px;
    background: rgba(63, 143, 172, 0.12);
    border-radius: 8px;
    line-height: 1.4;
}

.build-submit-loading-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d6a8f;
    letter-spacing: 0.02em;
}

.build-submit-loading-track {
    height: 6px;
    border-radius: 999px;
    background: rgba(63, 143, 172, 0.22);
    overflow: hidden;
}

.build-submit-loading-bar {
    height: 100%;
    width: 40%;
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        rgba(63, 143, 172, 0.15) 0%,
        #3f8fac 45%,
        rgba(63, 143, 172, 0.15) 100%
    );
    animation: buildSubmitIndeterminate 1.25s ease-in-out infinite;
}

@keyframes buildSubmitIndeterminate {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(280%);
    }
}

.inline-loading {
    display: none;
    margin-top: 8px;
    font-size: 13px;
    font-weight: 600;
    color: #3f8fac;
}

.inline-loading.visible {
    display: block;
}

.inline-loading.visible::after {
    content: "...";
    display: inline-block;
    width: 0;
    overflow: hidden;
    vertical-align: bottom;
    animation: loadingDots 1.2s steps(4, end) infinite;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes popIn {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pageFadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pageSoftRefresh {
    0% { opacity: 0.72; transform: translateY(6px) scale(0.995); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes loadingDots {
    0% { width: 0; }
    25% { width: 0.35em; }
    50% { width: 0.7em; }
    75%, 100% { width: 1.05em; }
}