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

:root {
  --primary:       #0066cc;
  --primary-dark:  #004fa3;
  --primary-light: #e8f0fb;
  --accent:        #00a3bf;
  --danger:        #d32f2f;
  --success:       #2e7d32;
  --text:          #1a1a2e;
  --text-muted:    #6b7280;
  --border:        #d1d5db;
  --bg:            #f3f4f6;
  --white:         #ffffff;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 12px rgba(0,0,0,.10);
  --radius:        8px;
  --font:          'Inter', system-ui, -apple-system, sans-serif;
  /* Chat-specific */
  --chat-bg:       #0b141a;
  --chat-sidebar:  #111b21;
  --chat-border:   #222d35;
  --chat-hover:    #202c33;
  --chat-active:   #2a3942;
  --chat-text:     #e9edef;
  --chat-text-sec: #8696a0;
  --chat-bubble:   #005c4b;
  --chat-bubble-in:#1f2c33;
  --chat-msg-bg:   #0b141a;
}

body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.5; }
a    { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   Utility
   ============================================================ */
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem 1.2rem; border: none; border-radius: var(--radius);
  font-size: .9rem; font-weight: 600; cursor: pointer; transition: background .2s, box-shadow .2s;
}
.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-sm); }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.badge {
  display: inline-block; padding: .15rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #dcfce7; color: #166534; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray   { background: #f3f4f6; color: #374151; }

/* ============================================================
   Login Page
   ============================================================ */
.login-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0a1628 0%, #0d2b5e 50%, #0a1628 100%);
}

.login-card {
  background: var(--white); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  padding: 2.5rem 2rem; width: 100%; max-width: 420px;
}

.login-logo {
  text-align: center; margin-bottom: 1.8rem;
}
.login-logo svg { width: 48px; height: 48px; margin-bottom: .5rem; }
.login-logo h1 { font-size: 1.5rem; font-weight: 700; color: var(--text); }
.login-logo p  { font-size: .85rem; color: var(--text-muted); margin-top: .2rem; }

.form-group { margin-bottom: 1.1rem; }
.form-group label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-group input {
  width: 100%; padding: .65rem .9rem; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; transition: border-color .2s, box-shadow .2s;
  outline: none;
}
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,102,204,.12); }
.form-group .input-wrap { position: relative; }
.form-group .input-wrap input { padding-right: 2.5rem; }
.form-group .toggle-pw {
  position: absolute; right: .75rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-muted); padding: 0; line-height: 1;
}

.login-error {
  background: #fee2e2; border: 1px solid #fca5a5; color: var(--danger);
  border-radius: var(--radius); padding: .65rem .9rem; font-size: .85rem; margin-bottom: 1rem;
}

.btn-login { width: 100%; justify-content: center; padding: .75rem; font-size: 1rem; border-radius: var(--radius); margin-top: .3rem; }

.login-divider {
  height: 1px; background: var(--border); margin: 1.2rem 0;
}

/* ============================================================
   Chat Layout (WhatsApp-style)
   ============================================================ */
.chat-layout {
  display: flex; height: 100vh; overflow: hidden;
  background: var(--chat-bg);
}

