/**
 * XPD 选片端 - 布局系统样式
 * 自由布局画布、模块容器、编辑手柄、网格线
 */

/* ============================================
   基础样式
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

/* ============================================
   布局画布
   ============================================ */
.xpd-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 0;
}

/* 编辑模式网格背景 */
.xpd-canvas.edit-mode {
    background-image:
        linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
    background-size: 20px 20px;
    overflow: visible;
}

/* ============================================
   模块容器
   ============================================ */
.layout-module {
    position: absolute;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

/* 展示模式 - 无边框沉浸 */
.layout-module.display-mode {
    border: none;
    background: transparent;
}

/* 编辑模式 - 虚线边框，允许手柄溢出可见 */
.layout-module.edit-mode {
    border: 2px dashed rgba(100, 149, 237, 0.5);
    background: rgba(30, 30, 60, 0.3);
    overflow: visible;
}

.layout-module.edit-mode:hover {
    border-color: rgba(100, 149, 237, 0.8);
    background: rgba(30, 30, 60, 0.5);
}

/* 编辑模式选中状态 */
.layout-module.edit-mode.selected {
    border: 2px solid rgba(100, 149, 237, 0.9);
    box-shadow: 0 0 20px rgba(100, 149, 237, 0.15);
    z-index: 9999 !important;
}

/* 拖拽中阴影 */
.layout-module.dragging {
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    opacity: 0.92;
    transition: none;
}

/* 缩放中 */
.layout-module.resizing {
    transition: none;
}

/* ============================================
   模块顶部拖拽手柄（编辑模式，hover 显示）
   ============================================ */
.module-drag-handle {
    display: none;
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 16px;
    cursor: move;
    z-index: 10;
    border-radius: 8px;
    background: rgba(100, 149, 237, 0.5);
    align-items: center;
    justify-content: center;
    gap: 3px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.layout-module.edit-mode:hover .module-drag-handle,
.layout-module.edit-mode.selected .module-drag-handle {
    display: flex;
    opacity: 1;
}

.module-drag-handle .handle-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: #fff;
}

.layout-module.edit-mode:hover .module-drag-handle {
    background: rgba(100, 149, 237, 0.8);
}

/* ============================================
   缩放手柄（仅选中模块显示）
   ============================================ */
.resize-handle {
    display: none;
    position: absolute;
    width: 12px;
    height: 12px;
    background: #4a90d9;
    border: 2px solid #fff;
    border-radius: 2px;
    z-index: 11;
    box-shadow: 0 0 6px rgba(74, 144, 217, 0.5);
    transition: transform 0.1s ease;
}

.layout-module.edit-mode.selected .resize-handle {
    display: block;
}

.resize-handle:hover {
    transform: scale(1.3);
    background: #ff6b6b;
    border-color: #fff;
    box-shadow: 0 0 10px rgba(255, 107, 107, 0.6);
}

/* 四角 */
.resize-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.resize-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.resize-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.resize-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

/* 四边中点 */
.resize-handle.n { top: -5px; left: calc(50% - 5px); cursor: n-resize; }
.resize-handle.s { bottom: -5px; left: calc(50% - 5px); cursor: s-resize; }
.resize-handle.w { left: -5px; top: calc(50% - 5px); cursor: w-resize; }
.resize-handle.e { right: -5px; top: calc(50% - 5px); cursor: e-resize; }

/* ============================================
   辅助对齐线（编辑模式）
   ============================================ */
.align-line {
    position: fixed;
    pointer-events: none;
    z-index: 10000;
    background: rgba(255, 107, 107, 0.6);
}

.align-line.h {
    left: 0;
    right: 0;
    height: 1px;
}

.align-line.v {
    top: 0;
    bottom: 0;
    width: 1px;
}

/* ============================================
   坐标提示气泡（编辑模式）
   ============================================ */
.position-tooltip {
    display: none;
    position: fixed;
    pointer-events: none;
    z-index: 10001;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 4px;
    font-family: monospace;
    white-space: nowrap;
}

.position-tooltip.show {
    display: block;
}

/* ============================================
   宽高拖拽数值输入框（Scrubber）— 幻灯/头像模块选中时显示
   ============================================ */
.size-scrubber {
    display: none;
    position: absolute;
    z-index: 13;
    height: 22px;
    padding: 0 8px;
    border-radius: 11px;
    background: rgba(20, 20, 50, 0.95);
    border: 1px solid #4a90d9;
    color: #fff;
    font-size: 11px;
    font-family: monospace;
    cursor: ew-resize;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    user-select: none;
    backdrop-filter: blur(4px);
    box-shadow: 0 0 8px rgba(74, 144, 217, 0.3);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.size-scrubber:hover {
    background: rgba(74, 144, 217, 0.85);
    border-color: #4a90d9;
}

.size-scrubber:active,
.size-scrubber.scrubbing {
    background: rgba(74, 144, 217, 1);
    border-color: #fff;
    box-shadow: 0 0 12px rgba(74, 144, 217, 0.5);
}

/* 编辑模式 hover 或选中时显示 */
.layout-module.edit-mode:hover .size-scrubber,
.layout-module.edit-mode.selected .size-scrubber {
    display: flex;
}

/* 宽度输入框 — 底边居中，半嵌入模块内部 */
.size-scrubber-w {
    bottom: 2px;
    left: 50%;
    transform: translateX(-50%);
}

/* 高度输入框 — 右边居中，半嵌入模块内部 */
.size-scrubber-h {
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
}

.scrub-label {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
    font-size: 10px;
    min-width: 12px;
}

.scrub-value {
    font-weight: 700;
    color: #fff;
    min-width: 36px;
    text-align: center;
}

/* ============================================
   模块类型标签（编辑模式，仅选中显示）
   ============================================ */
.module-type-label {
    display: none;
    position: absolute;
    top: -24px;
    left: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: rgba(74, 144, 217, 0.9);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: monospace;
    white-space: nowrap;
    z-index: 12;
    letter-spacing: 0.5px;
}

.layout-module.edit-mode.selected .module-type-label {
    display: block;
}

/* ============================================
   编辑模式底部工具栏
   ============================================ */
.edit-toolbar {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10002;
    background: rgba(20, 20, 40, 0.95);
    border: 1px solid rgba(100, 149, 237, 0.3);
    border-radius: 12px;
    padding: 8px 16px;
    gap: 12px;
    align-items: center;
    backdrop-filter: blur(10px);
}

.xpd-canvas.edit-mode .edit-toolbar {
    display: flex;
}

.edit-toolbar button {
    padding: 8px 18px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s ease;
}

.edit-toolbar .btn-save {
    background: #5cb85c;
    color: #fff;
}
.edit-toolbar .btn-save:hover {
    background: #4cae4c;
}

.edit-toolbar .btn-reset {
    background: #f0ad4e;
    color: #fff;
}
.edit-toolbar .btn-reset:hover {
    background: #eea236;
}

.edit-toolbar .btn-exit {
    background: #666;
    color: #fff;
}
.edit-toolbar .btn-exit:hover {
    background: #555;
}

.edit-toolbar .toolbar-sep {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.15);
}

.edit-toolbar .toolbar-info {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    font-family: monospace;
}

/* ============================================
   加载遮罩
   ============================================ */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #fff;
    z-index: 9999;
}

#loading-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #ff6b6b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#loading-overlay p {
    margin-top: 20px;
    font-size: 16px;
    color: #999;
}

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

/* ============================================
   错误提示
   ============================================ */
#error-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #ff6b6b;
    z-index: 10000;
    text-align: center;
}

#error-overlay.show {
    display: flex;
}
