/* ============================================================
   HAMDAN — Agent Operations Dashboard
   Design system: warm, minimal, Notion-like. Borders not shadows.
   Bilingual LTR/RTL via logical properties. Light only.
   ============================================================ */

:root {
  --bg-app:        #FBFAF7;
  --bg-sidebar:    #F6F5F1;
  --bg-cell:       #F3F2ED;
  --surface-card:  #FFFFFF;
  --border:        #E9E7E0;
  --border-strong: #DEDBD2;
  --text-primary:  #232220;
  --text-muted:    #93908A;
  --text-faint:    #B8B4AD;

  /* division accents — entity identity only */
  --ops:     #5E8C70;   /* Operations — sage green */
  --hr:      #BD9446;   /* HR — cardamom gold */
  --indep:   #6C5CE7;   /* Independent — indigo */

  /* states */
  --ok:      #4F8A63;
  --warn:    #C9892F;
  --fail:    #B85C4A;
  --live:    #3FAE6B;

  --r-card: 12px;
  --r-cell: 8px;
  --r-chip: 6px;
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

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

html, body { height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
:root[dir="rtl"] body { font-family: "Segoe UI", Tahoma, system-ui, sans-serif; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px; flex: none;
  background: var(--bg-sidebar);
  border-inline-end: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  padding: 22px 16px 16px;
}
.brand {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 6px 0 20px;
}
.brand .mark {
  width: 42px; height: 42px; border-radius: 11px;
  background: var(--text-primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 20px;
}
.brand .mark .ar { font-size: 20px; }
.brand .brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand .brand-sub { font-size: 12px; color: var(--text-muted); margin-top: -4px; }

.views-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-muted); font-weight: 600;
  padding: 8px 10px 6px;
}
:root[dir="rtl"] .views-label { text-transform: none; letter-spacing: 0; }

nav.views { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--r-cell);
  font-size: 14px; color: var(--text-primary);
  cursor: pointer; border: none; background: transparent; width: 100%;
  text-align: start; font-family: inherit;
  transition: background 0.15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex: none; color: var(--text-muted); }
.nav-item:hover { background: rgba(0, 0, 0, 0.035); }
.nav-item.active { background: rgba(0, 0, 0, 0.06); font-weight: 600; }
.nav-item.active svg { color: var(--text-primary); }
.nav-item:focus-visible { outline: 2px solid var(--indep); outline-offset: 1px; }
.nav-item.soon { cursor: default; color: var(--text-faint); }
.nav-item.soon:hover { background: transparent; }
.nav-item.soon svg { color: var(--text-faint); }
.nav-item .soon-pill {
  margin-inline-start: auto; font-size: 10px; color: var(--text-muted);
  background: var(--bg-cell); border: 1px solid var(--border);
  padding: 1px 6px; border-radius: 999px;
}

.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.live-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px 2px; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--live);
  box-shadow: 0 0 0 0 rgba(63, 174, 107, 0.5); animation: livepulse 2s infinite;
}
@keyframes livepulse {
  0% { box-shadow: 0 0 0 0 rgba(63, 174, 107, 0.45); }
  70% { box-shadow: 0 0 0 6px rgba(63, 174, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(63, 174, 107, 0); }
}
.live-text { font-size: 13px; color: var(--text-primary); font-variant-numeric: tabular-nums; }
.live-mode { font-size: 11px; color: var(--text-muted); padding: 0 10px 6px; }
.side-btn {
  display: block; width: 100%; text-align: start; font-family: inherit;
  padding: 8px 10px; border-radius: var(--r-cell); border: none; background: transparent;
  color: var(--text-muted); font-size: 13px; cursor: pointer;
}
.side-btn:hover { background: rgba(0, 0, 0, 0.035); color: var(--text-primary); }

/* ============================================================
   MAIN
   ============================================================ */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: color-mix(in srgb, var(--bg-app) 88%, transparent);
  backdrop-filter: blur(8px); z-index: 5;
}
.hamburger { display: none; border: none; background: transparent; cursor: pointer; padding: 4px; color: var(--text-muted); }
.hamburger svg { width: 20px; height: 20px; display: block; }
.topbar .crumb { font-size: 13px; color: var(--text-muted); }

.container { max-width: 920px; margin-inline: auto; width: 100%; padding: 34px 40px 90px; }

