:root {
  --sidebar: #161a2b;
  --sidebar-ink: #c5cad9;
  --sidebar-ink-dim: #7c829a;
  --sidebar-active: rgba(255, 255, 255, 0.07);
  --canvas: #f3f4f8;
  --surface: #ffffff;
  --ink: #1b1f2a;
  --muted: #717684;
  --line: #e6e8ee;
  --accent: #4b5bd7;
  --accent-soft: #eef0fc;
  --danger: #d6453c;
  --ok: #2f9e6e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.04), 0 8px 24px rgba(20, 24, 40, 0.05);
  font-family: "Readex Pro", system-ui, sans-serif;
}

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

body {
  background: var(--canvas);
  color: var(--ink);
  font-weight: 400;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }

/* ------------------------------ الشريط الجانبي ------------------------------ */
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-mark {
  width: 38px; height: 38px; display: grid; place-items: center;
  background: var(--accent); color: #fff; border-radius: 11px;
  font-size: 16px; flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.35; }
.brand-text strong { font-size: 15px; color: #fff; font-weight: 600; }
.brand-text span { font-size: 12px; color: var(--sidebar-ink-dim); }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  background: none; border: 0; cursor: pointer;
  color: var(--sidebar-ink); font-family: inherit; font-size: 14.5px;
  text-align: right; padding: 11px 13px; border-radius: 10px;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.is-active { background: var(--sidebar-active); color: #fff; }
.nav-ico { font-size: 14px; width: 18px; text-align: center; opacity: 0.85; }

.sidebar-foot { margin-top: auto; padding-top: 18px; }
.ghost-btn {
  display: block; text-align: center; text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.14); color: var(--sidebar-ink);
  padding: 10px; border-radius: 10px; font-size: 13.5px;
  transition: background 0.15s, border-color 0.15s;
}
.ghost-btn:hover { background: var(--sidebar-active); border-color: rgba(255, 255, 255, 0.28); }
.store-note { font-size: 11.5px; color: var(--sidebar-ink-dim); margin-top: 12px; line-height: 1.7; }
.store-note code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 5px; direction: ltr; display: inline-block; }

/* -------------------------------- المحتوى -------------------------------- */
.content { padding: 38px 44px; max-width: 1180px; }
.view { display: none; animation: fade 0.25s ease; }
.view.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.view-head { margin-bottom: 26px; }
.view-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.view-head p { color: var(--muted); margin-top: 4px; font-size: 14.5px; }

/* الإحصاءات */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.stat-num { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; line-height: 1; }
.stat-label { color: var(--muted); font-size: 13.5px; }

/* اللوحات */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head.stacked { flex-direction: column; align-items: stretch; gap: 14px; }
.panel-head h2 { font-size: 16px; font-weight: 600; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-family: inherit; font-size: 13.5px; }
.count-pill { background: var(--accent-soft); color: var(--accent); border-radius: 20px; padding: 2px 11px; font-size: 13px; font-weight: 600; }

/* أعمدة الوكلاء */
.agent-bars { display: flex; flex-direction: column; gap: 12px; }
.agent-bar { display: grid; grid-template-columns: 130px 1fr 38px; align-items: center; gap: 12px; }
.agent-bar .ab-name { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.agent-bar .ab-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.agent-bar .ab-track { display: block; background: var(--canvas); height: 9px; border-radius: 6px; overflow: hidden; }
.agent-bar .ab-fill { display: block; height: 100%; border-radius: 6px; min-width: 4px; }
.agent-bar .ab-val { font-size: 13px; color: var(--muted); text-align: left; }

/* النماذج */
.split { display: grid; grid-template-columns: 360px 1fr; gap: 20px; align-items: start; }
.form .field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 15px; }
.field span { font-size: 13.5px; font-weight: 500; }
.field em { color: var(--muted); font-style: normal; font-weight: 400; font-size: 12.5px; }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: #fff; transition: border-color 0.15s, box-shadow 0.15s; width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.field input::placeholder, .field textarea::placeholder { color: #aab0bd; }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 11px 20px; font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.07); }
.btn-text { background: none; border: 0; color: var(--muted); cursor: pointer; font-family: inherit; font-size: 13.5px; }
.btn-text:hover { color: var(--ink); }
.form-msg { font-size: 13px; margin-top: 10px; min-height: 18px; }
.form-msg.err { color: var(--danger); }
.form-msg.ok { color: var(--ok); }

