/* ============================================================
   components.css — 按钮 / 表单 / 查看器 / 拖放区 / 选区列表 /
                    标签页 / 模态 / 提示
   ============================================================ */

/* ---------------- 按钮 ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 30px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease,
        box-shadow 0.15s ease;
}

.btn:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--accent);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
    box-shadow: var(--shadow-sm);
}

.btn--primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn--soft {
    background: var(--accent-soft);
    border-color: color-mix(in srgb, var(--accent) 30%, transparent);
    color: var(--accent-hover);
}

.btn--soft:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent-soft) 70%, var(--accent) 12%);
}

.btn--danger {
    color: var(--danger);
    border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn--danger:hover:not(:disabled) {
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    border-color: var(--danger);
}

.btn--ghost {
    border-color: transparent;
    background: transparent;
}

.btn--ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border);
}

.btn--icon {
    width: 30px;
    padding: 0;
    font-size: 15px;
    line-height: 1;
}

.btn--sm {
    height: 26px;
    padding: 0 9px;
    font-size: 12px;
}

.btn--block {
    width: 100%;
}

/* 工具栏「更多」折叠按钮：默认隐藏，仅手机端显示。
   必须放在 .btn 之后，否则会被 .btn 的 display 覆盖。 */
.toolmore {
    display: none;
}

/* ---------------- 表单 ---------------- */

.field {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-dim);
    white-space: nowrap;
}

.input,
.select {
    height: 28px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.input--num {
    width: 54px;
    font-family: var(--font-mono);
    text-align: right;
}

.select {
    padding-right: 4px;
}

/* 复选框 */
.check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 26px;
    font-size: 12px;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.check input {
    appearance: none;
    width: 16px;
    height: 16px;
    margin: 0;
    border-radius: 5px;
    border: 1.5px solid var(--border-strong);
    background: var(--surface);
    display: grid;
    place-content: center;
    transition: background 0.15s ease, border-color 0.15s ease;
    flex: 0 0 auto;
}

.check input::after {
    content: "";
    width: 8px;
    height: 8px;
    transform: scale(0);
    border-radius: 2px;
    background: var(--accent-contrast);
    transition: transform 0.14s ease;
}

.check input:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.check input:checked::after {
    transform: scale(1);
}

.check:hover input {
    border-color: var(--accent);
}

/* 滑块 */
.range {
    appearance: none;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    outline: none;
}

.range::-webkit-slider-thumb {
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.range::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    cursor: pointer;
}

.range--zoom {
    width: 76px;
}

.range--opacity {
    width: 60px;
}

/* 分段控件 */
.segmented {
    display: inline-flex;
    padding: 2px;
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
    border: 1px solid var(--border);
}

.segmented__item {
    padding: 0 10px;
    height: 24px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    transition: background 0.15s ease, color 0.15s ease;
}

.segmented__item.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

/* ---------------- 主题选择器 ---------------- */

.theme-picker {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 2px;
    border-radius: 999px;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
}

.theme-dot {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-content: center;
    font-size: 13px;
    border: 2px solid transparent;
    transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.theme-dot:hover {
    transform: translateY(-1px);
    background: var(--surface);
}

.theme-dot.is-active {
    border-color: var(--accent);
    background: var(--surface);
}

/* ---------------- 标签页（合并用文件） ---------------- */

.tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 26px;
    max-width: 170px;
    padding: 0 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    transition: all 0.15s ease;
}

.tab:hover {
    border-color: var(--accent);
}

.tab.is-active {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.tab__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab__badge {
    font-size: 10px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--bg-sunken);
    color: var(--text-mute);
    font-family: var(--font-mono);
}

.tab__close {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    display: grid;
    place-content: center;
    font-size: 13px;
    line-height: 1;
    color: var(--text-mute);
}

.tab__close:hover {
    background: var(--danger);
    color: #fff;
}

/* ---------------- 查看器 ---------------- */

.viewer {
    position: absolute;
    inset: 0;
}

.viewer__viewport {
    position: absolute;
    inset: 0;
    overflow: auto;
    outline: none;
    overscroll-behavior: contain;
    background-image:
        linear-gradient(45deg, var(--bg-sunken) 25%, transparent 25%),
        linear-gradient(-45deg, var(--bg-sunken) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--bg-sunken) 75%),
        linear-gradient(-45deg, transparent 75%, var(--bg-sunken) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.viewer__stage {
    position: relative;
    display: grid;
    place-items: center;
    min-width: 100%;
    min-height: 100%;
    padding: 18px;
    width: max-content;
    height: max-content;
}

.viewer__frame {
    position: relative;
    box-shadow: var(--shadow);
    border-radius: 2px;
    overflow: hidden;
}

/* 两块画布都绝对定位在 frame 内，尺寸只跟视口一样大，
   靠 left/top 跟随滚动 —— 这样放大到几十倍也不会产生巨型画布。 */
.viewer__canvas,
.viewer__overlay {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    will-change: transform;
}

.viewer__overlay {
    touch-action: none;
}

.viewer.is-panning .viewer__viewport {
    cursor: grabbing;
}

/* ---------------- 拖放区 ---------------- */

.dropzone {
    position: absolute;
    inset: 12px;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 8px;
    border: 2px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    background: color-mix(in srgb, var(--surface) 60%, transparent);
    color: var(--text-dim);
    text-align: center;
    padding: 20px;
    transition: all 0.18s ease;
    z-index: 2;
}

.dropzone[hidden] {
    display: none;
}

.pane.is-dragover .dropzone {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent-hover);
}

.dropzone__icon {
    font-size: 30px;
    opacity: 0.75;
}

.dropzone__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.dropzone__desc {
    font-size: 12px;
    color: var(--text-mute);
    max-width: 260px;
}

/* 手机端选 XNB 的提示：电脑端 accept 能直接过滤 .xnb，不需要这条 */
.dropzone__tip {
    display: none;
    font-size: 11.5px;
    line-height: 1.5;
    color: var(--accent-hover);
    max-width: 260px;
    padding: 6px 9px;
    border-radius: var(--radius-sm);
    background: var(--accent-soft);
}

body.is-touch .dropzone__tip {
    display: block;
}

/* ---------------- 选区列表 ---------------- */

.region-list {
    display: grid;
    gap: 6px;
}

.region-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.region-item:hover {
    border-color: var(--border-strong);
}

.region-item.is-active {
    border-color: var(--region-active);
    background: var(--region-active-fill);
}

.region-item.is-disabled {
    opacity: 0.5;
}

/* 已锁定的选区：用锁定色描边，一眼区分 */
.region-item.is-locked {
    border-color: var(--region-locked);
    background: var(--region-locked-fill);
}

.region-item.is-locked .region-item__swatch {
    border-color: var(--region-locked);
    background: var(--region-locked-fill);
}

.region-lock {
    font-size: 10px;
    line-height: 1;
}

.icon-btn.is-locked {
    color: var(--region-locked);
}

.icon-btn.is-locked:hover {
    background: var(--region-locked-fill);
    color: var(--region-locked);
}

.region-tip {
    font-size: 11px;
    line-height: 1.65;
    margin: 0 0 8px;
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    background: var(--bg-sunken);
}

.region-tip b {
    color: var(--text-dim);
}

.region-item__main {
    min-width: 0;
    cursor: pointer;
}

.region-item__title {
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}

.region-item__swatch {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    border: 1px solid var(--region-stroke);
    background: var(--region-fill);
    flex: 0 0 auto;
}

.region-item.is-active .region-item__swatch {
    border-color: var(--region-active);
    background: var(--region-active-fill);
}

.region-item__meta {
    font-size: 11px;
    color: var(--text-mute);
    font-family: var(--font-mono);
}

.region-item__actions {
    display: flex;
    gap: 2px;
}

.icon-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    display: grid;
    place-content: center;
    font-size: 13px;
    color: var(--text-mute);
    transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg-sunken);
    color: var(--text);
}

