:root {
  --bg: #f4f3ef; --surface: #ffffff; --surface-2: #faf9f6; --ink: #1b1e23; --muted: #686d75; --line: #e3e1db;
  --brand: #0f5f5c; --brand-ink: #ffffff; --brand-soft: #e2efed;
  --ok: #1d7a46; --ok-soft: #e3f3e9; --warn: #9a5b00; --warn-soft: #fcf0da; --bad: #b42318; --bad-soft: #fde7e5;
  --info: #2d5bd7; --info-soft: #e7eefc; --radius: 14px; --side: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315; --surface: #1a1d20; --surface-2: #16191b; --ink: #eceded; --muted: #9ba0a6; --line: #2b2f34;
    --brand: #4fb3aa; --brand-ink: #0b1a19; --brand-soft: #1a2d2b;
    --ok: #5cc98a; --ok-soft: #162a1e; --warn: #e2a64a; --warn-soft: #2d2313; --bad: #f2877c; --bad-soft: #321918;
    --info: #8aa8ff; --info-soft: #19213f; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; font-size: 15px; line-height: 1.6; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 1.35rem; font-weight: 700; } h2 { font-size: 1rem; font-weight: 600; } h3 { font-size: .95rem; margin: 18px 0 8px; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .error { color: var(--bad); min-height: 1.2em; }
.eyebrow { display: block; font-size: .68rem; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; background: var(--brand-soft); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 8px 16px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--brand); }
.btn:focus-visible, textarea:focus-visible, input:focus-visible, .tab:focus-visible, .nav button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn.ghost { background: transparent; } .btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: progress; }

.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 700; font-size: 1.3rem; flex: none; }
.brand-mark.sm { width: 36px; height: 36px; font-size: 1.05rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; display: grid; gap: 10px; }
.login-card input { font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }

/* Layout: sidebar on desktop, horizontal scrolling nav on phones */
.layout { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; gap: 16px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand strong { display: block; font-size: .95rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { font: inherit; text-align: start; border: 0; background: transparent; color: var(--ink); padding: 9px 12px; border-radius: 9px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.nav button:hover { background: var(--surface-2); }
.nav button.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.pill { font-size: .72rem; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--info-soft); color: var(--info); text-align: center; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill:empty { display: none; }
.side-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.side-foot .btn { margin-inline-start: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.dot.off { background: var(--bad); }

.main { padding: 22px 26px 40px; min-width: 0; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; font-weight: 500; }
.banner.bad { background: var(--bad-soft); color: var(--bad); }

@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { min-width: 0; position: sticky; top: 0; z-index: 5; height: auto; flex-direction: column; padding: 10px 12px 0; gap: 8px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; padding-bottom: 8px; }
  .nav button { white-space: nowrap; flex: none; padding: 7px 11px; }
  .side-foot { position: absolute; inset-inline-end: 12px; top: 14px; padding: 0; }
  .main { padding: 16px; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card h2 { margin-bottom: 10px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; }
.kpi-n { font-size: 1.9rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi.warn .kpi-n { color: var(--warn); }
.cards3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.cards2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .cards3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .kpis { grid-template-columns: 1fr 1fr; } .cards3, .cards2 { grid-template-columns: 1fr; } }
dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 0; font-size: .88rem; }
dt { color: var(--muted); } dd { margin: 0; overflow-wrap: anywhere; }
.meter { height: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.meter > i { display: block; height: 100%; background: var(--brand); width: 0; transition: width .4s; }
.meter > i.warn { background: var(--warn); } .meter > i.bad { background: var(--bad); }

.chip { font-size: .72rem; padding: 2px 8px; border-radius: 999px; white-space: nowrap; font-weight: 600; display: inline-block; }
.s-RUNNING, .s-PLANNING, .s-REVIEWING, .s-RETRYING, .s-QUEUED { background: var(--info-soft); color: var(--info); }
.s-DONE, .ok-chip { background: var(--ok-soft); color: var(--ok); }
.s-NEEDS_APPROVAL, .s-BLOCKED, .warn-chip { background: var(--warn-soft); color: var(--warn); }
.s-FAILED, .s-CANCELLED, .bad-chip { background: var(--bad-soft); color: var(--bad); }

.chat-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 12px; }
@media (max-width: 1000px) { .chat-wrap { grid-template-columns: 1fr; } }
.chat { display: flex; flex-direction: column; padding: 0; height: calc(100vh - 170px); min-height: 460px; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.owner { align-self: flex-start; background: var(--brand); color: var(--brand-ink); border-end-start-radius: 4px; }
.msg.manager { align-self: flex-end; background: var(--surface-2); border: 1px solid var(--line); border-end-end-radius: 4px; }
.msg .when { display: block; font-size: .72rem; opacity: .7; margin-top: 4px; }
.msg a.task-link { color: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.empty { color: var(--muted); text-align: center; margin: auto; padding: 24px; }
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; font: inherit; resize: vertical; min-height: 64px; max-height: 320px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.mini-list li { padding: 10px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; display: grid; gap: 6px; }
.mini-list li:hover { border-color: var(--brand); }
.bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }

.tabs { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); padding: 3px; border-radius: 10px; }
.tab { font: inherit; font-size: .85rem; border: 0; background: transparent; color: var(--muted); padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.tab.on { background: var(--brand-soft); color: var(--brand); font-weight: 600; }

.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .86rem; min-width: 860px; }
.table th { text-align: start; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tbody tr { cursor: pointer; } .table tbody tr:hover { background: var(--surface-2); }
.table .t-title { font-weight: 600; max-width: 320px; }
.num { font-variant-numeric: tabular-nums; }

.agent-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.approval { padding: 14px 16px; border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); background: var(--warn-soft); border-radius: var(--radius); display: grid; gap: 8px; margin-bottom: 12px; }
.approval ul { margin: 0; padding-inline-start: 20px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.report-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 800px) { .report-grid { grid-template-columns: 1fr; } }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .88rem; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.list li:last-child { border-bottom: 0; }

.detail { width: min(880px, calc(100% - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; }
.detail::backdrop { background: rgb(0 0 0 / .45); }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.detail-actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.report { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 4px 16px 12px; overflow-x: auto; }
.report table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.report th, .report td { border: 1px solid var(--line); padding: 6px 8px; text-align: start; }
.report h1 { font-size: 1.05rem; margin-top: 12px; } .report h2 { font-size: .95rem; margin-top: 14px; }
.events { padding-inline-start: 20px; margin: 0; font-size: .86rem; display: grid; gap: 4px; }
.events .who { color: var(--muted); font-size: .76rem; }
.toggle { display: flex; gap: 6px; align-items: center; margin-top: 14px; font-size: .86rem; cursor: pointer; }
.tech { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: .75rem; max-height: 340px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval .note { font: inherit; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.approval li { white-space: pre-wrap; }
