/* NMY Virtual Office — black & gold, calm. RTL-first (logical properties throughout). */
:root {
  --bg: #0f0f10;
  --surface: #17171a;
  --surface-2: #1f1f23;
  --line: #2c2c31;
  --text: #f2efe8;
  --muted: #a7a29a;
  --gold: #c9a24a;
  --gold-strong: #e0bb62;
  --gold-soft: rgba(201, 162, 74, .14);
  --ok: #4fb286;
  --warn: #e0a84a;
  --bad: #e06a5a;
  --info: #6aa3e0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f3ec; --surface: #ffffff; --surface-2: #f1ede4; --line: #e2dccf; --text: #1b1a17; --muted: #6c665c;
  --gold: #a07a24; --gold-strong: #8a6516; --gold-soft: rgba(160,122,36,.12); color-scheme: light;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f6f3ec; --surface: #ffffff; --surface-2: #f1ede4; --line: #e2dccf; --text: #1b1a17; --muted: #6c665c;
    --gold: #a07a24; --gold-strong: #8a6516; --gold-soft: rgba(160,122,36,.12); color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 15px; line-height: 1.55; }
a { color: var(--gold-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.num, .ltr { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
/* Mixed-language user/assistant text: direction follows each paragraph's first strong character. */
pre.out, .final, .msg, textarea { unicode-bidi: plaintext; text-align: start; }

/* ── Shell ── */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.brand-mark { width: 34px; height: 34px; border-radius: 8px; background: #000; border: 1px solid var(--gold); color: var(--gold); display: grid; place-items: center; font-weight: 700; letter-spacing: .5px; font-size: 13px; }
.brand b { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 12px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text); font-size: 14px; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--gold-soft); color: var(--gold-strong); }
.nav .count { margin-inline-start: auto; background: var(--gold); color: #000; border-radius: 99px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.nav-sep { height: 1px; background: var(--line); margin: 10px 4px; }
.side-tools { padding: 0 8px; }
.mt { margin-top: 14px; }
.grow { flex: 1; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 20px 24px 60px; max-width: 1400px; }
.banner { padding: 8px 24px; font-size: 13px; background: var(--gold-soft); color: var(--gold-strong); border-bottom: 1px solid var(--line); }
.banner.bad { background: rgba(224,106,90,.12); color: var(--bad); }

/* ── Primitives ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; font-size: 14px; white-space: nowrap; }
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #111; font-weight: 600; }
.btn.primary:hover { background: var(--gold-strong); }
.btn.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card h2, .card h3 { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.grid { display: grid; gap: 14px; }
.grid.k { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 2px; }
.kpi.alert .value { color: var(--warn); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack > * + * { margin-top: 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; border: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.pill.hot, .pill.bad, .pill.failed, .pill.rejected, .pill.overdue { color: var(--bad); border-color: rgba(224,106,90,.5); }
.pill.warm, .pill.warn, .pill.waiting_approval, .pill.pending, .pill.needs_review, .pill.needs_reverification, .pill.pending_verification { color: var(--warn); border-color: rgba(224,168,74,.5); }
.pill.cold, .pill.info, .pill.queued, .pill.waiting_tool { color: var(--info); border-color: rgba(106,163,224,.5); }
.pill.ok, .pill.available, .pill.completed, .pill.approved, .pill.sent, .pill.available_confirmed, .pill.assigned, .pill.used { color: var(--ok); border-color: rgba(79,178,134,.5); }
.pill.running { color: var(--gold-strong); border-color: var(--gold); }
.pill.stopped, .pill.draft { color: var(--muted); }
.pill.demo { color: var(--gold); border-color: var(--gold); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Tables (become cards on phones) */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: start; color: var(--muted); font-weight: 500; font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }

/* Forms */
label.f { display: block; font-size: 13px; color: var(--muted); }
label.f > input, label.f > select, label.f > textarea { display: block; width: 100%; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], select, textarea {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
textarea { resize: vertical; min-height: 80px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input, .filters select { width: auto; }

/* ── Office scene (top view, 2D) ── */
.office { display: grid; gap: 12px; grid-template-columns: repeat(12, 1fr); grid-auto-rows: minmax(90px, auto); }
.zone { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; position: relative; min-width: 0; }
.desk-grid > *, .grid > *, .office > * { min-width: 0; }
.zone > .zt { font-size: 12px; color: var(--muted); letter-spacing: .3px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.zone.ahmed { grid-column: span 3; grid-row: span 2; border-color: var(--gold); }
.zone.aziza { grid-column: span 3; grid-row: span 2; }
.zone.desks { grid-column: span 6; grid-row: span 4; background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px); background-size: 24px 24px; background-color: var(--surface); }
.zone.meeting { grid-column: span 3; grid-row: span 2; }
.zone.board { grid-column: span 3; grid-row: span 2; }
.zone.approvals { grid-column: span 3; }
.zone.archive { grid-column: span 3; }
.human { display: flex; gap: 10px; align-items: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: #000; border: 2px solid var(--gold); color: var(--gold); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.agent { border-radius: 12px; border-color: var(--line); color: var(--text); background: var(--surface-2); }
.desk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.desk { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: pointer; text-align: start; display: flex; gap: 10px; align-items: center; width: 100%; }
.desk:hover { border-color: var(--gold); }
.desk .nm { font-weight: 600; font-size: 14px; display: block; }
.desk .ti { color: var(--muted); font-size: 12px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.desk .info { min-width: 0; flex: 1; }
.desk.running .avatar { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
.desk.stopped { opacity: .6; }
@media (prefers-reduced-motion: no-preference) {
  .desk.running .avatar { animation: pulse 1.6s ease-in-out infinite; }
  @keyframes pulse { 50% { box-shadow: 0 0 0 6px transparent; } }
}

/* Side panel */
.panel-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }
.panel { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(560px, 100vw); background: var(--surface); border-inline-start: 1px solid var(--line); z-index: 21; overflow-y: auto; padding: 18px; }
.panel header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.panel header h2 { margin: 0; font-size: 17px; flex: 1; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv .pill, .approval .pill { white-space: normal; }
.kv dd.ltr, .kv dd.num { text-align: end; }
[dir=ltr] .kv dd.ltr, [dir=ltr] .kv dd.num { text-align: start; }
pre.out { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-family: var(--font); font-size: 13px; margin: 0; max-height: 360px; overflow: auto; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; padding: 4px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); white-space: pre-wrap; font-size: 14px; }
.msg.me { align-self: flex-start; background: var(--gold-soft); }
.msg.agent { align-self: flex-end; border: 1px solid var(--line); }
.msg .who { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }
.chat-form input { flex: 1; }

/* Approval cards */
.approval { border-inline-start: 3px solid var(--warn); }
.approval .final { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; margin: 8px 0; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.login .brand { justify-content: center; border: 0; }

#toast { position: fixed; bottom: 18px; inset-inline-start: 50%; transform: translateX(50%); background: var(--surface-2); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100vw - 32px); }
[dir=ltr] #toast { transform: translateX(-50%); }
#toast.bad { border-color: var(--bad); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .zone.ahmed, .zone.aziza, .zone.meeting, .zone.board, .zone.approvals, .zone.archive { grid-column: span 6; grid-row: auto; }
  .zone.desks { grid-column: span 12; grid-row: auto; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; width: 250px; z-index: 30; transform: translateX(100%); transition: transform .2s; }
  [dir=ltr] .side { transform: translateX(-100%); }
  .side.open { transform: none !important; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 14px 16px 60px; }
  .office { grid-template-columns: 1fr; }
  .zone.ahmed, .zone.aziza, .zone.meeting, .zone.board, .zone.approvals, .zone.archive, .zone.desks { grid-column: 1 / -1; }
  .desk-grid { grid-template-columns: 1fr 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  /* tables → stacked cards */
  table.t thead { display: none; }
  table.t, table.t tbody, table.t tr, table.t td { display: block; width: 100%; }
  table.t tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; padding: 6px 0; background: var(--surface); }
  table.t td { border: 0; padding: 4px 12px; display: flex; gap: 10px; justify-content: space-between; }
  table.t td::before { content: attr(data-l); color: var(--muted); font-size: 12px; flex: none; }
}
@media (max-width: 420px) { .desk-grid { grid-template-columns: 1fr; } }