.page-title { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.page-sub { font-size: 15px; color: var(--text-muted); margin-top: 8px; }

/* section header */
.section { margin-top: 38px; }
.section-head {
  display: flex; align-items: center; gap: 9px; margin-bottom: 4px;
}
.section-head .sq { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.section-head .lbl { font-size: 16px; font-weight: 600; }
.section-head .count { font-size: 13px; color: var(--text-muted); font-weight: 400; }
.section-rule { height: 1px; background: var(--border); margin: 10px 0 18px; }

/* ============================================================
   STAT CARDS (hero — the day-cell pattern)
   ============================================================ */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 16px 18px 15px; box-shadow: var(--card-shadow);
}
.eyebrow {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 600;
}
:root[dir="rtl"] .eyebrow { text-transform: none; letter-spacing: 0; }
.stat-value { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; line-height: 1; }
.stat-value small { font-size: 16px; color: var(--text-faint); font-weight: 600; }
.stat-value.ok { color: var(--ok); }
.stat-value.warn { color: var(--warn); }
.stat-value.zero { color: var(--text-faint); }
.progress { height: 4px; border-radius: 999px; background: var(--border); margin-top: 12px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--ok); }
.progress > i.warn { background: var(--warn); }
.stat-cap { font-size: 12px; color: var(--text-muted); margin-top: 8px; }
.stat-cap.warn { color: var(--warn); }

/* ============================================================
   ENTITY CARDS (agents)
   ============================================================ */