/* الفلاتر */
.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.filters input, .filters select {
  font-family: inherit; font-size: 13.5px; border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 11px; background: #fff; color: var(--ink);
}
.filters input { flex: 1; min-width: 160px; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--accent); }

/* قائمة الحسابات */
.account-list { display: flex; flex-direction: column; gap: 10px; }
.account-row {
  display: flex; align-items: center; gap: 13px;
  border: 1px solid var(--line); border-radius: 11px; padding: 13px 15px;
  border-right: 4px solid var(--ag, var(--accent));
}
.account-row .ar-main { flex: 1; min-width: 0; }
.account-row .ar-email { font-size: 14px; font-weight: 500; direction: ltr; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-row .ar-meta { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.account-row .row-actions { display: flex; gap: 4px; flex-shrink: 0; }

.agent-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 20px;
  background: var(--ag-soft, var(--accent-soft)); color: var(--ag, var(--accent));
}
.agent-chip .ac-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.icon-btn {
  background: none; border: 1px solid transparent; cursor: pointer;
  width: 32px; height: 32px; border-radius: 8px; color: var(--muted);
  font-size: 14px; display: grid; place-items: center; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--canvas); color: var(--ink); }
.icon-btn.danger:hover { background: #fdecea; color: var(--danger); }

/* قائمة المحادثات */
.chat-list { display: flex; flex-direction: column; gap: 12px; }
.chat-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 15px 17px;
  border-right: 4px solid var(--ag, var(--accent)); position: relative;
}
.chat-card .cc-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 7px; }
.chat-card .cc-project { font-size: 12.5px; color: var(--muted); background: var(--canvas); padding: 2px 9px; border-radius: 20px; }
.chat-card .cc-desc { font-size: 14px; line-height: 1.65; margin: 4px 0 9px; }
.chat-card .cc-desc.empty { color: #aab0bd; font-style: italic; }
.chat-card .cc-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chat-card .cc-link {
  font-size: 12.5px; color: var(--accent); text-decoration: none; direction: ltr;
  max-width: 60ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block;
}
.chat-card .cc-link:hover { text-decoration: underline; }
.chat-card .cc-actions { display: flex; gap: 4px; }
.chat-card .cc-date { font-size: 12px; color: var(--muted); }
.cc-meta { display: flex; align-items: center; gap: 9px; margin-inline-start: auto; }

/* حالة فارغة */
.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state .es-ico { font-size: 30px; opacity: 0.4; }
.empty-state p { margin-top: 8px; font-size: 14px; }

/* ------------------------------ صفحة الاستيراد ------------------------------ */
.import-controls { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--canvas); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn {
  border: 0; background: none; cursor: pointer; font-family: inherit; font-size: 13.5px;
  color: var(--muted); padding: 7px 16px; border-radius: 8px; transition: background 0.15s, color 0.15s;
}
.seg-btn.is-active { background: #fff; color: var(--ink); font-weight: 500; box-shadow: 0 1px 2px rgba(20,24,40,0.06); }
#downloadTemplate { cursor: pointer; }

.cols-hint {
  font-size: 13px; color: var(--muted); background: var(--canvas);
  border-radius: 10px; padding: 11px 14px; margin-bottom: 16px; line-height: 1.9;
}
.cols-hint b { color: var(--ink); font-weight: 500; }
.cols-hint .opt { color: #9aa0ad; }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 1.5px dashed #cdd2dd; border-radius: 14px; padding: 34px 20px;
  cursor: pointer; text-align: center; transition: border-color 0.15s, background 0.15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-ico { font-size: 26px; color: var(--accent); }
.dz-main { font-size: 15px; font-weight: 500; }
.dz-sub { font-size: 12.5px; color: var(--muted); }

.preview-summary { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13.5px; }
.preview-summary .ps { display: inline-flex; align-items: center; gap: 6px; }
.preview-summary .ps b { font-weight: 600; }
.preview-summary .dot { width: 8px; height: 8px; border-radius: 50%; }
.preview-summary .dot.ok { background: var(--ok); }
.preview-summary .dot.dup { background: #e0a32e; }
.preview-summary .dot.bad { background: var(--danger); }

.preview-wrap { overflow-x: auto; margin-top: 6px; }
.preview-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.preview-table th, .preview-table td { text-align: right; padding: 9px 11px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.preview-table th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
.preview-table td.wrap { white-space: normal; max-width: 320px; }
.preview-table tr.row-bad td { background: #fdf2f1; }
.preview-table tr.row-dup td { background: #fdf8ee; }
.preview-table .status-tag { font-size: 11.5px; font-weight: 500; padding: 2px 8px; border-radius: 20px; }
.preview-table .status-tag.ok { background: #e7f6ee; color: var(--ok); }
.preview-table .status-tag.dup { background: #fbf0d8; color: #b07d12; }
.preview-table .status-tag.bad { background: #fdecea; color: var(--danger); }
.preview-table td.ltr { direction: ltr; text-align: right; }

/* ------------------------------ زر النجمة ------------------------------ */
.icon-btn.fav { color: #c9ced8; }
.icon-btn.fav:hover { background: #fdf6e3; color: #e0a32e; }
.icon-btn.fav.on { color: #e0a32e; }

/* ------------------------------ صفحة المفضلة ------------------------------ */
.fav-list { display: flex; flex-direction: column; gap: 12px; }
.fav-card {
  display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start;
  border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  border-right: 4px solid var(--ag, var(--accent)); background: #fff;
  transition: box-shadow 0.15s, opacity 0.15s, transform 0.05s;
}
.fav-card.dragging { opacity: 0.45; box-shadow: var(--shadow); }
.fav-card.drop-target { border-color: var(--accent); }
.fav-handle {
  cursor: grab; color: #c2c7d2; font-size: 18px; line-height: 1; user-select: none;
  display: grid; place-items: center; height: 26px; border-radius: 7px; transition: background 0.15s, color 0.15s;
}
.fav-handle:hover { background: var(--canvas); color: var(--muted); }
.fav-handle:active { cursor: grabbing; }
.fav-body { min-width: 0; }
.fav-top { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 6px; }
.fav-order { font-size: 12px; color: var(--muted); background: var(--canvas); border-radius: 20px; padding: 1px 9px; }
.fav-desc { font-size: 14px; font-weight: 500; line-height: 1.55; margin-bottom: 6px; }
.fav-desc.empty { color: #aab0bd; font-style: italic; font-weight: 400; }
.fav-link { font-size: 12.5px; color: var(--accent); text-decoration: none; direction: ltr; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav-link:hover { text-decoration: underline; }

.fav-note { margin-top: 10px; }
.fav-note textarea {
  width: 100%; font-family: inherit; font-size: 13px; color: var(--ink); line-height: 1.6;
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px; background: #fcfcfd;
  resize: vertical; min-height: 38px; transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.fav-note textarea::placeholder { color: #aab0bd; }
.fav-note textarea:focus { outline: none; border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.fav-note-bar { display: flex; align-items: center; gap: 8px; margin-top: 7px; min-height: 20px; }
.fav-note-save { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 6px 14px; font-family: inherit; font-size: 12.5px; cursor: pointer; }
.fav-note-save:hover { filter: brightness(1.07); }
.fav-note-hint { font-size: 12px; color: var(--muted); }
.fav-note-hint.saved { color: var(--ok); }

.fav-actions { display: flex; gap: 4px; flex-shrink: 0; margin-inline-start: auto; }

/* تنبيه عائم */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 80px);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 11px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  opacity: 0; transition: transform 0.3s, opacity 0.3s; pointer-events: none; z-index: 50;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.err { background: var(--danger); }

/* استجابة الشاشات */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; }
  .brand { padding: 0; flex: 1; }
  .nav { flex-direction: row; margin: 0; }
  .sidebar-foot { margin: 0; padding: 0; }
  .store-note { display: none; }
  .content { padding: 24px 18px; }
  .split { grid-template-columns: 1fr; }
  .stat-row { grid-template-columns: 1fr; }
  .agent-bar { grid-template-columns: 110px 1fr 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