/* ── OTP Login Styles ──────────────────────────────────────────────────── */
.otp-phone-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem .75rem;
  background: var(--bg, #f3f4f6);
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: .85rem;
  color: var(--text-muted, #6b7280);
}
.otp-input-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.otp-box {
  width: 44px;
  height: 50px;
  text-align: center;
  font-size: 1.3rem;
  font-weight: 700;
  border: 2px solid var(--border, #d1d5db);
  border-radius: 8px;
  outline: none;
  font-family: var(--font);
  transition: border-color .15s;
}
.otp-box:focus { border-color: #00a884; }
.otp-resend-row {
  text-align: center;
  margin-top: .75rem;
  font-size: .8rem;
  color: var(--text-muted, #6b7280);
}
.btn-link {
  background: none;
  border: none;
  color: #00a884;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  font-family: var(--font);
}
.btn-link:hover { text-decoration: underline; }

/* ── Left Panel: Chat Sidebar ──────────────────────────────────────────── */
.chat-sidebar {
  width: 380px; min-width: 320px; max-width: 420px;
  background: var(--chat-sidebar); display: flex; flex-direction: column;
  border-right: 1px solid var(--chat-border); flex-shrink: 0;
}

.chat-sidebar-header {
  padding: .8rem 1rem; display: flex; align-items: center; justify-content: space-between;
  background: var(--chat-sidebar); border-bottom: 1px solid var(--chat-border);
}
.chat-sidebar-brand {
  display: flex; align-items: center; gap: .6rem;
}
.brand-title { font-size: 1.1rem; font-weight: 700; color: var(--chat-text); }
.brand-version { font-size: .65rem; color: var(--chat-text-sec); margin-left: .3rem; }

.chat-sidebar-actions {
  display: flex; align-items: center; gap: .2rem;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: transparent; color: var(--chat-text-sec); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s; position: relative;
}
.icon-btn:hover { background: var(--chat-hover); color: var(--chat-text); }
.icon-btn::after {
  content: attr(title); position: absolute; bottom: -28px; left: 50%;
  transform: translateX(-50%); padding: 3px 8px; border-radius: 4px;
  background: #e9edef; color: #111b21; font-size: .65rem; font-weight: 600;
  white-space: nowrap; pointer-events: none; opacity: 0;
  transition: opacity .15s; z-index: 10;
}
.icon-btn:hover::after { opacity: 1; }

/* Search */
.chat-sidebar-search {
  padding: .5rem .8rem; position: relative;
  background: var(--chat-sidebar);
}
.chat-sidebar-search svg {
  position: absolute; left: 1.6rem; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--chat-text-sec); pointer-events: none;
}
.chat-sidebar-search input {
  width: 100%; padding: .5rem .8rem .5rem 2.4rem;
  background: var(--chat-hover); border: none; border-radius: 8px;
  color: var(--chat-text); font-size: .85rem; outline: none;
}
.chat-sidebar-search input::placeholder { color: var(--chat-text-sec); }


.sidebar-section-label {
  padding: .5rem 1rem .3rem; font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--chat-text-sec);
}

/* Group List */
.chat-group-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
}
.chat-group-list::-webkit-scrollbar { width: 6px; }
.chat-group-list::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 3px; }

.chat-group-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1rem; cursor: pointer; transition: background .1s;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.chat-group-item:hover { background: var(--chat-hover); }
.chat-group-item.active { background: var(--chat-active); }

.chat-group-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: #00a884; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 700; flex-shrink: 0;
  text-transform: uppercase;
}

.chat-group-info { flex: 1; min-width: 0; }
.chat-group-name {
  font-size: .9rem; font-weight: 500; color: var(--chat-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-group-preview {
  font-size: .78rem; color: var(--chat-text-sec);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-group-unread {
  background: #00a884; color: #fff;
  font-size: .7rem; font-weight: 700;
  min-width: 20px; height: 20px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px; flex-shrink: 0;
}

.chat-group-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0;
}
.chat-group-time {
  font-size: .7rem; color: var(--chat-text-sec); white-space: nowrap;
}
.chat-group-count {
  font-size: .65rem; color: #fff; background: #00a884;
  border-radius: 999px; padding: 1px 6px; font-weight: 600;
}

/* Sidebar Footer */
.chat-sidebar-footer {
  padding: .75rem 1rem; border-top: 1px solid var(--chat-border);
  background: var(--chat-sidebar);
}
.app-version {
  font-size: .6rem;
  color: var(--chat-text-sec);
  opacity: .5;
  margin-top: .4rem;
  letter-spacing: .03em;
  padding-left: calc(34px + .6rem);
}
.user-info-row {
  display: flex; align-items: center; gap: .6rem;
}
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; color: #fff; flex-shrink: 0;
}
.user-details { flex: 1; min-width: 0; }
.user-name { display: block; font-size: .85rem; font-weight: 600; color: var(--chat-text); }
.user-phone { display: block; font-size: .7rem; color: var(--chat-text-sec); }
.admin-badge {
  font-size: .6rem; font-weight: 700; color: #00a884;
  border: 1px solid #00a884; border-radius: 4px; padding: 1px 6px;
}

/* ── Right Panel: Chat Main ────────────────────────────────────────────── */
.chat-main {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--chat-msg-bg);
}

