/* --- 视觉重构版 CSS --- */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --warning-light: #fff7ed;
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.85);
    --text-main: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-md: 8px;
    --radius-lg: 16px;
    --radius-full: 9999px;
}

/* 全局盒模型设置 */
* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0; padding: 0;
    background: linear-gradient(135deg, #f0f4ff 0%, #e2e8f0 100%);
    color: var(--text-main);
    height: 100vh;
    display: flex; flex-direction: column; overflow: hidden;
}

/* SVG 图标样式 */
.icon { width: 18px; height: 18px; vertical-align: text-bottom; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; margin-right: 6px; }

/* 顶部工具栏 */
header {
    background: var(--surface-glass); backdrop-filter: blur(12px);
    padding: 12px 24px; box-shadow: var(--shadow-sm);
    display: flex; justify-content: space-between; align-items: center;
    z-index: 100; border-bottom: 1px solid rgba(255,255,255,0.5);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

#btn-back {
    background: var(--primary);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

#btn-back:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

h1 { margin: 0; font-size: 1.25rem; font-weight: 700; color: var(--text-main); display: flex; align-items: center; }
h1 .icon { width: 28px; height: 28px; margin-right: 10px; color: var(--primary); }

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

/* Zoom Slider */
.zoom-control {
    display: flex; align-items: center; gap: 8px;
    background: rgba(0,0,0,0.05); padding: 4px 12px; border-radius: 20px; margin-right: 10px;
    transition: all 0.2s ease;
}
.zoom-control span { font-size: 12px; font-weight: 600; color: var(--text-sub); width: 32px; text-align: right; }

/* 按钮样式 */
button {
    border: 1px solid transparent; background: transparent;
    padding: 8px 14px; border-radius: var(--radius-md);
    cursor: pointer; font-size: 14px; font-weight: 500;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s ease; white-space: nowrap; color: var(--text-sub);
}
button:hover { background-color: rgba(0,0,0,0.03); color: var(--text-main); transform: translateY(-1px); }

/* 禁用状态按钮 */
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

button.active { background-color: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
#btn-swap.active { background-color: var(--warning-light); color: #b45309; }

.btn-primary { background-color: var(--primary); color: white; box-shadow: 0 2px 4px rgba(99, 102, 241, 0.3); }
.btn-primary:hover { background-color: var(--primary-dark); color: white; }
.btn-danger { color: var(--danger); background: #fee2e2; }
.btn-danger:hover { background-color: #fecaca; color: #b91c1c; }
.btn-success { background-color: var(--success); color: white; }
.btn-success:hover { background-color: #059669; }
.btn-warning { background-color: #fff7ed; color: #d97706; border: 1px solid #fed7aa; }
.btn-warning:hover { background-color: #ffedd5; }
.btn-action { background-color: #f3f4f6; border: 1px solid #e5e7eb; color: #374151; }
.btn-action:hover { background-color: #e5e7eb; border-color: #d1d5db; }

.btn-primary.printing { background-color: #94a3b8; cursor: wait; }

.divider { width: 1px; height: 24px; background: var(--border); margin: 0 8px; }

#main-area {
    flex: 1; position: relative; padding: 0; 
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    overflow: hidden; 
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px); background-size: 20px 20px;
}

#hint {
    position: absolute; top: 20px; z-index: 50;
    background: var(--surface); padding: 8px 20px; border-radius: var(--radius-full);
    font-size: 13px; font-weight: 500; color: var(--text-sub);
    box-shadow: var(--shadow-sm); border: 1px solid var(--border);
}

#viewport {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    overflow: auto; 
}

/* 教室容器 */
#classroom {
    background-color: #f8fafc;
    border: 8px solid #cbd5e1;
    border-left: 12px solid #64748b; 
    border-right: 12px solid #64748b; 
    border-radius: 4px;
    position: relative;
    box-shadow: var(--shadow-lg);
    overflow: visible; 
    background-image: linear-gradient(#e2e8f0 1px, transparent 1px), linear-gradient(90deg, #e2e8f0 1px, transparent 1px);
    background-size: 20px 20px; 
    flex-shrink: 0; 
    margin: 100px;
    transition: width 0.3s, height 0.3s, transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: center center;
}

#classroom.mode-teacher { transform: rotate(180deg); box-shadow: 0 -10px 25px -5px rgba(0, 0, 0, 0.1); }
#classroom.mode-teacher .seat-name, #classroom.mode-teacher .name-input, #classroom.mode-teacher .delete-btn { transform: rotate(180deg); }
/* 过道文字也需要旋转回来 */
#classroom.mode-teacher .seat.type-aisle { transform: rotate(180deg); }
#classroom.mode-teacher .seat.type-aisle .seat-name { transform: rotate(0deg); }

#classroom.mode-teacher .podium { transform: translateX(-50%) rotate(180deg); border-radius: 12px 12px 4px 4px; }

.podium {
    position: absolute; top: 0; left: 50%; transform: translateX(-50%); 
    width: 300px; height: 60px;
    background: linear-gradient(180deg, #475569 0%, #334155 100%);
    color: #cbd5e1;
    display: flex; align-items: center; justify-content: center;
    border-radius: 0 0 16px 16px;
    font-weight: 700; font-size: 18px; letter-spacing: 2px;
    z-index: 0; box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-bottom: 2px solid #1e293b;
}

/* --------------------------
   座位样式 (支持单人、双人、过道)
   -------------------------- */
.seat {
    position: absolute; background: white;
    border: 1px solid #cbd5e1; 
    border-left: 6px solid #94a3b8; 
    border-radius: 12px;
    display: flex; 
    user-select: none; box-shadow: var(--shadow-sm);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    /* 改为 visible，让删除按钮显示 */
    overflow: visible; 
}

.seat:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: #94a3b8; z-index: 100; } 

/* 过道样式 */
.seat.type-aisle {
    background: rgba(203, 213, 225, 0.3); 
    border: 1px solid #e2e8f0; 
    border-radius: 8px;
    box-shadow: none;
    color: #94a3b8;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 0;
    pointer-events: none; 
    writing-mode: vertical-lr; 
    letter-spacing: 4px;
}
.seat.type-aisle:hover { transform: none; }
.mode-layout .seat.type-aisle { pointer-events: auto; cursor: move; border: 1px dashed #94a3b8; } 

/* 内部名字插槽 */
.seat-inner {
    flex: 1; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    height: 100%; 
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 0;
}

/* 圆角处理 */
.seat.type-single .seat-inner { border-radius: 0 10px 10px 0; }
.seat.type-double .seat-inner:first-child { border-right: none; border-radius: 0; } 
.seat.type-double .seat-inner:last-child { border-radius: 0 10px 10px 0; }

.seat-inner.has-name { background: linear-gradient(to bottom right, #fff, #f0f9ff); }
.seat-inner.has-name .seat-name { color: var(--text-main); }

.mode-layout .seat { cursor: grab; }
.mode-layout .seat:active { cursor: grabbing; }
.mode-layout .seat-inner { pointer-events: none; } 

.seat-inner.is-swapping { background-color: #fffbeb; box-shadow: inset 0 0 0 3px var(--warning); }

.seat-name { 
    font-weight: 700; font-size: 24px; color: #94a3b8; 
    max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    transition: transform 0.5s ease-in-out; 
}

.seat-inner.has-name .seat-name { color: var(--text-main); }
.seat.active-group { border-left-color: var(--primary); }

.delete-btn {
    position: absolute; 
    top: -10px; 
    right: -10px;
    width: 24px; 
    height: 24px; 
    background: var(--danger); 
    color: white; 
    border-radius: 50%;
    text-align: center; 
    line-height: 22px; 
    font-size: 16px;
    cursor: pointer; 
    display: none; 
    z-index: 200; 
    pointer-events: auto;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    border: 2px solid white; 
}
.delete-btn:hover { transform: scale(1.1); background-color: #dc2626; }
.mode-layout .seat:hover .delete-btn { display: block; }

.name-input {
    width: 90%; height: 80%;
    border: 2px solid var(--primary-light); text-align: center;
    font-weight: bold; font-size: 20px; color: var(--text-main);
    background: #f8fafc; border-radius: 6px;
}
.name-input:focus { outline: none; border-color: var(--primary); background: white; }

footer {
    background: var(--surface-glass); backdrop-filter: blur(5px);
    padding: 10px 20px; text-align: center; font-size: 13px; color: var(--text-sub);
    border-top: 1px solid var(--border); position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    border-radius: var(--radius-full); box-shadow: var(--shadow-md); z-index: 100;
}

.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(4px);
    display: none; justify-content: center; align-items: center; z-index: 200;
}
.modal-content {
    background: white; padding: 24px; border-radius: 16px;
    width: 400px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
}
.modal-content h3 { margin-top: 0; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center; font-size: 18px; color: var(--text-main); }
.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
.form-group input { width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 6px; box-sizing: border-box; }
.btn-preset { padding: 6px 12px; font-size: 12px; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 20px; cursor: pointer;}
.btn-preset:hover { background: white; color: var(--primary); border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; }

/* 矩阵生成器样式 */
#grid-preview-area {
    background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: 8px;
    padding: 15px; margin-bottom: 15px; min-height: 60px;
    display: flex; gap: 0; align-items: center; overflow-x: auto;
}
.grid-block {
    display: flex; align-items: center; justify-content: center;
    background: white; border: 1px solid #94a3b8; border-radius: 0;
    color: #475569; font-size: 12px; font-weight: bold;
    padding: 0 10px; height: 40px; cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); user-select: none;
    transition: all 0.2s; flex-shrink: 0;
}
.grid-block:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.grid-block:last-child { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }
.grid-block:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; z-index: 10; }
.grid-block.block-single { width: 40px; border-left: 3px solid #94a3b8; }
.grid-block.block-double { width: 80px; border-left: 3px solid #4f46e5; }
.grid-block.block-aisle { width: 40px; background: #f1f5f9; border: 2px dashed #cbd5e1; color: #94a3b8; writing-mode: vertical-lr; }

.block-adder-group { display: flex; gap: 8px; margin-bottom: 20px; }
.block-adder-group button { flex: 1; background: #f1f5f9; border: 1px solid #e2e8f0; color: var(--text-main); }
.block-adder-group button:hover { background: white; border-color: var(--primary); color: var(--primary); }

@media print {
    body { display: none; }
}
