/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100vh; min-height: 100dvh; }
html { touch-action: manipulation; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Helvetica Neue", "PingFang SC", sans-serif;
    background: #ededed;
    color: #333;
    -webkit-font-smoothing: antialiased;
    animation: pageFadeIn 0.15s ease;
    overflow-x: hidden;
}
@keyframes pageFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: linear-gradient(180deg, #667eea, #764ba2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: linear-gradient(180deg, #764ba2, #667eea); }

/* ══════════════════════════════════════════════
   Admin Styles
   ══════════════════════════════════════════════ */

/* ── Admin Tabs ── */
.admin-tabs {
    display: flex; gap: 6px; margin-bottom: 16px; padding: 6px;
    background: linear-gradient(135deg, #f0f4ff, #f5f0ff);
    border-radius: 14px; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.admin-tab {
    flex: 1; padding: 10px 14px; border: none; background: transparent; cursor: pointer;
    font-size: 13px; color: #888; text-align: center; transition: all 0.25s;
    border-radius: 10px; white-space: nowrap; font-weight: 500;
}
.admin-tab.active {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}
.admin-tab:hover:not(.active) {
    background: rgba(102,126,234,0.08); color: #667eea;
}
.admin-tab-content.hidden { display: none; }
.admin-tab-content { animation: tabFadeIn 0.25s ease; }
@keyframes tabFadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* ── Stats Grid (admin) ── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat-card {
    background: linear-gradient(135deg, #fff, #f8f9ff);
    border-radius: 14px; padding: 20px 16px; text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    transition: transform 0.2s, box-shadow 0.2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,0.08); }
.stat-value { font-size: 28px; font-weight: 700; color: #333; }
.stat-label { font-size: 13px; color: #999; margin-top: 4px; }

/* ── Preset Tags ── */
.preset-keywords {
    background: linear-gradient(135deg, #e3f2fd, #e8eaf6);
    color: #1565c0; padding: 3px 10px; border-radius: 6px;
    font-size: 12px; font-weight: 600;
}
.preset-match-badge {
    background: linear-gradient(135deg, #f3e5f5, #e8eaf6);
    color: #7b1fa2; padding: 3px 8px; border-radius: 6px;
    font-size: 11px; font-weight: 500;
}
.preset-priority {
    background: linear-gradient(135deg, #fff3e0, #fff8e1);
    color: #e65100; padding: 3px 8px; border-radius: 6px;
    font-size: 11px; font-weight: 500;
}
.preset-inactive { color: #999; font-size: 11px; font-style: italic; }

/* ── Quota ── */
.quota-display { padding: 8px 0; }
.quota-bar-container {
    height: 24px; background: #f0f0f0; border-radius: 12px; overflow: hidden;
    margin-bottom: 8px; box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}
.quota-bar {
    height: 100%; border-radius: 12px; transition: width 0.6s ease;
    min-width: 0; background: linear-gradient(90deg, #95ec69, #52c41a);
}
.quota-text { font-size: 14px; color: #666; text-align: center; }
.quota-recharge { display: flex; flex-direction: column; gap: 8px; }
.quota-presets { display: flex; gap: 8px; flex-wrap: wrap; }
.quota-btn {
    flex: 1; min-width: 60px; padding: 10px; border: 1px solid #e8e8e8;
    border-radius: 10px; background: #fff; cursor: pointer; font-size: 14px;
    text-align: center; transition: all 0.2s; font-weight: 500;
}
.quota-btn:hover {
    border-color: #667eea; background: #f0f4ff;
    transform: translateY(-1px); box-shadow: 0 2px 8px rgba(102,126,234,0.15);
}
.quota-custom { display: flex; gap: 8px; }
.quota-custom input { flex: 1; padding: 8px; border: 1px solid #ddd; border-radius: 6px; font-size: 14px; }

/* ── Quota Notice ── */
.quota-notice {
    text-align: center; padding: 16px; margin: 16px;
    background: #fff3e0; border-radius: 8px; border: 1px solid #ffe082;
}
.quota-notice .title { font-size: 16px; font-weight: 500; color: #e65100; margin-bottom: 4px; }
.quota-notice .desc { font-size: 13px; color: #bf8c00; margin-bottom: 8px; }
.quota-notice .btn {
    display: inline-block; padding: 8px 20px; background: #ff6b6b; color: #fff;
    border: none; border-radius: 20px; font-size: 14px; cursor: pointer;
    text-decoration: none;
}

/* ── Emotion Badge ── */
.emotion-badge {
    font-size: 12px; color: #999; text-align: center;
    padding: 2px 0; animation: msgIn 0.3s ease;
}

/* ── Settings Page ── */
.settings-content {
    flex: 1; overflow-y: auto; padding: 20px 16px;
    background: linear-gradient(135deg, #f7f7f7 0%, #f0f4ff 100%);
}
.settings-section {
    background: #fff; border-radius: 14px; padding: 18px 16px; margin-bottom: 14px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04); transition: box-shadow 0.2s;
}
.settings-section:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.06); }
.settings-section h3 { font-size: 16px; margin-bottom: 8px; font-weight: 600; color: #444; }
.section-desc { font-size: 13px; color: #999; margin-bottom: 12px; }
.current-char { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.memories-list { display: flex; flex-direction: column; gap: 8px; }
.memory-item {
    display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px;
    background: #f9f9f9; border-radius: 10px; justify-content: space-between;
    transition: all 0.2s; border: 1px solid transparent;
}
.memory-item:hover { background: #f0f4ff; border-color: #e8e0ff; }
.memory-content { flex: 1; font-size: 14px; line-height: 1.5; }
.memory-meta { font-size: 11px; color: #bbb; margin-top: 4px; }
.memory-delete {
    background: none; border: none; color: #ff6b6b; cursor: pointer;
    font-size: 14px; padding: 4px; flex-shrink: 0;
}
.profile-display { font-size: 14px; line-height: 1.8; }
.profile-field { margin-bottom: 12px; }
.profile-field-label { font-weight: 500; color: #666; font-size: 13px; margin-bottom: 4px; }
.profile-field-value { color: #333; }

/* ── Character Editor ── */
.editor-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 13px; font-weight: 500; color: #666; }
.form-group input[type="text"],
.form-group input[type="color"],
.form-group textarea {
    padding: 8px 10px; border: 1px solid #ddd; border-radius: 6px;
    font-size: 14px; font-family: inherit; resize: vertical;
}
.form-group textarea { min-height: 60px; }
.form-group input[type="text"]:focus,
.form-group textarea:focus { outline: none; border-color: #4f6ef7; }
.form-group input[type="color"] { height: 40px; padding: 2px 4px; cursor: pointer; }
.field-list { display: flex; flex-direction: column; gap: 6px; }
.field-list-item {
    display: flex; align-items: center; gap: 6px;
    background: #f5f5f5; border-radius: 4px; padding: 6px 10px;
}
.field-list-item span { flex: 1; font-size: 14px; }
.field-list-item .del-field {
    background: none; border: none; color: #ff6b6b; cursor: pointer;
    font-size: 14px; padding: 2px;
}
.add-field-btn {
    background: none; border: 1px dashed #ccc; border-radius: 4px;
    padding: 6px; font-size: 13px; color: #999; cursor: pointer;
    text-align: center; margin-top: 4px;
}
.add-field-btn:hover { border-color: #4f6ef7; color: #666; }
.save-config-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    border: none; border-radius: 10px; padding: 12px; font-size: 15px;
    font-weight: 600; cursor: pointer; width: 100%; margin-top: 8px;
    color: #fff; transition: all 0.25s; box-shadow: 0 4px 12px rgba(102,126,234,0.25);
}
.save-config-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(102,126,234,0.35); }
.save-config-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.save-feedback {
    text-align: center; font-size: 13px; padding: 8px;
    border-radius: 4px; animation: msgIn 0.3s ease;
}
.save-feedback.success { background: #e8f5e9; color: #2e7d32; }
.save-feedback.error { background: #fbe9e7; color: #c62828; }
.loading { color: #999; text-align: center; padding: 20px; }
.empty { color: #bbb; text-align: center; padding: 20px; font-size: 13px; }

/* ── WeChat Tab (admin) ── */
.wechat-state { min-height: 200px; }
.wechat-state.hidden { display: none; }
.wechat-placeholder {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 40px 20px;
}
.wechat-spinner {
    width: 36px; height: 36px; border: 3px solid #e0e0e0;
    border-top-color: #4f6ef7; border-radius: 50%;
    animation: wechatSpin 0.8s linear infinite;
}
@keyframes wechatSpin { to { transform: rotate(360deg); } }
.qr-container {
    display: flex; justify-content: center; padding: 20px;
    background: #fff; border-radius: 8px; margin: 0 auto;
    max-width: 240px;
}
.qr-container img {
    width: 200px; height: 200px; image-rendering: pixelated;
}
.wechat-progress { text-align: center; padding: 12px 0; }
.wechat-progress-text {
    font-size: 14px; color: #999;
    animation: wechatPulse 1.5s ease-in-out infinite;
}
@keyframes wechatPulse { 0%,100% { opacity: 0.4; } 50% { opacity: 1; } }
.wechat-result-icon { font-size: 48px; text-align: center; padding: 20px 0 8px; }
.wechat-result-text { font-size: 18px; font-weight: 500; text-align: center; padding: 0 0 8px; }

/* ── Gateway Status ── */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-dot.active { background: #4f6ef7; }
.status-dot.inactive { background: #ccc; }

/* ══════════════════════════════════════════════
   Desktop Sidebar Navigation
   ══════════════════════════════════════════════ */
.sidebar-nav {
    position: fixed; top: 0; left: 0; width: 260px; height: 100vh;
    background: #fff; z-index: 200;
    display: flex; flex-direction: column;
    box-shadow: 1px 0 8px rgba(0,0,0,0.08);
    transition: transform 0.25s ease;
}
.sidebar-nav.hidden { transform: translateX(-100%); }
.sidebar-nav-header {
    padding: 24px 20px 16px;
    background: linear-gradient(135deg, #f8f9ff, #f0e6ff);
    border-bottom: 1px solid #f0f0f0;
}
.sidebar-logo { font-size: 18px; font-weight: 700;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}
.sidebar-nav-items {
    flex: 1; overflow-y: auto; padding: 12px 10px;
    display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; border-radius: 10px;
    text-decoration: none; color: #555; font-size: 15px;
    transition: all 0.2s;
}
.nav-item:hover { background: #f0f4ff; color: #667eea; }
.nav-item.active {
    background: linear-gradient(135deg, #eef2ff, #f0e6ff);
    color: #667eea; font-weight: 600;
}
.nav-icon { width: 20px; height: 20px; flex-shrink: 0; }
.nav-label { flex: 1; }
.sidebar-nav-footer {
    padding: 16px 20px; border-top: 1px solid #f0f0f0;
}
.sidebar-user {
    display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.sidebar-username { font-size: 14px; font-weight: 500; color: #333; }
.user-role-badge {
    font-size: 11px; padding: 2px 8px; border-radius: 10px;
    background: #f0f0f0; color: #999;
}
.user-role-badge.role-admin { background: #e3f2fd; color: #1565c0; }
.user-role-badge.role-user { background: #f3e5f5; color: #7b1fa2; }
.nav-logout {
    width: 100%; padding: 8px; border: 1px solid #eee; border-radius: 6px;
    background: #fff; cursor: pointer; font-size: 13px; color: #999;
    text-align: center; transition: all 0.15s;
}
.nav-logout:hover { border-color: #ff6b6b; color: #ff6b6b; }
.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.3); z-index: 150;
}
.sidebar-overlay.hidden { display: none; }

/* ── (bottom-nav removed — replaced by FAB) ── */

/* ══════════════════════════════════════════════
   Auth Pages (Login / Register)
   ══════════════════════════════════════════════ */
.auth-body {
    background: linear-gradient(135deg, #eef2ff 0%, #f0f7ff 100%);
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; overflow: auto;
}
.auth-container {
    width: 100%; max-width: 400px; padding: 20px;
}
.auth-card {
    background: #fff; border-radius: 16px; padding: 40px 32px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
    text-align: center;
}
.auth-logo { font-size: 56px; margin-bottom: 8px; }
.auth-title { font-size: 24px; font-weight: 600; color: #333; margin-bottom: 4px; }
.auth-subtitle { font-size: 14px; color: #999; margin-bottom: 28px; }
.auth-card .form-group {
    text-align: left; margin-bottom: 16px;
}
.auth-card .form-group label {
    display: block; font-size: 13px; color: #666; margin-bottom: 6px; font-weight: 500;
}
.auth-card .form-group input {
    width: 100%; padding: 12px 14px; border: 1px solid #ddd; border-radius: 8px;
    font-size: 15px; outline: none; transition: border-color 0.15s;
    box-sizing: border-box;
}
.auth-card .form-group input:focus { border-color: #4f6ef7; }
.auth-btn { margin-top: 8px; border-radius: 8px; padding: 12px; font-size: 16px; }
.auth-link { font-size: 14px; color: #999; margin-top: 20px; }
.auth-link a { color: #4f6ef7; text-decoration: none; font-weight: 500; }
.auth-hint { font-size: 12px; color: #ccc; margin-top: 12px; }

/* ══════════════════════════════════════════════
   Dashboard
   ══════════════════════════════════════════════ */
.dash-stats-grid {
    display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px;
}
.dash-stat-card {
    background: #fff; border-radius: 12px; padding: 16px;
    display: flex; align-items: center; gap: 14px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.dash-stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; flex-shrink: 0;
}
.dash-stat-primary .dash-stat-icon { background: #e3f2fd; }
.dash-stat-success .dash-stat-icon { background: #e8f5e9; }
.dash-stat-warning .dash-stat-icon { background: #fff3e0; }
.dash-stat-info .dash-stat-icon { background: #f3e5f5; }
.dash-stat-body { flex: 1; }
.dash-stat-value { font-size: 24px; font-weight: 600; color: #333; }
.dash-stat-label { font-size: 13px; color: #999; margin-top: 2px; }
.dash-grid { display: flex; flex-direction: column; gap: 16px; }
.dash-char-info { font-size: 15px; color: #333; padding: 4px 0; }
.dash-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dash-action-btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 18px; background: #f5f5f5; border-radius: 8px;
    text-decoration: none; color: #555; font-size: 14px;
    transition: all 0.15s;
}
.dash-action-btn:hover { background: #eef2ff; color: #4f6ef7; }

/* ══════════════════════════════════════════════
   Permission Toggle UI
   ══════════════════════════════════════════════ */
.permissions-list { display: flex; flex-direction: column; gap: 8px; }
.perm-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px; background: #f9f9f9; border-radius: 8px;
}
.perm-info { display: flex; flex-direction: column; gap: 2px; }
.perm-label { font-size: 15px; font-weight: 500; color: #333; }
.perm-key { font-size: 12px; color: #bbb; }
.perm-toggle {
    position: relative; display: inline-block; width: 48px; height: 26px;
    cursor: pointer;
}
.perm-toggle input { display: none; }
.perm-slider {
    position: absolute; inset: 0; background: #ddd; border-radius: 26px;
    transition: 0.2s;
}
.perm-slider::before {
    content: ''; position: absolute; left: 3px; top: 3px;
    width: 20px; height: 20px; background: #fff; border-radius: 50%;
    transition: 0.2s;
}
.perm-toggle input:checked + .perm-slider { background: #4f6ef7; }
.perm-toggle input:checked + .perm-slider::before { transform: translateX(22px); }

/* ══════════════════════════════════════════════
   Responsive Breakpoints
   ══════════════════════════════════════════════ */

/* Mobile */
@media (max-width: 767px) {
    .sidebar-nav:not(.hidden) { transform: translateX(0); }
    #app { max-width: 100%; margin: 0 auto; }
}

/* Desktop */
@media (min-width: 768px) {
    body { padding-left: 260px; }
    .sidebar-nav { transform: translateX(0); }
    .sidebar-nav.hidden { transform: translateX(-100%); }
    #app { max-width: none; margin: 0; }
    .sidebar-overlay { display: none !important; }
    .dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .dash-stats-grid { grid-template-columns: repeat(4, 1fr); }
    .admin-tab { font-size: 15px; padding: 12px 16px; }
    #admin-content { max-width: none; }
}

/* Large screens */
@media (min-width: 1200px) {
    #app { max-width: none; margin: 0; }
    .settings-content { padding: 24px; }
    #chat-area { max-width: 100%; }
    #input-area { max-width: 100%; }
}