/* Chat Header */
.chat-header {
  padding: .6rem 1rem; display: flex; align-items: center; justify-content: space-between;
  background: var(--chat-sidebar); border-bottom: 1px solid var(--chat-border);
  flex-shrink: 0;
}
.chat-header-info { display: flex; align-items: center; gap: .75rem; }
.chat-header-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--chat-active); color: var(--chat-text-sec);
  display: flex; align-items: center; justify-content: center;
}
.chat-header-name { font-size: .95rem; font-weight: 600; color: var(--chat-text); }
.chat-header-count { font-size: .75rem; color: var(--chat-text-sec); }

.chat-header-actions { display: flex; align-items: center; gap: .5rem; }

/* Message search (right panel) */
.msg-search-wrap {
  position: relative; width: 200px;
}
.msg-search-wrap svg {
  position: absolute; left: .6rem; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--chat-text-sec); pointer-events: none;
}
.msg-search-wrap input {
  width: 100%; padding: .35rem .6rem .35rem 2rem;
  background: var(--chat-hover); border: 1px solid var(--chat-border); border-radius: 6px;
  color: var(--chat-text); font-size: .78rem; outline: none;
  transition: border-color .15s;
}
.msg-search-wrap input::placeholder { color: var(--chat-text-sec); }
.msg-search-wrap input:focus { border-color: #00a884; }

/* Messages Area */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 3rem;
  background: var(--chat-msg-bg);
  position: relative;
}

/* Sticky floating date header (WhatsApp style) */
.chat-sticky-date {
  position: sticky;
  top: 0;
  z-index: 10;
  text-align: center;
  padding: .4rem 0;
  pointer-events: none;
}
.chat-sticky-date span {
  display: inline-block;
  padding: .25rem .9rem;
  background: var(--chat-hover);
  border-radius: 7px;
  font-size: .72rem;
  color: var(--chat-text-sec);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
  transition: opacity .2s;
}
.chat-sticky-date.hidden-date span {
  opacity: 0;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--chat-border); border-radius: 3px; }

