/* ============================================================================
   داشبورد المدير — أنماط مشتركة، مبنية على هوية Awn Agents البصرية
   (نفس الألوان والخطوط والمكوّنات من دليل البراند).
   ============================================================================ */

:root {
  color-scheme: light;

  --ink-strong: #18191b;   /* السايدبار + العناوين القوية */
  --ink: #313337;
  --ink-text: #18191b;
  --orange: #ff3c00;       /* لون العلامة الأساسي — أفعال أساسية / هوية الـ AI */
  --orange-dark: #d63500;
  --orange-light: #ffeae0;
  --blue: #2492ff;
  --peach: #ffb199;
  --paper: #faf6f1;        /* خلفية الصفحة */
  --white: #ffffff;
  --grey-1: #6b6660;
  --grey-2: #9a958e;
  --grey-3: #b5afa8;
  --rule: #ebe4dc;

  --good: #2e7d32;
  --good-bg: #eaf5ea;
  --good-border: #bfe0c2;
  --critical: #c62828;
  --critical-bg: #fff8f8;
  --critical-border: #ffcdd2;

  --radius: 6px;
  --radius-lg: 14px;
  --shadow: 0 2px 12px rgba(24, 25, 27, 0.06);
  --shadow-md: 0 4px 24px rgba(24, 25, 27, 0.1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink-text);
  font-family: "IBM Plex Sans Arabic", "IBM Plex Sans", system-ui, sans-serif;
}

body { direction: rtl; }
[dir="auto"] { unicode-bidi: plaintext; }

a { color: var(--orange-dark); }

.brand-accent { color: var(--orange); }

.center-msg {
  max-width: 480px;
  margin: 20vh auto;
  padding: 28px;
  text-align: center;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  line-height: 1.9;
}

code {
  background: var(--orange-light);
  color: var(--orange-dark);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  direction: ltr;
  unicode-bidi: embed;
  display: inline-block;
}

/* ---- App shell / sidebar ---- */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--ink-strong);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 26px 0 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 0 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 16px;
}
.sidebar-brand .brand-name { font-size: 17px; font-weight: 700; color: var(--white); }
.sidebar-brand .brand-name span { color: var(--orange); }
.sidebar-brand .brand-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.4);
  margin-top: 4px;
  letter-spacing: 0.02em;
}
.sidebar-nav { flex: 1; padding: 0 12px; display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link i { font-size: 17px; width: 18px; text-align: center; opacity: 0.85; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.08); color: var(--white); }
.sidebar-link.active { background: var(--orange); color: var(--white); }
.sidebar-footer {
  padding: 16px 16px 0;
  margin-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.sidebar-footer .user-email {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.45);
  margin-bottom: 10px;
  word-break: break-all;
  direction: ltr;
  text-align: right;
}

.main { flex: 1; min-width: 0; }

/* ---- Layout ---- */
.page { max-width: 1100px; margin: 0 auto; padding: 44px 36px; }
.page h1 { font-size: 1.55em; margin: 0 0 6px; color: var(--ink-strong); }
.page .subtitle { color: var(--grey-1); margin: 0 0 24px; }

.toolbar {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.card {
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow);
}

/* ---- Stat tiles ---- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.stat-tile {
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.stat-tile .value {
  font-size: 1.9em;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--ink-strong);
}
.stat-tile .label { color: var(--grey-1); font-size: 0.85em; margin-top: 2px; }

/* ---- Table ---- */
table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius-lg); overflow: hidden; }
th, td { padding: 12px 14px; text-align: right; border-bottom: 1px solid var(--rule); font-size: 0.92em; }
th {
  color: var(--grey-2);
  font-weight: 700;
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--paper);
}
td.num, th.num { font-variant-numeric: tabular-nums; text-align: center; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--orange-light); }

