/* =====================================================================
   CH88 LiveChat Pro — Admin Panel
   Design tokens (dark default, light via [data-theme="light"])
   ===================================================================== */
:root,
[data-theme="dark"] {
    --bg-app: #0b0d12;
    --bg-rail: #08090d;
    --bg-panel: #10131a;
    --bg-surface: #151922;
    --bg-elevated: #1b202b;
    --bg-hover: #1a1f2a;
    --bg-input: #0d1016;
    --border: #222837;
    --border-strong: #2d3446;

    --text-primary: #e8eaf0;
    --text-secondary: #a3aabb;
    --text-muted: #6b7386;

    --brand: #6366f1;
    --brand-hover: #5558e6;
    --brand-soft: rgba(99, 102, 241, .14);
    --brand-ring: rgba(99, 102, 241, .35);

    --success: #22c55e;
    --success-soft: rgba(34, 197, 94, .14);
    --warning: #f59e0b;
    --warning-soft: rgba(245, 158, 11, .14);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, .14);
    --info: #3b82f6;
    --info-soft: rgba(59, 130, 246, .12);

    --bubble-in: #1b202b;
    --bubble-out: #6366f1;
    --bubble-out-text: #fff;
    --bubble-ai: #1e2140;
    --bubble-ai-text: #d7d9ff;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .5);

    /* alias lama (dipakai beberapa style inline) */
    --bg-dark: var(--bg-input);
    --text-secondary-alias: var(--text-secondary);
    --accent: var(--brand);
    --accent-hover: var(--brand-hover);
    --accent-soft: var(--brand-soft);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    color-scheme: dark;
}

[data-theme="light"] {
    --bg-app: #f4f5f8;
    --bg-rail: #ffffff;
    --bg-panel: #ffffff;
    --bg-surface: #f7f8fa;
    --bg-elevated: #eef0f4;
    --bg-hover: #f2f3f7;
    --bg-input: #ffffff;
    --border: #e4e7ec;
    --border-strong: #d3d8e0;

    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #8a93a3;

    --brand: #4f46e5;
    --brand-hover: #4338ca;
    --brand-soft: rgba(79, 70, 229, .09);
    --brand-ring: rgba(79, 70, 229, .25);

    --bubble-in: #f1f3f7;
    --bubble-out: #4f46e5;
    --bubble-ai: #eef0ff;
    --bubble-ai-text: #3730a3;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, .08);
    --shadow-lg: 0 24px 60px rgba(16, 24, 40, .16);
    color-scheme: light;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'cv11', 'ss01';
}
#app { height: 100%; }
button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
kbd {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 5px;
    font-family: inherit; font-size: 11px; font-weight: 600;
    color: var(--text-secondary); background: var(--bg-elevated);
    border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }

/* =====================================================================
   LOGIN
   ===================================================================== */
