/* LEVEL Performance AI — tokens and layout follow Level Studio (studio.levelmena.com). */
:root {
  --surface: #fffdfd; --surface-2: #f4f7f5; --surface-3: #dee7e0; --canvas: #fffdfd;
  --line: #e3e9e5; --line-strong: #c9d2cc;
  --ink-900: #000; --ink-700: #111; --ink-500: #6e6e73; --ink-400: #8e8e93; --ink-300: #c7c7cc;
  --blue: #1129d3; --blue-hover: #0e22b0; --blue-deep: #0b1a8a; --blue-soft: #e9ecfb; --blue-pale: #c4caf2;
  --lime: #bbf714; --lime-soft: #f1fdc9; --mint-soft: #eef3ef;
  --orange: #ff5a00; --beige: #ffe6d0;
  --gradient: linear-gradient(135deg, #cfd5f8 0%, #dbe3ee 45%, #dee7e0 60%, #eaf9b8 100%);
  --gradient-bar: linear-gradient(90deg, #8f9ded 0%, #b9cfe0 45%, #c9e6a4 75%, #bbf714 100%);
  --accent: var(--blue); --accent-soft: var(--blue-soft);
  --success: #2e8b57; --success-soft: #e7f4ec;
  --warning: #ff5a00; --warning-text: #c24400; --warning-soft: #ffe6d0;
  --danger: #d12b2b; --danger-soft: #fdecec;
  --info: #007bff; --info-soft: #e6f1ff;
  --shadow-sm: 0 1px 2px #1a1a1a0f, 0 1px 1px #1a1a1a0a;
  --shadow-md: 0 8px 24px -8px #1a1a1a2e;
  --ring: 0 0 0 4px #2038e238;
  --dur-fast: .14s; --dur: .22s; --ease-out: cubic-bezier(.2, .8, .2, 1);
  --on-fill: #fff; --rail: 264px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --canvas: #0b0b0c; --surface: #141416; --surface-2: #19191c; --surface-3: #232327;
    --line: #26262b; --line-strong: #35353b;
    --ink-900: #fffdfd; --ink-700: #ececec; --ink-500: #a1a1a6; --ink-400: #8e8e93; --ink-300: #636366;
    --blue: #4a5ff0; --blue-hover: #6878ff; --blue-deep: #1b1b1f; --blue-soft: #131a46; --blue-pale: #26348f;
    --lime-soft: #23300a; --mint-soft: #171a18;
    --gradient: linear-gradient(135deg, #1c2a8a 0%, #15223a 45%, #1d2a22 60%, #4d6a0c 100%);
    --accent: #5b6ff5; --accent-soft: #131a46;
    --success: #4cc27a; --success-soft: #16302a; --warning: #ff7a33; --warning-text: #ffb38a; --warning-soft: #3a2416;
    --danger: #ff6464; --danger-soft: #3a1f24; --info-soft: #132238;
    --shadow-sm: 0 1px 2px #0006; --shadow-md: 0 6px 18px -6px #0009; --ring: 0 0 0 4px #4d6cff59;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0b0b0c; --surface: #141416; --surface-2: #19191c; --surface-3: #232327;
  --line: #26262b; --line-strong: #35353b;
  --ink-900: #fffdfd; --ink-700: #ececec; --ink-500: #a1a1a6; --ink-400: #8e8e93; --ink-300: #636366;
  --blue: #4a5ff0; --blue-hover: #6878ff; --blue-deep: #1b1b1f; --blue-soft: #131a46; --blue-pale: #26348f;
  --lime-soft: #23300a; --mint-soft: #171a18;
  --gradient: linear-gradient(135deg, #1c2a8a 0%, #15223a 45%, #1d2a22 60%, #4d6a0c 100%);
  --accent: #5b6ff5; --accent-soft: #131a46;
  --success: #4cc27a; --success-soft: #16302a; --warning: #ff7a33; --warning-text: #ffb38a; --warning-soft: #3a2416;
  --danger: #ff6464; --danger-soft: #3a1f24; --info-soft: #132238;
  --shadow-sm: 0 1px 2px #0006; --shadow-md: 0 6px 18px -6px #0009; --ring: 0 0 0 4px #4d6cff59;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  margin: 0; background: var(--canvas); color: var(--ink-900);
  font: 15px/1.5 Inter, Tajawal, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[dir="rtl"] body { font-family: Tajawal, Inter, Arial, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-500); }
.small { font-size: 12px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--rail) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow: hidden; display: flex; flex-direction: column; gap: 14px;
  padding: 18px 14px 14px; background: var(--surface); border-inline-end: 1px solid var(--line);
}
.sidebar-brand { display: flex; flex-direction: column; gap: 5px; padding: 4px 8px; color: var(--ink-900); }
.sidebar-wordmark { height: 20px; width: auto; color: var(--ink-900); align-self: flex-start; display: block; }
.safety svg { width: 15px; height: 15px; vertical-align: -3px; color: var(--success); }
.sidebar-brand small { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--ink-400); }
.sidebar-nav { display: flex; flex-direction: column; gap: 1px; }
.sidebar-nav button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 9px;
  background: none; color: var(--ink-500); font-size: 14px; font-weight: 500; text-align: start;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.sidebar-nav button:hover { background: var(--surface-2); color: var(--ink-900); }
.sidebar-nav button.active { background: var(--surface-3); color: var(--ink-900); }
.sidebar-nav svg { width: 17px; height: 17px; flex: none; }
.count {
  margin-inline-start: auto; padding: 1px 7px; border-radius: 999px; font-size: 11px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-400);
}
.count.waiting { background: var(--gradient-bar); color: #fff; border-color: transparent; font-weight: 700; }
.client-list { flex: 1; min-height: 0; overflow: auto; border-top: 1px solid var(--line); padding-top: 12px; }
.client-list-head {
  display: flex; justify-content: space-between; align-items: center; padding: 2px 10px 8px;
  font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-400);
}
.client-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 9px;
  background: none; color: var(--ink-700); text-align: start;
}
.client-row:hover { background: var(--surface-2); }
.client-row.active { background: var(--surface-3); color: var(--ink-900); box-shadow: inset 0 0 0 1px var(--line-strong); }
.initials {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 8px;
  background: var(--blue); color: var(--on-fill); font-size: 12px; font-weight: 700;
}
.client-row-name { display: flex; flex-direction: column; min-width: 0; font-size: 14px; font-weight: 500; line-height: 1.2; }
.client-row-name small { margin-top: 2px; font-size: 11px; font-weight: 400; color: var(--ink-400); }
.client-row-name, .client-row-name small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sidebar-foot { display: flex; flex-direction: column; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.sidebar-status {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-700);
}
.sidebar-status small { display: block; margin-top: 2px; font-size: 11px; font-weight: 400; color: var(--ink-400); }
.sidebar-status svg { color: var(--success); flex: none; width: 18px; height: 18px; }
.sidebar-status.stopped { background: var(--danger-soft); border-color: transparent; }
.sidebar-status.stopped svg { color: var(--danger); }
.sidebar-user { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.avatar {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--surface-3); font-size: 11px; font-weight: 700;
}
.sidebar-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 500; color: var(--ink-700); }
.icon-button {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px;
  background: none; color: var(--ink-500);
}
.icon-button:hover { background: var(--surface-2); color: var(--ink-900); }
.icon-button svg { width: 16px; height: 16px; }