.icon-btn--danger:hover {
    background: color-mix(in srgb, var(--danger) 15%, transparent);
    color: var(--danger);
}

.empty-hint {
    display: grid;
    place-items: center;
    gap: 6px;
    padding: 24px 12px;
    text-align: center;
    color: var(--text-mute);
    font-size: 12px;
    line-height: 1.7;
}

.empty-hint__icon {
    font-size: 24px;
    opacity: 0.6;
}

/* ---------------- 信息面板 ---------------- */

.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 10px;
    font-size: 12px;
    padding: 2px 4px 6px;
}

.info-grid__key {
    color: var(--text-mute);
}

.info-grid__val {
    font-family: var(--font-mono);
    text-align: right;
}

.bar {
    height: 6px;
    border-radius: 999px;
    background: var(--bg-sunken);
    overflow: hidden;
    margin-top: 6px;
}

.bar__fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--region-stroke));
    transition: width 0.3s ease;
}

/* ---------------- 工具栏溢出面板 ---------------- */

/* 放不下时显示的「⋯」按钮，由 toolbarOverflow.js 控制 hidden */
.toolpop-btn {
    display: inline-flex;
    min-width: 34px;
}

.toolpop-btn[hidden] {
    display: none;
}

.toolpop {
    position: fixed;
    z-index: 90;
    width: 240px;
    max-height: 72vh;
    overflow-y: auto;
    padding: 6px;
    display: grid;
    gap: 6px;
    align-content: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: pop-in 0.14s ease;
}

.toolpop[hidden] {
    display: none;
}

