:root {
  --bg: #f4f6f3;
  --panel: #ffffff;
  --ink: #142019;
  --muted: #5f6d64;
  --line: #e2e7e1;
  --brand: #0f3d2e;
  --brand-2: #1f6b4f;
  --accent: #c6f05a;
  --ok: #1f8a5b;
  --warn: #b7791f;
  --bad: #c0392b;
  --mine: #0f3d2e;
  --theirs: #eef2ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 61, 46, .06), 0 4px 16px rgba(15, 61, 46, .05);
  font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-2); }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--brand); color: #fff;
}
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.brand::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: .9rem; opacity: .95; }
.topbar button { background: rgba(255,255,255,.12); border: 0; color: #fff; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.topbar button:hover { background: rgba(255,255,255,.22); }
main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 96px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 1.45rem; }
.sub { color: var(--muted); margin: 4px 0 0; font-size: .92rem; }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 18px; padding-bottom: 2px; }
.tabs a {
  flex: none; text-decoration: none; color: var(--muted); padding: 8px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: .92rem; position: relative;
}
.tabs a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.dot-badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-inline-start: 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .72rem; line-height: 18px; text-align: center; }

/* bottom nav on phones for trainees */
.bottom-nav { display: none; }
@media (max-width: 640px) {
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; inset-inline: 0; z-index: 10;
    background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a { flex: 1; text-align: center; text-decoration: none; color: var(--muted); font-size: .78rem; padding: 6px 2px; border-radius: 10px; position: relative; }
  .bottom-nav a .ic { display: block; font-size: 1.2rem; line-height: 1.3; }
  .bottom-nav a.on { color: var(--brand); background: #e9f3ec; font-weight: 600; }
  .trainee .tabs { display: none; }
  main { padding: 16px 12px 96px; }
  .topbar { padding: 10px 14px; }
}

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card h2 { margin: 0 0 4px; font-size: 1.05rem; }
.card .note { color: var(--muted); font-size: .85rem; margin: 0 0 14px; }
.grid { display: grid; gap: 14px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.stack { display: flex; flex-direction: column; gap: 14px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .lbl { color: var(--muted); font-size: .82rem; }
.kpi .val { font-size: 1.6rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: .85rem; font-weight: 500; color: var(--muted); margin-inline-start: 4px; }
.kpi .delta { font-size: .82rem; margin-top: 2px; }
.good { color: var(--ok); } .warn { color: var(--warn); } .bad { color: var(--bad); }

.chart-box { position: relative; height: 240px; }

/* ---------- forms ---------- */
form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .88rem; color: var(--muted); }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fbfcfa; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.range-wrap { display: flex; align-items: center; gap: 10px; }
.range-wrap input { padding: 0; accent-color: var(--brand-2); }
.range-wrap output { min-width: 2ch; font-weight: 700; color: var(--ink); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 10px; padding: 10px 18px; cursor: pointer; background: var(--brand); color: #fff; font-weight: 600; text-decoration: none;
}
.btn:hover { background: var(--brand-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
.btn.ghost:hover { background: #eef3ee; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid #f0d3cf; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(circle at 80% 0%, #dff3c4 0, transparent 45%), var(--bg); }
.auth { width: min(460px, 100%); }
.auth .brand { color: var(--brand); font-size: 1.4rem; margin-bottom: 6px; }
.auth .switch { display: flex; background: #eaefe8; border-radius: 12px; padding: 4px; margin: 16px 0; }
.auth .switch button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 9px; cursor: pointer; color: var(--muted); }
.auth .switch button.on { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.linkish { background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 0; text-decoration: underline; font-size: .88rem; }
.center-msg { text-align: center; padding: 30px 10px; }
.center-msg .big { font-size: 2.4rem; }

/* ---------- tables & lists ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f6f9f5; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.ok { background: #e3f4ea; color: var(--ok); }
.pill.warn { background: #fbf0dc; color: var(--warn); }
.pill.bad { background: #fbe5e2; color: var(--bad); }
.pill.muted { background: #eceeeb; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 280px; }
.check { flex-direction: row; align-items: center; gap: 6px; }
.check input { width: auto; }

.req { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.req:last-child { border-bottom: 0; }
.req .meta { color: var(--muted); font-size: .85rem; }

.entry { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.entry-head strong { font-size: .98rem; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .88rem; color: var(--muted); }
.facts b { color: var(--ink); font-weight: 600; }
.entry .notes { margin: 10px 0 0; white-space: pre-wrap; }
.coach-note { margin-top: 10px; background: #f1f8e4; border-inline-start: 3px solid #8cc63f; padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; }
.coach-note .lbl { font-size: .78rem; color: var(--muted); display: block; margin-bottom: 2px; }
.empty { color: var(--muted); text-align: center; padding: 26px 10px; }
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; background: #fff7e6; border: 1px solid #f3dfb4; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; }

.plan { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; padding: 14px 0; border-bottom: 1px solid var(--line); }
.plan:last-child { border-bottom: 0; }
.plan p { margin: 4px 0 0; color: var(--muted); white-space: pre-wrap; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: min(70vh, 640px); padding: 0; overflow: hidden; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: #fafcf9; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.55; }
.msg.mine { align-self: flex-start; background: var(--mine); color: #fff; border-start-start-radius: 4px; }
.msg.theirs { align-self: flex-end; background: var(--theirs); border-start-end-radius: 4px; }
.msg time { display: block; font-size: .7rem; opacity: .7; margin-top: 3px; }
.day-sep { align-self: center; font-size: .75rem; color: var(--muted); background: #eef1ec; padding: 2px 10px; border-radius: 999px; margin: 6px 0; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--panel); }
.chat-form textarea { min-height: 44px; max-height: 140px; flex: 1; }

#toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 50; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }
