:root {
    --primary: #667eea;
    --primary-dark: #764ba2;
    --bg: #0a0e17;
    --surface: rgba(16, 21, 34, 0.95);
    --panel: #111827;
    --text: #fff;
    --text-secondary: #8a9bb8;
    --border: rgba(255, 255, 255, 0.1);
    --danger: #ff416c;
    --success: #2ed8a6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', 'PingFang SC', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ---------- 登录页 ---------- */
.login-page { display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }

.login-bg {
    position: fixed; inset: 0; z-index: 0;
    background:
        radial-gradient(circle at 0% 0%, rgba(102,126,234,.4), transparent 45%),
        radial-gradient(circle at 100% 100%, rgba(245,87,108,.4), transparent 45%);
}

.login-card {
    position: relative; z-index: 1;
    width: min(92vw, 420px);
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 40px;
    border: 1px solid var(--border);
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-brand { display: flex; align-items: center; gap: 16px; margin-bottom: 28px; }

.brand-icon {
    width: 52px; height: 52px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: 800; color: #fff;
}

.login-brand h1 { font-size: 18px; margin-bottom: 4px; }
.login-brand p { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

.alert {
    padding: 12px 16px; border-radius: 12px; margin-bottom: 20px;
    font-size: 14px; font-weight: 500;
}
.alert-error { background: linear-gradient(135deg, #ff416c, #ff4b2b); color: #fff; }

.field { margin-bottom: 18px; }
.field label { display: block; color: var(--text-secondary); font-size: 13px; font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px; }
.field input, .panel input[type=text] {
    width: 100%;
    padding: 15px 16px;
    background: rgba(255,255,255,.05);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 15px;
    outline: none;
    transition: all .2s;
}
.field input:focus, .panel input[type=text]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(102,126,234,.1); }

.login-footer { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); text-align: center; color: var(--text-secondary); font-size: 13px; }

/* ---------- 按钮 ---------- */
.btn {
    padding: 12px 20px;
    background: rgba(255,255,255,.08);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font-size: 14px; font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.14); }
.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border: none;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-block { width: 100%; padding: 17px; font-size: 15px; margin-top: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 布局 ---------- */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 20px 14px;
    z-index: 10;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 20px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.sidebar-brand .brand-icon { width: 40px; height: 40px; font-size: 18px; }
.sidebar-brand span { font-weight: 700; font-size: 15px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
    text-align: left; padding: 12px 14px;
    background: transparent; border: none; border-radius: 10px;
    color: var(--text-secondary); font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all .2s;
    text-decoration: none; display: block;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: var(--text); }
.nav-item.active { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.nav-item.logout { color: var(--danger); }

.main { margin-left: 220px; padding: 28px 32px; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.page-head h2 { font-size: 22px; }

/* ---------- 卡片/面板 ---------- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
    padding: 24px; 
}
.stat-card h3 { font-size: 30px; margin-bottom: 6px; background: linear-gradient(135deg, #fff, #a0aec0); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.stat-card p { color: var(--text-secondary); font-size: 13px; font-weight: 500; }

.panel {
    background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
    padding: 24px; margin-bottom: 24px;
}
.panel h3 { font-size: 16px; margin-bottom: 16px; }
.panel h3.mt { margin-top: 24px; }
.panel .muted { color: var(--text-secondary); font-size: 13px; margin-bottom: 14px; }

.row { display: flex; gap: 10px; }
.row input { flex: 1; }

.test-result { margin-top: 16px; padding: 14px 16px; border-radius: 12px; background: rgba(255,255,255,.04); font-size: 14px; min-height: 46px; line-height: 1.6; }
.test-result.hit { border: 1px solid var(--success); }
.test-result.miss { border: 1px solid var(--danger); }

/* ---------- 表格 ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
    text-align: left; padding: 12px 12px; color: var(--text-secondary);
    font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid rgba(255,255,255,.05); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,.02); }
.table .trigger { font-weight: 600; }
.table .reply-cell { max-width: 320px; white-space: pre-wrap; word-break: break-all; color: var(--text-secondary); }
.table .ops { display: flex; gap: 6px; }

.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600;
}
.badge.on { background: rgba(46,216,166,.15); color: var(--success); }
.badge.off { background: rgba(255,65,108,.15); color: var(--danger); }
.badge.type { background: rgba(102,126,234,.15); color: #93a5ff; }

.empty { text-align: center; color: var(--text-secondary); padding: 32px 0; font-size: 14px; }

code, .code {
    background: rgba(0,0,0,.4); border: 1px solid var(--border); border-radius: 10px;
    padding: 12px; font-size: 12px; line-height: 1.6; display: block;
    overflow-x: auto; color: #a5b4fc;
}

/* ---------- 弹窗 ---------- */
.modal-mask {
    position: fixed; inset: 0; background: rgba(0,0,0,.6);
    display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal {
    width: min(92vw, 560px);
    background: #141b2d; border: 1px solid var(--border); border-radius: 16px;
    padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h3 { margin-bottom: 20px; font-size: 18px; }
.modal .field input, .modal select, .modal textarea {
    width: 100%; padding: 12px 14px;
    background: rgba(255,255,255,.05); border: 1px solid var(--border); border-radius: 10px;
    color: var(--text); font-size: 14px; outline: none; font-family: inherit;
}
.modal select option { background: #141b2d; }
.modal .field { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #1a2332; border: 1px solid var(--border); border-radius: 10px;
    padding: 12px 20px; font-size: 14px; z-index: 200;
    opacity: 0; transition: opacity .3s; pointer-events: none;
}
.toast.show { opacity: 1; }

@media (max-width: 768px) {
    body { padding-bottom: 64px; }
    .sidebar {
        position: fixed; top: auto; bottom: 0; left: 0; right: 0;
        width: 100%; height: auto; flex-direction: row; align-items: center;
        padding: 8px 6px; border-top: 1px solid var(--border); border-right: none;
        z-index: 100;
    }
    .sidebar-brand { display: none; }
    .nav { flex-direction: row; justify-content: space-around; flex: 1; gap: 2px; }
    .nav-item { padding: 10px 6px; font-size: 12px; text-align: center; flex: 1; white-space: nowrap; }
    .nav-item.logout { flex: none; padding: 10px 12px; }
    .main { margin-left: 0; padding: 16px 10px; }
    .page-head { margin-bottom: 16px; }
    .page-head h2 { font-size: 18px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 16px; }
    .stat-card h3 { font-size: 22px; }
    .panel { padding: 16px; border-radius: 12px; }
    .row { flex-direction: column; gap: 8px; }
    .row .btn { width: 100%; }
    .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; font-size: 13px; }
    .table th, .table td { padding: 10px 8px; }
    .modal { width: 94vw; max-height: 88vh; overflow-y: auto; padding: 18px; }
    .modal-actions { flex-direction: column-reverse; }
    .modal-actions .btn { width: 100%; }
    #dict-modal-content { font-size: 12px !important; min-height: 240px; }
    .login-card { padding: 28px 20px; }
}

@media (max-width: 480px) {
    .nav-item { font-size: 11px; padding: 10px 2px; }
    .reply-cell { max-width: 100px; }
    .ops { flex-wrap: wrap; gap: 4px; }
    .ops .btn { padding: 6px 8px; font-size: 12px; }
}