/* ---- Badges / pills (تُبنى على مكوّن .tag من دليل البراند) ---- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 0.76em;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.pill-good { color: var(--good); background: var(--good-bg); border-color: var(--good-border); }
.pill-warning { color: var(--orange-dark); background: var(--orange-light); border-color: #f5c5a8; }
.pill-critical { color: var(--critical); background: var(--critical-bg); border-color: var(--critical-border); }
.pill-muted { color: var(--grey-2); background: var(--paper); border-color: var(--rule); }

/* ---- Form controls ---- */
select, input[type="date"], input[type="month"], input[type="email"], input[type="password"] {
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1.5px solid var(--rule);
  background: var(--white);
  color: var(--ink-text);
  font-family: inherit;
  font-size: 0.92em;
}
select:focus, input:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px var(--orange-light);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  border-radius: 100px;
  border: 2px solid var(--orange);
  background: var(--orange);
  color: var(--white);
  font-family: inherit;
  font-size: 0.92em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:hover { background: var(--orange-dark); border-color: var(--orange-dark); }

.btn-ghost {
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  border: 2px solid rgba(255, 255, 255, 0.35);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.1); border-color: var(--white); color: var(--white); }

.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1.5px solid var(--orange);
  color: var(--orange-dark);
  padding: 5px 12px;
  font-size: 0.8em;
  font-weight: 600;
  border-radius: 100px;
  cursor: pointer;
  text-decoration: none;
}
.btn-link:hover { background: var(--orange-light); }

.muted { color: var(--grey-1); font-size: 0.9em; }
.empty-state { text-align: center; padding: 48px; color: var(--grey-2); }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--white);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { font-size: 1.35em; margin-top: 0; margin-bottom: 6px; color: var(--ink-strong); }
.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85em; color: var(--grey-1); font-weight: 500; }
.field input { width: 100%; }
.error-msg { color: var(--critical); font-size: 0.88em; margin-top: 12px; min-height: 1.2em; }

/* ---- Conversations: تطبيق شات فعلي بتاعين (قايمة + Thread) ---- */
.chatapp { display: flex; height: 100vh; }

.chatapp-list {
  width: 320px;
  min-width: 280px;
  background: var(--white);
  border-left: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
}
.chatapp-list-header { padding: 20px 18px 14px; border-bottom: 1px solid var(--rule); }
.chatapp-list-header h2 { margin: 0 0 12px; font-size: 1.05em; color: var(--ink-strong); }
.search-box { position: relative; }
.search-box input {
  width: 100%;
  padding: 9px 36px 9px 14px;
  border-radius: 100px;
  border: 1.5px solid var(--rule);
  background: var(--paper);
}
.search-box i { position: absolute; top: 50%; right: 13px; transform: translateY(-50%); color: var(--grey-2); font-size: 15px; }
.chatapp-list-items { flex: 1; overflow-y: auto; }

.chat-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--rule);
  transition: background 0.1s;
}
.chat-row:hover { background: var(--paper); }
.chat-row.active { background: var(--orange-light); }
.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink-strong);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9em;
  flex-shrink: 0;
}
.chat-row-info { min-width: 0; flex: 1; }
.chat-row-name {
  font-weight: 600;
  font-size: 0.92em;
  color: var(--ink-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-row-meta {
  font-size: 0.78em;
  color: var(--grey-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-row-meta i { font-size: 12px; }

.chatapp-thread { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--paper); }
.chatapp-thread-header {
  padding: 14px 24px;
  background: var(--white);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 30px;
}
.chatapp-thread-header .chat-avatar { width: 36px; height: 36px; font-size: 0.8em; }
.chatapp-thread-header .title { font-weight: 700; color: var(--ink-strong); font-size: 0.95em; }
.chatapp-thread-header .subtitle { font-size: 0.8em; color: var(--grey-2); }
.chatapp-thread-body { flex: 1; overflow-y: auto; padding: 20px 28px; display: flex; flex-direction: column; }

.bubble {
  max-width: 58%;
  padding: 9px 14px;
  border-radius: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  font-size: 0.92em;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.bubble.grouped { margin-bottom: 3px; }
.bubble-human { align-self: flex-start; background: var(--white); border-bottom-right-radius: 4px; }
.bubble-ai { align-self: flex-end; background: var(--orange-light); border: 1px solid #f5c5a8; border-bottom-left-radius: 4px; }
.bubble-time {
  font-size: 0.72em;
  color: var(--grey-2);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  justify-content: flex-end;
}
.bubble-ai .bubble-time { justify-content: flex-start; }
.chatapp-thread-body .empty-state { margin: auto; }
