/* ══════════════════════════════════════════
   CandidShutters ChatBot v2 — Admin Panel
   Dark-first, clean, mobile-friendly
══════════════════════════════════════════ */
:root {
  --bg:       #0b0d12;
  --surface:  #141720;
  --surface2: #1c2030;
  --border:   #252a3a;
  --border2:  #2e3448;
  --fg:       #e8eaf0;
  --fg2:      #8890a8;
  --accent:   #4f6ef7;
  --accent2:  #3d5ce8;
  --green:    #22c55e;
  --red:      #ef4444;
  --orange:   #f97316;
  --yellow:   #fbbf24;
  --radius:   10px;
  --radius-sm:6px;
  --sidebar-w:240px;
  --topbar-h: 56px;
  color-scheme: dark;
}

*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{font-family:'Inter',system-ui,sans-serif;background:var(--bg);color:var(--fg);font-size:14px;line-height:1.5}
a{text-decoration:none;color:inherit}
img{max-width:100%}

/* ── SCROLLBAR ── */
::-webkit-scrollbar{width:5px;height:5px}
::-webkit-scrollbar-track{background:transparent}
::-webkit-scrollbar-thumb{background:var(--border2);border-radius:4px}

/* ══ LOGIN ══════════════════════════════ */
.login-layout{display:flex;align-items:center;justify-content:center;min-height:100vh}
.login-wrapper{width:100%;max-width:400px;padding:24px}
.login-card{background:var(--surface);border:1px solid var(--border);border-radius:16px;padding:40px 36px}
.login-logo{display:flex;align-items:center;gap:14px;margin-bottom:32px}
.logo-title{font-weight:700;font-size:17px}
.logo-sub{font-size:12px;color:var(--fg2)}
.logo-mark{width:44px;height:44px;border-radius:12px;background:var(--accent);display:flex;align-items:center;justify-content:center;font-weight:700;font-size:16px;flex-shrink:0}
.logo-mark.sm{width:32px;height:32px;border-radius:8px;font-size:12px}