/* Message Bubble */
.msg-bubble {
  max-width: 65%; margin-bottom: .5rem;
  background: var(--chat-bubble-in); border-radius: 8px;
  padding: .5rem .65rem; position: relative;
  box-shadow: 0 1px 1px rgba(0,0,0,.13);
}
.msg-top-actions {
  position: absolute; top: 8px; right: 8px;
  display: flex; align-items: center; gap: 4px;
  z-index: 2;
}
.msg-report-icon {
  background: none; border: none; cursor: pointer;
  color: var(--chat-text-sec); opacity: .5;
  padding: 4px; border-radius: 6px; display: flex; align-items: center;
  transition: opacity .15s, background .15s, color .15s;
  position: relative;
}
.msg-report-icon:hover {
  opacity: 1; color: #00a884;
  background: rgba(0,168,132,.12);
}
.msg-report-tooltip {
  display: none; position: absolute; bottom: calc(100% + 6px); right: 0;
  background: #1a1a2e; color: #fff; font-size: .68rem; font-weight: 500;
  padding: 4px 8px; border-radius: 4px; white-space: nowrap;
  pointer-events: none;
}
.msg-report-icon:hover .msg-report-tooltip { display: block; }
.msg-po-badge {
  background: rgba(0,168,132,.18);
  color: #00a884;
  font-size: .7rem; font-weight: 600;
  padding: 3px 8px; border-radius: 10px;
  border: 1px solid rgba(0,168,132,.4);
  letter-spacing: .2px; line-height: 1;
  max-width: 140px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.msg-sender {
  font-size: .78rem; font-weight: 600; color: #00a884;
  margin-bottom: 2px;
}

.msg-text {
  font-size: .87rem; color: var(--chat-text); line-height: 1.45;
  word-wrap: break-word; white-space: pre-wrap;
}

.msg-media {
  margin-top: .4rem;
}
.msg-media img {
  max-width: 200px; max-height: 150px; border-radius: 6px;
  cursor: pointer; object-fit: cover;
}
.msg-media-video {
  position: relative; cursor: pointer; display: inline-block;
}
.msg-media-video video {
  max-width: 250px; max-height: 200px; border-radius: 6px;
  object-fit: cover; pointer-events: none; display: block;
}
.msg-video-play {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(0,0,0,.55); display: flex; align-items: center;
  justify-content: center; transition: background .15s;
}
.msg-media-video:hover .msg-video-play { background: rgba(0,0,0,.75); }
.msg-media-fallback {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .4rem .7rem; background: rgba(255,255,255,.06);
  border-radius: 6px; color: var(--chat-text-sec); font-size: .78rem;
}
.msg-doc-card {
  display: flex; align-items: center; gap: .65rem;
  padding: .6rem .75rem; background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08); border-radius: 10px;
  color: var(--chat-text); text-decoration: none;
  transition: background .15s; min-width: 220px; max-width: 320px;
}
.msg-doc-card:hover { background: rgba(255,255,255,.1); }
.msg-doc-icon {
  width: 42px; height: 42px; border-radius: 8px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  position: relative;
}
.msg-doc-ext {
  font-size: .55rem; font-weight: 700; letter-spacing: .03em;
  margin-top: -2px;
}
.msg-doc-info {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px;
}
.msg-doc-name {
  font-size: .82rem; font-weight: 500; color: var(--chat-text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-doc-meta {
  font-size: .68rem; color: var(--chat-text-sec);
}
.msg-doc-dl {
  flex-shrink: 0; color: var(--chat-text-sec); opacity: .6;
  transition: opacity .15s;
}
.msg-doc-card:hover .msg-doc-dl { opacity: 1; }
.msg-media-audio { margin-top: .4rem; }
.msg-audio-wrap {
  display: flex; align-items: center; gap: .4rem;
  color: var(--chat-text-sec); font-size: .75rem; margin-bottom: .25rem;
}
.msg-location-card { margin-top: .4rem; max-width: 280px; }
.msg-location-card-link {
  display: block; text-decoration: none; border-radius: 8px;
  overflow: hidden; border: 1px solid rgba(255,255,255,.08);
  transition: border-color .15s;
}
.msg-location-card-link:hover { border-color: rgba(0,168,132,.3); }
.msg-location-map {
  width: 100%; height: 140px; background: #1a2233;
  position: relative; overflow: hidden;
}
.msg-location-map img {
  width: 100%; height: 100%; object-fit: cover;
  filter: brightness(.85);
}
.msg-location-pin {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -80%);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.4));
  pointer-events: none;
}
.msg-location-info {
  display: flex; align-items: center; gap: .4rem;
  padding: .45rem .6rem; background: rgba(0,168,132,.06);
  color: #00a884; font-size: .78rem;
}
.msg-location-info span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-vcard {
  margin-top: .4rem; display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .75rem; background: rgba(255,255,255,.06);
  border-radius: 8px; color: var(--chat-text); font-size: .8rem;
}

.msg-time {
  font-size: .65rem; color: var(--chat-text-sec); text-align: right;
  margin-top: 2px;
}

/* AI Processed Block */
.msg-ai-block {
  margin-top: .4rem; padding: .5rem .6rem;
  background: rgba(0,168,132,.08); border-left: 3px solid #00a884;
  border-radius: 0 6px 6px 0;
}
.msg-ai-label {
  font-size: .65rem; color: var(--chat-text-sec); text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: 3px;
}
.msg-ai-class {
  font-size: .82rem; font-weight: 600; color: #00a884; margin-bottom: 2px;
}
.msg-ai-info {
  font-size: .78rem; color: var(--chat-text-sec); line-height: 1.4;
  font-style: italic;
}

/* AI metadata (verified by, analysed by, shift) */
.msg-ai-meta {
  display: flex; flex-wrap: wrap; gap: .4rem .8rem;
  margin-top: .4rem; padding-top: .35rem;
  border-top: 1px solid rgba(0,168,132,.15);
}
.msg-ai-meta-item {
  font-size: .72rem; color: var(--chat-text-sec);
}
.msg-ai-meta-label {
  font-weight: 700; color: var(--chat-text-sec); text-transform: uppercase;
  font-size: .65rem; letter-spacing: .03em;
}

