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

:root {
  /* Light theme */
  --bg: #eef1f6;
  --bg-gradient: linear-gradient(135deg, #e8ecf1 0%, #dce2ea 100%);
  --card: #ffffff;
  --card-secondary: #f7f8fa;
  --primary: #1a1a2e;
  --primary-light: #16213e;
  --primary-hover: #2d2d44;
  --text: #2c2c3a;
  --text-secondary: #5a5a6e;
  --muted: #909098;
  --border: #dde0e7;
  --border-light: #eef0f4;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-xl: 0 8px 32px rgba(0,0,0,0.10);
  --shadow-glow: 0 0 0 3px rgba(26,26,46,0.12);
  --accent: #4f8cf7;
  --accent-hover: #3570db;
  --accent-light: #e8f0fe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --danger-hover: #dc2626;
  --gradient-primary: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  --gradient-sidebar: linear-gradient(180deg, #1a1a2e 0%, #0f0f23 100%);
  --gradient-accent: linear-gradient(135deg, #4f8cf7 0%, #6366f1 100%);
  --gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);
  --gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --glass-bg: rgba(255,255,255,0.06);
  --glass-border: rgba(255,255,255,0.08);
  --sidebar-active: rgba(79,140,247,0.15);
  --sidebar-hover: rgba(255,255,255,0.06);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark {
  --bg: #0f0f1a;
  --bg-gradient: linear-gradient(135deg, #0a0a14 0%, #12121f 100%);
  --card: #1a1a2e;
  --card-secondary: #212240;
  --primary: #e2e2f0;
  --primary-light: #c8c8dc;
  --primary-hover: #f0f0ff;
  --text: #dcdce8;
  --text-secondary: #a0a0b4;
  --muted: #6e6e80;
  --border: #2a2a42;
  --border-light: #242450;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-xl: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 0 3px rgba(79,140,247,0.2);
  --accent: #6095f8;
  --accent-hover: #7aaaff;
  --accent-light: rgba(79,140,247,0.12);
  --success-light: rgba(16,185,129,0.12);
  --warning-light: rgba(245,158,11,0.12);
  --danger-light: rgba(239,68,68,0.12);
  --gradient-primary: linear-gradient(135deg, #1a1a2e 0%, #252545 100%);
  --gradient-sidebar: linear-gradient(180deg, #12122a 0%, #0a0a1a 100%);
  --card-hover: #252548;
  --glass-bg: rgba(255,255,255,0.03);
  --glass-border: rgba(255,255,255,0.05);
  --sidebar-active: rgba(79,140,247,0.2);
  --sidebar-hover: rgba(255,255,255,0.04);
}

html { font-size: 15px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans Arabic', system-ui, sans-serif;
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  direction: var(--app-dir, rtl);
  transition: background var(--transition-slow), color var(--transition-slow);
  line-height: 1.6;
}

::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 240px; min-width: 240px;
  background: var(--gradient-sidebar);
  color: #fff; padding: 0;
  display: flex; flex-direction: column;
  position: relative; overflow: hidden;
  transition: all var(--transition);
}
.sidebar::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(79,140,247,0.08) 0%, transparent 70%);
  pointer-events: none;
}

.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 22px 16px 14px; position: relative; z-index: 1; }
.sidebar-header h2 { padding: 0; font-size: 19px; letter-spacing: -0.4px; margin: 0; font-weight: 800; color: #fff; }

.sidebar-user { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 12px; position: relative; z-index: 1; }
.user-badge { font-size: 11px; color: #888; font-weight: 500; }
.logout-btn {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08);
  color: #ff8a80; width: 34px; height: 34px; border-radius: 10px;
  cursor: pointer; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.logout-btn:hover { background: rgba(255,255,255,0.12); border-color: rgba(255,140,128,0.3); transform: scale(1.05); }

.sidebar-role { padding: 0 12px 14px; position: relative; z-index: 1; }
.role-select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08); background: rgba(255,255,255,0.04);
  color: #ddd; font-size: 12px; cursor: pointer;
  transition: all var(--transition);
}
.role-select:hover { border-color: rgba(255,255,255,0.15); }
.role-select:focus { outline: none; border-color: var(--accent); }
.role-select option { background: var(--primary); color: #fff; }

.sidebar nav { display: flex; flex-direction: column; gap: 3px; padding: 0 10px; position: relative; z-index: 1; flex: 1; }
.sidebar nav button {
  display: flex; align-items: center; gap: 11px;
  width: 100%; padding: 11px 14px;
  background: transparent; border: none;
  color: #a0a0b8; text-align: start;
  font-size: 13px; font-weight: 500;
  cursor: pointer; border-radius: 10px;
  transition: all var(--transition);
  position: relative;
}
.sidebar nav button:hover { background: var(--sidebar-hover); color: #ddd; }
.sidebar nav button.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.sidebar nav button.active::before { content: ''; position: absolute; inset-inline-start: 0; top: 6px; bottom: 6px; width: 3px; background: var(--accent); border-radius: 0 3px 3px 0; }
.sidebar nav button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Dark mode toggle */
.sidebar-theme { padding: 12px 14px; position: relative; z-index: 1; border-top: 1px solid rgba(255,255,255,0.06); display: flex; align-items: center; gap: 10px; }
.theme-toggle { display: flex; align-items: center; gap: 8px; background: none; border: none; color: rgba(255,255,255,0.65); font-size: 12px; font-weight: 600; cursor: pointer; padding: 6px 8px; border-radius: 8px; transition: all var(--transition); width: 100%; }
.theme-toggle:hover { background: rgba(255,255,255,0.08); color: #fff; }
.theme-toggle svg { flex-shrink: 0; }
.theme-toggle-btn {
  width: 44px; height: 24px; border-radius: 12px;
  border: none; background: rgba(255,255,255,0.12);
  cursor: pointer; position: relative;
  transition: all var(--transition);
}
.theme-toggle-btn::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: all var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.theme-toggle-btn.dark { background: var(--accent); }
.theme-toggle-btn.dark::after { left: 22px; }
.theme-label { font-size: 12px; color: #888; font-weight: 500; user-select: none; }

/* Language switcher */
.lang-switcher { display: flex; gap: 0; flex-shrink: 0; position: relative; z-index: 1; }
.lang-switcher .lang-btn {
  padding: 5px 13px; border: 1px solid rgba(255,255,255,0.2);
  background: transparent; color: #aaa;
  font-size: 12px; font-weight: 700;
  cursor: pointer; letter-spacing: 0.5px;
  transition: all var(--transition);
}
.lang-switcher .lang-btn:first-child { border-radius: 6px 0 0 6px; }
.lang-switcher .lang-btn:last-child { border-radius: 0 6px 6px 0; }
.lang-switcher .lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.lang-switcher .lang-btn:hover:not(.active) { background: rgba(255,255,255,0.12); color: #eee; }
[dir="ltr"] .lang-switcher .lang-btn:first-child { border-radius: 0 6px 6px 0; }
[dir="ltr"] .lang-switcher .lang-btn:last-child { border-radius: 6px 0 0 6px; }
[dir="ltr"] .sidebar nav button.active::before { border-radius: 3px 0 0 3px; }

/* Main Content */
.main { flex: 1; padding: 28px; overflow-y: auto; min-width: 0; max-width: 100%; transition: all var(--transition); }

h1 {
  font-size: 22px; font-weight: 800; color: var(--primary);
  margin-bottom: 20px; padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
  letter-spacing: -0.3px;
  transition: color var(--transition);
}

/* Cards */
.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 24px; }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px 24px; min-width: 160px; flex: 1;
  box-shadow: var(--shadow-md); border: 1px solid var(--border-light);
  transition: all var(--transition); position: relative; overflow: hidden;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.card::before {
  content: ''; position: absolute; top: 0; inset-inline-start: 0; inset-inline-end: 0;
  height: 3px; background: var(--gradient-accent);
  opacity: 0; transition: opacity var(--transition);
}
.card:hover::before { opacity: 1; }
.card h3 { font-size: 11px; color: var(--muted); font-weight: 700; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.7px; display: flex; align-items: center; gap: 6px; }
.card p { font-size: 30px; font-weight: 800; color: var(--primary); transition: color var(--transition); letter-spacing: -0.5px; }

/* Table Wrap */
.table-wrap {
  overflow-x: auto; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--card);
  box-shadow: var(--shadow-sm);
}
.table { width: 100%; border-collapse: collapse; min-width: 550px; font-size: 13px; }
.table th {
  background: var(--card-secondary); padding: 12px 14px;
  font-size: 11px; font-weight: 700; color: var(--text-secondary);
  text-align: start; border-bottom: 2px solid var(--border);
  text-transform: uppercase; letter-spacing: 0.3px;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border-light); }
.table td button {
  background: var(--primary); color: #fff; border: none;
  padding: 6px 14px; border-radius: 8px; cursor: pointer;
  font-size: 12px; font-weight: 500; transition: all var(--transition);
}
.table td button:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.table tbody tr:hover { background: var(--accent-light); }

/* Chat Window */
.chat-window { margin-top: 20px; background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-md); border: 1px solid var(--border-light); }
.messages { max-height: 350px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.msg { display: flex; flex-direction: column; }
.msg.assistant { align-items: flex-start; }
.msg.user { align-items: flex-end; }
.msg .bubble { max-width: 85%; padding: 8px 14px; border-radius: 12px; line-height: 1.5; font-size: 13px; }
.msg.assistant .bubble { background: var(--accent-light); border-bottom-right-radius: 3px; }
.msg.user .bubble { background: var(--gradient-primary); color: #fff; border-bottom-left-radius: 3px; }
.msg small { color: var(--muted); margin-top: 2px; font-size: 10px; }

/* Settings */
.settings-section {
  background: var(--card); border-radius: var(--radius);
  padding: 20px 24px; margin-bottom: 16px;
  box-shadow: var(--shadow-md); border: 1px solid var(--border-light);
  transition: all var(--transition);
}
.settings-section:hover { box-shadow: var(--shadow-lg); }
.settings-section h2 {
  font-size: 15px; font-weight: 700; margin-bottom: 16px; padding-bottom: 12px;
  border-bottom: 1px solid var(--border); color: var(--primary);
  display: flex; align-items: center; gap: 8px;
}
.settings-section label { display: block; margin-top: 12px; margin-bottom: 5px; font-weight: 600; font-size: 12px; color: var(--text-secondary); }
.settings-section input, .settings-section select, .settings-section textarea {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 13px; background: var(--card-secondary);
  transition: all var(--transition); color: var(--text);
}
.settings-section input:focus, .settings-section select:focus, .settings-section textarea:focus {
  border-color: var(--accent); outline: none; background: var(--card); box-shadow: var(--shadow-glow);
}
.settings-section textarea { text-align: start; resize: vertical; }

.btn-save {
  width: 100%; padding: 13px; background: var(--gradient-primary);
  color: #fff; border: none; border-radius: 12px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all var(--transition); letter-spacing: 0.2px;
}
.btn-save:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-save:active { transform: scale(0.98); }
.btn-save:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.save-msg { margin-top: 10px; font-size: 13px; color: var(--success); font-weight: 600; }

.secret-input-row { display: flex; gap: 6px; }
.secret-input-row input {
  flex: 1; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 13px; direction: ltr; text-align: left;
  background: var(--card-secondary); color: var(--text);
}
.secret-input-row input.masked { color: var(--muted); font-family: monospace; font-size: 11px; }
.toggle-vis {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card-secondary); cursor: pointer;
  font-size: 15px; min-width: 40px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.toggle-vis:hover { background: var(--border); }

.key-badge { font-size: 10px; background: var(--success-light); color: var(--success); padding: 2px 8px; border-radius: 10px; margin-inline-end: 6px; font-weight: 400; direction: ltr; vertical-align: middle; }
.meta-fields, .twilio-fields { padding: 14px; background: var(--card-secondary); border-radius: 10px; border: 1px solid var(--border); margin-top: 8px; }

.helper-text {
  margin-top: 14px; padding: 12px; background: var(--warning-light);
  border-radius: 10px; border: 1px solid rgba(245,158,11,0.2);
  font-size: 12px; line-height: 1.6;
}
.helper-text code { background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 4px; font-size: 11px; direction: ltr; display: inline-block; word-break: break-all; }
body.dark .helper-text code { background: rgba(255,255,255,0.08); }

.checkbox-label { display: flex !important; align-items: center; gap: 8px; cursor: pointer; font-size: 13px !important; }
.checkbox-label input { width: auto !important; }
.prompt-editor { text-align: start; font-family: 'JetBrains Mono', 'Fira Code', monospace; line-height: 1.7; font-size: 13px; }
.helper-note { font-size: 12px; color: var(--muted); margin: 4px 0 8px; line-height: 1.5; }

.model-select-group { display: flex; flex-direction: column; gap: 8px; }
.model-custom-input { font-family: monospace !important; direction: ltr !important; text-align: left !important; }

/* Danger Zone */
.settings-divider { border: none; border-top: 1px solid var(--border); margin: 28px 0 12px; }
.danger-zone {
  background: var(--danger-light); border: 1px solid rgba(239,68,68,0.2);
  border-radius: var(--radius); padding: 20px; margin-top: 16px;
}
.danger-zone h3 { color: var(--danger); font-size: 14px; margin-bottom: 6px; font-weight: 700; }
.danger-zone p { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; }
.confirm-text { font-size: 13px; color: var(--danger); margin-bottom: 10px; font-weight: 600; }
.btn-danger {
  background: var(--gradient-danger); color: #fff; border: none;
  padding: 11px 22px; border-radius: 10px; font-size: 13px;
  font-weight: 600; cursor: pointer; transition: all var(--transition);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(239,68,68,0.3); }
.btn-cancel {
  background: var(--card-secondary); color: var(--text);
  border: 1px solid var(--border); padding: 11px 22px;
  border-radius: 10px; font-size: 13px; cursor: pointer;
  transition: all var(--transition);
}
.btn-cancel:hover { background: var(--border); }
.danger-actions { display: flex; gap: 10px; align-items: center; }

/* Password Manager */
.pw-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pw-row select { flex: 1; min-width: 100px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--card-secondary); color: var(--text); }
.pw-input { flex: 2; min-width: 140px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; direction: ltr; background: var(--card-secondary); color: var(--text); }
.btn-save-sm { padding: 10px 20px; background: var(--gradient-primary); color: #fff; border: none; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; transition: all var(--transition); }
.btn-save-sm:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.pw-msg { margin-top: 8px; font-size: 13px; color: var(--success); font-weight: 600; }

/* Analytics */
.analytics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.analytics-card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-md); border: 1px solid var(--border-light); transition: all var(--transition); }
.analytics-card:hover { box-shadow: var(--shadow-lg); }
.analytics-card h3 { font-size: 14px; font-weight: 700; margin-bottom: 16px; color: var(--primary); }
.bar-chart { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.bar-label { width: 110px; font-size: 12px; color: var(--text-secondary); text-align: start; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.bar-track { flex: 1; height: 22px; background: var(--card-secondary); border-radius: 11px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 11px; transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1); min-width: 3px; }
.bar-value { width: 36px; font-size: 13px; font-weight: 800; color: var(--primary); text-align: center; }
.empty-chart { color: var(--muted); padding: 20px; text-align: center; font-size: 13px; }

/* Knowledge Base */
.kb-card {
  background: var(--card); border-radius: var(--radius-lg);
  padding: 24px 28px; box-shadow: var(--shadow-md);
  border: 1px solid var(--border-light);
  transition: all var(--transition);
}
.kb-card:hover { box-shadow: var(--shadow-lg); }
.kb-card-header { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 8px; }
.kb-icon {
  width: 46px; height: 46px; border-radius: 12px;
  background: var(--gradient-accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79,140,247,0.3);
}
.kb-header-text h2 {
  font-size: 17px; font-weight: 700; color: var(--primary);
  margin: 0 0 4px; border: none; padding: 0;
}
.kb-header-text p { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0; }

.kb-info-box {
  margin: 16px 0; padding: 14px 16px;
  background: var(--accent-light);
  border: 1px solid rgba(79,140,247,0.15);
  border-radius: var(--radius-sm);
  display: flex; align-items: flex-start; gap: 10px;
  font-size: 13px; line-height: 1.6;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.kb-info-box .kb-info-icon { font-size: 18px; flex-shrink: 0; margin-top: 1px; }

.kb-textarea-wrap { position: relative; margin-bottom: 4px; }
.kb-textarea-wrap textarea {
  width: 100%; padding: 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; line-height: 1.8;
  background: var(--card-secondary); color: var(--text);
  resize: vertical; min-height: 220px;
  transition: all var(--transition);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.kb-textarea-wrap textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: var(--shadow-glow); background: var(--card);
}
.kb-textarea-wrap textarea::placeholder { color: var(--muted); opacity: 0.7; font-style: italic; }

.kb-stats { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; margin-bottom: 16px; flex-wrap: wrap; gap: 8px; }
.kb-char-count { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kb-char-count .char-num { font-weight: 700; color: var(--text-secondary); }
.kb-progress { width: 100px; height: 5px; background: var(--border-light); border-radius: 10px; overflow: hidden; }
.kb-progress-fill { height: 100%; border-radius: 10px; background: var(--gradient-accent); transition: width var(--transition); }
.kb-chunk-estimate { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.kb-chunk-estimate .chunk-num { font-weight: 700; color: var(--accent); }

.kb-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.kb-btn-save {
  flex: 1; min-width: 140px; padding: 13px 20px;
  background: var(--gradient-accent); color: #fff;
  border: none; border-radius: 12px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all var(--transition); letter-spacing: 0.2px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.kb-btn-save:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,140,247,0.4); }
.kb-btn-save:active { transform: scale(0.98); }
.kb-btn-save:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.kb-btn-reindex {
  flex: 1; min-width: 140px; padding: 13px 20px;
  background: transparent; color: var(--text-secondary);
  border: 2px solid var(--border); border-radius: 12px;
  font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all var(--transition);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.kb-btn-reindex:hover { background: var(--card-secondary); border-color: var(--accent); color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.kb-btn-reindex:active { transform: scale(0.98); }

.kb-msg {
  margin-top: 14px; padding: 12px 16px;
  border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  animation: kbSlideUp 0.3s ease;
  display: flex; align-items: center; gap: 8px;
}
@keyframes kbSlideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.kb-msg.success { background: var(--success-light); color: var(--success); border: 1px solid rgba(16,185,129,0.2); }
.kb-msg.error { background: var(--danger-light); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }

/* Chat Simulator */
.sim-role-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.sim-role-bar span { font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.sim-role-btn { padding: 7px 16px; border-radius: 20px; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-size: 12px; font-weight: 500; transition: all var(--transition); color: var(--text); }
.sim-role-btn:hover { background: var(--card-secondary); transform: translateY(-1px); }
.sim-role-btn:active { transform: scale(0.97); }

.chat-container { background: #ece5dd; border-radius: 16px; overflow: hidden; box-shadow: 0 4px 24px rgba(0,0,0,0.1); max-width: 600px; }
.chat-header { background: #075e54; color: #fff; padding: 14px 18px; font-size: 14px; font-weight: 700; }
.chat-role-label { font-weight: 400; font-size: 12px; opacity: 0.85; }
.chat-messages { background: #ece5dd; padding: 14px; max-height: 500px; min-height: 350px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.chat-msg { display: flex; flex-direction: column; max-width: 85%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.assistant { align-self: flex-start; align-items: flex-start; }
.chat-bubble { padding: 8px 14px; border-radius: 8px; font-size: 13px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.chat-bubble.user { background: #d9fdd3; border-bottom-right-radius: 2px; }
.chat-bubble.assistant { background: #fff; border-bottom-left-radius: 2px; }
.chat-name { font-size: 11px; font-weight: 700; color: #075e54; margin-bottom: 1px; }
.chat-time { font-size: 9px; color: #999; margin-top: 1px; padding: 0 4px; }
.chat-typing { align-self: flex-start; padding: 8px 14px; background: #fff; border-radius: 8px; font-size: 12px; color: #888; }
.chat-input-row { display: flex; gap: 0; background: #f0f0f0; padding: 8px; border-top: 1px solid #e0e0e0; }
.chat-input { flex: 1; padding: 10px 14px; border: none; border-radius: 20px; font-size: 13px; resize: none; background: #fff; outline: none; }
.chat-send { width: 42px; height: 42px; border-radius: 50%; border: none; background: #075e54; color: #fff; font-size: 18px; cursor: pointer; margin-inline-start: 8px; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.chat-send:hover { background: #055a4f; transform: scale(1.05); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.test-playground { max-width: 100%; }
.ctx-details { margin-top: 16px; }
.ctx-details summary { cursor: pointer; font-weight: 600; color: var(--text-secondary); font-size: 12px; padding: 8px 0; }
.ctx-chunk { background: var(--card-secondary); padding: 10px; border-radius: 8px; font-size: 11px; margin: 4px 0; border: 1px solid var(--border); overflow-x: auto; white-space: pre-wrap; word-break: break-word; }

/* Menu Manager */
.menu-manager { display: flex; gap: 0; background: var(--bg); border-radius: var(--radius); overflow: hidden; min-height: 60vh; border: 1px solid var(--border); }
.mm-sidebar { width: 220px; min-width: 220px; background: var(--gradient-primary); color: #fff; padding: 12px 0; }
.mm-sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 14px 10px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.mm-sidebar-header h3 { font-size: 13px; font-weight: 700; }
.mm-btn-icon { width: 30px; height: 30px; border-radius: 8px; border: none; background: rgba(255,255,255,0.1); color: #fff; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all var(--transition); }
.mm-btn-icon:hover { background: rgba(255,255,255,0.18); transform: scale(1.05); }
.mm-cat-list { overflow-y: auto; max-height: calc(100vh - 200px); }
.mm-cat-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer; transition: all var(--transition); border-inline-start: 3px solid transparent; }
.mm-cat-item:hover { background: rgba(255,255,255,0.06); }
.mm-cat-item.active { background: rgba(79,140,247,0.15); border-inline-start-color: var(--accent); }
.mm-cat-icon { font-size: 16px; }
.mm-cat-name { flex: 1; font-size: 12px; }
.mm-cat-count { background: rgba(255,255,255,0.1); padding: 1px 7px; border-radius: 10px; font-size: 10px; color: #999; }
.mm-cat-actions { display: none; gap: 3px; }
.mm-cat-item:hover .mm-cat-actions { display: flex; }
.mm-act-sm { background: none; border: none; color: #ccc; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; cursor: pointer; font-size: 13px; border-radius: 4px; }
.mm-act-sm:hover { background: rgba(255,255,255,0.15); color: #fff; }
.mm-act-sm.danger:hover { background: rgba(255,0,0,0.2); }
.mm-content { flex: 1; padding: 16px; overflow-y: auto; background: var(--bg); }
.mm-empty { display: flex; align-items: center; justify-content: center; height: 40vh; color: var(--muted); font-size: 14px; }
.mm-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.mm-toolbar-left { display: flex; align-items: center; gap: 8px; }
.mm-toolbar-left h2 { margin: 0; border: none; padding: 0; font-size: 18px; color: var(--primary); }
.mm-count-badge { background: var(--accent-light); color: var(--accent); padding: 3px 10px; border-radius: 14px; font-size: 11px; font-weight: 600; }
.mm-toolbar-right { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mm-search { padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; width: 160px; background: var(--card); color: var(--text); transition: all var(--transition); }
.mm-search:focus { outline: none; border-color: var(--accent); box-shadow: var(--shadow-glow); }
.mm-btn-primary { padding: 9px 18px; background: var(--gradient-primary); color: #fff; border: none; border-radius: 10px; font-size: 13px; cursor: pointer; white-space: nowrap; font-weight: 600; transition: all var(--transition); }
.mm-btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.mm-btn-secondary { padding: 9px 18px; background: var(--card-secondary); color: var(--text); border: 1px solid var(--border); border-radius: 10px; font-size: 13px; cursor: pointer; transition: all var(--transition); }
.mm-btn-secondary:hover { background: var(--border); }
.mm-table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); background: var(--card); }
.mm-table { width: 100%; border-collapse: collapse; min-width: 750px; font-size: 12px; }
.mm-table th { background: var(--card-secondary); padding: 10px 12px; font-size: 11px; font-weight: 700; color: var(--text-secondary); text-align: start; border-bottom: 2px solid var(--border); }
.mm-table td { padding: 9px 12px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.mm-table tbody tr:hover { background: var(--accent-light); }
.mm-row-disabled { opacity: 0.4; }
.mm-cell-name { font-weight: 700; color: var(--primary); white-space: nowrap; }
.mm-cell-desc { color: var(--muted); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-cell-notes { color: var(--muted); font-size: 11px; max-width: 100px; }
.mm-row-actions { display: flex; gap: 3px; }
.mm-toggle { background: none; border: none; cursor: pointer; font-size: 16px; padding: 0; line-height: 1; }

/* Modal */
.mm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 16px; backdrop-filter: blur(4px); animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.mm-modal { background: var(--card); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 400px; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow-xl); animation: modalIn 0.25s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.mm-modal-lg { max-width: 580px; }
.mm-modal-xl { max-width: 1100px; width: min(1100px, 95vw); }
.mm-modal h3 { font-size: 17px; margin-bottom: 16px; color: var(--primary); padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.mm-modal-body label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin: 12px 0 4px; }
.mm-modal-body input, .mm-modal-body textarea, .mm-modal-body select {
  width: 100%; padding: 9px 13px; border: 1px solid var(--border);
  border-radius: 9px; font-size: 13px;
  background: var(--card-secondary); color: var(--text);
  transition: all var(--transition);
}
.mm-modal-body input:focus, .mm-modal-body textarea:focus { border-color: var(--accent); outline: none; box-shadow: var(--shadow-glow); background: var(--card); }
.mm-modal-body textarea { resize: vertical; min-height: 55px; }
.mm-emoji { max-width: 70px; text-align: center; font-size: 24px; }
.mm-form-row { display: flex; gap: 12px; }
.mm-form-group.flex-1 { flex: 1; }
.mm-form-group.flex-2 { flex: 2; }
.mm-modal-footer { display: flex; gap: 10px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.mm-price-row { display: flex; gap: 10px; margin-bottom: 8px; }
.mm-price-field { flex: 1; background: var(--card-secondary); padding: 10px 12px; border-radius: 9px; }
.mm-price-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.mm-price-field input { width: calc(100% - 36px); border: none; background: transparent; font-size: 13px; font-weight: 700; padding: 0; color: var(--text); }
.mm-price-field input:focus { outline: none; }
.mm-price-currency { font-size: 11px; color: var(--muted); }
.mm-price-single { display: flex; align-items: center; gap: 8px; }
.mm-price-single input { flex: 1; max-width: 170px; }
.mm-checkbox { display: flex !important; align-items: center; gap: 8px; cursor: pointer; margin-top: 12px !important; }
.mm-checkbox input { width: auto !important; }
.en-field-row { display: flex; gap: 8px; }
.en-field-row input { flex: 1; }

/* Orders Grid */
.orders-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.orders-toolbar-left { display: flex; align-items: center; gap: 10px; }
.orders-toolbar-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.order-filter { padding: 9px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 13px; background: var(--card); color: var(--text); }
.orders-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.orders-empty { grid-column: 1 / -1; text-align: center; padding: 50px; color: var(--muted); font-size: 14px; }
.order-card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04); border: 1px solid var(--border-light);
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.order-card::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-accent);
  opacity: 0;
  border-radius: 0 3px 3px 0;
  transition: opacity var(--transition);
}
.order-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.order-card:hover::before { opacity: 0.7; }
.order-card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.order-id { font-size: 12px; font-weight: 700; color: var(--primary); background: var(--card-secondary); padding: 3px 10px; border-radius: 6px; }
.order-status-badge { padding: 5px 12px; border-radius: 16px; font-size: 11px; white-space: nowrap; font-weight: 700; display: inline-flex; align-items: center; gap: 4px; letter-spacing: 0.02em; }
.order-customer { font-weight: 700; font-size: 15px; color: var(--primary); margin-bottom: 3px; }
.order-items-count { font-size: 12px; color: var(--muted); }
.order-phone { font-size: 11px; color: var(--text-secondary); margin-top: 3px; }
.order-time { font-size: 10px; color: var(--muted); }
.order-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Order action buttons — high contrast badge style */
.qact-btn {
  padding: 8px 16px;
  border: 1.5px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  letter-spacing: 0.01em;
}

.qact-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

/* Status-specific colors — light bg + dark text for readability */
.qact-btn.pending           { background: #fff3e0; color: #bf360c; border-color: #ffcc80; }
.qact-btn.pending:hover     { background: #ffe0b2; }

.qact-btn.awaiting_payment  { background: #fff3e0; color: #bf360c; border-color: #ffcc80; }
.qact-btn.awaiting_payment:hover { background: #ffe0b2; }

.qact-btn.payment_confirmed { background: #e8f0fe; color: #0d47a1; border-color: #90caf9; }
.qact-btn.payment_confirmed:hover { background: #bbdefb; }

.qact-btn.preparing         { background: #e3f2fd; color: #0d47a1; border-color: #90caf9; }
.qact-btn.preparing:hover   { background: #bbdefb; }

.qact-btn.prepared          { background: #e8f5e9; color: #1b5e20; border-color: #a5d6a7; }
.qact-btn.prepared:hover    { background: #c8e6c9; }

.qact-btn.delivering        { background: #f3e5f5; color: #4a148c; border-color: #ce93d8; }
.qact-btn.delivering:hover  { background: #e1bee7; }

.qact-btn.delivered         { background: #e8f5e9; color: #1b5e20; border-color: #a5d6a7; }
.qact-btn.delivered:hover   { background: #c8e6c9; }

.qact-btn.returnables_collected { background: #efebe9; color: #4e342e; border-color: #bcaaa4; }
.qact-btn.returnables_collected:hover { background: #d7ccc8; }

.qact-btn.cancelled         { background: #ffebee; color: #b71c1c; border-color: #ef9a9a; }
.qact-btn.cancelled:hover   { background: #ffcdd2; }

/* Order Detail */
.order-detail-body { max-height: 65vh; overflow-y: auto; }
.detail-status-bar { margin-bottom: 14px; }
.detail-status { display: inline-flex; padding: 7px 20px; border-radius: 20px; font-size: 14px; font-weight: 700; align-items: center; gap: 6px; letter-spacing: 0.02em; }
.detail-info { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 13px; margin-bottom: 16px; padding: 14px 16px; background: var(--card-secondary); border-radius: 12px; }
.detail-info div { line-height: 1.6; }
.detail-items-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 12px; }
.detail-items-table th { background: var(--card-secondary); padding: 8px 12px; font-size: 11px; text-align: start; border-bottom: 2px solid var(--border); white-space: nowrap; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.3px; }
.detail-items-table td { padding: 8px 12px; font-size: 12px; border-bottom: 1px solid var(--border-light); }
.detail-items-table tbody tr:hover { background: var(--accent-light); }
.detail-items-table tfoot td { padding: 10px 14px; font-size: 15px; border-top: 2px solid var(--primary); font-weight: 800; }
.detail-timeline { margin: 14px 0; }
.detail-timeline h4 { margin-bottom: 12px; font-size: 13px; color: var(--text-secondary); }
.timeline-item { display: flex; gap: 12px; margin-bottom: 10px; position: relative; }
.timeline-dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 4px; flex-shrink: 0; box-shadow: 0 0 0 3px var(--card); }
.timeline-content { font-size: 12px; }
.timeline-status { font-weight: 600; font-size: 12px; }
.timeline-time { font-size: 10px; color: var(--muted); }
.timeline-notes { font-size: 11px; color: var(--text-secondary); }
.detail-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.detail-actions-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  background: var(--card);
  border-radius: 14px;
  border: 1px solid var(--border-light);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.detail-actions-row::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-accent);
  opacity: 0.6;
  border-radius: 0 3px 3px 0;
}
.detail-actions-row:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 12px rgba(79,140,247,0.08);
}
.detail-actions-row .row-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  padding: 4px 0;
}
.detail-actions-row .row-label svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  flex-shrink: 0;
}
.detail-actions-row .action-group {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.detail-actions-row .action-group select {
  flex: 1;
  min-width: 160px;
  max-width: 280px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  background: var(--card-secondary);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236e6e80' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  padding-inline-start: 32px;
}
[dir="ltr"] .detail-actions-row .action-group select {
  background-position: right 10px center;
  padding-left: 32px;
  padding-right: 14px;
}
.detail-actions-row .action-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,140,247,0.12);
}
.detail-actions-row .action-group .qact-btn,
.detail-actions-row .action-group .mm-btn-secondary,
.detail-actions-row .action-group .mm-btn-primary {
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 600;
  font-size: 13px;
  padding: 9px 18px;
  border-radius: 10px;
  letter-spacing: 0.02em;
  transition: all 0.15s ease;
}
.detail-actions-row .action-group .mm-btn-primary {
  background: var(--gradient-accent);
  color: #fff;
  border: none;
}
.detail-actions-row .action-group .mm-btn-primary:hover {
  box-shadow: 0 4px 14px rgba(79,140,247,0.35);
  transform: translateY(-1px);
}
.detail-actions-row .action-group .mm-btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
}
.detail-actions-row .action-group .mm-btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.detail-actions-row .action-group .qact-btn {
  border: 1.5px solid transparent;
}
.detail-actions-row .action-group .qact-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(0,0,0,0.08);
}

/* Status transitions row - no card style */
.detail-actions-row.status-row {
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}
.detail-actions-row.status-row::before { display: none; }
.mm-btn-danger { padding: 9px 18px; background: var(--gradient-danger); color: #fff; border: none; border-radius: 10px; font-size: 13px; cursor: pointer; font-weight: 600; transition: all var(--transition); }
.mm-btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(239,68,68,0.3); }

/* Order Items */
.order-item-info { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.order-item-name { font-weight: 600; font-size: 14px; white-space: nowrap; }
.order-item-sizes { display: flex; gap: 4px; flex-shrink: 0; }
.order-item-size-label { font-size: 11px; color: var(--muted); background: var(--card-secondary); padding: 2px 6px; border-radius: 3px; flex-shrink: 0; }
.size-tag { background: var(--accent-light); border: 1px solid rgba(79,140,247,0.2); color: var(--accent); padding: 3px 10px; border-radius: 14px; font-size: 12px; cursor: pointer; transition: all var(--transition); white-space: nowrap; flex-shrink: 0; }
.size-tag:hover { background: rgba(79,140,247,0.2); }
.order-item-qty-row { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.order-item-qty-row .qty-input { width: 34px; padding: 3px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; text-align: center; }
.qty-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 3px; flex-shrink: 0; }
.order-item-row { display: flex; align-items: flex-start; gap: 8px; padding: 6px 8px; border-radius: 6px; flex-wrap: wrap; }
.order-item-row:hover { background: var(--accent-light); }
.order-items-selector details { margin-bottom: 2px; }
.order-items-selector summary { cursor: pointer; font-weight: 600; padding: 4px 6px; font-size: 12px; border-radius: 4px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.order-items-selector summary:hover { background: var(--card-secondary); }
.order-search-item { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; background: var(--card); color: var(--text); }
.search-results { max-height: 240px; overflow-y: auto; }
.search-no-results { text-align: center; color: var(--muted); padding: 14px; font-size: 13px; }
.sel-items-summary strong { display: block; margin-bottom: 4px; font-size: 12px; }
.sel-item { padding: 4px 0; font-size: 12px; }
.sel-item-main { display: flex; justify-content: space-between; align-items: center; width: 100%; gap: 4px; }
.sel-item button { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; flex-shrink: 0; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg-gradient); background-attachment: fixed; padding: 16px; position: relative; }
.login-card {
  background: var(--card); border-radius: var(--radius-xl);
  padding: 36px; width: 100%; max-width: 370px;
  box-shadow: var(--shadow-xl); border: 1px solid var(--border-light);
  animation: modalIn 0.3s ease;
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-icon { font-size: 44px; display: block; margin-bottom: 8px; }
.login-header h1 { font-size: 24px; margin: 0 0 4px; border: none; padding: 0; letter-spacing: -0.5px; }
.login-header p { color: var(--muted); font-size: 13px; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.login-field select, .login-field input {
  width: 100%; padding: 11px 14px; border: 1px solid var(--border);
  border-radius: 10px; font-size: 14px;
  background: var(--card-secondary); color: var(--text);
  transition: all var(--transition);
}
.login-field select:focus, .login-field input:focus { border-color: var(--accent); outline: none; box-shadow: var(--shadow-glow); }
.btn-login {
  width: 100%; padding: 13px; background: var(--gradient-accent);
  color: #fff; border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  transition: all var(--transition); margin-top: 6px;
}
.btn-login:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79,140,247,0.4); }
.btn-login:active { transform: scale(0.98); }
.login-error { color: var(--danger); font-size: 12px; margin-bottom: 12px; text-align: center; font-weight: 600; }
.login-success { color: var(--success); font-size: 12px; margin-bottom: 12px; text-align: center; font-weight: 600; background: var(--success-light); padding: 8px 12px; border-radius: 8px; }
.login-toggle { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); font-size: 13px; font-weight: 700; cursor: pointer; text-decoration: none; transition: color var(--transition); }
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }
.login-footer { margin-top: 20px; text-align: center; }
.login-footer small { color: var(--muted); font-size: 10px; }
.login-footer code { background: var(--card-secondary); padding: 2px 6px; border-radius: 4px; direction: ltr; display: inline-block; }
.login-lang-bar { position: absolute; top: 18px; right: 18px; display: flex; gap: 0; z-index: 10; background: var(--card); border-radius: 7px; box-shadow: var(--shadow-md); overflow: hidden; border: 1px solid var(--border); }
.login-lang-bar .lang-btn {
  padding: 7px 16px; border: none;
  background: transparent; color: var(--text-secondary);
  font-size: 12px; font-weight: 700; cursor: pointer;
  letter-spacing: 0.5px; transition: all var(--transition);
}
.login-lang-bar .lang-btn:first-child { border-radius: 7px 0 0 7px; }
.login-lang-bar .lang-btn:last-child { border-radius: 0 7px 7px 0; }
.login-lang-bar .lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.login-lang-bar .lang-btn:hover:not(.active) { background: var(--card-secondary); }
[dir="ltr"] .login-lang-bar { right: auto; left: 18px; }
[dir="ltr"] .login-lang-bar .lang-btn:first-child { border-radius: 0 7px 7px 0; }
[dir="ltr"] .login-lang-bar .lang-btn:last-child { border-radius: 7px 0 0 7px; }

/* Item Thumbnail */
.mm-item-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; }
.mm-no-img { color: #ccc; font-size: 16px; }
.mm-image-lightbox { max-width: 90vw; max-height: 90vh; border-radius: 10px; overflow: hidden; box-shadow: var(--shadow-xl); }
.mm-image-lightbox img { display: block; width: auto; height: auto; max-width: 90vw; max-height: 90vh; object-fit: contain; }
.mm-image-upload { display: flex; align-items: flex-start; gap: 14px; margin-top: 6px; }
.mm-image-preview { width: 80px; height: 80px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); flex-shrink: 0; }
.mm-image-preview img { width: 100%; height: 100%; object-fit: cover; }
.mm-image-actions { display: flex; flex-direction: column; gap: 6px; }
.mm-helper-text { font-size: 11px; color: var(--muted); }

/* Specs Management */
.mm-spec-card { background: var(--card-secondary); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.mm-spec-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mm-spec-header strong { flex: 1; font-size: 13px; color: var(--text); }
.mm-spec-type { font-size: 10px; color: var(--text-secondary); background: var(--accent-light); padding: 2px 8px; border-radius: 10px; }
.mm-spec-type.required { background: var(--warning-light); color: #e65100; }
.mm-spec-choices { display: flex; flex-direction: column; gap: 4px; margin-inline-start: 12px; }
.mm-choice-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px 8px; background: var(--card); border-radius: 5px; }
.mm-choice-row span:first-child { flex: 1; }
.mm-choice-price { font-size: 10px; color: var(--success); font-weight: 600; }
.mm-btn-sm { padding: 5px 12px; font-size: 11px; border: 1px solid var(--border); background: var(--card); border-radius: 6px; cursor: pointer; color: var(--text); transition: all var(--transition); }
.mm-btn-sm:hover { background: var(--card-secondary); }
.mm-spec-add-form { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.mm-spec-add-form label { font-size: 12px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 5px; }
.mm-spec-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mm-spec-add-row input { flex: 1; min-width: 120px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; background: var(--card-secondary); color: var(--text); }
.mm-spec-add-row select { padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; background: var(--card-secondary); color: var(--text); }
.mm-empty-hint { color: var(--muted); text-align: center; padding: 18px; font-size: 13px; }

/* Order Form */
.order-form-header { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.order-form-header label { font-size: 11px; font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; display: block; }
.order-form-header input, .order-form-header select { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; background: var(--card-secondary); color: var(--text); box-sizing: border-box; }
.order-form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; max-height: 58vh; height: 58vh; overflow: hidden; }
.order-form-left, .order-form-right { min-width: 0; display: flex; flex-direction: column; gap: 6px; overflow: hidden; height: 100%; }
.order-form-right { border-inline-start: 1px solid var(--border); padding-inline-start: 18px; }
.order-form-left label, .order-form-right label { font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-top: 4px; flex-shrink: 0; }
.order-form-left input, .order-form-right input { padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; background: var(--card-secondary); color: var(--text); flex-shrink: 0; }
.order-form-left .order-search-item { flex-shrink: 0; }
.order-items-selector { flex: 1; overflow-y: auto; min-height: 80px; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--card); }
.sel-items-summary { flex: 1; overflow-y: auto; max-height: 220px; padding: 12px; background: var(--card-secondary); border-radius: 10px; min-height: 60px; }
.order-form-right textarea { resize: vertical; min-height: 55px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-size: 13px; background: var(--card-secondary); color: var(--text); flex-shrink: 0; }
.order-item-thumb { width: 24px; height: 24px; object-fit: cover; border-radius: 4px; vertical-align: middle; margin-inline-end: 4px; }
.order-item-qty-row .item-note-input { width: 220px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; background: var(--card); color: var(--text); }
.item-note-input::placeholder { color: var(--muted); font-size: 10px; }
.sel-item-edit-controls { display: flex; gap: 4px; align-items: center; }
.sel-item-rm { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 14px; padding: 0 3px; }
.sel-item-details { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; margin-inline-start: 8px; }
.sel-item-note { font-size: 10px; color: #e65100; background: var(--warning-light); padding: 1px 6px; border-radius: 3px; }
.sel-item-spec { font-size: 10px; color: var(--accent); background: var(--accent-light); padding: 1px 6px; border-radius: 3px; cursor: pointer; user-select: none; }
.sel-item-spec:hover { background: rgba(79,140,247,0.2); }
.sel-items-empty { color: var(--muted); text-align: center; padding: 24px; font-size: 12px; }

/* Spec Selectors in Order */
.order-specs-select { margin-inline-start: 12px; padding: 6px 8px; background: var(--card-secondary); border-radius: 6px; margin-top: 4px; }
.order-spec-size-label { font-size: 10px; color: var(--accent); font-weight: 600; margin-bottom: 4px; }
.order-spec-row { margin-bottom: 3px; }
.order-spec-label { font-size: 11px; font-weight: 600; color: var(--text-secondary); display: block; margin-bottom: 2px; }
.order-spec-choices { display: flex; gap: 3px; flex-wrap: wrap; }
.order-spec-choice { display: flex; align-items: center; gap: 2px; font-size: 11px; padding: 2px 7px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; cursor: pointer; color: var(--text); }
.order-spec-choice.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.order-spec-choice input.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
.spec-price-adjust { font-size: 9px; color: var(--success); font-weight: 600; }
.detail-item-notes { min-width: 100px; max-width: 220px; font-size: 11px; color: #e65100; white-space: pre-wrap; word-break: break-word; }
.detail-item-specs { min-width: 100px; max-width: 220px; font-size: 11px; color: var(--accent); white-space: pre-wrap; word-break: break-word; }

/* Media preview in chat messages */
.media-preview { margin-bottom: 6px; }
.media-preview img { max-width: 240px; max-height: 240px; border-radius: 8px; border: 1px solid var(--border); object-fit: cover; }
.media-preview.audio { background: var(--card-secondary); padding: 8px 12px; border-radius: 8px; font-size: 12px; }
.media-preview.video { background: var(--card-secondary); padding: 8px 12px; border-radius: 8px; font-size: 12px; }
.media-preview.doc { background: var(--card-secondary); padding: 8px 12px; border-radius: 8px; font-size: 12px; }
.media-preview a { color: var(--accent); text-decoration: none; }

/* Badges for rules table */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--card-secondary); color: var(--text); }
.badge-analyze { background: #e3f2fd; color: #1565c0; }
.badge-forward { background: #fff3e0; color: #e65100; }
.badge-reply_with_media { background: #e8f5e9; color: #2e7d32; }
.badge-ignore { background: #f5f5f5; color: #757575; }

/* Dark mode badge overrides */
body.dark .badge { background: var(--card); }
body.dark .badge-analyze { background: #1a237e30; color: #64b5f6; }
body.dark .badge-forward { background: #bf360c30; color: #ffab91; }
body.dark .badge-reply_with_media { background: #1b5e2030; color: #81c784; }
body.dark .badge-ignore { background: #424242; color: #bdbdbd; }

/* Responsive */
.hamburger { display: none; position: fixed; top: 12px; inset-inline-start: 12px; z-index: 100; width: 40px; height: 40px; background: var(--gradient-primary); border: none; border-radius: 10px; color: #fff; font-size: 20px; cursor: pointer; align-items: center; justify-content: center; box-shadow: var(--shadow-md); transition: all var(--transition); }
.hamburger:hover { transform: scale(1.05); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 50; backdrop-filter: blur(3px); opacity: 0; visibility: hidden; transition: opacity 0.3s ease, visibility 0.3s ease; }
.overlay.active { opacity: 1; visibility: visible; }

@media (max-width: 768px) {
  .hamburger { display: flex; }
  .sidebar { position: fixed; top: 0; inset-inline-start: 0; bottom: 0; z-index: 99; transform: translateX(100%); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); width: 250px; }
  [dir="ltr"] .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 60px 14px 20px; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .cards { flex-direction: column; }
  .card { min-width: auto; }
  .analytics-grid { grid-template-columns: 1fr; }
  .menu-manager { flex-direction: column; }
  .mm-sidebar { width: 100%; min-width: auto; max-height: 180px; overflow-y: auto; }
  .mm-price-row { flex-wrap: wrap; }
  .mm-price-field { min-width: 80px; flex: 1 1 100px; }
  .mm-form-row { flex-direction: column; }
  .orders-grid { grid-template-columns: 1fr; }
  .detail-info { grid-template-columns: 1fr; }
  .mm-table { min-width: 600px; }
  .table { min-width: 400px; }
  .chat-container { max-width: 100%; }
  .sim-role-bar { flex-direction: column; align-items: stretch; }
  .mm-overlay { padding: 4px; align-items: flex-end; }
  .order-form-grid { grid-template-columns: 1fr; max-height: none; height: auto; overflow: visible; }
  .order-form-right { border-inline-start: none; padding-inline-start: 0; }
  .order-form-header { grid-template-columns: 1fr; }
  .order-items-selector { max-height: 180px; }
  .sel-items-summary { max-height: 180px; }
  .kb-card { padding: 18px 16px; }
  .kb-card-header { flex-direction: column; gap: 10px; }
  .kb-actions { flex-direction: column; }
  .kb-stats { flex-direction: column; align-items: flex-start; }
  /* Mobile detail-actions fix */
  .detail-actions-row { grid-template-columns: 1fr; gap: 10px; padding: 12px 14px; }
  .detail-actions-row .action-group { justify-content: stretch; }
  .detail-actions-row .action-group select { max-width: none; flex: 1; }
  .detail-actions-row .action-group .qact-btn,
  .detail-actions-row .action-group .mm-btn-secondary,
  .detail-actions-row .action-group .mm-btn-primary { flex: 1; text-align: center; justify-content: center; }
  .detail-actions-row.status-row { flex-direction: row; flex-wrap: wrap; justify-content: center; }
  .detail-actions-row.status-row .qact-btn { flex: 1; min-width: 100px; text-align: center; }
  /* Dashboard mobile */
  .donut-svg { width: 180px; height: 180px; }
  /* Modal mobile fix */
  .mm-modal { max-width: 100%; margin: 0; border-radius: 16px 16px 0 0; max-height: 90vh; }
  .mm-modal-lg, .mm-modal-xl { max-width: 100%; width: 100%; border-radius: 16px 16px 0 0; }
  .order-detail-body { max-height: 70vh; }
  .detail-items-table { font-size: 11px; }
  .detail-items-table th, .detail-items-table td { padding: 6px 8px; }
}

@media (max-width: 480px) {
  .main { padding: 54px 8px 16px; }
  .bar-label { width: 60px; font-size: 9px; }
  .mm-modal { margin: 0; padding: 14px; border-radius: 12px 12px 0 0; }
  .detail-actions-row { padding: 10px 12px; gap: 8px; }
  .detail-actions-row .action-group select { min-width: 120px; padding: 7px 10px; font-size: 12px; }
  .detail-actions-row .action-group .qact-btn,
  .detail-actions-row .action-group .mm-btn-secondary,
  .detail-actions-row .action-group .mm-btn-primary { padding: 7px 12px; font-size: 12px; }
  .detail-status { font-size: 12px; padding: 5px 14px; }
  .order-card { padding: 12px; }
  .donut-svg { width: 150px; height: 150px; }
  .pw-row { flex-direction: column; }
  .kb-card { padding: 14px 12px; }
}
/* Modern Sessions Layout */
.sessions-modern {
  display: flex;
  height: calc(100vh - 56px);
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.sessions-sidebar {
  width: 320px;
  min-width: 320px;
  border-inline-end: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  background: var(--card-secondary);
}

.sessions-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-light);
}

.sessions-sidebar-header h2 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: 16px;
  font-weight: 700;
}

.sessions-count {
  background: var(--accent-light);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.sessions-search-wrap {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
}

.sessions-search {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  background: var(--card);
  color: var(--text);
  transition: all var(--transition);
}

.sessions-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: all var(--transition);
  border-inline-start: 3px solid transparent;
}

.session-item:hover {
  background: var(--accent-light);
}

.session-item.active {
  background: var(--accent-light);
  border-inline-start-color: var(--accent);
}

.session-item.handoff {
  background: rgba(245, 158, 11, 0.06);
}

.session-item.handoff:hover {
  background: rgba(245, 158, 11, 0.12);
}

.session-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.session-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.session-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-time {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.session-phone {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

.session-badge.bot {
  background: var(--accent-light);
  color: var(--accent);
}

.session-badge.agent {
  background: var(--warning-light);
  color: #e65100;
}

.sessions-chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

.chat-empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 16px;
  padding: 40px 20px;
  text-align: center;
}

.chat-empty-icon {
  font-size: 56px;
  opacity: 0.35;
}

.sessions-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  gap: 12px;
}

.chat-header-modern {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border-light);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.chat-header-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--primary);
}

.chat-header-meta {
  font-size: 12px;
  color: var(--muted);
}

.chat-header-actions {
  display: flex;
  gap: 8px;
}

.chat-header-btn {
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.chat-header-btn.handoff {
  background: var(--warning-light);
  color: #e65100;
}

.chat-header-btn.handoff:hover {
  background: #ffe0b2;
}

.chat-header-btn.release {
  background: var(--accent-light);
  color: var(--accent);
}

.chat-header-btn.release:hover {
  background: rgba(79,140,247,0.2);
}

.chat-messages-modern {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 80%;
}

.chat-message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-message-avatar-small {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 12px;
  flex-shrink: 0;
}

.chat-message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13px;
  line-height: 1.6;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  max-width: 100%;
  word-break: break-word;
}

.chat-message-bubble.user {
  background: var(--gradient-primary);
  color: #fff;
  border-bottom-end-radius: 4px;
}

.chat-message-bubble.assistant {
  border-bottom-start-radius: 4px;
}

.chat-message-bubble.agent {
  background: var(--success-light);
  color: #065f46;
  border-bottom-start-radius: 4px;
}

.chat-media {
  margin-bottom: 6px;
}

.chat-media img {
  max-width: 260px;
  max-height: 260px;
  border-radius: 12px;
  display: block;
  object-fit: cover;
}

.chat-media.audio,
.chat-media.video,
.chat-media.doc {
  background: var(--card-secondary);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 12px;
}

.chat-media.audio audio,
.chat-media.video video {
  max-width: 240px;
  margin-top: 6px;
  border-radius: 8px;
}

.chat-media.doc a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

.chat-text {
  white-space: pre-wrap;
}

.chat-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.chat-message-bubble.user .chat-meta {
  justify-content: flex-start;
}

.chat-time {
  font-size: 10px;
  color: var(--muted);
}

.chat-message-bubble.user .chat-time {
  color: rgba(255,255,255,0.7);
}

.chat-input-modern {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 20px;
  background: var(--card);
  border-top: 1px solid var(--border-light);
}

.chat-input-modern textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  background: var(--card-secondary);
  color: var(--text);
  resize: none;
  max-height: 120px;
  min-height: 44px;
  transition: all var(--transition);
}

.chat-input-modern textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--shadow-glow);
  background: var(--card);
}

.chat-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.chat-send-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(79,140,247,0.4);
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* Responsive sessions */
@media (max-width: 768px) {
  .sessions-modern {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 56px);
  }
  .sessions-sidebar {
    width: 100%;
    min-width: auto;
    max-height: 40vh;
    border-inline-end: none;
    border-bottom: 1px solid var(--border-light);
  }
  .chat-messages-modern {
    padding: 14px;
  }
  .chat-message-row {
    max-width: 90%;
  }
}


/* Templates Page — Redesigned */
.templates-page { padding: 24px; max-width: 1200px; margin: 0 auto; }
.templates-header { margin-bottom: 20px; }
.templates-header h1 { margin: 0; font-size: 26px; font-weight: 800; }
.templates-subtitle { font-size: 13px; color: var(--muted); margin-top: 4px; }

.templates-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.templates-search-wrap { flex: 1; min-width: 240px; }
.templates-search { width: 100%; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 14px; }
.templates-search:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,247,0.12); }

.templates-cats { display: flex; gap: 6px; flex-wrap: wrap; }
.cat-pill { padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--card-bg); color: var(--text); font-size: 13px; cursor: pointer; transition: all 0.15s; font-weight: 500; }
.cat-pill:hover { border-color: var(--accent); }
.cat-pill.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.templates-loading { text-align: center; padding: 40px; color: var(--muted); }
.templates-table-wrap { background: var(--card-bg); border-radius: 14px; border: 1px solid var(--border); overflow: hidden; }
.templates-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.templates-table thead { background: rgba(0,0,0,0.02); }
.templates-table th { padding: 14px 16px; text-align: start; font-weight: 600; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; border-bottom: 1px solid var(--border); }
.templates-table td { padding: 14px 16px; border-bottom: 1px solid var(--border-light); vertical-align: top; }
.templates-table tbody tr:last-child td { border-bottom: none; }

.tpl-row { cursor: pointer; transition: background 0.1s; }
.tpl-row:hover { background: rgba(79,140,247,0.04); }
.tpl-row.inactive { opacity: 0.55; }
.tpl-name { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.tpl-vars { display: flex; gap: 4px; flex-wrap: wrap; }
.var-chip { font-size: 11px; padding: 2px 7px; border-radius: 4px; background: rgba(79,140,247,0.08); color: var(--accent); font-family: monospace; }
.cat-badge { font-size: 12px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.status-dot { font-size: 12px; padding: 4px 10px; border-radius: 20px; font-weight: 600; }
.status-dot.active { background: #dcfce7; color: #166534; }
.status-dot.inactive { background: #fee2e2; color: #991b1b; }
.tpl-preview-text { font-size: 13px; color: var(--muted); line-height: 1.5; }
.icon-btn { background: none; border: none; font-size: 16px; cursor: pointer; padding: 6px; border-radius: 8px; transition: background 0.15s; }
.icon-btn:hover { background: rgba(0,0,0,0.06); }

.tpl-expand-row { background: rgba(0,0,0,0.015); }
.tpl-editor { padding: 16px; }
.tpl-editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.tpl-field { display: flex; flex-direction: column; gap: 6px; }
.tpl-field label { font-size: 12px; font-weight: 600; color: var(--muted); }
.tpl-field textarea { padding: 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-family: inherit; font-size: 14px; resize: vertical; line-height: 1.6; }
.tpl-field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,140,247,0.12); }

.tpl-editor-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.tpl-editor-meta label { font-size: 12px; font-weight: 600; color: var(--muted); }
.tpl-editor-meta select { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13px; }

.tpl-preview-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; background: rgba(79,140,247,0.04); padding: 10px 12px; border-radius: 10px; }
.tpl-preview-bar label { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tpl-preview-bar input { flex: 1; min-width: 200px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-family: monospace; font-size: 13px; }

.tpl-live-preview { background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 14px; }
.tpl-live-preview .preview-lang { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 8px; }
.tpl-live-preview pre { margin: 0; white-space: pre-wrap; font-family: inherit; font-size: 14px; line-height: 1.7; }

.tpl-editor-actions { display: flex; gap: 10px; }

.templates-empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.templates-empty .empty-icon { font-size: 48px; margin-bottom: 12px; }

@media (max-width: 768px) {
  .tpl-editor-grid { grid-template-columns: 1fr; }
  .templates-toolbar { flex-direction: column; align-items: stretch; }
  .templates-table th:nth-child(3),
  .templates-table td:nth-child(3) { display: none; }
}

/* Meta Status */
.meta-status-wrap { display: flex; flex-direction: column; gap: 4px; }
.meta-badge { font-size: 11px; padding: 3px 10px; border-radius: 20px; font-weight: 600; width: fit-content; }
.meta-reason { font-size: 11px; color: #ef4444; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-editor-meta-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.tpl-editor-meta-row .tpl-editor-meta { margin-bottom: 0; }

/* Submit to Meta */
.tpl-actions { display: flex; gap: 4px; }
.icon-btn.submit-btn { color: #2563eb; }
.icon-btn.submit-btn:hover { background: #dbeafe; }
.icon-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.submit-result { font-size: 11px; margin-top: 4px; font-weight: 600; }
.submit-result.ok { color: #166534; }

/* ── Calendar View ── */
.calendar-view {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  margin-top: 16px;
  box-shadow: var(--shadow-md);
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.cal-header h3 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.cal-weekday {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 6px 0;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-cell {
  background: var(--card-secondary);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  min-height: 70px;
  padding: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
}
.cal-cell:hover {
  background: var(--hover);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  transform: translateY(-1px);
}
.cal-cell:active {
  transform: scale(0.97);
}
.cal-cell.empty {
  background: transparent;
  border-color: transparent;
  cursor: default;
  transform: none;
  box-shadow: none;
}
.cal-day-num {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
.cal-day-orders {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  align-items: center;
}
.cal-order-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.cal-order-count {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}
.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.cal-legend-item {
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
}
.cal-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

/* ── Dashboard Modern ── */
.dashboard-page { animation: fadeIn 0.3s ease; }
.dashboard-title { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; margin-bottom: 18px; color: var(--primary); border: none; padding: 0; }

/* Cards with icons */
.card-icon { font-size: 16px; line-height: 1; vertical-align: middle; }

/* ── Pie / Donut Chart ── */
.donut-card {
  background: var(--card);
  border: 1px solid var(--border-light);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all 0.2s ease;
}
.donut-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.06);
}
.donut-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.donut-card-header h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  color: var(--primary);
}
.donut-chart-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Donut SVG container */
.donut-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 18px;
}
.donut-svg {
  width: 220px;
  height: 220px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.08));
}

/* Donut path segments */
.donut-svg path {
  transition: opacity 0.2s ease;
  cursor: pointer;
  stroke: var(--card);
  stroke-width: 0.5;
}
.donut-svg path:hover {
  opacity: 0.75;
}

/* Donut legend */
.donut-legend {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.donut-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 10px;
  transition: background 0.15s ease;
  cursor: default;
}
.donut-row:hover {
  background: var(--accent-light);
}
.donut-dot {
  width: 12px;
  height: 12px;
  border-radius: 4px;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.donut-label {
  font-size: 13px;
  flex: 1;
  color: var(--text);
  font-weight: 500;
}
.donut-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 4px;
}
.donut-pct {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

/* ── Top Items Modern ── */
.top-items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ti-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 12px;
  transition: background 0.15s ease;
  cursor: default;
}
.ti-row:hover {
  background: var(--accent-light);
}
.ti-rank {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  flex-shrink: 0;
  letter-spacing: -0.3px;
}
.ti-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ti-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ti-bar-track {
  height: 8px;
  background: var(--card-secondary);
  border-radius: 6px;
  overflow: hidden;
}
.ti-bar-fill {
  height: 100%;
  border-radius: 6px;
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 4px;
}
.ti-count {
  font-size: 14px;
  font-weight: 800;
  color: var(--primary);
  min-width: 32px;
  text-align: center;
  font-feature-settings: 'tnum';
}

@media (max-width: 768px) {
  .analytics-grid { grid-template-columns: 1fr; }
}
.submit-result.err { color: #991b1b; }