.main { min-width: 0; padding: 28px 36px 64px; }
.workspace-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.workspace-head h1 { font-size: 26px; font-weight: 600; letter-spacing: -.6px; line-height: 1.2; }
.workspace-head p { margin-top: 6px; font-size: 14px; color: var(--ink-500); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- controls ---------- */
.primary, .secondary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 9px 16px;
  border-radius: 12px; font-size: 14px; font-weight: 600; white-space: nowrap; letter-spacing: -.005em;
  transition: background-color var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
}
.primary { border: 0; background: var(--blue); color: var(--on-fill); box-shadow: var(--shadow-sm); }
.primary:hover:enabled { background: var(--blue-hover); }
.secondary { border: 1px solid var(--line); background: var(--surface); color: var(--ink-700); box-shadow: var(--shadow-sm); }
.secondary:hover:enabled { border-color: var(--line-strong); }
.danger-button { border: 1px solid transparent; background: var(--danger); color: #fff; }
.primary:active:enabled, .secondary:active:enabled { transform: scale(.97); }
button:disabled { opacity: .5; cursor: not-allowed; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: none; box-shadow: var(--ring); }
.primary svg, .secondary svg { width: 16px; height: 16px; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-3); }
.segmented button {
  border: 0; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; background: none; color: var(--ink-500);
}
.segmented button.on { background: var(--surface); color: var(--blue); box-shadow: var(--shadow-sm); }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  font-size: 14px; color: var(--ink-900);
}
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--ink-400); font-size: 12px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; }
.card h2 { font-size: 15px; font-weight: 600; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.grid { display: grid; gap: 14px; }
.grid.q6 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.question { display: flex; flex-direction: column; gap: 8px; min-height: 150px; }
.question .q { font-size: 12px; font-weight: 600; color: var(--ink-500); }
.big { font-size: 28px; font-weight: 600; letter-spacing: -.8px; line-height: 1.1; }
.big small { font-size: 14px; font-weight: 500; color: var(--ink-500); letter-spacing: 0; }
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--success); } .delta.down { color: var(--danger); } .delta.flat { color: var(--ink-500); }
.delta.bad.up { color: var(--danger); } .delta.bad.down { color: var(--success); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-500); white-space: nowrap; }
.pill.ok { background: var(--success-soft); color: var(--success); }
.pill.warn { background: var(--warning-soft); color: var(--warning-text); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.info { background: var(--blue-soft); color: var(--blue); }
.pill.sim { background: var(--lime); color: #1a1a1a; }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.status-dot.ok { background: var(--success); } .status-dot.bad { background: var(--danger); } .status-dot.warn { background: var(--warning); }

.notice { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; font-size: 13.5px; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.notice.sim { background: var(--lime-soft); border: 1px solid #d8f08a; color: var(--ink-900); }
.notice.warn { background: var(--warning-soft); color: var(--ink-900); }
.notice.warn svg { color: var(--warning); }
.notice.bad { background: var(--danger-soft); }
.notice.bad svg { color: var(--danger); }
.notice.info { background: var(--blue-soft); }
.notice.info svg { color: var(--blue); }
.notices { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }

.bar { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--gradient-bar); }
.bar > b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink-900); }
.bar.over > i { background: linear-gradient(90deg, #ffb38a, var(--warning)); }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: start; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-400); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.data td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.r, table.data th.r { text-align: end; }
.table-wrap { overflow-x: auto; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: flex-start; padding: 11px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item strong { font-size: 14px; font-weight: 600; }

/* recommendation card */
.rec { display: flex; flex-direction: column; gap: 12px; }
.rec-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.rec-head h3 { font-size: 16px; font-weight: 600; letter-spacing: -.2px; }
.rec-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kv div { padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.kv dt { font-size: 11px; color: var(--ink-500); font-weight: 600; }
.kv dd { margin: 3px 0 0; font-size: 14px; font-weight: 600; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13.5px; }
.cols h4 { margin: 0 0 6px; font-size: 12px; color: var(--ink-500); font-weight: 600; }
.cols ul { margin: 0; padding-inline-start: 18px; }
.cols li { margin-bottom: 4px; }
details.evidence summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--accent); }
details.evidence pre { margin: 10px 0 0; padding: 12px; border-radius: 10px; background: var(--surface-2); font-size: 12px; overflow: auto; }
.rec-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.safety { font-size: 12.5px; padding: 9px 12px; border-radius: 10px; background: var(--surface-2); }
.safety.blocked { background: var(--danger-soft); }

.empty { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 48px 24px; text-align: center; color: var(--ink-500); }
.empty-icon { display: grid; place-items: center; width: 84px; height: 84px; border-radius: 12px; border: 1px solid var(--blue-pale); color: var(--blue); background: linear-gradient(90deg, transparent 49.5%, var(--blue-pale) 50%, transparent 50.5%), linear-gradient(0deg, transparent 49.5%, var(--blue-pale) 50%, transparent 50.5%); }
.empty-icon svg { width: 30px; height: 30px; background: var(--surface); border-radius: 6px; padding: 3px; }
.empty h3 { font-size: 20px; font-weight: 500; color: var(--ink-700); }
.empty p { max-width: 520px; font-size: 14px; line-height: 1.7; }
.empty ul { text-align: start; font-size: 13.5px; line-height: 1.8; max-width: 520px; color: var(--ink-700); }

.spark { width: 120px; height: 28px; display: block; }
.spark path { fill: none; stroke: var(--blue); stroke-width: 1.6; }
.spark .area { fill: var(--blue-soft); stroke: none; }

/* login */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--gradient); }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px 24px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-md); }
.auth-card .sidebar-wordmark { height: 26px; }
.auth-card h1 { font-size: 20px; font-weight: 600; margin-top: 8px; }
.error { color: var(--danger); font-size: 13px; }