/* View Report button */
.msg-view-report-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  margin-top: .6rem; padding: .35rem .8rem;
  background: rgba(0,168,132,.12); color: #00a884;
  border: 1px solid rgba(0,168,132,.25); border-radius: 6px;
  font-size: .78rem; font-weight: 600; cursor: pointer;
  transition: all .15s;
}
.msg-view-report-btn:hover {
  background: rgba(0,168,132,.22); border-color: #00a884;
}
.msg-view-report-btn svg { flex-shrink: 0; }

/* Feedback buttons (kept for future use) */
.msg-feedback {
  display: flex; align-items: center; gap: .8rem;
  margin-top: .5rem; padding-top: .4rem;
  border-top: 1px dashed var(--chat-border);
}
.msg-feedback-label {
  font-size: .72rem; color: var(--chat-text-sec);
}
.feedback-btn {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .2rem .6rem; border-radius: 999px;
  border: 1px solid var(--chat-border); background: transparent;
  color: var(--chat-text-sec); font-size: .72rem; font-weight: 500;
  cursor: pointer; transition: all .15s;
}
.feedback-btn:hover {
  background: var(--chat-hover); color: var(--chat-text);
}
.feedback-btn.correct:hover { border-color: #00a884; color: #00a884; }
.feedback-btn.incorrect:hover { border-color: #ef4444; color: #ef4444; }
.feedback-btn svg { width: 12px; height: 12px; }

/* Approved status */
.msg-status {
  display: flex; align-items: center; gap: .3rem;
  font-size: .72rem; color: #00a884; margin-top: 3px;
}
.msg-status svg { width: 12px; height: 12px; }

/* Overlay states */
.chat-overlay {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 3rem 1rem; color: var(--chat-text-sec); gap: .7rem; flex: 1;
}
.chat-overlay svg { width: 40px; height: 40px; opacity: .35; }
.chat-overlay p   { font-size: .9rem; }

.spinner {
  width: 36px; height: 36px; border: 3px solid var(--chat-border);
  border-top-color: #00a884; border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Scroll status bar */
.chat-pagination {
  padding: .4rem 1rem; border-top: 1px solid var(--chat-border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: .5rem; background: var(--chat-sidebar);
  flex-shrink: 0;
}
.page-info { font-size: .8rem; color: var(--chat-text-sec); }
.page-btns { display: flex; align-items: center; gap: .3rem; }
.scroll-loading-hint {
  font-size: .78rem; color: var(--chat-text-sec); font-style: italic;
}

/* Error banner */
.error-banner {
  background: #fee2e2; border: 1px solid #fca5a5; color: var(--danger);
  border-radius: 0; padding: .75rem 1rem; font-size: .875rem;
  display: flex; align-items: center; gap: .6rem;
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Toast */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: #1f2937; color: #f9fafb; padding: .7rem 1.1rem; border-radius: var(--radius);
  font-size: .85rem; box-shadow: var(--shadow-md); animation: slideIn .25s ease;
  display: flex; align-items: center; gap: .5rem; max-width: 340px;
}
.toast.success { border-left: 3px solid #22c55e; }
.toast.error   { border-left: 3px solid var(--danger); }
@keyframes slideIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Date range picker */
.date-range-picker { position: relative; }

.date-range-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .3rem .65rem; border: 1px solid var(--chat-border); border-radius: 6px;
  background: var(--chat-hover); color: var(--chat-text-sec); font-size: .78rem; font-weight: 500;
  cursor: pointer; transition: border-color .15s; white-space: nowrap;
}
.date-range-btn:hover { border-color: #00a884; color: var(--chat-text); }
.date-range-btn .chevron { opacity: .5; transition: transform .2s; }

.date-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 500;
  background: var(--chat-sidebar); border: 1px solid var(--chat-border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); min-width: 220px; overflow: hidden;
}

.date-presets { padding: .4rem 0; }
.date-preset {
  display: block; width: 100%; padding: .45rem 1rem;
  background: none; border: none; text-align: left;
  font-size: .83rem; color: var(--chat-text); cursor: pointer; transition: background .1s;
}
.date-preset:hover  { background: var(--chat-hover); }
.date-preset.active { background: rgba(0,168,132,.15); color: #00a884; font-weight: 600; }

.date-divider { height: 1px; background: var(--chat-border); margin: .2rem 0; }

.date-custom-section { padding: .75rem 1rem; display: flex; flex-direction: column; gap: .5rem; }
.date-custom-title   { font-size: .75rem; font-weight: 700; color: var(--chat-text-sec); text-transform: uppercase; letter-spacing: .04em; }
.date-custom-row     { display: flex; align-items: center; gap: .5rem; }
.date-custom-row label { font-size: .78rem; color: var(--chat-text-sec); width: 28px; flex-shrink: 0; }
.date-custom-row input {
  flex: 1; padding: .3rem .5rem; border: 1px solid var(--chat-border); border-radius: 6px;
  font-size: .78rem; outline: none; font-family: var(--font);
  background: var(--chat-hover); color: var(--chat-text);
}
.date-custom-row input:focus { border-color: #00a884; }

/* Filter select */
.filter-select {
  padding: .3rem .6rem; border: 1px solid var(--chat-border); border-radius: 6px;
  font-size: .78rem; outline: none; background: var(--chat-hover);
  cursor: pointer; color: var(--chat-text-sec);
}
.filter-select:focus { border-color: #00a884; }

/* ── AI Class button ──────────────────────────────────────────────────────── */
.ai-class-btn {
  display: inline-block; padding: .25rem .6rem;
  background: var(--primary-light); color: var(--primary);
  border: 1px solid var(--primary); border-radius: 6px;
  font-size: .78rem; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.ai-class-btn:hover { background: var(--primary); color: #fff; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--white); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-width: 1100px; width: 100%;
  max-height: 85vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.modal-close {
  background: none; border: none; font-size: 1.1rem;
  cursor: pointer; color: var(--text-muted); padding: .25rem .4rem;
  border-radius: 4px; line-height: 1;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { overflow: auto; padding: 1rem 1.25rem; }

.modal-table-wrap { overflow-x: auto; }

.modal-table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
  white-space: nowrap;
}
.modal-table th {
  background: var(--bg); color: var(--text-muted);
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; padding: .5rem .7rem; text-align: left;
  border-bottom: 1px solid var(--border); position: sticky; top: 0;
}
.modal-table td {
  padding: .45rem .7rem; border-bottom: 1px solid var(--border);
  color: var(--text);
}
.modal-table tr:last-child td { border-bottom: none; }
.modal-table tr:hover td { background: var(--bg); }

/* ── Detail strip (compact row inside AI modal) ──────────────────────────── */
.detail-strip {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  background: var(--bg); border-radius: var(--radius); padding: .6rem 1rem;
  margin-bottom: .75rem;
}
.detail-strip-item {
  display: flex; align-items: center; gap: .35rem;
}
.detail-strip-label {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); white-space: nowrap;
}
.detail-strip-value {
  font-size: .82rem; color: var(--text); font-weight: 500;
}
.detail-strip-sep {
  width: 1px; height: 1.1rem; background: var(--border); flex-shrink: 0;
}
.detail-summary {
  display: flex; align-items: baseline; gap: .5rem;
  padding: .5rem 1rem; margin-bottom: .75rem;
  background: var(--bg); border-radius: var(--radius);
}
.detail-summary-text {
  font-size: .82rem; color: var(--text); line-height: 1.5;
}

.media-modal-box { max-width: 800px; }

.detail-section-title {
  font-size: .8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); margin-bottom: .6rem;
  padding-bottom: .4rem; border-bottom: 1px solid var(--border);
}

/* ── Date separator in chat ──────────────────────────────────────────────── */
.chat-date-sep {
  text-align: center; margin: 1rem 0 .5rem;
}
.chat-date-sep span {
  display: inline-block; padding: .25rem .8rem;
  background: var(--chat-hover); border-radius: 6px;
  font-size: .72rem; color: var(--chat-text-sec); font-weight: 500;
}

/* ── Reports Button ──────────────────────────────────────────── */
.reports-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: #00a884;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.reports-btn:hover { background: #00c49a; }
.reports-btn.hidden { display: none; }

/* Report type selector dropdown */
.report-selector-dropdown {
  position: absolute; top: 100%; left: 0; z-index: 100;
  background: var(--white); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); min-width: 180px; padding: 4px 0;
  margin-top: 4px;
}
.report-selector-item {
  display: block; padding: 10px 16px; color: var(--text); text-decoration: none;
  font-size: .85rem; font-weight: 500; transition: background .15s;
}
.report-selector-item:hover { background: var(--bg); color: #00a884; }

/* ── Reports Modal ──────────────────────────────────────────── */
.reports-modal-box {
  max-width: 900px;
  width: 95vw;
}
.reports-modal-box .modal-body {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 0;
}
.rm-table-scroll {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.rm-summary-strip {
  display: flex;
  gap: 1rem;
  padding: .75rem 1rem;
  background: var(--chat-hover, #202c33);
  border-radius: 8px;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.rm-summary-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 100px;
}
.rm-summary-label {
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--chat-text-sec, #8696a0);
  letter-spacing: .5px;
}
.rm-summary-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: #00a884;
}

/* ── Admin Dashboard Modal ───────────────────────────────────── */
.admin-modal-box {
  max-width: 960px;
  width: 95vw;
  max-height: 85vh;
}
.admin-tabs {
  display: flex;
  border-bottom: 2px solid var(--border, #d1d5db);
  padding: 0 1.25rem;
  background: var(--white, #fff);
}
.admin-tab {
  padding: .65rem 1.25rem;
  border: none;
  background: none;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-muted, #6b7280);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.admin-tab:hover { color: var(--text, #1a1a2e); }
.admin-tab.active {
  color: #00a884;
  border-bottom-color: #00a884;
  font-weight: 600;
}
.admin-body {
  overflow-y: auto;
  padding: 1.25rem !important;
}
.admin-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
.admin-form-panel,
.admin-list-panel,
.admin-access-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}
.admin-access-footer {
  position: sticky;
  bottom: 0;
  background: #fff;
  padding: .75rem 0 0;
  border-top: 1px solid var(--border, #e5e7eb);
  margin-top: .5rem;
  z-index: 5;
}
.admin-panel-title {
  font-size: .9rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: var(--text, #1a1a2e);
}
.admin-form-group {
  margin-bottom: .85rem;
}
.admin-form-group label {
  display: block;
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-muted, #6b7280);
  margin-bottom: 4px;
}
.admin-form-group input,
.admin-form-group select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  font-size: .85rem;
  font-family: var(--font);
}
.admin-form-group input:focus,
.admin-form-group select:focus {
  outline: none;
  border-color: #00a884;
}
.admin-radio-group {
  display: flex;
  gap: 1.25rem;
}
.admin-radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: .85rem;
  color: var(--text, #1a1a2e);
  cursor: pointer;
}
.admin-create-btn {
  width: 100%;
  padding: 10px;
  background: #00a884;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: .5rem;
  transition: background .15s;
}
.admin-create-btn:hover { background: #00c49a; }

/* User list */
.admin-user-list {
  max-height: 400px;
  overflow-y: auto;
}
.admin-user-card {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem .75rem;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 8px;
  margin-bottom: .5rem;
}
.admin-user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #00a884;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .85rem;
  flex-shrink: 0;
}
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-name {
  font-weight: 600;
  font-size: .85rem;
  color: var(--text, #1a1a2e);
}
.admin-user-meta {
  font-size: .72rem;
  color: var(--text-muted, #6b7280);
}
.admin-user-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  cursor: pointer;
  flex: 1;
}
.admin-expand-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform .2s;
}
.admin-delete-btn {
  background: none;
  border: none;
  color: #d32f2f;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.admin-delete-btn:hover { background: #fef2f2; }

/* Expandable group section */
.admin-user-expand {
  padding: .5rem 0 0 calc(36px + .75rem);
}
.admin-user-expand.hidden { display: none; }
.admin-group-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.admin-group-tag {
  display: inline-block;
  padding: 3px 10px;
  background: #e8f5e9;
  color: #2e7d32;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 500;
}
.admin-group-more {
  display: inline-block;
  padding: 3px 10px;
  background: #f3f4f6;
  color: #00a884;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.admin-group-more:hover { background: #e5e7eb; }
.admin-group-more.hidden { display: none; }
.admin-group-tags-extra {
  display: contents;
}
.admin-group-tags-extra.hidden { display: none; }
.admin-no-groups {
  font-size: .75rem;
  color: var(--text-muted, #6b7280);
  font-style: italic;
}

/* Group mapping */
.admin-group-search {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: .5rem;
}
.admin-group-search input {
  border: none;
  outline: none;
  flex: 1;
  font-size: .82rem;
  font-family: var(--font);
}
.admin-group-search svg { color: var(--text-muted); flex-shrink: 0; }
.admin-group-list {
  max-height: 320px;
  overflow-y: auto;
  flex: 1;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
}
.admin-group-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: .85rem;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
}
.admin-group-item:last-child { border-bottom: none; }
.admin-group-item:hover { background: #f8f9fb; }
.admin-group-item input[type="checkbox"] {
  accent-color: #00a884;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin: 0;
}

@media (max-width: 768px) {
  .admin-split { grid-template-columns: 1fr; }
}

/* ── Raw Material Filters ────────────────────────────────────── */
.rm-filters {
  display: flex;
  gap: 1rem;
  padding: .75rem 0;
  margin-bottom: .5rem;
  flex-wrap: wrap;
  align-items: flex-end;
}
.rm-filter-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.rm-filter-item label {
  font-size: .7rem;
  text-transform: uppercase;
  color: var(--text-muted, #6b7280);
  letter-spacing: .5px;
}
.rm-filter-select,
.rm-filter-input {
  padding: 6px 10px;
  border: 1px solid var(--border, #d1d5db);
  border-radius: 6px;
  font-size: .8rem;
  font-family: var(--font);
  background: var(--white, #fff);
  color: var(--text, #1a1a2e);
  min-width: 140px;
}
.rm-filter-select:focus,
.rm-filter-input:focus {
  outline: none;
  border-color: #00a884;
}

/* ── Raw Material Detail Rows ────────────────────────────────── */
.rm-source-cell { font-weight: 600; }
.rm-details-cell { padding: .4rem .75rem !important; }
.rm-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}
.rm-detail-row + .rm-detail-row {
  border-top: 1px dashed var(--border, #d1d5db);
}
.rm-count {
  font-weight: 600;
  min-width: 36px;
  color: var(--text, #1a1a2e);
}
.rm-sep {
  color: var(--text-muted, #6b7280);
  font-size: .8rem;
}
.rm-price {
  color: #00a884;
  font-weight: 500;
}

/* ── Searchable Select ───────────────────────────────────────── */
.ss-wrap { position: relative; display: inline-block; }
.ss-btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .35rem .6rem; border: 1px solid var(--border, #d1d5db);
  border-radius: 6px; background: #fff; cursor: pointer;
  font-size: .78rem; font-family: var(--font); color: var(--text);
  min-width: 120px; justify-content: space-between;
}
.ss-btn:hover { border-color: #9ca3af; }
.ss-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ss-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 200;
  min-width: 100%; max-height: 260px; background: #fff;
  border: 1px solid var(--border, #d1d5db); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); overflow: hidden;
}
.ss-panel.hidden { display: none; }
.ss-search {
  width: 100%; padding: .45rem .6rem; border: none;
  border-bottom: 1px solid var(--border, #e5e7eb);
  font-size: .78rem; font-family: var(--font); outline: none;
}
.ss-options { max-height: 200px; overflow-y: auto; }
.ss-option {
  padding: .4rem .65rem; cursor: pointer; font-size: .78rem;
  transition: background .1s;
}
.ss-option:hover { background: #f3f4f6; }
.ss-option.ss-active { background: #e8f0fb; color: var(--primary); font-weight: 500; }
.ss-empty { padding: .6rem; text-align: center; color: #9ca3af; font-size: .78rem; }

/* Responsive */
@media (max-width: 768px) {
  .chat-sidebar { width: 100%; max-width: 100%; }
  .chat-main { display: none; }
  .chat-layout.chat-open .chat-sidebar { display: none; }
  .chat-layout.chat-open .chat-main { display: flex; }
}