.login-wrapper { display: grid; grid-template-columns: 1.15fr 1fr; min-height: 100vh; }
.login-showcase {
    position: relative; overflow: hidden;
    padding: 48px 56px; display: flex; flex-direction: column; gap: 40px;
    background:
        radial-gradient(1200px 600px at -10% -20%, rgba(99, 102, 241, .35), transparent 60%),
        radial-gradient(800px 500px at 110% 110%, rgba(14, 165, 233, .22), transparent 60%),
        #0a0c14;
    color: #e8eaf0;
}
.login-showcase::after {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(ellipse at 30% 40%, #000 30%, transparent 75%);
}
.brand { display: flex; align-items: center; gap: 12px; position: relative; z-index: 1; }
.brand-mark {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    background: linear-gradient(135deg, #818cf8, #6366f1 55%, #4f46e5); color: #fff; font-size: 18px;
    box-shadow: 0 8px 24px rgba(99, 102, 241, .45);
}
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.brand-name span { font-weight: 500; color: rgba(232, 234, 240, .65); }
.showcase-copy { position: relative; z-index: 1; margin-top: auto; max-width: 520px; }
.showcase-copy h1 { font-size: 40px; line-height: 1.15; letter-spacing: -.03em; font-weight: 700; margin-bottom: 16px; }
.showcase-copy p { color: rgba(232, 234, 240, .7); font-size: 16px; line-height: 1.65; }
.showcase-preview { position: relative; z-index: 1; display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; max-width: 560px; }
.sp-card, .sp-stats > div {
    background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .09);
    backdrop-filter: blur(10px); border-radius: 16px;
}
.sp-card { padding: 8px; }
.sp-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; }
.sp-row.active { background: rgba(99, 102, 241, .18); }
.sp-row div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sp-row b { font-size: 13px; font-weight: 600; }
.sp-row small { font-size: 12px; color: rgba(232, 234, 240, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-row em { font-style: normal; font-size: 11px; color: rgba(232, 234, 240, .45); }
.sp-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff; flex-shrink: 0; }
.sp-stats { display: flex; flex-direction: column; gap: 14px; }
.sp-stats > div { padding: 16px; flex: 1; display: flex; flex-direction: column; justify-content: center; }
.sp-stats b { font-size: 15px; font-weight: 700; }
.sp-stats small { font-size: 12px; color: rgba(232, 234, 240, .6); }
.showcase-foot { position: relative; z-index: 1; display: flex; gap: 24px; flex-wrap: wrap; font-size: 13px; color: rgba(232, 234, 240, .6); }
.showcase-foot i { color: #a5b4fc; margin-right: 6px; }

.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 32px; background: var(--bg-panel); }
.login-form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 18px; }
.login-form h2 { font-size: 26px; letter-spacing: -.02em; }
.login-form > p { margin-top: -8px; line-height: 1.6; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-secondary); }
.field input, .input-password {
    width: 100%; height: 46px; padding: 0 14px;
    background: var(--bg-input); border: 1px solid var(--border-strong); border-radius: var(--radius-md);
    color: var(--text-primary); transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .input-password:focus-within { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.input-password { display: flex; align-items: center; padding: 0 4px 0 0; }
.input-password input { border: none; height: 100%; background: transparent; box-shadow: none !important; }
.input-password button { width: 38px; height: 38px; border: none; background: none; color: var(--text-muted); border-radius: 8px; }
.input-password button:hover { color: var(--text-primary); background: var(--bg-hover); }
.input-row { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.checkbox { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); cursor: pointer; }
.checkbox input { accent-color: var(--brand); width: 16px; height: 16px; }
.btn-submit {
    height: 46px; border: none; border-radius: var(--radius-md);
    background: var(--brand); color: #fff; font-weight: 600; font-size: 15px;
    display: flex; align-items: center; justify-content: center; gap: 10px;
    box-shadow: 0 6px 18px rgba(99, 102, 241, .35); transition: background .15s, transform .1s;
}
.btn-submit:hover { background: var(--brand-hover); }
.btn-submit:active { transform: translateY(1px); }
.login-error { display: none; font-size: 13px; color: var(--danger); background: var(--danger-soft); padding: 10px 12px; border-radius: 8px; }
.login-error.show { display: block; }
.login-footer { margin-top: 40px; font-size: 12px; color: var(--text-muted); }

/* =====================================================================
   SHELL: RAIL + WORKSPACE
   ===================================================================== */
.dashboard { height: 100vh; display: flex; overflow: hidden; }
.rail {
    width: 76px; flex-shrink: 0; background: var(--bg-rail); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; align-items: center; padding: 16px 0;
}
.rail-logo {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    background: linear-gradient(135deg, #818cf8, #6366f1 55%, #4f46e5); color: #fff; font-size: 17px;
    box-shadow: 0 6px 18px rgba(99, 102, 241, .4); margin-bottom: 24px;
}
.rail-nav, .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail-nav { flex: 1; }
.rail-btn {
    position: relative; width: 56px; padding: 9px 0 7px; border: none; border-radius: 12px; background: none;
    color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 4px;
    font-size: 18px; transition: background .15s, color .15s;
}
.rail-bottom .rail-btn { width: 42px; height: 42px; padding: 0; justify-content: center; font-size: 16px; }
.rail-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.rail-btn.active { background: var(--brand-soft); color: var(--brand); }
.rail-btn.active::before { content: ''; position: absolute; left: -10px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.rail-btn.off { color: var(--danger); }
.rail-label { font-size: 10.5px; font-weight: 600; letter-spacing: .01em; }
.rail-btn .badge {
    position: absolute; top: 3px; right: 5px; min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: 9px; font-size: 10px; font-weight: 700; display: grid; place-items: center;
    background: var(--bg-elevated); color: var(--text-secondary); border: 2px solid var(--bg-rail);
}
.rail-btn .badge.hot { background: var(--danger); color: #fff; }
.user-menu { position: relative; margin-top: 10px; cursor: pointer; }
.user-avatar {
    width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
    background: var(--brand); color: #fff; font-weight: 700; font-size: 13px;
}
.presence { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: var(--success); border: 2px solid var(--bg-rail); }
.user-pop {
    position: absolute; left: 52px; bottom: 0; min-width: 220px; z-index: 50;
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg); padding: 6px; opacity: 0; visibility: hidden; transform: translateX(-6px);
    transition: all .15s;
}
.user-menu:hover .user-pop, .user-menu:focus-within .user-pop { opacity: 1; visibility: visible; transform: none; }
.user-pop-head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; display: flex; flex-direction: column; }
.user-pop-head b { font-size: 14px; }
.user-pop-head small { color: var(--text-muted); font-size: 12px; }
.user-pop button { width: 100%; text-align: left; padding: 9px 12px; border: none; background: none; border-radius: 8px; color: var(--text-secondary); display: flex; gap: 10px; align-items: center; }
.user-pop button:hover { background: var(--danger-soft); color: var(--danger); }

.main-wrapper { flex: 1; min-width: 0; display: flex; }
.view-panel { flex: 1; min-width: 0; display: none; }
.view-panel.active { display: flex; }

/* =====================================================================
   INBOX LIST
   ===================================================================== */
.conversations-sidebar { width: 340px; flex-shrink: 0; background: var(--bg-panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; }
.sidebar-header { padding: 20px 16px 12px; display: flex; flex-direction: column; gap: 14px; border-bottom: 1px solid var(--border); }
.sidebar-title { display: flex; justify-content: space-between; align-items: center; }
.sidebar-title h3 { font-size: 19px; font-weight: 700; letter-spacing: -.02em; }
.online-count { font-size: 12px; color: var(--success); background: var(--success-soft); padding: 3px 10px; border-radius: 20px; font-weight: 500; }
.online-count i { font-size: 7px; vertical-align: middle; margin-right: 4px; }
.search-wrap { position: relative; }
.search-wrap i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; }
.search-wrap input {
    width: 100%; height: 38px; padding: 0 12px 0 36px; border-radius: var(--radius-md);
    background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-primary);
}
.search-wrap input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.filter-tabs { display: flex; gap: 2px; padding: 3px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.filter-tab { flex: 1; padding: 6px 4px; border: none; background: none; border-radius: 7px; font-size: 12px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.filter-tab:hover { color: var(--text-primary); }
.filter-tab.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
[data-theme="dark"] .filter-tab.active { background: var(--bg-elevated); }
.conversation-list { flex: 1; overflow-y: auto; padding: 8px; }

.conv-item {
    position: relative; display: flex; gap: 12px; padding: 12px; border-radius: 12px; cursor: pointer;
    transition: background .12s; margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--brand-soft); }
.conv-item.active::before { content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 3px; background: var(--brand); }
.conv-body { flex: 1; min-width: 0; }
.conv-header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.conv-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-mail { color: var(--warning); font-size: 11px; margin-right: 6px; }
.conv-time { font-size: 11.5px; color: var(--text-muted); flex-shrink: 0; }
.conv-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item.unread .conv-name { color: var(--text-primary); }
.conv-item.unread .conv-preview { color: var(--text-primary); font-weight: 500; }
.conv-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.conv-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.conv-tag i { font-size: 10px; }
.conv-tag.ai { background: var(--brand-soft); color: var(--brand); }
.conv-tag.agent { background: var(--success-soft); color: var(--success); }
.conv-tag.archived { background: var(--bg-elevated); color: var(--text-secondary); }
.conv-item.attention .conv-tag.agent { background: var(--warning-soft); color: var(--warning); }
.unread-badge { background: var(--brand); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center; }

.avatar {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
    color: #fff; font-weight: 700; font-size: 13.5px; letter-spacing: .02em;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.12);
}
.avatar-lg { width: 64px; height: 64px; font-size: 20px; }

.empty-state { padding: 56px 24px; text-align: center; color: var(--text-muted); }
.empty-state i { font-size: 34px; margin-bottom: 14px; opacity: .5; display: block; }
.empty-state p { font-size: 14px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state small { font-size: 13px; line-height: 1.5; }

/* =====================================================================
   CHAT PANEL
   ===================================================================== */
.chat-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg-app); position: relative; }
.chat-placeholder { margin: auto; text-align: center; max-width: 360px; padding: 40px 20px; color: var(--text-muted); }
.placeholder-icon {
    width: 72px; height: 72px; margin: 0 auto 20px; border-radius: 22px; display: grid; place-items: center;
    background: var(--brand-soft); color: var(--brand); font-size: 28px;
}
.chat-placeholder h3 { color: var(--text-primary); font-size: 18px; margin-bottom: 8px; letter-spacing: -.01em; }
.chat-placeholder p { line-height: 1.6; }
.chat-placeholder.small i { font-size: 28px; opacity: .5; margin-bottom: 10px; display: block; }
.placeholder-tips { display: flex; gap: 16px; justify-content: center; margin-top: 20px; font-size: 12px; }
.placeholder-tips span { display: flex; align-items: center; gap: 6px; }

.chat-header {
    height: 72px; flex-shrink: 0; padding: 0 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
    background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
.chat-user { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-user-info { min-width: 0; }
.chat-user-info h4 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-user-sub { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-top: 3px; min-width: 0; }
.chat-user-sub .muted { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.handler-status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; white-space: nowrap; }
.handler-status.ai { color: var(--brand); }
.handler-status.agent { color: var(--success); }
.handler-status.archived { color: var(--text-secondary); }
.chat-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.takeover-btn, .release-btn, .archive-btn, .ghost-btn {
    height: 36px; padding: 0 14px; border-radius: var(--radius-md); font-size: 13px; font-weight: 600;
    display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; transition: all .15s;
}
.takeover-btn { background: var(--brand); color: #fff; border: 1px solid var(--brand); box-shadow: 0 4px 12px rgba(99,102,241,.3); }
.takeover-btn:hover { background: var(--brand-hover); }
.release-btn, .archive-btn, .ghost-btn { background: var(--bg-panel); color: var(--text-secondary); border: 1px solid var(--border-strong); }
.release-btn:hover, .archive-btn:hover, .ghost-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.archive-btn:hover, .ghost-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.icon-btn {
    width: 36px; height: 36px; border-radius: var(--radius-md); border: 1px solid transparent; background: none;
    color: var(--text-muted); display: grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.chat-messages { flex: 1; overflow-y: auto; padding: 24px clamp(16px, 4vw, 48px); display: flex; flex-direction: column; gap: 6px; }
.day-sep { display: flex; align-items: center; gap: 12px; margin: 14px 0 8px; color: var(--text-muted); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.message { max-width: min(68%, 560px); padding: 10px 14px 8px; border-radius: 18px; font-size: 14px; line-height: 1.55; position: relative; }
.message.in { align-self: flex-start; background: var(--bubble-in); color: var(--text-primary); border-bottom-left-radius: 6px; }
.message.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-bottom-right-radius: 6px; }
.message.out.ai { background: var(--bubble-ai); color: var(--bubble-ai-text); border: 1px solid var(--brand-soft); }
.message + .message.in, .message + .message.out { margin-top: 2px; }
.message.system {
    align-self: center; max-width: 80%; background: transparent; color: var(--text-muted);
    font-size: 12.5px; text-align: center; padding: 6px 14px; border: 1px dashed var(--border-strong); border-radius: 999px;
}
.message.system i { color: var(--info); margin-right: 4px; }
.message.system .msg-time { margin-left: 6px; font-size: 11px; }
.msg-content { white-space: pre-wrap; word-break: break-word; }
.msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 6px; margin-top: 4px; }
.msg-time { font-size: 11px; opacity: .65; }
.msg-handler { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,.18); }
.message.out.ai .msg-handler { background: var(--brand-soft); color: var(--brand); }
.message.in .msg-meta { justify-content: flex-start; }
.message.has-image { padding: 4px 4px 6px; }
.message.has-image .msg-content { padding: 6px 10px 0; }
.message.has-image .msg-meta { padding: 0 8px; }
.msg-image-link { display: block; line-height: 0; }
.msg-image { max-width: 280px; max-height: 320px; width: auto; height: auto; border-radius: 14px; display: block; cursor: zoom-in; background: var(--bg-elevated); object-fit: cover; }
/* Lampiran file (dari agen) */
.msg-file { display: flex; align-items: center; gap: 12px; min-width: 220px; max-width: 300px; padding: 10px 12px; border-radius: 12px; background: rgba(127,127,127,.13); color: inherit; text-decoration: none; transition: background .15s; }
.msg-file:hover { background: rgba(127,127,127,.22); }
.msg-file-icon { font-size: 26px; flex-shrink: 0; opacity: .9; }
.msg-file-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.msg-file-name { font-weight: 600; font-size: 13.5px; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.msg-file-size { font-size: 11.5px; opacity: .75; }
.msg-file-dl { font-size: 14px; opacity: .8; flex-shrink: 0; }
.message.has-file .msg-content { margin-top: 6px; }
.attach-btn { width: 36px; height: 36px; margin-left: -8px; border-radius: 10px; border: none; background: transparent; color: var(--text-muted); font-size: 16px; flex-shrink: 0; transition: background .15s, color .15s; }
.attach-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--brand); }
.attach-btn:disabled { cursor: wait; color: var(--brand); }
#chatPanel.drag-over { outline: 3px dashed var(--brand); outline-offset: -10px; }

.chat-input-wrap { padding: 12px 20px 16px; background: var(--bg-app); position: relative; flex-shrink: 0; }
.composer { background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: 16px; padding: 8px 8px 6px 16px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.chat-input-row { display: flex; gap: 10px; align-items: center; }
.chat-input-row input { flex: 1; min-width: 0; height: 40px; border: none; background: transparent; color: var(--text-primary); font-size: 14.5px; }
.chat-input-row input:focus { outline: none; }
.chat-input-row input::placeholder { color: var(--text-muted); }
.send-btn { width: 40px; height: 40px; border-radius: 12px; border: none; background: var(--brand); color: #fff; font-size: 15px; flex-shrink: 0; transition: background .15s, transform .1s; }
.send-btn:hover { background: var(--brand-hover); }
.send-btn:active { transform: scale(.96); }
.composer-hint { display: flex; gap: 14px; font-size: 11.5px; color: var(--text-muted); padding: 2px 0 2px; }
.composer-hint span { display: inline-flex; align-items: center; gap: 4px; }
.composer-hint kbd { height: 17px; min-width: 17px; font-size: 10px; }

/* Shortcut dropdown */
.shortcut-dropdown {
    position: absolute; bottom: calc(100% - 6px); left: 20px; right: 20px; max-height: 320px; overflow-y: auto; display: none; z-index: 100;
    background: var(--bg-panel); border: 1px solid var(--border-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 6px;
}
.shortcut-dropdown.show { display: block; }
.shortcut-item { padding: 10px 12px; border-radius: 10px; cursor: pointer; display: flex; gap: 12px; align-items: baseline; }
.shortcut-item:hover, .shortcut-item.active { background: var(--brand-soft); }
.shortcut-key { font-weight: 700; color: var(--brand); font-size: 13px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; flex-shrink: 0; }
.shortcut-preview { color: var(--text-secondary); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* =====================================================================
   DETAIL PELANGGAN
   ===================================================================== */
.visitor-panel { width: 320px; flex-shrink: 0; background: var(--bg-panel); border-left: 1px solid var(--border); flex-direction: column; overflow-y: auto; }
.visitor-header { height: 72px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 16px 0 20px; border-bottom: 1px solid var(--border); }
.visitor-header h4 { font-size: 14px; font-weight: 600; }
.visitor-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 24px 20px 20px; border-bottom: 1px solid var(--border); text-align: center; }
.visitor-hero b { font-size: 16px; word-break: break-word; }
.chip { font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 20px; background: var(--bg-elevated); color: var(--text-secondary); }
.chip.ai { background: var(--brand-soft); color: var(--brand); }
.chip.agent { background: var(--success-soft); color: var(--success); }
.visitor-section { padding: 18px 20px; border-bottom: 1px solid var(--border); }
.visitor-section h5 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 12px; font-weight: 700; }
.info-row { display: grid; grid-template-columns: 18px 76px 1fr; align-items: baseline; gap: 8px; padding: 6px 0; font-size: 13px; }
.info-row i { color: var(--text-muted); font-size: 12px; text-align: center; }
.info-label { color: var(--text-muted); }
.info-value { color: var(--text-primary); word-break: break-word; min-width: 0; }
.visitor-section textarea {
    width: 100%; resize: vertical; min-height: 90px; padding: 10px 12px; border-radius: var(--radius-md);
    background: var(--bg-surface); border: 1px solid var(--border); color: var(--text-primary); font-size: 13px; line-height: 1.5;
}
.visitor-section textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.note-status { display: block; margin-top: 6px; font-size: 11.5px; color: var(--text-muted); min-height: 16px; }

/* =====================================================================
   ARSIP
   ===================================================================== */
.archive-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.archive-summary div { background: var(--bg-panel); padding: 12px 20px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.archive-summary small { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.archive-summary b { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.archive-note { margin: 16px clamp(16px, 4vw, 48px) 0; padding: 10px 14px; border-radius: var(--radius-md); background: var(--warning-soft); color: var(--text-primary); font-size: 13px; }
.archive-note i { color: var(--warning); margin-right: 6px; }
.archive-footer { padding: 14px 20px; text-align: center; font-size: 12.5px; color: var(--text-muted); border-top: 1px solid var(--border); background: var(--bg-panel); }
.archive-footer i { margin-right: 6px; }

/* =====================================================================
   LAPORAN
   ===================================================================== */
.reports { flex: 1; overflow-y: auto; padding: 32px clamp(20px, 4vw, 48px); }
.reports-head { margin-bottom: 24px; }
.reports-head h2 { font-size: 24px; letter-spacing: -.02em; margin-bottom: 4px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; display: flex; gap: 14px; align-items: flex-start; box-shadow: var(--shadow-sm); }
.stat-card small { display: block; font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.stat-card b { display: block; font-size: 26px; letter-spacing: -.02em; margin: 2px 0; }
.stat-card span { font-size: 12px; color: var(--text-secondary); }
.stat-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 16px; flex-shrink: 0; }
.stat-card.indigo .stat-icon { background: rgba(99,102,241,.14); color: #818cf8; }
.stat-card.slate .stat-icon { background: rgba(148,163,184,.14); color: #94a3b8; }
.stat-card.sky .stat-icon { background: rgba(14,165,233,.14); color: #38bdf8; }
.stat-card.violet .stat-icon { background: rgba(139,92,246,.14); color: #a78bfa; }
.stat-card.emerald .stat-icon { background: rgba(16,185,129,.14); color: #34d399; }
.report-card { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.report-card-head h3 { font-size: 14px; font-weight: 600; margin-bottom: 16px; }
.bar-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 14px; height: 200px; align-items: end; }
.bar-col { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; }
.bar { width: 100%; max-width: 48px; min-height: 3px; border-radius: 8px 8px 3px 3px; background: linear-gradient(180deg, #818cf8, #6366f1); transition: height .3s; }
.bar-value { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.bar-label { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }

/* =====================================================================
   MODAL PENGATURAN
   ===================================================================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; padding: 24px;
    background: rgba(5, 7, 12, .6); backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes popIn { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-container { width: 100%; max-width: 1040px; height: min(760px, 100%); display: flex; overflow: hidden; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg); animation: popIn .2s ease; }
.modal-sidebar { width: 240px; flex-shrink: 0; background: var(--bg-surface); border-right: 1px solid var(--border); padding: 24px 14px; display: flex; flex-direction: column; }
.modal-sidebar h3 { font-size: 16px; padding: 0 10px 16px; letter-spacing: -.01em; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.settings-link { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 9px; color: var(--text-secondary); font-size: 13.5px; font-weight: 500; }
.settings-link i { width: 16px; text-align: center; color: var(--text-muted); }
.settings-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.settings-link.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.settings-link.active i { color: var(--brand); }
.settings-nav-footer { padding-top: 12px; border-top: 1px solid var(--border); }
.btn-logout { width: 100%; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border); background: none; color: var(--text-secondary); display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 500; }
.btn-logout:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.modal-content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.modal-header { height: 68px; flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; padding: 0 20px 0 28px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 18px; letter-spacing: -.01em; }
.modal-body { flex: 1; overflow-y: auto; padding: 24px 28px 32px; }

.settings-section { margin-bottom: 24px; }
.settings-section h3, .section-header h3 { font-size: 13.5px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; color: var(--text-primary); }
.settings-section h3 i, .section-header h3 i { color: var(--text-muted); }
.settings-card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 16px; }
.settings-card.highlight { background: linear-gradient(135deg, var(--brand-soft), transparent); border-color: var(--border); }
.settings-card p { line-height: 1.6; }
.form-field { margin-bottom: 16px; }
.form-field:last-child { margin-bottom: 0; }
.form-field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 8px; color: var(--text-secondary); }
.form-field input, .form-field textarea, .form-field select {
    width: 100%; padding: 10px 12px; background: var(--bg-input); border: 1px solid var(--border-strong);
    border-radius: var(--radius-md); color: var(--text-primary); font-size: 14px; line-height: 1.5; transition: border-color .15s, box-shadow .15s;
}
.form-field textarea { resize: vertical; }
.form-field input:focus, .form-field textarea:focus, .form-field select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.form-field small { display: block; margin-top: 6px; font-size: 12px; color: var(--text-muted); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.color-options { display: flex; gap: 10px; }
.color-opt { width: 36px; height: 36px; border-radius: 10px; cursor: pointer; border: 3px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); transition: transform .1s; }
.color-opt:hover { transform: scale(1.06); }
.color-opt.active { border-color: var(--bg-panel); box-shadow: 0 0 0 2px var(--text-primary); }
.btn-primary, .btn-secondary {
    display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: var(--radius-md);
    font-size: 13.5px; font-weight: 600; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: #fff; border: 1px solid var(--brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.btn-secondary { background: var(--bg-panel); color: var(--text-primary); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--bg-hover); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.toggle-info { display: flex; gap: 14px; align-items: flex-start; flex: 1; }
.toggle-info i { font-size: 16px; color: var(--brand); margin-top: 2px; }
.toggle-info h4 { font-size: 14px; margin-bottom: 2px; }
.toggle-info p { font-size: 13px; color: var(--text-muted); }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; cursor: pointer; background: var(--border-strong); border-radius: 24px; transition: .2s; }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.toggle input:checked + .toggle-slider { background: var(--brand); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }
input[type="range"] { accent-color: var(--brand); }
.code-block { background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 16px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; color: var(--text-secondary); word-break: break-all; line-height: 1.6; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: var(--bg-elevated); padding: 1px 5px; border-radius: 4px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.section-header h3 { margin-bottom: 0; font-size: 15px; }

/* Widget preview */
.widget-preview-wrap { display: flex; justify-content: center; }
.widget-preview { width: 320px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-md); }
.wp-header { padding: 16px; display: flex; align-items: center; gap: 12px; }
.wp-avatar { width: 42px; height: 42px; background: rgba(255,255,255,.22); border-radius: 50%; display: grid; place-items: center; font-size: 18px; color: #fff; }
.wp-name { font-size: 15px; font-weight: 600; color: #fff; }
.wp-status { font-size: 12px; color: rgba(255,255,255,.85); display: flex; align-items: center; gap: 5px; }
.wp-status i { font-size: 7px; color: #4ade80; }
.wp-body { padding: 14px 16px 16px; background: #f8fafc; }
.wp-message { background: #fff; padding: 12px 14px; border-radius: 14px; border-bottom-left-radius: 4px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.wp-msg-sender { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.wp-msg-text { font-size: 13.5px; color: #1e293b; }

/* Lists (Knowledge / Aturan / Shortcut) */
.item-list { display: flex; flex-direction: column; gap: 10px; }
.list-item { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 16px; display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; transition: border-color .15s; }
.list-item:hover { border-color: var(--border-strong); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-item-title .badge { background: var(--success-soft); color: var(--success); padding: 2px 8px; border-radius: 20px; font-size: 10.5px; font-weight: 700; }
.list-item-title .badge.off { background: var(--bg-elevated); color: var(--text-muted); }
.list-item-text { font-size: 13px; color: var(--text-secondary); line-height: 1.55; }
.list-item-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.list-tag { background: var(--bg-elevated); color: var(--text-secondary); padding: 3px 9px; border-radius: 6px; font-size: 11.5px; }
.list-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.list-item-actions button { width: 32px; height: 32px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); }
.list-item-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.list-item-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.list-item-actions button .fa-toggle-on { color: var(--success); }
.crud-search { position: relative; margin-bottom: 14px; }
.crud-search i { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-size: 13px; }
.crud-search input { width: 100%; height: 38px; padding: 0 12px 0 36px; background: var(--bg-input); border: 1px solid var(--border-strong); border-radius: var(--radius-md); color: var(--text-primary); }
.crud-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.crud-form { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.crud-check label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-primary); }
.crud-check input { width: 16px !important; height: 16px; accent-color: var(--brand); }
.input-prefix { display: flex; align-items: stretch; }
.input-prefix span { display: flex; align-items: center; padding: 0 12px; background: var(--bg-elevated); border: 1px solid var(--border-strong); border-right: none; border-radius: var(--radius-md) 0 0 var(--radius-md); color: var(--text-secondary); font-family: ui-monospace, monospace; }
.input-prefix input { border-radius: 0 var(--radius-md) var(--radius-md) 0 !important; }
.shortcut-chip { background: var(--brand-soft); color: var(--brand); padding: 3px 10px; border-radius: 6px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.form-error { display: none; background: var(--danger-soft); border: 1px solid var(--danger); color: var(--danger); padding: 10px 14px; border-radius: var(--radius-md); margin-bottom: 16px; font-size: 13px; }
.form-error.show { display: block; }

/* =====================================================================
   LIGHTBOX & TOAST
   ===================================================================== */
.lightbox { position: fixed; inset: 0; z-index: 2000; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: rgba(3, 4, 8, .88); backdrop-filter: blur(6px); padding: 40px; }
.lightbox.show { display: flex; animation: fadeIn .15s ease; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 140px); border-radius: 12px; box-shadow: var(--shadow-lg); }
.lightbox-close { position: absolute; top: 20px; right: 20px; width: 42px; height: 42px; border-radius: 50%; border: none; background: rgba(255,255,255,.1); color: #fff; font-size: 18px; }
.lightbox-close:hover { background: rgba(255,255,255,.2); }
.lightbox-open { color: #e5e7eb; font-size: 13px; padding: 8px 14px; border-radius: 8px; background: rgba(255,255,255,.08); }
.lightbox-open:hover { background: rgba(255,255,255,.16); }

.toast {
    position: fixed; bottom: 24px; right: 24px; z-index: 3000; max-width: 380px;
    display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px;
    background: var(--bg-panel); color: var(--text-primary); border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13.5px;
    transform: translateY(16px); opacity: 0; pointer-events: none; transition: all .25s ease;
}
.toast i { color: var(--success); font-size: 16px; }
.toast.error i { color: var(--danger); }
.toast.warning i { color: var(--warning); }
.toast.show { transform: none; opacity: 1; }

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 1280px) {
    .visitor-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow-lg); }
    #chatsView { position: relative; }
}
@media (max-width: 1024px) {
    .login-wrapper { grid-template-columns: 1fr; }
    .login-showcase { display: none; }
    .conversations-sidebar { width: 290px; }
    .archive-summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .rail { width: 64px; }
    .rail-label { display: none; }
    .conversations-sidebar { width: 100%; }
    .chat-panel { display: none; }
    .modal-sidebar { width: 64px; padding: 16px 8px; }
    .modal-sidebar h3, .settings-link span { display: none; }
}

/* =====================================================================
   v5: ROLE, AGEN, ARSIP RENTANG TANGGAL, LAPORAN AGEN, DETAIL PELANGGAN
   ===================================================================== */
body[data-role="agent"] .super-only { display: none !important; }

.setup-badge { align-self: flex-start; font-size: 12px; font-weight: 600; color: var(--brand); background: var(--brand-soft); padding: 4px 10px; border-radius: 20px; }
.role-badge { display: inline-flex; align-items: center; font-size: 10.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; padding: 2px 8px; border-radius: 20px; background: var(--success-soft); color: var(--success); }
.role-badge.superadmin { background: rgba(245, 158, 11, .15); color: var(--warning); }
.user-pop-head .role-badge { margin-top: 6px; align-self: flex-start; }
.user-pop .pop-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.user-pop .pop-item.danger:hover { background: var(--danger-soft); color: var(--danger); }
.user-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.user-avatar { overflow: hidden; }

/* Avatar & status online */
.avatar-wrap { position: relative; flex-shrink: 0; display: inline-flex; }
.online-dot { position: absolute; right: -1px; bottom: -1px; width: 12px; height: 12px; border-radius: 50%; background: var(--text-muted); border: 2px solid var(--bg-panel); }
.online-dot.on { background: var(--success); }
.avatar-lg + .online-dot { width: 16px; height: 16px; right: 2px; bottom: 2px; }
.avatar-sm { width: 28px; height: 28px; font-size: 10.5px; }
.avatar-xs { width: 22px; height: 22px; font-size: 9px; }
.avatar-xxs { width: 16px; height: 16px; font-size: 7px; box-shadow: none; }
.avatar.photo { object-fit: cover; padding: 0; background: var(--bg-elevated); }
.avatar.bot { background: var(--brand-soft); color: var(--brand); font-size: 12px; box-shadow: none; }
.avatar-stack { display: inline-flex; }
.avatar-stack > * { margin-left: -4px; border: 1.5px solid var(--bg-panel); border-radius: 50%; }

/* Inbox */
.conv-tag.agent { background: var(--success-soft); color: var(--success); }
.conv-tag.agent .avatar { margin-right: 1px; }
.conv-tag.waiting, .conv-item.attention .conv-tag.agent { background: var(--warning-soft); color: var(--warning); }
.conv-meta-right { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.conv-loc { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.handler-status.waiting { color: var(--warning); }

/* Pesan keluar dengan avatar agen */
.message-row { display: flex; justify-content: flex-end; align-items: flex-end; gap: 8px; }
.message-row .message { max-width: min(68%, 560px); }
.msg-avatar { width: 28px; flex-shrink: 0; }
.message.out .msg-handler { white-space: nowrap; }
.composer-as { display: inline-flex; align-items: center; gap: 6px; margin-right: auto; }
.composer-as b { color: var(--text-secondary); font-weight: 600; }

/* Detail pelanggan */
.hero-loc { font-size: 12.5px; color: var(--text-secondary); }
.chip.waiting { background: var(--warning-soft); color: var(--warning); }
.info-value a { color: var(--brand); word-break: break-all; }

/* Arsip: filter */
.range-presets { display: flex; gap: 2px; padding: 3px; background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.range-presets button { flex: 1; padding: 6px 8px; border: none; background: none; border-radius: 7px; font-size: 12px; font-weight: 500; color: var(--text-secondary); white-space: nowrap; }
.range-presets button:hover { color: var(--text-primary); }
.range-presets button.active { background: var(--bg-panel); color: var(--text-primary); box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
[data-theme="dark"] .range-presets button.active { background: var(--bg-elevated); }
.range-custom { display: none; grid-template-columns: 1fr 1fr; gap: 8px; }
.range-custom.show { display: grid; }
.range-custom label { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--text-muted); font-weight: 600; }
.range-custom input, .filter-row select, .range-custom.inline input {
    width: 100%; height: 34px; padding: 0 8px; border-radius: 8px; background: var(--bg-input); border: 1px solid var(--border-strong); color: var(--text-primary); font-size: 12.5px;
}
.range-custom input:focus, .filter-row select:focus { outline: none; border-color: var(--brand); }
.range-custom.inline { grid-template-columns: auto auto auto; align-items: center; }
.range-custom.inline.show { display: grid; }
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.list-summary { padding: 8px 16px; font-size: 11.5px; color: var(--text-muted); border-bottom: 1px solid var(--border); background: var(--bg-surface); }
.list-summary i { margin-right: 4px; }
.archive-summary { grid-template-columns: repeat(4, 1fr); }
.agent-chips { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; white-space: normal !important; }

/* Laporan */
.reports-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.reports-controls { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.stat-card.amber .stat-icon { background: rgba(245,158,11,.14); color: #fbbf24; }
.report-card { margin-bottom: 20px; }
.report-card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.report-card-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.report-card-head h3 i { color: var(--text-muted); }
.table-wrap { overflow-x: auto; }
.agent-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.agent-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.agent-table td { padding: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.agent-table tbody tr:hover { background: var(--bg-hover); }
.agent-table tbody tr:last-child td { border-bottom: none; }
.agent-cell { display: flex; align-items: center; gap: 10px; }
.agent-cell div { display: flex; flex-direction: column; }
.agent-cell small { font-size: 11.5px; color: var(--text-muted); }
.bar-inline { display: inline-block; width: 60px; height: 6px; border-radius: 3px; background: var(--bg-elevated); margin-right: 8px; vertical-align: middle; overflow: hidden; }
.bar-inline span { display: block; height: 100%; background: var(--brand); border-radius: 3px; }
.agent-table td.fast { color: var(--success); font-weight: 600; }
.agent-table td.ok { color: var(--warning); font-weight: 600; }
.agent-table td.slow { color: var(--danger); font-weight: 600; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-secondary); }
.legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.lg.customer, .seg.customer { background: #38bdf8; }
.lg.agent, .seg.agent { background: #22c55e; }
.lg.ai, .seg.ai { background: #818cf8; }
.bar-chart { gap: 6px; }
.bar-stack { width: 100%; max-width: 44px; min-height: 3px; display: flex; flex-direction: column; border-radius: 6px 6px 2px 2px; overflow: hidden; background: var(--bg-elevated); }
.bar-stack .seg { min-height: 0; }

/* Pengaturan: grup, kartu info, foto, agen */
.settings-group { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 14px 12px 6px; }
.settings-group:first-child { padding-top: 0; }
.info-card { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; margin-bottom: 20px; border-radius: var(--radius-md); background: var(--info-soft); border: 1px solid rgba(59,130,246,.25); color: var(--text-secondary); font-size: 13px; line-height: 1.6; }
.info-card i { color: var(--info); margin-top: 3px; }
.status-card.ok { background: var(--success-soft); border-color: rgba(34,197,94,.35); color: var(--success); }
.status-card.warn { background: var(--warning-soft); border-color: rgba(245,158,11,.35); color: var(--warning); }
.status-card h4 { color: inherit; }
.photo-field { display: flex; align-items: center; gap: 18px; }
.photo-preview { width: 76px; height: 76px; border-radius: 50%; flex-shrink: 0; overflow: hidden; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 700; font-size: 22px; border: 2px dashed var(--border-strong); }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.photo-actions small { font-size: 11.5px; color: var(--text-muted); }
.btn-link { background: none; border: none; color: var(--danger); font-size: 12.5px; padding: 0; }
.btn-link:hover { text-decoration: underline; }
.profile-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.profile-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.agent-grid > .crud-form { grid-column: 1 / -1; }
.agent-card { display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: var(--radius-lg); background: var(--bg-surface); border: 1px solid var(--border); transition: border-color .15s; }
.agent-card:hover { border-color: var(--border-strong); }
.agent-card.inactive { opacity: .6; }
.agent-card .avatar-lg { width: 52px; height: 52px; font-size: 17px; }
.agent-card-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-card-body b { font-size: 14.5px; }
.agent-card-body small { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-card-tags { display: flex; gap: 6px; margin: 6px 0 2px; flex-wrap: wrap; }
.badge-off, .badge-you { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.badge-off { background: var(--bg-elevated); color: var(--text-muted); }
.badge-you { background: var(--brand-soft); color: var(--brand); }
.wp-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.wp-avatar { overflow: hidden; }

/* Banner koneksi */
.conn-banner { position: fixed; top: 12px; left: 50%; transform: translate(-50%, -80px); z-index: 4000; background: var(--warning); color: #111; font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: 20px; box-shadow: var(--shadow-md); transition: transform .25s; }
.conn-banner.show { transform: translate(-50%, 0); }

@media (max-width: 1024px) { .archive-summary { grid-template-columns: repeat(2, 1fr); } }
#reportsContent { transition: opacity .15s; }
#reportsContent.loading { opacity: .45; pointer-events: none; }

/* filter tanggal arsip: susun ke bawah agar tidak terpotong */
#archiveCustom { grid-template-columns: 1fr; }
#archiveCustom label { flex-direction: row; align-items: center; gap: 8px; }
#archiveCustom label span { width: 48px; flex-shrink: 0; }

/* =====================================================================
   v6: PENGATURAN WIDGET (sambutan, link, pra-chat)
   ===================================================================== */
.widget-settings-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 4px; }
.widget-settings-head .info-card { flex: 1; margin-bottom: 16px; }
.widget-settings-head .btn-secondary { flex-shrink: 0; }
.section-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.section-title-row h3 { margin-bottom: 0 !important; }
.settings-card.disabled { opacity: .45; pointer-events: none; }
.row-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.row-item { display: flex; gap: 8px; align-items: flex-start; padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-panel); }
.row-item input, .row-item textarea {
    min-width: 0; padding: 9px 11px; background: var(--bg-input); border: 1px solid var(--border-strong); border-radius: 8px;
    color: var(--text-primary); font-size: 13.5px; line-height: 1.45; font-family: inherit;
}
.row-item input:focus, .row-item textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring); }
.link-row input[data-f="label"] { flex: 0 0 34%; }
.link-row input[data-f="url"] { flex: 1; }
.row-num { width: 22px; height: 22px; flex-shrink: 0; margin-top: 8px; border-radius: 50%; background: var(--bg-elevated); color: var(--text-muted); font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.row-actions { display: flex; gap: 2px; flex-shrink: 0; }
.row-actions .icon-btn { width: 32px; height: 36px; font-size: 13px; }
.row-actions .icon-btn:disabled { opacity: .3; cursor: default; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.topic-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.topic-fields textarea { resize: vertical; }
.crud-check-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-secondary); cursor: pointer; }
.crud-check-inline input { width: 15px; height: 15px; accent-color: var(--brand); }
.btn-secondary.small { height: 32px; padding: 0 12px; font-size: 12.5px; }
.banner-field { display: flex; gap: 16px; align-items: center; }
.banner-preview { width: 120px; height: 90px; border-radius: 12px; overflow: hidden; flex-shrink: 0; display: grid; place-items: center; background: var(--bg-elevated); border: 2px dashed var(--border-strong); color: var(--text-muted); font-size: 12px; }
.banner-preview img { width: 100%; height: 100%; object-fit: cover; }
.sticky-actions { position: sticky; bottom: -32px; margin: 0 -28px -32px; padding: 14px 28px; display: flex; gap: 10px; background: var(--bg-panel); border-top: 1px solid var(--border); z-index: 2; }

/* =====================================================================
   v7: TEKS BRAND ANIMASI DI SIDEBAR
   ===================================================================== */
.rail-nav { flex: 0 0 auto; }
.rail-brand {
    position: relative; flex: 1; width: 100%; min-height: 0;
    display: flex; align-items: center; justify-content: center; overflow: hidden;
    margin: 12px 0;
}
/* garis cahaya tipis di atas & bawah teks */
.rail-brand::before, .rail-brand::after {
    content: ''; position: absolute; left: 50%; width: 2px; height: 18%; transform: translateX(-50%);
    border-radius: 2px; opacity: .7;
    background: linear-gradient(180deg, transparent, #818cf8, #22d3ee, transparent);
    animation: railBeam 3.2s ease-in-out infinite;
}
.rail-brand::before { top: 4%; }
.rail-brand::after { bottom: 4%; animation-delay: 1.6s; }
@keyframes railBeam { 0%, 100% { opacity: .15; transform: translateX(-50%) scaleY(.5); } 50% { opacity: .9; transform: translateX(-50%) scaleY(1); } }

.rail-brand-text {
    position: relative; writing-mode: vertical-rl; transform: rotate(180deg);
    font-size: 15px; font-weight: 700; letter-spacing: .2em; white-space: nowrap; user-select: none;
    /* lapisan 1: kilau putih yang menyapu · lapisan 2: gradasi warna-warni yang mengalir */
    background-image:
        linear-gradient(180deg, transparent 42%, rgba(255,255,255,.95) 50%, transparent 58%),
        linear-gradient(180deg, #818cf8 0%, #22d3ee 18%, #34d399 36%, #fbbf24 54%, #f472b6 72%, #a78bfa 88%, #818cf8 100%);
    background-size: 100% 260%, 100% 300%;
    background-repeat: no-repeat, repeat;
    -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: railFlow 6s linear infinite, railGlow 2.8s ease-in-out infinite;
}
.rail-brand-text b { font-weight: 800; letter-spacing: .26em; }
.rail-brand-text i { font-style: italic; font-weight: 800; }
@keyframes railFlow {
    0% { background-position: 0 160%, 0 0%; }
    45% { background-position: 0 -60%, 0 150%; }
    100% { background-position: 0 -60%, 0 300%; }
}
@keyframes railGlow {
    0%, 100% { filter: drop-shadow(0 0 2px rgba(129,140,248,.35)); }
    50% { filter: drop-shadow(0 0 8px rgba(34,211,238,.75)) drop-shadow(0 0 14px rgba(244,114,182,.35)); }
}

/* partikel kecil yang melayang */
.rail-sparkle { position: absolute; width: 4px; height: 4px; border-radius: 50%; opacity: 0; animation: railSpark 4.5s ease-in-out infinite; }
.rail-sparkle.s1 { left: 18px; background: #22d3ee; box-shadow: 0 0 8px #22d3ee; animation-delay: 0s; }
.rail-sparkle.s2 { right: 16px; background: #f472b6; box-shadow: 0 0 8px #f472b6; animation-delay: 1.5s; }
.rail-sparkle.s3 { left: 50%; background: #fbbf24; box-shadow: 0 0 8px #fbbf24; animation-delay: 3s; }
@keyframes railSpark {
    0% { bottom: 10%; opacity: 0; transform: scale(.4); }
    20% { opacity: 1; transform: scale(1); }
    80% { opacity: .8; }
    100% { bottom: 88%; opacity: 0; transform: scale(.3); }
}
[data-theme="light"] .rail-brand-text {
    background-image:
        linear-gradient(180deg, transparent 42%, rgba(255,255,255,.9) 50%, transparent 58%),
        linear-gradient(180deg, #4f46e5 0%, #0891b2 18%, #059669 36%, #d97706 54%, #db2777 72%, #7c3aed 88%, #4f46e5 100%);
}
@media (max-height: 600px) { .rail-brand { display: none; } .rail-nav { flex: 1; } }
@media (prefers-reduced-motion: reduce) {
    .rail-brand-text, .rail-brand::before, .rail-brand::after, .rail-sparkle { animation: none; }
}