/* ══ APP LAYOUT ══════════════════════════ */
.app-layout{display:flex;height:100vh;overflow:hidden}
.sidebar{
  width:var(--sidebar-w);flex-shrink:0;background:var(--surface);
  border-right:1px solid var(--border);display:flex;flex-direction:column;
  height:100vh;overflow-y:auto;transition:transform .25s ease;z-index:100
}
.sidebar-top{flex:1;padding:16px 12px}
.sidebar-bottom{padding:12px;border-top:1px solid var(--border);display:flex;align-items:center;gap:8px}
.sidebar-logo{display:flex;align-items:center;gap:10px;padding:8px 6px;margin-bottom:16px}
.sidebar-brand{font-weight:700;font-size:15px}
.sidebar-brand span{color:var(--fg2);font-weight:400;font-size:12px}
.nav-section{margin-bottom:20px}
.nav-label{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.06em;color:var(--fg2);padding:0 8px;margin-bottom:4px}
.nav-item{
  display:flex;align-items:center;gap:10px;padding:8px 10px;border-radius:var(--radius-sm);
  color:var(--fg2);font-size:13px;font-weight:500;cursor:pointer;transition:.15s;margin-bottom:2px
}
.nav-item svg{width:17px;height:17px;fill:currentColor;flex-shrink:0}
.nav-item:hover{background:var(--surface2);color:var(--fg)}
.nav-item.active{background:rgba(79,110,247,.15);color:var(--accent)}
.user-info{display:flex;align-items:center;gap:8px;flex:1;min-width:0}
.avatar{width:30px;height:30px;border-radius:50%;background:var(--accent);display:flex;align-items:center;justify-content:center;font-weight:700;font-size:13px;flex-shrink:0}
.user-name{font-size:13px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user-role{font-size:11px;color:var(--fg2);text-transform:capitalize}
.main{flex:1;display:flex;flex-direction:column;overflow:hidden}
.topbar{
  height:var(--topbar-h);background:var(--surface);border-bottom:1px solid var(--border);
  display:flex;align-items:center;gap:12px;padding:0 20px;flex-shrink:0
}
.topbar-title{font-size:15px;font-weight:600;flex:1}
.topbar-actions{display:flex;align-items:center;gap:10px}
.content{flex:1;overflow-y:auto;padding:24px}

/* ══ COMMON COMPONENTS ═══════════════════ */

/* Buttons */
.btn{display:inline-flex;align-items:center;gap:6px;padding:7px 16px;border-radius:var(--radius-sm);font-size:13px;font-weight:500;border:1px solid transparent;cursor:pointer;transition:.15s;line-height:1.4}
.btn-primary{background:var(--accent);color:#fff}
.btn-primary:hover{background:var(--accent2)}
.btn-secondary{background:var(--surface2);color:var(--fg);border-color:var(--border2)}
.btn-secondary:hover{background:var(--border)}
.btn-danger{background:#7f1d1d;color:#fca5a5}
.btn-danger:hover{background:#991b1b}
.btn-sm{padding:5px 12px;font-size:12px}
.btn-full{width:100%;justify-content:center}
.btn-icon{background:none;border:none;cursor:pointer;color:var(--fg2);padding:6px;border-radius:6px;display:flex;align-items:center;justify-content:center}
.btn-icon:hover{background:var(--surface2);color:var(--fg)}
.btn-icon svg{width:18px;height:18px;fill:currentColor}
.logout-btn{color:var(--fg2)}

/* Forms */
.field{margin-bottom:16px}
.field label{display:block;font-size:12px;font-weight:500;color:var(--fg2);margin-bottom:6px;text-transform:uppercase;letter-spacing:.04em}
input[type=text],input[type=email],input[type=password],input[type=tel],textarea,select{
  width:100%;background:var(--surface2);border:1px solid var(--border2);border-radius:var(--radius-sm);
  color:var(--fg);font-family:inherit;font-size:13px;padding:9px 12px;outline:none;transition:.15s
}
input::placeholder,textarea::placeholder{color:var(--fg2)}
input:focus,textarea:focus,select:focus{border-color:var(--accent)}
textarea{resize:vertical;min-height:90px}
select option{background:var(--surface)}
.select-sm{padding:5px 10px;font-size:12px;background:var(--surface2);border:1px solid var(--border);border-radius:var(--radius-sm);color:var(--fg);cursor:pointer}

/* Alerts */
.alert{padding:10px 14px;border-radius:var(--radius-sm);font-size:13px;margin-bottom:14px}
.alert-error{background:#7f1d1d40;border:1px solid #7f1d1d;color:#fca5a5}
.alert-success{background:#14532d40;border:1px solid #14532d;color:#86efac}

/* Badge */
.badge{background:var(--red);color:#fff;font-size:10px;font-weight:700;padding:1px 6px;border-radius:10px;margin-left:auto}
.badge.warn{background:var(--orange)}

/* Tables */
.table-wrap{overflow-x:auto;border-radius:var(--radius);border:1px solid var(--border)}
table{width:100%;border-collapse:collapse}
th{background:var(--surface2);font-size:11px;font-weight:600;text-transform:uppercase;letter-spacing:.05em;color:var(--fg2);padding:10px 14px;text-align:left;white-space:nowrap}
td{padding:11px 14px;border-top:1px solid var(--border);font-size:13px;color:var(--fg)}
tr:hover td{background:var(--surface2)}
.td-action{display:flex;gap:6px}

/* Cards */
.cards-row{display:grid;grid-template-columns:repeat(auto-fill,minmax(180px,1fr));gap:14px;margin-bottom:24px}
.stat-card{background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:18px 20px}
.stat-label{font-size:11px;font-weight:600;color:var(--fg2);text-transform:uppercase;letter-spacing:.05em;margin-bottom:8px}
.stat-value{font-size:28px;font-weight:700;line-height:1}
.stat-sub{font-size:12px;color:var(--fg2);margin-top:4px}

/* Section header */
.section-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}
.section-title{font-size:16px;font-weight:600}
.section-actions{display:flex;gap:8px;align-items:center}

/* Status pills */
.pill{display:inline-flex;align-items:center;padding:2px 9px;border-radius:20px;font-size:11px;font-weight:600}
.pill-open{background:#1e3a5f;color:#60a5fa}
.pill-progress{background:#3b1f0a;color:#fb923c}
.pill-closed{background:#14532d;color:#86efac}
.pill-active{background:#14532d;color:#86efac}

/* Empty state */
.empty{text-align:center;padding:48px 24px;color:var(--fg2)}
.empty svg{width:48px;height:48px;fill:var(--border2);margin-bottom:12px}
.empty p{font-size:14px}

/* Tabs */
.tabs{display:flex;border-bottom:1px solid var(--border);margin-bottom:20px;gap:0}
.tab{padding:10px 18px;font-size:13px;font-weight:500;color:var(--fg2);cursor:pointer;border-bottom:2px solid transparent;margin-bottom:-1px}
.tab.active{color:var(--accent);border-bottom-color:var(--accent)}
.tab:hover:not(.active){color:var(--fg)}

/* Code block */
.code-block{background:var(--bg);border:1px solid var(--border);border-radius:var(--radius-sm);padding:14px 16px;font-family:'SF Mono',Consolas,monospace;font-size:12px;line-height:1.7;color:#a5f3fc;overflow-x:auto;white-space:pre}

/* Modal */
.modal-overlay{position:fixed;inset:0;background:#00000080;z-index:1000;display:flex;align-items:center;justify-content:center;padding:20px;backdrop-filter:blur(2px)}
.modal{background:var(--surface);border:1px solid var(--border);border-radius:14px;width:100%;max-width:560px;max-height:90vh;overflow:hidden;display:flex;flex-direction:column}
.modal-header{display:flex;align-items:center;justify-content:space-between;padding:16px 20px;border-bottom:1px solid var(--border)}
.modal-title{font-size:15px;font-weight:600}
.modal-body{padding:20px;overflow-y:auto;flex:1}
.modal-footer{padding:14px 20px;border-top:1px solid var(--border);display:flex;justify-content:flex-end;gap:8px}

/* Toast */
#toast-wrap{position:fixed;bottom:24px;right:24px;z-index:2000;display:flex;flex-direction:column;gap:8px}
.toast{background:var(--surface2);border:1px solid var(--border2);border-radius:var(--radius-sm);padding:10px 16px;font-size:13px;box-shadow:0 4px 16px #0006;animation:slideIn .2s ease;min-width:220px}
.toast.ok{border-left:3px solid var(--green)}
.toast.err{border-left:3px solid var(--red)}
@keyframes slideIn{from{transform:translateX(20px);opacity:0}to{transform:none;opacity:1}}

/* Chat preview */
.chat-msgs{max-height:320px;overflow-y:auto;padding:12px;background:var(--bg);border-radius:var(--radius-sm);border:1px solid var(--border);margin-bottom:12px}
.chat-bubble{margin-bottom:10px;display:flex;gap:8px}
.chat-bubble.user{flex-direction:row-reverse}
.chat-text{max-width:75%;padding:8px 12px;border-radius:10px;font-size:13px;line-height:1.5}
.chat-bubble.user .chat-text{background:var(--accent);color:#fff;border-radius:10px 10px 3px 10px}
.chat-bubble.assistant .chat-text{background:var(--surface2);border-radius:10px 10px 10px 3px}
.chat-time{font-size:10px;color:var(--fg2);align-self:flex-end}

/* KB source badge */
.kb-type{padding:2px 7px;border-radius:4px;font-size:10px;font-weight:600;text-transform:uppercase}
.kb-manual{background:#1e3a5f;color:#60a5fa}
.kb-crawl{background:#3b2060;color:#c084fc}
.kb-url{background:#1a3a2a;color:#4ade80}

/* Embed code copy area */
.embed-preview{background:var(--bg);border:1px solid var(--border);border-radius:var(--radius-sm);padding:16px;position:relative}
.copy-btn{position:absolute;top:10px;right:10px}

/* Loader */
.loader{display:flex;justify-content:center;padding:40px}
.spinner{width:28px;height:28px;border:3px solid var(--border2);border-top-color:var(--accent);border-radius:50%;animation:spin .7s linear infinite}
@keyframes spin{to{transform:rotate(360deg)}}

/* Grid 2-col */
.grid-2{display:grid;grid-template-columns:1fr 1fr;gap:14px}
@media(max-width:640px){.grid-2{grid-template-columns:1fr}}

/* Responsive */
@media(max-width:768px){
  .sidebar{position:fixed;transform:translateX(-100%)}
  .sidebar.open{transform:none}
  .content{padding:16px}
  .cards-row{grid-template-columns:1fr 1fr}
  #menu-toggle{display:flex}
}
@media(min-width:769px){#menu-toggle{display:none}}

/* Ticket detail */
.ticket-info-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;font-size:13px;margin-bottom:16px}
.ti-label{color:var(--fg2);font-size:11px;font-weight:600;text-transform:uppercase}
.note-card{background:var(--surface2);border:1px solid var(--border);border-radius:8px;padding:10px 14px;margin-bottom:8px}
.note-meta{font-size:11px;color:var(--fg2);margin-bottom:4px}
.note-text{font-size:13px}

/* Progress bar */
.progress-wrap{background:var(--border);border-radius:4px;height:6px;margin-top:6px;overflow:hidden}
.progress-fill{height:100%;border-radius:4px;background:var(--accent);transition:.4s}
