/* ============================================
   WhatsApp Bot Admin - Main Styles
   ============================================ */

/* ---------- Reset & Variables ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --sidebar-w: 260px;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-active: #312e81;
    --accent: #6366f1;
    --accent-grad: linear-gradient(135deg, #6366f1, #8b5cf6);
    --bg: #f1f5f9;
    --card: #fff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .06);
}

html {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

body {
    min-height: 100dvh;
    display: flex;
}

/* ---------- Modal（通用遮罩 + 卡片） ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(3px);
}
.modal-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .4);
    padding: 24px;
    width: 100%;
    max-width: min(680px, 92vw);
    max-height: 88vh;
    overflow: auto;
    box-sizing: border-box;
}

/* ---------- Workflow 节点工具箱（画布左上悬浮，实体加号按钮） ---------- */
.wf-toolbox {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 10;
    width: 258px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .12);
    padding: 12px;
    box-sizing: border-box;
}
.wf-toolbox-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    color: #475569;
    margin-bottom: 10px;
}
.wf-toolbox-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}
.wf-tool-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 8px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    color: #1e293b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 9px;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease, background .12s ease;
}
.wf-tool-btn:hover {
    border-color: var(--c);
    background: #f8fafc;
    box-shadow: 0 3px 10px rgba(15, 23, 42, .10);
    transform: translateY(-1px);
}
.wf-tool-btn:active {
    transform: scale(.97);
}
.wf-tool-btn .wf-dot {
    width: 8px;
    height: 8px;
    background: var(--c);
    margin: 0;
    flex: none;
}

/* ---------- Workflow 顶栏输入框（Name / Trigger keywords，明显可编辑） ---------- */
.wf-topbar-input {
    padding: 7px 10px;
    font-size: 13px;
    color: #0f172a;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, .05);
    box-sizing: border-box;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.wf-topbar-input:hover { border-color: #94a3b8; }
.wf-topbar-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .15);
}

/* ---------- Workflow 顶栏折叠按钮（添加节点 / 聊天预览，显眼不融合） ---------- */
.wf-toggle-btn {
    --tc: #0891b2;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--tc);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .18);
    transition: transform .12s ease, box-shadow .12s ease, filter .12s ease, opacity .12s ease;
    font-family: inherit;
}
.wf-toggle-btn:hover {
    filter: brightness(1.08);
    box-shadow: 0 4px 14px rgba(15, 23, 42, .24);
    transform: translateY(-1px);
}
.wf-toggle-btn:active { transform: scale(.96); }
.wf-toggle-btn.collapsed {
    opacity: .55;
    box-shadow: none;
    filter: saturate(.7);
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.sidebar-header h1 {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    color: #94a3b8;
    font-size: 14px;
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    transition: all .15s;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-footer {
    padding: 12px 10px;
    border-top: 1px solid rgba(255, 255, 255, .06);
}

/* ---------- Main Content ---------- */
.main {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    padding: 24px 28px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

/* ---------- Impersonate Banner ---------- */
.impersonate-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 20px;
    background: #312e81;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
}

.impersonate-banner .btn {
    background: #fff;
    color: #312e81;
    width: auto;
    padding: 6px 14px;
}

/* ---------- Login Page ---------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    background: linear-gradient(135deg, #0f172a, #1e1b4b);
    width: 100%;
    padding: 20px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, .25);
}

.login-card h1 {
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 24px;
}

/* ---------- Form Elements ---------- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .1);
}

.form-group textarea {
    resize: vertical;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all .15s;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent-grad);
    color: #fff;
    width: 100%;
}

.btn-primary:hover {
    opacity: .9;
}

.btn-sm {
    font-size: 12px;
    padding: 6px 12px;
}

.btn-danger {
    background: #ef4444;
    color: #fff;
}

.btn-success {
    background: #22c55e;
    color: #fff;
}

.btn-outline {
    background: #dbeafe;
    border: 1px solid #93c5fd;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-outline:hover {
    background: #bfdbfe;
}

.btn-warning {
    background: #e2e8f0;
    border: 1px solid #cbd5e1;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-warning:hover {
    background: #cbd5e1;
}

.btn-impersonate {
    background: #e0e7ff;
    border: 1px solid #a5b4fc;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.btn-impersonate:hover {
    background: #c7d2fe;
}

/* ---------- Cards ---------- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 16px;
}

/* ---------- Page Headers ---------- */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.page-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.page-header p {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---------- Pages ---------- */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* ---------- Forms ---------- */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

/* ---------- Tables ---------- */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-wrap table {
    min-width: 900px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    text-align: left;
    padding: 10px 12px;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover {
    background: #f8fafc;
}

/* ---------- Users table: actions / token / plan ---------- */
.actions-cell {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-width: 260px;
}

.actions-cell .btn-sm {
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 30px;
}

.token-cell {
    display: inline-block;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: middle;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
}

.token-copy-btn {
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    margin-left: 6px;
    transition: opacity .15s ease;
    vertical-align: middle;
}

.token-copy-btn:hover {
    opacity: .85;
}

.plan-select {
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: border-color .15s ease;
}

.plan-select:focus {
    outline: none;
    border-color: var(--accent);
}

.plan-pill {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
}

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 600;
}

/* ---------- Toast Notifications ---------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 16px;
    border-radius: 8px;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
    animation: slideIn .3s ease-out;
}

.toast-error {
    background: #ef4444;
}

.toast-success {
    background: #22c55e;
}

/* ---------- Animations ---------- */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main {
        margin-left: 0;
    }
    .content {
        padding: 16px;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
}

/* ---------- Utilities ---------- */
code {
    background: #f1f5f9;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 12px;
}

.dashboard-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.dashboard-stats .card {
    flex: 1;
    min-width: 140px;
    text-align: center;
    padding: 16px;
}

.dashboard-stats .stat-value {
    font-size: 20px;
    font-weight: 700;
}

.dashboard-stats .stat-label {
    font-size: 12px;
    color: var(--text-muted);
}

.dashboard-stats .stat-detail {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.token-copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
}

.token-copy-btn:hover {
    opacity: 0.7;
}
