* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: #f0f2f5; color: #333; }
::selection { background: rgba(102,126,234,0.2); }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.login-container { background: #fff; padding: 40px; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,0.15); width: 400px; max-width: 90vw; }
.login-container h1 { text-align: center; font-size: 24px; color: #667eea; margin-bottom: 4px; }
.login-container h2 { text-align: center; font-size: 16px; color: #666; margin-bottom: 24px; font-weight: 400; }

/* Layout */
.layout { height: 100vh; overflow: hidden; }
.sidebar { position: fixed; inset: 0 auto 0 0; z-index: 100; width: 220px; height: 100vh; overflow-y: auto; background: #1a1a2e; color: #fff; display: flex; flex-direction: column; }
.sidebar-header { padding: 24px 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header h2 { font-size: 17px; line-height: 1.35; }
.sidebar-user { font-size: 12px; opacity: 0.7; margin-top: 4px; }
.nav-list { list-style: none; padding: 8px 0; flex: 1; display: flex; flex-direction: column; }
.nav-list li:last-child { margin-top: auto; }
.nav-list li a { display: block; padding: 12px 20px; color: rgba(255,255,255,0.8); text-decoration: none; font-size: 14px; transition: all 0.2s; }
.nav-list li a:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-list li a.active { background: rgba(102,126,234,0.3); color: #fff; border-right: 3px solid #667eea; }
.nav-list li a.logout-link { margin-top: auto; color: #ff6b6b; }
.main-content { min-width: 0; height: 100vh; margin-left: 220px; padding: 24px 32px; overflow: auto; }

/* Cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 16px; margin-bottom: 32px; }
.stat-card { background: #fff; border-radius: 10px; padding: 24px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); transition: transform 0.2s, box-shadow 0.2s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,0.12); }
.stat-card-wide { grid-column: span 2; }
.stat-number { font-size: 28px; font-weight: 700; color: #667eea; }
.stat-label { font-size: 13px; color: #999; margin-top: 4px; }

/* Table */
.table-wrapper { width: 100%; overflow-x: auto; }
.data-table { width: 100%; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.06); border-collapse: collapse; }
.data-table th { background: #f8f9fa; text-align: left; padding: 12px 16px; font-size: 13px; color: #666; font-weight: 600; }
.data-table td { padding: 10px 16px; font-size: 13px; border-top: 1px solid #f0f0f0; }
.data-table tbody tr:nth-child(even) td { background: #fafafa; }
.data-table tr:hover td { background: #f0f4ff; }
.data-table .empty { text-align: center; color: #999; padding: 40px !important; }
.wrap-cell { max-width: 300px; word-break: break-all; }
.table-actions { display: flex; gap: 6px; white-space: nowrap; }
.plan-name { color: #334bd3; border-bottom: 1px dotted #667eea; cursor: help; }
.hint-text { font-size: 13px; color: #777; }
.data-table tbody tr.row-expired td,
.data-table tbody tr.row-expired:nth-child(even) td {
    background: #f3f4f6;
    color: #8c8c8c;
}
.data-table tbody tr.row-expired:hover td { background: #eceff3; }
.inline-action-form { display: inline-flex; margin: 0; }

/* Form */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: #666; margin-bottom: 6px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 12px; border: 1px solid #d9d9d9; border-radius: 6px; font-size: 14px; transition: border 0.2s; }
.form-group input:focus, .form-group select:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.1); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.input-with-btn { display: flex; gap: 8px; align-items: flex-start; }
.input-with-btn input { flex: 1; }
.input-with-btn .btn { white-space: nowrap; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 20px; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; text-decoration: none; transition: all 0.2s; }
.btn-primary { background: #667eea; color: #fff; }
.btn-primary:hover { background: #5a6fd6; }
.btn-success { background: #52c41a; color: #fff; }
.btn-success:hover { background: #46b519; }
.btn-warning { background: #faad14; color: #fff; }
.btn-warning:hover { background: #e59f13; }
.btn-danger { background: #ff4757; color: #fff; }
.btn-danger:hover { background: #ee3b4b; }
.btn-secondary { background: #e8e8e8; color: #333; }
.btn-secondary:hover { background: #d9d9d9; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Messages */
.msg { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.msg-error { background: #fff2f0; border: 1px solid #ffccc7; color: #cf1322; }
.msg-success { background: #f6ffed; border: 1px solid #b7eb8f; color: #389e0d; }
.msg-info { background: #e6f7ff; border: 1px solid #91d5ff; color: #0958d9; }

/* Page Header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-header-actions { display: flex; align-items: center; gap: 12px; }
.page-header h1 { font-size: 20px; }
.section-title { font-size: 16px; font-weight: 600; margin: 12px 0 16px; padding-bottom: 6px; border-bottom: 2px solid #667eea; display: inline-block; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 8px; margin-top: 16px; justify-content: center; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid #d9d9d9; border-radius: 4px; font-size: 13px; text-decoration: none; color: #333; }
.pagination a:hover { border-color: #667eea; color: #667eea; }
.pagination .current { background: #667eea; color: #fff; border-color: #667eea; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); align-items: center; justify-content: center; z-index: 1000; }
.modal-overlay.active { display: flex; }
.modal-box { background: #fff; border-radius: 12px; padding: 32px; width: 500px; max-width: 90vw; max-height: 80vh; overflow-y: auto; }
.modal-box h2 { margin-bottom: 20px; font-size: 18px; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-vip0 { background: #f2f2f2; color: #999; }
.badge-vip1 { background: #f0f0f0; color: #666; border: 1px solid #d9d9d9; }
.badge-vip2 { background: #fff7e6; color: #d48806; border: 1px solid #ffd591; }
.badge-vip3 { background: linear-gradient(135deg, #fff7e6, #ffe58f); color: #d46b08; }
.badge-vip4 { background: linear-gradient(135deg, #fff0e6, #ffd591); color: #d4380d; }
.badge-paid { background: #f6ffed; color: #389e0d; }
.badge-pending { background: #fffbe6; color: #d4b106; }
.badge-failed { background: #fff2f0; color: #cf1322; }
.badge-canceled { background: #f5f5f5; color: #8c8c8c; }
.badge-reversed { background: #fff1f0; color: #cf1322; }
.points-positive { color: #389e0d; font-weight: 700; }
.points-negative { color: #cf1322; font-weight: 700; }
.volunteer-band { display: inline-flex; align-items: center; margin-right: 4px; padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.band-rush { background: #fff1f0; color: #cf1322; }
.band-stable { background: #fffbe6; color: #ad6800; }
.band-safe { background: #f6ffed; color: #237804; }
.volunteer-modal-box { width: min(1180px, 94vw); max-height: 88vh; padding: 0; overflow: hidden; }
.volunteer-modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 22px 26px; border-bottom: 1px solid #f0f0f0; }
.volunteer-modal-header h2 { margin: 0 0 5px; }
.volunteer-modal-header p { color: #777; font-size: 13px; }
.volunteer-analysis { margin: 18px 26px 0; padding: 12px 14px; border-left: 3px solid #667eea; border-radius: 4px; background: #f5f7ff; color: #555; font-size: 13px; line-height: 1.7; }
.volunteer-detail-table { max-height: calc(88vh - 150px); padding: 18px 26px 26px; overflow: auto; }
.volunteer-detail-table .data-table { box-shadow: none; border: 1px solid #f0f0f0; }
.volunteer-detail-table .data-table th { position: sticky; top: 0; z-index: 1; }
.volunteer-reason { min-width: 260px; line-height: 1.55; }

/* Avatar */
.avatar-thumb { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; vertical-align: middle; margin-right: 6px; border: 1px solid #eee; }

/* Toast */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 20px; border-radius: 8px; color: #fff; font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s ease; }
.toast-success { background: #52c41a; }
.toast-error { background: #ff4d4f; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Spinner */
.spinner { width: 24px; height: 24px; border: 3px solid #e8e8e8; border-top-color: #667eea; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty-state { text-align: center; padding: 60px 20px; color: #999; }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.3; }
.highlight { background: #fff3cd; padding: 0 2px; border-radius: 2px; }

/* Filter Bar */
.filter-bar { display: flex; gap: 12px; margin-bottom: 16px; align-items: flex-end; flex-wrap: wrap; }
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }
.search-input { min-width: 200px !important; }

/* Customer Service */
.customer-service-main { display: flex; flex-direction: column; overflow: hidden; }
.customer-service-main > .page-header,
.customer-service-main > .msg { flex-shrink: 0; }
.customer-layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; flex: 1; min-height: 0; }
.customer-list, .chat-panel { background: #fff; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); overflow: hidden; }
.customer-list { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.conversation-item { display: block; padding: 14px 16px; color: #333; text-decoration: none; border-bottom: 1px solid #f0f0f0; transition: background 0.2s; }
.conversation-item:hover { background: #f7f8ff; }
.conversation-item.active { background: #eef2ff; border-left: 3px solid #667eea; padding-left: 13px; }
.conversation-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.conversation-title em { min-width: 18px; height: 18px; padding: 0 6px; border-radius: 9px; background: #ff4d4f; color: #fff; font-size: 11px; font-style: normal; line-height: 18px; text-align: center; }
.conversation-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; font-size: 12px; color: #888; }
.conversation-preview { margin-top: 8px; color: #666; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-openid { margin-top: 6px; color: #aaa; font-size: 11px; word-break: break-all; }
.chat-panel { display: flex; flex-direction: column; min-height: 0; }
.chat-header { display: flex; flex-shrink: 0; justify-content: space-between; align-items: flex-start; gap: 18px; padding: 16px 20px; border-bottom: 1px solid #f0f0f0; }
.chat-header h2 { font-size: 16px; margin-bottom: 4px; }
.chat-header p { color: #777; font-size: 12px; word-break: break-all; }
.customer-profile { flex: 1; min-width: 0; }
.customer-profile-heading { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.customer-profile-heading h2 { margin: 0; }
.customer-profile-grid { display: grid; grid-template-columns: repeat(3, minmax(130px, 1fr)); gap: 8px 16px; }
.customer-profile-grid div { min-width: 0; }
.customer-profile-grid span { display: block; margin-bottom: 2px; color: #999; font-size: 11px; }
.customer-profile-grid strong { display: block; color: #333; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.customer-openid { margin-top: 10px; }
.message-stream { flex: 1; min-height: 0; padding: 20px; overflow-y: auto; background: #f8f9fb; }
.message-row { display: flex; flex-direction: column; margin-bottom: 14px; }
.message-row.outgoing { align-items: flex-end; }
.message-row.incoming { align-items: flex-start; }
.message-bubble { max-width: min(680px, 78%); padding: 10px 12px; border-radius: 8px; font-size: 14px; line-height: 1.55; word-break: break-word; box-shadow: 0 1px 2px rgba(0,0,0,0.04); }
.message-row.incoming .message-bubble { background: #fff; color: #333; border: 1px solid #edf0f5; }
.message-row.outgoing .message-bubble { background: #667eea; color: #fff; }
.message-row.outgoing .message-bubble a { color: #fff; }
.message-time { margin-top: 4px; color: #aaa; font-size: 11px; }
.customer-image-link { display: block; line-height: 0; }
.customer-image-link img { display: block; width: auto; max-width: min(320px, 100%); max-height: 360px; border-radius: 6px; object-fit: contain; }
.customer-mini-card { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 4px 10px; min-width: 260px; max-width: 420px; }
.customer-mini-card img { grid-row: span 2; width: 64px; height: 64px; border-radius: 6px; object-fit: cover; background: #f3f4f6; }
.customer-mini-card strong { align-self: end; font-size: 14px; overflow-wrap: anywhere; }
.customer-mini-card span { align-self: start; color: #888; font-size: 11px; overflow-wrap: anywhere; }
.reply-form { flex-shrink: 0; padding: 12px 20px; border-top: 1px solid #f0f0f0; background: #fff; }
.reply-form .form-group { margin-bottom: 10px; }
.reply-form .form-actions { margin-top: 0; }
.reply-form textarea { min-height: 68px; max-height: 140px; resize: none; }
.customer-empty { padding: 32px 16px; color: #999; text-align: center; font-size: 13px; }
.customer-empty.large { display: flex; align-items: center; justify-content: center; min-height: 420px; }

/* Business Acceptance */
.business-main { padding: 0; overflow: hidden; background: #eef1f6; }
.business-layout { height: 100vh; display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: 0; }
.business-user-panel { display: flex; flex-direction: column; min-height: 0; padding: 22px 18px; background: #fff; border-right: 1px solid #dde2eb; overflow-y: auto; }
.business-user-panel h1 { font-size: 20px; margin-bottom: 18px; }
.business-login-form { margin-bottom: 14px; }
.business-user-card { padding: 16px; border-radius: 8px; background: #f5f7ff; border: 1px solid #e0e6ff; margin-bottom: 16px; }
.business-user-card strong { display: block; margin-top: 6px; font-size: 17px; color: #26335f; overflow-wrap: anywhere; }
.business-user-card p { margin-top: 4px; color: #687084; font-size: 13px; }
.business-user-id { color: #667eea; font-size: 12px; font-weight: 700; }
.business-user-meta { display: grid; grid-template-columns: 80px minmax(0, 1fr); gap: 10px 8px; margin-bottom: 18px; font-size: 13px; }
.business-user-meta dt { color: #8b95a7; }
.business-user-meta dd { min-width: 0; color: #30384a; overflow-wrap: anywhere; }
.business-workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 18px 22px; overflow: hidden; }
.business-toolbar { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.business-operation-search { display: flex; align-items: center; gap: 8px; min-width: min(480px, 100%); }
.business-operation-search input { flex: 1; min-width: 220px; padding: 9px 12px; border: 1px solid #ccd3df; border-radius: 6px; font-size: 14px; }
.business-current-user { color: #667085; font-size: 13px; }
.business-tabs { flex-shrink: 0; display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.business-tabs a { padding: 9px 13px; border-radius: 7px 7px 0 0; background: #e1e5ef; color: #505d75; text-decoration: none; font-size: 13px; white-space: nowrap; }
.business-tabs a.active { background: #fff; color: #334bd3; font-weight: 700; }
.business-page { flex: 1; min-height: 0; overflow-y: auto; background: #fff; border-radius: 0 8px 8px 8px; padding: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.06); }
.business-page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.business-page-header h2 { font-size: 18px; margin-bottom: 4px; }
.business-page-header p { color: #778196; font-size: 13px; }
.business-empty { display: flex; min-height: 320px; flex-direction: column; align-items: center; justify-content: center; color: #8b95a7; text-align: center; background: #fff; border-radius: 8px; border: 1px dashed #cfd6e4; }
.business-empty h2 { font-size: 18px; color: #465164; margin-bottom: 8px; }
.business-empty.small { min-height: 90px; margin-bottom: 18px; font-size: 13px; }
.business-inline-form { display: flex; gap: 6px; align-items: center; }
.business-inline-form input { width: 96px; padding: 6px 8px; border: 1px solid #d9d9d9; border-radius: 5px; }
.business-detail-section { margin-bottom: 18px; }
.business-detail-section .business-subtitle { margin-top: 0; }
.business-detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.business-detail-item { padding: 12px; border: 1px solid #edf0f5; border-radius: 8px; background: #fbfcff; min-width: 0; }
.business-detail-item span { display: block; margin-bottom: 5px; color: #99a2b3; font-size: 12px; }
.business-detail-item strong { display: block; color: #30384a; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; line-height: 1.55; }
.business-detail-item a { color: #334bd3; text-decoration: none; border-bottom: 1px dotted #667eea; }
.business-detail-item a:hover { color: #2638a8; }
.business-subtitle { margin: 20px 0 12px; font-size: 15px; color: #30384a; }
.business-subtitle:first-child { margin-top: 0; }
.business-conversation-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.business-conversation, .business-plan-detail { border: 1px solid #edf0f5; border-radius: 8px; background: #fbfcff; overflow: hidden; margin-bottom: 12px; }
.business-conversation summary, .business-plan-detail summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; cursor: pointer; background: #f8f9fc; }
.business-conversation summary span, .business-plan-detail summary span { color: #778196; font-size: 12px; }
.business-message-list { padding: 12px 14px; background: #fff; }
.business-message-row { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid #f0f2f6; }
.business-message-row:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
.business-message-row span { display: block; margin-bottom: 5px; color: #99a2b3; font-size: 11px; }
.business-message-row p { color: #333; font-size: 13px; line-height: 1.65; white-space: normal; }
.business-message-row.role-user p { color: #0958d9; }
.business-message-row.role-assistant p { color: #23451f; }
.business-change-grid { display: grid; grid-template-columns: repeat(2, minmax(260px, 1fr)); gap: 16px; margin-top: 18px; }
.business-form-card { padding: 16px; border: 1px solid #edf0f5; border-radius: 8px; background: #fbfcff; }
.business-form-card h3 { font-size: 15px; margin-bottom: 14px; }
.business-plan-select-table input[type="radio"] { width: 16px; height: 16px; }
.business-action-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0; padding: 12px; border: 1px solid #edf0f5; border-radius: 8px; background: #fbfcff; }
.business-action-bar .hint-text { margin-left: auto; }
.business-change-panels { margin-top: 12px; }
.business-change-panel { max-width: 760px; }
.business-segment { display: flex; gap: 12px; margin-bottom: 16px; }
.business-segment label { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border: 1px solid #d8deeb; border-radius: 6px; background: #fff; font-size: 13px; cursor: pointer; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar { width: 60px; }
    .sidebar-header h2, .sidebar-user, .nav-list li a span { display: none; }
    .nav-list li a { text-align: center; padding: 12px 8px; font-size: 20px; }
    .main-content { margin-left: 60px; padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2,1fr); }
    .stat-card-wide { grid-column: span 2; }
    .form-row { flex-direction: column; }
    .filter-bar { flex-direction: column; }
    .filter-bar .form-group { min-width: auto; }
    .customer-layout { grid-template-columns: 1fr; }
    .customer-list { max-height: 240px; }
    .chat-panel { min-height: 0; }
    .customer-profile-grid { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
    .business-layout { grid-template-columns: 1fr; }
    .business-user-panel { max-height: 260px; border-right: none; border-bottom: 1px solid #dde2eb; }
    .business-workspace { padding: 12px; }
    .business-toolbar { align-items: stretch; flex-direction: column; }
    .business-change-grid { grid-template-columns: 1fr; }
}