.toast { position: fixed; inset-block-end: 20px; inset-inline-end: 20px; z-index: 10; max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--ink-900); color: var(--surface); font-size: 13.5px; box-shadow: var(--shadow-md); }

.fade { animation: rise var(--dur) var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .grid.q6 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.two { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 10px 12px; gap: 10px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .sidebar-nav { flex-direction: row; overflow-x: auto; }
  .sidebar-nav button { width: auto; white-space: nowrap; }
  .client-list { display: flex; gap: 6px; overflow-x: auto; border-top: 0; padding-top: 0; flex: none; }
  .client-list-head { display: none; }
  .client-row { flex: none; width: auto; border: 1px solid var(--line); }
  .sidebar-foot { flex-direction: row; align-items: center; border-top: 0; padding-top: 0; }
  .sidebar-status { flex: 1; }
  .main { padding: 18px 16px 48px; }
  .grid.q6 { grid-template-columns: 1fr; }
  .workspace-head { flex-direction: column; align-items: stretch; }
  .cols { grid-template-columns: 1fr; }
}

/* launcher post picker */
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.post { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: start; font-size: 12px; color: var(--ink-700); }
.post img, .post .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-400); }
.post small { color: var(--ink-400); }
.post.on { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.post.ineligible { opacity: .45; }
select { appearance: auto; }
