/* ===== Base ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: #f5f6fa; color: #333; }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; padding: 8px 12px; border: 1px solid #ddd; border-radius: 6px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #4a90d9; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #eee; }
th { background: #f8f9fa; font-weight: 600; color: #666; font-size: 13px; }
tr:hover { background: #f8f9fa; }

/* ===== Layout ===== */
.app { display: flex; height: 100vh; }
.sidebar { width: 220px; background: #1e293b; color: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .logo { padding: 20px; font-size: 18px; font-weight: 700; border-bottom: 1px solid #334155; }
.sidebar .nav { flex: 1; padding: 10px 0; }
.sidebar .nav a { display: block; padding: 12px 20px; color: #94a3b8; font-size: 14px; transition: all .2s; }
.sidebar .nav a:hover, .sidebar .nav a.active { color: #fff; background: #334155; }
.sidebar .user { padding: 15px 20px; border-top: 1px solid #334155; font-size: 13px; }
.sidebar .user button { margin-top: 8px; width: 100%; padding: 8px; background: #ef4444; color: #fff; border-radius: 6px; font-size: 13px; }
.main { flex: 1; overflow: auto; padding: 24px; }

/* ===== Login ===== */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-box { background: #fff; padding: 40px; border-radius: 12px; width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.login-box h2 { margin-bottom: 24px; text-align: center; }
.login-box .field { margin-bottom: 16px; }
.login-box .field label { display: block; margin-bottom: 6px; font-size: 13px; color: #666; }
.login-box .field input { width: 100%; }
.login-box .actions { margin-top: 20px; }
.login-box .actions button { width: 100%; padding: 12px; background: #4a90d9; color: #fff; border-radius: 6px; font-size: 15px; }
.login-box .actions button:hover { background: #357abd; }
.login-box .link { text-align: center; margin-top: 16px; font-size: 13px; color: #4a90d9; cursor: pointer; }
.login-box .error { color: #ef4444; font-size: 13px; margin-top: 10px; text-align: center; }

/* ===== Cards ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card { background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.card .label { font-size: 13px; color: #888; margin-bottom: 8px; }
.card .value { font-size: 28px; font-weight: 700; color: #1e293b; }
.card.online .value { color: #22c55e; }
.card.offline .value { color: #ef4444; }

/* ===== Page Header ===== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-header h1 { font-size: 20px; font-weight: 600; }
.page-header .actions { display: flex; gap: 10px; }
.btn { padding: 8px 16px; border-radius: 6px; font-size: 14px; background: #4a90d9; color: #fff; }
.btn:hover { background: #357abd; }
.btn.secondary { background: #e2e8f0; color: #334155; }
.btn.secondary:hover { background: #cbd5e1; }
.btn.danger { background: #ef4444; }
.btn.danger:hover { background: #dc2626; }
.btn.small { padding: 6px 12px; font-size: 12px; }
.msg-date-title { font-size: 15px; font-weight: 600; margin: 18px 0 8px; }

/* ===== Filters ===== */
.filters { display: flex; gap: 10px; margin-bottom: 16px; }
.filters select, .filters input { min-width: 140px; }

/* ===== Table Actions ===== */
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.table-actions button { padding: 4px 10px; font-size: 12px; border-radius: 4px; }

/* ===== Modal ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 10px; width: 480px; max-width: 90vw; max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal-header { padding: 16px 20px; border-bottom: 1px solid #eee; font-size: 16px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; }
.modal-body .field { margin-bottom: 14px; }
.modal-body .field label { display: block; margin-bottom: 6px; font-size: 13px; color: #555; }
.modal-body .field input, .modal-body .field select, .modal-body .field textarea { width: 100%; }
.modal-footer { padding: 14px 20px; border-top: 1px solid #eee; display: flex; justify-content: flex-end; gap: 10px; }
/* 素材选择弹框：80% 宽，顶部搜索栏 + 中部滚动区 + 底部固定按钮 */
.modal.material-selector-modal { width: 80vw; max-width: 80vw; height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal.material-selector-modal .modal-header { flex-shrink: 0; }
.modal.material-selector-modal .modal-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.modal.material-selector-modal .modal-footer { flex-shrink: 0; }
.material-selector-top { display: flex; gap: 10px; margin-bottom: 10px; flex-shrink: 0; }
.material-selector-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-right: 4px; }

/* ===== Editor ===== */
.editor-wrap { display: flex; height: calc(100vh - 120px); gap: 12px; }
.editor-sidebar { width: 200px; background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.editor-sidebar h3 { font-size: 14px; margin-bottom: 12px; color: #666; }
.component-item { padding: 10px; margin-bottom: 8px; background: #f8f9fa; border-radius: 6px; cursor: pointer; text-align: center; font-size: 13px; border: 1px solid transparent; }
.component-item:hover { border-color: #4a90d9; background: #eff6ff; }
.editor-canvas-wrap { flex: 1; background: #e2e8f0; border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: auto; position: relative; }
.editor-canvas { background: #fff; position: relative; box-shadow: 0 4px 20px rgba(0,0,0,.1); overflow: hidden; }
.editor-canvas .element { position: absolute; cursor: move; border: 1px dashed transparent; }
.editor-canvas .element:hover { border-color: #4a90d9; }
.editor-canvas .element.selected { border: 2px solid #4a90d9; }
.editor-canvas .element img { display: block; width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.editor-canvas .element video { display: block; width: 100%; height: 100%; object-fit: cover; }
.editor-canvas .element .text-content { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; word-break: break-all; }
.editor-props { width: 260px; background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,.04); }
.editor-props h3 { font-size: 14px; margin-bottom: 12px; color: #666; }
.editor-props .field { margin-bottom: 10px; }
.editor-props .field label { display: block; font-size: 12px; color: #666; margin-bottom: 4px; }
.editor-props .field input, .editor-props .field select, .editor-props .field textarea { width: 100%; padding: 6px 8px; font-size: 13px; }
.editor-props .field input[type="checkbox"] { width: auto; }
.editor-toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }

/* Resize handles */
.resize-handle { position: absolute; width: 8px; height: 8px; background: #4a90d9; border: 1px solid #fff; border-radius: 2px; z-index: 10; }
.resize-handle[data-dir="nw"] { top: -4px; left: -4px; cursor: nw-resize; }
.resize-handle[data-dir="n"]  { top: -4px; left: 50%; transform: translateX(-50%); cursor: n-resize; }
.resize-handle[data-dir="ne"] { top: -4px; right: -4px; cursor: ne-resize; }
.resize-handle[data-dir="w"]  { top: 50%; left: -4px; transform: translateY(-50%); cursor: w-resize; }
.resize-handle[data-dir="e"]  { top: 50%; right: -4px; transform: translateY(-50%); cursor: e-resize; }
.resize-handle[data-dir="sw"] { bottom: -4px; left: -4px; cursor: sw-resize; }
.resize-handle[data-dir="s"]  { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.resize-handle[data-dir="se"] { bottom: -4px; right: -4px; cursor: se-resize; }

/* ===== Material Grid ===== */
.material-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.material-item { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,.04); position: relative; }
.material-item .thumb { height: 120px; background: #f0f0f0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.material-item .thumb img, .material-item .thumb video { width: 100%; height: 100%; object-fit: cover; }
.material-item .info { padding: 10px; }
.material-item .info .name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.material-item .info .type { font-size: 11px; color: #888; margin-top: 4px; }
.material-item .actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .2s; }
.material-item:hover .actions { opacity: 1; }
.material-item .actions button { width: 28px; height: 28px; background: rgba(0,0,0,.6); color: #fff; border-radius: 4px; font-size: 12px; }

/* ===== Content Poster Grid（Canva 风格海报墙） ===== */
.content-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 20px; }
.content-card { position: relative; aspect-ratio: 5 / 8; border-radius: 12px; overflow: hidden; background: #f0f0f0; box-shadow: 0 1px 4px rgba(0,0,0,.08); cursor: pointer; transition: box-shadow .2s, transform .2s; }
.content-card:hover { box-shadow: 0 10px 28px rgba(0,0,0,.18); transform: translateY(-2px); }
.content-card > img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .3s ease; }
.content-card:hover > img { transform: scale(1.04); }
.content-card .no-thumb { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; color: #999; font-size: 13px; }
.content-card .badge { position: absolute; top: 8px; left: 8px; padding: 3px 9px; border-radius: 4px; font-size: 11px; font-weight: 600; color: #fff; background: rgba(0,0,0,.55); z-index: 2; pointer-events: none; }
.content-card .badge.builtin { background: #e64545; }
.content-card .card-mask { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: flex-end; background: linear-gradient(to top, rgba(0,0,0,.75), rgba(0,0,0,0) 45%); opacity: 0; transition: opacity .2s; z-index: 1; }
.content-card:hover .card-mask { opacity: 1; }
.content-card .card-mask .cname { color: #fff; font-size: 14px; font-weight: 500; padding: 0 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content-card .card-mask .cactions { display: flex; gap: 8px; padding: 8px 12px 12px; }
.content-card .card-mask .cactions button { flex: 1; padding: 7px 0; border-radius: 6px; background: rgba(255,255,255,.92); color: #222; font-size: 13px; white-space: nowrap; }
.content-card .card-mask .cactions button:hover { background: #fff; }

/* ===== Toast ===== */
.toast { position: fixed; top: 20px; right: 20px; padding: 12px 20px; background: #1e293b; color: #fff; border-radius: 8px; z-index: 200; animation: slideIn .3s ease; }
.toast.error { background: #ef4444; }
.toast.success { background: #22c55e; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ===== Content Preview ===== */
.preview-overlay { position: fixed; inset: 0; background: rgba(12,12,18,.92); z-index: 300; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.preview-title { color: rgba(255,255,255,.85); font-size: 15px; font-weight: 500; max-width: 80vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-wrap { background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 24px 80px rgba(0,0,0,.55); flex-shrink: 0; }
.preview-iframe { border: none; display: block; transform-origin: top left; }
.preview-close { position: fixed; top: 12px; right: 20px; padding: 10px 24px; background: #fff; color: #333; border-radius: 8px; font-size: 14px; z-index: 301; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.preview-close:hover { background: #f0f0f0; }

/* ===== Hide ===== */
.hidden { display: none !important; }
