*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #4361ee;
    --primary-dark: #3451d1;
    --danger: #e63946;
    --bg: #f5f6fa;
    --surface: #ffffff;
    --text: #2d3436;
    --text-light: #636e72;
    --border: #dfe6e9;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); display: flex; min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }

/* Sidebar: rail ikon (tutup) <-> menu lengkap (buka). State disimpan di localStorage. */
:root { --sidebar-w: 64px; --sidebar-w-open: 250px; --sidebar-w-closed: 64px; }
html.sidebar-open { --sidebar-w: var(--sidebar-w-open); }

.sidebar {
    width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100; padding: .9rem 0; transition: width .2s ease; overflow-x: hidden;
}
.main-content { transition: margin-left .2s ease; }

.sidebar-top { display: flex; align-items: center; padding-bottom: .6rem; margin-bottom: .5rem; border-bottom: 1px solid var(--border); }
.sidebar-toggle {
    position: relative; width: var(--sidebar-w-closed, 64px); height: 44px; flex-shrink: 0; border: none; background: none; cursor: pointer;
    font-size: 1.35rem; color: var(--text-light); display: flex; align-items: center; justify-content: center; transition: color .15s, background .15s;
}
.sidebar-toggle:hover { color: var(--primary); background: #eef1ff; }
.logo { font-size: .95rem; font-weight: 700; color: var(--primary); line-height: 1.2; white-space: normal; padding-right: .8rem; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: .15rem; overflow-y: auto; }
.nav-item {
    position: relative; display: flex; align-items: center; gap: .9rem; height: 50px; padding: 0 1.15rem;
    font-size: 1.3rem; color: var(--text-light); background: none; border: none; width: 100%; font-family: inherit;
    cursor: pointer; text-align: left; white-space: nowrap; transition: background .15s, color .15s;
}
.nav-item i { width: 26px; text-align: center; flex-shrink: 0; }
.nav-item:hover, .nav-item.active { background: #eef1ff; color: var(--primary); }
.nav-item.active { box-shadow: inset 3px 0 0 var(--primary); }
.nav-label { font-size: .9rem; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .15s; }
html.sidebar-open .nav-label { opacity: 1; pointer-events: auto; }

.sidebar-bottom { border-top: 1px solid var(--border); padding-top: .4rem; }
.sidebar-footer { position: relative; display: flex; align-items: center; gap: .9rem; padding: .7rem 1.15rem .2rem; font-size: 1.5rem; color: var(--text-light); white-space: nowrap; }
.sidebar-footer i { width: 26px; text-align: center; flex-shrink: 0; }
.footer-text { display: flex; flex-direction: column; line-height: 1.25; }
.footer-text strong { font-size: .85rem; color: var(--text); }
.footer-text small { font-size: .72rem; text-transform: uppercase; color: var(--text-light); }

/* tooltip hanya saat sidebar tertutup */
html:not(.sidebar-open) [data-tip]:hover::after {
    content: attr(data-tip); position: absolute; left: calc(100% - 6px); top: 50%; transform: translateY(-50%);
    background: #2d3436; color: #fff; font-size: .78rem; padding: .3rem .6rem; border-radius: 6px; white-space: nowrap; z-index: 200; pointer-events: none;
}

/* Main */
.main-content { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }
.top-bar {
    background: var(--surface); border-bottom: 1px solid var(--border); padding: .8rem 1.5rem;
    display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 50;
}
.top-title { font-weight: 600; font-size: 1.05rem; }
.menu-btn { display: none; border: none; background: none; font-size: 1.5rem; cursor: pointer; color: var(--text); }
.content-area { flex: 1; padding: 1rem; max-width: none; width: 100%; margin: 0 auto; display: flex; flex-direction: column; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 90; }

/* Buttons & forms */
.btn {
    display: inline-flex; align-items: center; gap: .4rem; padding: .55rem 1.2rem; border: none;
    border-radius: var(--radius); font: inherit; font-size: .9rem; font-weight: 500; cursor: pointer;
    transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-small { padding: .3rem .7rem; font-size: .8rem; background: var(--bg); color: var(--text); }
.btn-small:hover { background: var(--border); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; box-shadow: var(--shadow); }
.form-group { margin-bottom: .9rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 500; margin-bottom: .3rem; }
input[type="text"], input[type="password"], textarea {
    width: 100%; padding: .55rem .75rem; border: 1px solid var(--border); border-radius: 6px;
    font: inherit; font-size: .92rem; background: var(--surface); transition: border-color .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); }

/* Chat */
.chat-wrap {
    display: flex; flex-direction: column; height: calc(100vh - 5.2rem);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat-messages { flex: 1; overflow-y: auto; padding: 1.2rem 1.5rem; display: flex; flex-direction: column; gap: .9rem; }
.chat-hero { margin: auto; text-align: center; max-width: 760px; padding: 2rem 1rem; }
.chat-hero h1 { font-size: 2.2rem; font-weight: 800; color: #1f4e9c; margin-bottom: .6rem; line-height: 1.25; }
.chat-hero p { color: var(--text-light); font-size: .95rem; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
    max-width: 80%; padding: .7rem 1rem; border-radius: 14px; line-height: 1.55; font-size: .92rem;
    white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: var(--bg); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.bot .bubble:has(.chat-table), .msg.bot .bubble:has(.chat-chart) { max-width: 100%; width: 100%; }
.bubble.error { background: #fdeaea !important; color: var(--danger); border-color: #f5c2c7 !important; }
.chat-meta { margin-top: .5rem; font-size: .8rem; color: var(--text-light); }

.chat-chart { margin-top: .8rem; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); height: 360px; }
.chat-table { margin-top: .8rem; max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; white-space: normal; }
.chat-table table { border-collapse: collapse; width: 100%; font-size: .8rem; }
.chat-table th { position: sticky; top: 0; background: #eef1ff; color: #1f4e9c; text-align: left; padding: .5rem .6rem; white-space: nowrap; }
.chat-table td { padding: .4rem .6rem; border-top: 1px solid var(--border); white-space: nowrap; }
.chat-table tr:hover td { background: #f7f8ff; }
.btn-excel { margin-top: .7rem; background: #1d6f42; color: #fff; }
.btn-excel:hover { background: #155a35; }

.chat-input { display: flex; gap: .6rem; padding: .8rem 1rem; border-top: 1px solid var(--border); align-items: flex-end; }
.chat-input textarea { resize: none; max-height: 140px; line-height: 1.4; }

.typing { display: inline-flex; gap: 3px; margin-right: .4rem; vertical-align: middle; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--primary); opacity: .3; animation: typing 1s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes typing { 50% { opacity: 1; transform: translateY(-2px); } }

/* ── Umum: halaman admin ─────────────────────────── */
.muted { color: var(--text-light); font-size: .85rem; }
.error-text { color: var(--danger); }
select, input[type="date"] {
    padding: .5rem .7rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; font-size: .9rem; background: var(--surface);
}
select { width: 100%; }
.checkbox-label { display: inline-flex; align-items: center; gap: .4rem; font-size: .9rem; cursor: pointer; }
.page-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.4rem 1.6rem; }
.page-toolbar { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-toolbar h2 { font-size: 1.2rem; margin-bottom: .2rem; }
.toolbar-right { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.toolbar-right input[type="text"] { width: 260px; }

.user-chip { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--text-light); }
.role-badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; background: var(--bg); color: var(--text-light); margin-left: .4rem; }
.role-badge.role-admin { background: #eef1ff; color: var(--primary); }
.role-badge.role-sales { background: #e8faf3; color: #1a7a54; }
.status { font-size: .8rem; font-weight: 600; }
.status.on { color: #1a7a54; }
.status.off { color: var(--danger); }

.data-table { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.data-table table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.data-table th { background: var(--bg); text-align: left; padding: .65rem .9rem; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-light); }
.data-table td { padding: .6rem .9rem; border-top: 1px solid var(--border); }
.data-table tr:hover td { background: #f7f8ff; }
.icon-btn { border: none; background: none; cursor: pointer; font-size: 1.05rem; color: var(--primary); padding: .2rem .4rem; border-radius: 6px; }
.icon-btn:hover { background: #eef1ff; }
.icon-btn.danger { color: var(--danger); }
.icon-btn.danger:hover { background: #fdeaea; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay[hidden] { display: none; }
.modal-box { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 440px; box-shadow: 0 8px 32px rgba(0,0,0,.15); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.2rem; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal-close { border: none; background: none; cursor: pointer; font-size: 1rem; color: var(--text-light); }
.modal-body { padding: 1.1rem 1.2rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.2rem; border-top: 1px solid var(--border); }
.form-error { margin-top: .8rem; background: #fdeaea; color: var(--danger); padding: .55rem .8rem; border-radius: 6px; font-size: .85rem; }
input:disabled { background: var(--bg); color: var(--text-light); }

/* History */
#history-summary { margin-bottom: .8rem; }
.h-group { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .7rem; background: var(--surface); }
.h-group summary { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; cursor: pointer; list-style: none; }
.h-group summary::-webkit-details-marker { display: none; }
.h-group[open] summary { border-bottom: 1px solid var(--border); background: #fafbff; }
.h-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.h-who { flex: 1; }
.h-meta { font-size: .8rem; color: var(--text-light); }
.h-list { padding: .6rem 1rem 1rem; display: flex; flex-direction: column; gap: .7rem; max-height: 560px; overflow-y: auto; }
.h-item { border-left: 3px solid var(--primary); background: var(--bg); border-radius: 0 var(--radius) var(--radius) 0; padding: .7rem .9rem; }
.h-item-head { display: flex; gap: .6rem; align-items: center; margin-bottom: .35rem; flex-wrap: wrap; }
.h-time { font-size: .78rem; color: var(--text-light); }
.h-q { font-weight: 600; margin-bottom: .3rem; }
.h-a { font-size: .88rem; line-height: 1.5; white-space: pre-wrap; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.chip { font-size: .72rem; background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: .15rem .55rem; color: var(--text-light); }
.chip-blue { background: #eef1ff; border-color: #d5dcff; color: var(--primary); }
.btn-rerun { margin-top: .6rem; display: flex; }
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-light); }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .8rem; color: var(--border); }
.empty-state h2 { font-size: 2rem; color: var(--text); }