.toolpop__section {
    display: grid;
    gap: 6px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.toolpop__title {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.7px;
    color: var(--text-mute);
}

/* 搬进面板的分组要能换行，且去掉原本的左侧分隔线 */
.toolpop .toolbar__group {
    flex-wrap: wrap;
    border-left: none;
    padding-left: 0;
    gap: 8px;
}

/* ---------------- 小尺寸变体 ---------------- */

.select--sm {
    height: 26px;
    font-size: 12px;
    padding: 0 2px;
}

/* ---------------- 触控 ---------------- */

/* 画布上的手势全部由代码接管（单指平移/框选 + 双指缩放），
   禁掉浏览器默认滚动与页面缩放，避免手势打架。 */
.viewer__viewport {
    touch-action: none;
}

/* 单指手势切换：仅在触屏设备显示 */
.toolmode {
    display: none;
}

body.is-touch .toolmode {
    display: inline-flex;
}

@media (max-width: 680px) {
    .btn {
        height: 34px;
        padding: 0 13px;
        font-size: 13px;
    }

    .btn--sm {
        height: 32px;
        padding: 0 11px;
        font-size: 13px;
    }

    .btn--icon {
        width: 34px;
    }

    .input,
    .select {
        height: 32px;
        font-size: 13px;
    }

    .input--num {
        width: 66px;
    }

    .check {
        font-size: 13px;
        gap: 7px;
        /* 扩大可点区域到 32px 以上，方便手指点按 */
        min-height: 32px;
        padding: 5px 2px;
        margin: -5px -2px;
    }

    .check input {
        width: 22px;
        height: 22px;
        border-radius: 7px;
    }

    .check input::after {
        width: 11px;
        height: 11px;
    }

    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 15px;
    }

    .segmented__item {
        height: 30px;
        padding: 0 12px;
        font-size: 13px;
    }

    .theme-dot {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }

    /* 手机上显示「更多」折叠按钮（基础规则同在本文件，必须在这里覆盖） */
    .toolmore {
        display: inline-flex;
    }

    .toast__close {
        width: 24px;
        height: 24px;
        border-radius: 6px;
        display: grid;
        place-content: center;
    }

    .tab {
        height: 30px;
        max-width: 150px;
        font-size: 13px;
    }

    .region-item {
        padding: 9px 8px;
    }

    .range--zoom {
        width: 84px;
    }

    .modal {
        max-height: 90vh;
        border-radius: var(--radius-lg);
    }

    .modal__footer .btn {
        min-width: 92px;
    }

    .toast-host {
        right: 10px;
        left: 10px;
        bottom: 38px;
        justify-items: stretch;
    }

    .toast {
        max-width: none;
    }
}

/* ---------------- 模态 ---------------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(20, 24, 30, 0.42);
    backdrop-filter: blur(3px);
    animation: fade-in 0.18s ease;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: 100%;
    max-height: 86vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: pop-in 0.2s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.modal__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.modal__title {
    font-size: 15px;
    font-weight: 700;
}

.modal__close {
    margin-left: auto;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: grid;
    place-content: center;
    font-size: 18px;
    color: var(--text-mute);
}

.modal__close:hover {
    background: var(--bg-sunken);
    color: var(--text);
}

.modal__body {
    padding: 16px;
    overflow: auto;
    display: grid;
    gap: 12px;
}

.modal__footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}

.modal__section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-dim);
    letter-spacing: 0.4px;
}

/* ---------------- 提示 ---------------- */

.toast-host {
    position: fixed;
    right: 16px;
    bottom: 42px;
    z-index: 200;
    display: grid;
    gap: 8px;
    justify-items: end;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 340px;
    padding: 9px 12px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 13px;
    pointer-events: auto;
    animation: slide-in 0.22s ease;
}

.toast.is-leaving {
    animation: slide-out 0.2s ease forwards;
}

.toast__icon {
    font-size: 15px;
}

.toast__text {
    flex: 1 1 auto;
    word-break: break-word;
}

.toast__close {
    width: 22px;
    height: 22px;
    display: grid;
    place-content: center;
    border-radius: 6px;
    color: var(--text-mute);
    font-size: 16px;
    line-height: 1;
}

.toast__close:hover {
    background: var(--bg-sunken);
    color: var(--text);
}

.toast--success {
    border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

.toast--warn {
    border-color: color-mix(in srgb, var(--warn) 45%, transparent);
}

.toast--error {
    border-color: color-mix(in srgb, var(--danger) 50%, transparent);
}

/* ---------------- 加载遮罩 ---------------- */

.busy {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    background: rgba(20, 24, 30, 0.28);
    backdrop-filter: blur(2px);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.busy[hidden] {
    display: none;
}

.spinner {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
}

/* ---------------- 动画 ---------------- */

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fade-in {
    from {
        opacity: 0;
    }
}

@keyframes pop-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
}

@keyframes slide-in {
    from {
        opacity: 0;
        transform: translateX(16px);
    }
}

@keyframes slide-out {
    to {
        opacity: 0;
        transform: translateX(16px);
    }
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