.card-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 680px) { .card-grid { grid-template-columns: 1fr; } }
.entity-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 18px; box-shadow: var(--card-shadow);
  transition: border-color 0.2s ease;
}
.entity-card.working { border-color: color-mix(in srgb, var(--live) 55%, var(--border)); }
.entity-card.dim { opacity: 0.62; }
.entity-card.flash { animation: cardflash 1.5s ease; }
@keyframes cardflash {
  0% { border-color: var(--live); box-shadow: 0 0 0 3px rgba(63, 174, 107, 0.14); }
  100% { border-color: var(--border); box-shadow: var(--card-shadow); }
}
.entity-head { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px; height: 40px; border-radius: var(--r-cell); flex: none;
  display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 14px;
}
.entity-id { min-width: 0; flex: 1; }
.entity-name {
  font-size: 16px; font-weight: 600; display: flex; align-items: baseline; gap: 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entity-name .ar { font-size: 12px; font-weight: 400; color: var(--text-muted); }
.entity-sub { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status-dot.working { background: var(--live); box-shadow: 0 0 0 0 rgba(63, 174, 107, 0.5); animation: livepulse 1.6s infinite; }
.status-dot.active { background: var(--ok); }
.status-dot.dormant { background: var(--text-faint); }
.status-dot.retired { background: var(--fail); }

.entity-cell {
  background: var(--bg-cell); border-radius: var(--r-cell);
  padding: 11px 12px; margin-top: 14px;
}
.entity-cell .cell-eyebrow { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
:root[dir="rtl"] .cell-eyebrow { text-transform: none; letter-spacing: 0; }
.entity-cell .cell-body { font-size: 13px; margin-top: 3px; color: var(--text-primary); }
.entity-cell .cell-body.idle { color: var(--text-faint); }
.entity-cell .cell-body .ago { color: var(--text-muted); }

.entity-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.meta-chip {
  font-size: 12px; color: var(--text-muted);
  background: var(--bg-cell); border: 1px solid var(--border);
  padding: 2px 9px; border-radius: var(--r-chip);
}
.meta-chip b { color: var(--text-primary); font-weight: 600; }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); overflow: hidden; box-shadow: var(--card-shadow);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  background: var(--bg-cell); text-align: start; font-weight: 600;
  font-size: 12px; color: var(--text-muted); padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
td.num { font-variant-numeric: tabular-nums; color: var(--text-muted); }
.t-title { font-weight: 550; }
.t-reason { color: var(--fail); font-size: 12.5px; }

/* escalate-to-Noora */
.ask-noora {
  margin-top: 6px; font-family: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--hr); background: color-mix(in srgb, var(--hr) 10%, #fff);
  border: 1px solid color-mix(in srgb, var(--hr) 30%, var(--border));
  border-radius: var(--r-chip); padding: 4px 11px; cursor: pointer;
}
.ask-noora:hover { background: color-mix(in srgb, var(--hr) 18%, #fff); }
.ask-noora:disabled { opacity: 0.6; cursor: default; }
.hr-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--hr); flex: none; display: inline-block; }
.noora-review {
  margin-top: 6px; font-size: 12.5px; color: var(--hr); font-weight: 500;
  display: flex; align-items: center; gap: 7px;
}
.noora-review .hr-dot { animation: livepulse 1.4s infinite; }
.noora-panel {
  margin-top: 8px; border: 1px solid color-mix(in srgb, var(--hr) 28%, var(--border));
  border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--hr) 5%, #fff);
  max-width: 640px;
}
.noora-head {
  display: flex; align-items: center; gap: 7px; padding: 7px 12px;
  font-size: 12px; font-weight: 700; color: var(--hr);
  background: color-mix(in srgb, var(--hr) 11%, #fff);
  border-bottom: 1px solid color-mix(in srgb, var(--hr) 22%, var(--border));
}
.noora-body {
  padding: 10px 12px; font-size: 13px; color: var(--text-primary);
  white-space: pre-wrap; line-height: 1.55;
}
.noora-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-top: 1px solid color-mix(in srgb, var(--hr) 18%, var(--border));
}
.approve-btn {
  font-family: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
  color: #fff; background: var(--ok); border: 1px solid var(--ok);
  border-radius: var(--r-chip); padding: 6px 13px;
}
.approve-btn:hover { background: color-mix(in srgb, var(--ok) 88%, #000); }
.dismiss-btn {
  font-family: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
  color: var(--text-muted); background: transparent; border: 1px solid var(--border);
  border-radius: var(--r-chip); padding: 6px 13px;
}
.dismiss-btn:hover { color: var(--text-primary); border-color: var(--border-strong); }
.noora-decision {
  padding: 9px 12px; font-size: 12.5px; font-weight: 600;
  border-top: 1px solid color-mix(in srgb, var(--hr) 18%, var(--border));
  display: flex; align-items: center; gap: 7px; color: var(--text-secondary);
}
.noora-decision.ok { color: var(--ok); }
.noora-decision.err { color: var(--fail); font-weight: 500; }
.noora-decision .hr-dot { animation: livepulse 1.4s infinite; }

/* ---------- conflict banner (Overview) ---------- */
.conflict-banner {
  display: flex; align-items: center; gap: 12px; width: 100%;
  margin-top: 20px; padding: 13px 18px; cursor: pointer;
  font-family: inherit; font-size: 13.5px; text-align: start;
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--card-shadow);
  transition: border-color 0.15s ease;
}
.conflict-banner:hover { border-color: var(--border-strong); }
.conflict-banner .cb-icon { font-size: 15px; flex: none; }
.conflict-banner .cb-text { flex: 1; color: var(--text-secondary); }
.conflict-banner .cb-text b { color: var(--text-primary); }
.conflict-banner .cb-go { flex: none; font-weight: 600; color: var(--indep); font-size: 12.5px; }
.conflict-banner.ok { border-inline-start: 3px solid var(--ok); }
.conflict-banner.ok .cb-icon { color: var(--ok); }
.conflict-banner.alert { border-inline-start: 3px solid var(--fail);
  background: color-mix(in srgb, var(--fail) 4%, var(--surface-card)); }
.conflict-banner.alert .cb-icon { color: var(--fail); }

/* ---------- calendar & conflicts ---------- */
.alert-pill {
  margin-inline-start: auto; font-size: 11px; font-weight: 700; color: #fff;
  background: var(--fail); border-radius: 999px; padding: 1px 7px; min-width: 18px; text-align: center;
}
.all-clear {
  background: var(--surface-card); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: 18px 20px; color: var(--ok); font-weight: 600; font-size: 13.5px; box-shadow: var(--card-shadow);
}
.conflict {
  background: var(--surface-card); border: 1px solid var(--border);
  border-inline-start: 3px solid var(--warn);
  border-radius: var(--r-card); box-shadow: var(--card-shadow);
  padding: 16px 18px; margin-bottom: 14px;
}
.conflict.high { border-inline-start-color: var(--fail); }
.conflict-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.sev { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 2px 9px; border-radius: var(--r-chip); }
.sev.high { background: color-mix(in srgb, var(--fail) 13%, #fff); color: var(--fail); }
.sev.medium { background: color-mix(in srgb, var(--warn) 15%, #fff); color: var(--warn); }
.ckind { font-size: 13.5px; font-weight: 600; }
.cstatus { margin-inline-start: auto; font-size: 12px; color: var(--text-muted); }
.conflict-events { display: flex; flex-direction: column; gap: 8px; }

.cal-list { background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--card-shadow); padding: 8px 14px; }
.cal-list .cal-ev + .cal-ev { border-top: 1px solid var(--border); }
.cal-ev { display: flex; align-items: center; gap: 11px; padding: 9px 0; }
.conflict .cal-ev { background: var(--bg-cell); border-radius: var(--r-cell); padding: 9px 11px; }
.conflict .cal-ev.keep { background: color-mix(in srgb, var(--ok) 9%, #fff);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ok) 35%, transparent); }
.cal-bar { width: 3px; align-self: stretch; border-radius: 2px; flex: none; min-height: 30px; }
.cal-ev-body { flex: 1; min-width: 0; }
.cal-ev-title { font-size: 13.5px; font-weight: 600; }
.keep-tag { font-size: 11px; font-weight: 700; color: var(--ok); margin-inline-start: 4px; }
.cal-ev-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.cal-open { color: var(--text-faint); text-decoration: none; font-size: 15px; padding: 2px 6px; flex: none; }
.cal-open:hover { color: var(--indep); }

.adel-note { margin-top: 12px; border: 1px solid color-mix(in srgb, var(--indep) 25%, var(--border));
  border-radius: 10px; overflow: hidden; background: color-mix(in srgb, var(--indep) 4%, #fff); }
.adel-head { display: flex; align-items: center; gap: 7px; padding: 7px 12px; font-size: 12px;
  font-weight: 700; color: var(--indep);
  background: color-mix(in srgb, var(--indep) 9%, #fff);
  border-bottom: 1px solid color-mix(in srgb, var(--indep) 18%, var(--border)); }
.adel-body { padding: 9px 12px; font-size: 13px; line-height: 1.55; }
.conflict-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.move-btn {
  font-family: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer;
  color: #fff; background: var(--indep); border: 1px solid var(--indep);
  border-radius: var(--r-chip); padding: 6px 13px;
}
.move-btn:hover { background: color-mix(in srgb, var(--indep) 85%, #000); }
.move-note { font-size: 11.5px; color: var(--text-muted); margin-top: 7px; }
.past-conflicts { margin-top: 14px; }
.past-conflicts summary { cursor: pointer; font-size: 12.5px; color: var(--text-muted); padding: 6px 0; }

.del-btn {
  font-family: inherit; font-size: 13px; line-height: 1; cursor: pointer;
  color: var(--text-faint); background: transparent; border: none;
  border-radius: 6px; padding: 5px 8px;
}
.del-btn:hover { color: var(--fail); background: color-mix(in srgb, var(--fail) 10%, #fff); }
table td:last-child { text-align: end; width: 40px; }
.pill {
  display: inline-block; color: #fff; font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--r-chip); white-space: nowrap;
}
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: var(--r-chip); }
.tag.done { background: color-mix(in srgb, var(--ok) 13%, #fff); color: var(--ok); }
.tag.doing { background: color-mix(in srgb, var(--live) 14%, #fff); color: var(--ok); }
.tag.new { background: var(--bg-cell); color: var(--text-muted); }
.tag.failed { background: color-mix(in srgb, var(--fail) 13%, #fff); color: var(--fail); }

/* ============================================================
   ACTIVITY FEED
   ============================================================ */
.feed-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--card-shadow); padding: 6px 18px;
}
.feed-item { display: flex; gap: 12px; padding: 12px 0; }
.feed-item + .feed-item { border-top: 1px solid var(--border); }
.feed-item .ic { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; }
.feed-item .fx { font-size: 13.5px; color: var(--text-primary); }
.feed-item .fx .who { font-weight: 600; }
.feed-item .fx .detail { color: var(--text-muted); }
.feed-item .ft { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.feed-item.new { animation: feedin 0.5s ease; }
@keyframes feedin { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: none; } }
.empty { color: var(--text-muted); font-size: 13px; padding: 16px 2px; }

/* ============================================================
   CHART
   ============================================================ */
.chart-card {
  background: var(--surface-card); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--card-shadow); padding: 18px 20px 14px;
}
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 8px; }
.legend .k { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
#chart svg { display: block; width: 100%; height: auto; }
.viz-tip {
  position: fixed; pointer-events: none; z-index: 30;
  background: var(--surface-card); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 7px 11px; font-size: 12.5px; color: var(--text-primary);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08); display: none;
}
.viz-tip .l { color: var(--text-muted); font-size: 11px; }

/* two-column overview split */
.split { display: grid; grid-template-columns: 1.5fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 820px) { .split { grid-template-columns: 1fr; } }

/* ============================================================
   RESPONSIVE / MOBILE DRAWER
   ============================================================ */
.scrim { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset-block: 0; inset-inline-start: 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  :root[dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .scrim.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.25); z-index: 35; }
  .container { padding: 26px 20px 80px; }
  .page-title { font-size: 30px; }
}
