:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --primary: #229ed9;
    --primary-dark: #1783b6;
    --primary-soft: #e6f5fc;
    --danger: #e5484d;
    --danger-soft: #fdecec;
    --success: #12a06b;
    --success-soft: #e7f8f1;
    --border: #e3e9f2;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    gap: 28px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: var(--ink);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #2eb4f0, #1783b6);
    display: grid;
    place-items: center;
    color: #fff;
    box-shadow: 0 6px 14px rgba(34, 158, 217, .3);
}
.brand-logo svg { width: 18px; height: 18px; }

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.nav a {
    color: var(--muted);
    padding: 8px 14px;
    border-radius: 9px;
    font-weight: 500;
}
.nav a:hover { background: #f1f5f9; color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }

.user {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.container {
    max-width: 1120px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
.page-head h1 {
    margin: 0;
    font-size: 22px;
    letter-spacing: -.3px;
}
.page-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); align-items: start; }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.card + .card { margin-top: 18px; }

/* 栅格内的卡片并排，不需要额外的上间距 */
.grid > .card + .card { margin-top: 0; }

.card h2 {
    margin: 0 0 4px;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card .sub {
    color: var(--muted);
    font-size: 13px;
    margin: 0 0 18px;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.section-title h2 { margin: 0; }

.form-row { margin-bottom: 16px; }
.form-row:last-child { margin-bottom: 0; }

label.label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}
.label .req { color: var(--danger); }

.form-control,
.form-select,
textarea.form-control {
    width: 100%;
    border: 1px solid var(--border);
    background: #fbfdff;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ink);
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.form-control:focus,
.form-select:focus,
textarea.form-control:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(34, 158, 217, .14);
}
textarea.form-control { resize: vertical; min-height: 120px; line-height: 1.7; }

.hint {
    color: var(--muted);
    font-size: 12px;
    margin-top: 6px;
}
.hint code {
    background: #eef2f7;
    border-radius: 5px;
    padding: 1px 5px;
    font-size: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--ink);
    border-radius: 9px;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, transform .05s;
    font-family: inherit;
    white-space: nowrap;
}
.btn:hover { background: #f6f9fc; text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(34, 158, 217, .25);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--ink); }

.btn-danger { color: var(--danger); border-color: #f5d3d4; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }

.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

.btn-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 18px;
}
.inline { display: inline; }

.alert {
    border-radius: 10px;
    padding: 11px 14px;
    margin-bottom: 18px;
    font-size: 13px;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); color: #0b7a50; border-color: #c5eddd; }
.alert-error { background: var(--danger-soft); color: #b42318; border-color: #f5cdcd; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: #eef2f7;
    color: var(--muted);
}
.badge-blue { background: var(--primary-soft); color: var(--primary-dark); }
.badge-green { background: var(--success-soft); color: var(--success); }
.badge-gray { background: #eef2f7; color: var(--muted); }
.badge-orange { background: #fff4e5; color: #b45309; }

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
}
table.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
    background: #fff;
}
.table th,
.table td {
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table td {
    white-space: nowrap;
}
.table th {
    background: #f8fafc;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafcff; }
.table .actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
}
.cell-ellipsis {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--muted);
}
.cell-title { font-weight: 600; }

.empty {
    padding: 48px 20px;
    text-align: center;
    color: var(--muted);
}
.empty .empty-icon { font-size: 26px; margin-bottom: 6px; }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted);
    margin-right: 6px;
}
.status-dot.on { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }

.copy-row { display: flex; gap: 8px; }
.copy-row .form-control { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

.steps { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.steps li { margin-bottom: 8px; }
.steps b { color: var(--ink); }

.footer {
    text-align: center;
    color: #9aa8b9;
    font-size: 12px;
    padding: 24px 20px 36px;
}

/* 登录页 */
body.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background:
        radial-gradient(900px 500px at 15% 10%, rgba(46, 180, 240, .35), transparent 60%),
        radial-gradient(700px 500px at 90% 90%, rgba(23, 131, 182, .3), transparent 60%),
        #0b2a40;
    padding: 24px;
}
.login-card {
    width: min(400px, 100%);
    background: #fff;
    border-radius: 18px;
    padding: 34px 32px 30px;
    box-shadow: 0 30px 60px rgba(3, 18, 31, .35);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-brand .brand-logo {
    width: 52px;
    height: 52px;
    border-radius: 15px;
    margin: 0 auto 14px;
    display: grid;
}
.login-brand .brand-logo svg { width: 26px; height: 26px; }
.login-brand h1 { margin: 0; font-size: 19px; }
.login-brand p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.login-tip {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    text-align: center;
    color: var(--muted);
    font-size: 12px;
}

/* 聊天管理 */
.chat-shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    height: calc(100vh - 220px);
    min-height: 480px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.chat-side {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #fbfdff;
    border-right: 1px solid var(--border);
}
.chat-side-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    font-weight: 600;
}
.chat-side-list { flex: 1; overflow-y: auto; }
.chat-side-empty { padding: 40px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--ink);
}
.chat-item:hover { background: #f1f8fd; text-decoration: none; }
.chat-item.active { background: var(--primary-soft); }
.chat-avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2eb4f0, #1783b6);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 15px;
    font-weight: 600;
}
.chat-avatar-lg { flex: 0 0 42px; width: 42px; height: 42px; font-size: 16px; }
.chat-item-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}
.chat-item-name {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-item-sub {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chat-unread {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: grid;
    place-items: center;
}
.chat-unread:empty { display: none; }

.chat-main {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #f7fafd;
}
.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 18px;
    background: #fff;
    border-bottom: 1px solid var(--border);
}
.chat-head-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-head-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
}
.chat-head-sub { margin-top: 2px; color: var(--muted); font-size: 12px; word-break: break-all; }
.chat-head-actions { display: flex; gap: 8px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-empty { margin: auto; text-align: center; color: var(--muted); font-size: 13px; }
.msg { display: flex; flex-direction: column; max-width: 72%; }
.msg-in { align-self: flex-start; align-items: flex-start; }
.msg-out { align-self: flex-end; align-items: flex-end; }
.msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
.msg-in .msg-bubble {
    background: #fff;
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.msg-out .msg-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-meta { margin-top: 4px; color: var(--muted); font-size: 11px; }

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid var(--border);
}
.chat-composer textarea {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fbfdff;
    font-family: inherit;
    font-size: 14px;
    color: var(--ink);
    resize: none;
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.chat-composer textarea:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(34, 158, 217, .14);
}
.chat-placeholder { margin: auto; padding: 40px; text-align: center; color: var(--muted); }
.chat-placeholder-title { margin-bottom: 6px; font-size: 16px; font-weight: 600; color: var(--ink); }

.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.form-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 26px 0 18px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .04em;
}
.form-divider::before,
.form-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.status-block + .status-block {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
}
.status-block-title { margin-bottom: 10px; font-size: 13px; font-weight: 600; color: var(--muted); }

@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-3 { grid-template-columns: 1fr; }
    .chat-shell { grid-template-columns: 240px minmax(0, 1fr); }
}

@media (max-width: 720px) {
    .topbar-inner { height: auto; padding: 12px 16px; flex-wrap: wrap; gap: 12px; }
    .nav { order: 3; flex: 0 0 100%; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
    .nav a { white-space: nowrap; }
    .container { padding: 20px 16px 40px; }
    .page-head { flex-direction: column; align-items: flex-start; }
    .kv { grid-template-columns: 1fr; gap: 2px; }
    .kv dd { margin-bottom: 8px; }
    .chat-shell {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }
    .chat-side {
        max-height: 220px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .chat-main { height: 60vh; min-height: 380px; }
    .msg { max-width: 86%; }
}
