:root {
  --bg: #0b0f14;
  --bg2: #111821;
  --card: #151d28;
  --card2: #1b2532;
  --line: #24303f;
  --text: #e8eef5;
  --muted: #8b9bb0;
  --accent: #4fd1c5;
  --accent2: #63b3ed;
  --ok: #48bb78;
  --mild: #ecc94b;
  --strong: #ed8936;
  --critical: #f56565;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: 'Cairo', system-ui, sans-serif; -webkit-font-smoothing: antialiased; overscroll-behavior: none; }
body { min-height: 100dvh; }
.app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-top); }
button { font-family: inherit; }
input, select { font-family: inherit; }

.boot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Header ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 8px; }
.topbar .clock { display: inline-flex; direction: ltr; align-items: baseline; white-space: nowrap; font-size: 34px; font-weight: 800; letter-spacing: 1px; line-height: 1; font-variant-numeric: tabular-nums; }
.topbar .clock small { font-size: 14px; color: var(--muted); font-weight: 600; margin-inline-start: 4px; }
.topbar .date { font-size: 12px; color: var(--muted); margin-top: 4px; }
.weather { text-align: left; direction: ltr; }
.weather .t { font-size: 26px; font-weight: 800; line-height: 1; }
.weather .d { font-size: 12px; color: var(--muted); direction: rtl; }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; margin: 8px 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; color: var(--muted); font-weight: 700; letter-spacing: .3px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.muted { color: var(--muted); font-size: 12px; }

/* ---------- Status hero ---------- */
.hero { display: flex; gap: 14px; align-items: center; }
.avatar { width: 62px; height: 62px; border-radius: 50%; background: linear-gradient(135deg, var(--accent2), var(--accent)); display: grid; place-items: center; font-size: 30px; flex-shrink: 0; }
.hero .name { font-size: 18px; font-weight: 800; }
.hero .sub { font-size: 12px; color: var(--muted); }
.activity-pill { display: inline-flex; align-items: center; gap: 6px; background: var(--card2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 700; margin-top: 6px; }
.activity-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.6s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.timer { font-variant-numeric: tabular-nums; color: var(--accent); }

/* ---------- Energy ring ---------- */
.energy { display: flex; align-items: center; gap: 14px; }
.ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--line) 0); flex-shrink: 0; }
.ring > div { width: 50px; height: 50px; border-radius: 50%; background: var(--card); display: grid; place-items: center; font-weight: 800; font-size: 15px; }

/* ---------- Needs ---------- */
.needs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.need { background: var(--card2); border-radius: 14px; padding: 10px 12px; }
.need .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.need .val { font-size: 13px; font-weight: 700; margin-top: 6px; }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; transition: width .6s ease; }
.sev-ok > i { background: var(--ok); } .sev-mild > i { background: var(--mild); } .sev-strong > i { background: var(--strong); } .sev-critical > i { background: var(--critical); }
.txt-ok { color: var(--ok); } .txt-mild { color: var(--mild); } .txt-strong { color: var(--strong); } .txt-critical { color: var(--critical); }

/* ---------- Body ---------- */
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kv div { background: var(--card2); border-radius: 12px; padding: 8px 10px; text-align: center; }
.kv b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.kv span { font-size: 11px; color: var(--muted); }

/* ---------- Actions ---------- */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.act { background: var(--card2); border: 1px solid var(--line); border-radius: 16px; padding: 12px 4px 10px; color: var(--text); display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; cursor: pointer; transition: transform .1s, background .2s; }
.act:active { transform: scale(.94); background: var(--line); }
.act .ic { font-size: 24px; }
.act[disabled] { opacity: .35; pointer-events: none; }
.act.urgent { border-color: var(--critical); box-shadow: 0 0 0 2px rgba(245,101,101,.25); }

.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 800; font-size: 15px; cursor: pointer; width: 100%; }
.btn-primary { background: var(--accent); color: #062a27; }
.btn-primary:disabled { opacity: .5; }
.btn-ghost { background: var(--card2); color: var(--text); border: 1px solid var(--line); }
.btn-danger { background: transparent; color: var(--critical); border: 1px solid var(--critical); }

/* ---------- Events ---------- */
.events { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.events li { display: flex; gap: 10px; font-size: 13px; line-height: 1.4; }
.events time { color: var(--muted); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; padding-top: 2px; }
.events li.need { color: var(--mild); }
.events li.accident, .events li.death { color: var(--critical); }

/* ---------- Sleep overlay ---------- */
.sleep-screen { position: fixed; inset: 0; background: radial-gradient(ellipse at top, #0f1a2b, #05080d); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 50; padding: 24px; text-align: center; }
.sleep-screen .big { font-size: 56px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sleep-screen .moon { font-size: 60px; animation: float 4s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }
.sleep-screen p { color: var(--muted); margin: 0; }
.sleep-screen .btn { max-width: 260px; margin-top: 18px; }

/* ---------- Sheet / modal ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 40; display: flex; align-items: flex-end; }
.sheet { background: var(--bg2); width: 100%; max-width: 520px; margin: 0 auto; border-radius: 22px 22px 0 0; padding: 16px 16px calc(16px + var(--safe-bottom)); max-height: 82dvh; overflow: auto; animation: up .25s ease; }
@keyframes up { from { transform: translateY(40px); opacity: 0 } }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.tabs button { flex: 1; background: var(--card2); border: 1px solid var(--line); color: var(--muted); border-radius: 12px; padding: 8px; font-weight: 700; }
.tabs button.on { color: var(--text); border-color: var(--accent); }
.food { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.food:active { background: var(--card2); }
.food .ic { font-size: 26px; }
.food .n { font-weight: 700; font-size: 14px; }
.food .m { font-size: 11px; color: var(--muted); }
.food .k { margin-inline-start: auto; text-align: center; font-size: 12px; color: var(--accent); font-weight: 800; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); background: #1f2a38; border: 1px solid var(--line); color: var(--text); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 700; z-index: 60; max-width: 90%; text-align: center; animation: up .2s ease; box-shadow: 0 8px 30px rgba(0,0,0,.4); }
.toast.err { border-color: var(--critical); }

/* ---------- Create form ---------- */
.form { padding: 18px 18px calc(30px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 14px; }
.form h1 { margin: 6px 0 0; font-size: 26px; font-weight: 800; }
.form .lead { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 700; }
.field input, .field select { width: 100%; background: var(--card); border: 1px solid var(--line); color: var(--text); border-radius: 14px; padding: 13px 14px; font-size: 16px; outline: none; }
.field input:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.seg button { flex: 1; padding: 12px; background: transparent; border: 0; color: var(--muted); font-weight: 800; font-size: 15px; }
.seg button.on { background: var(--accent); color: #062a27; }
.geo-list { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-top: 6px; overflow: hidden; }
.geo-item { padding: 12px 14px; border-bottom: 1px solid var(--line); font-size: 14px; cursor: pointer; }
.geo-item:last-child { border-bottom: 0; }
.geo-item small { display: block; color: var(--muted); font-size: 11px; }
.geo-item.on { background: var(--card2); border-inline-start: 3px solid var(--accent); }
.err-msg { color: var(--critical); font-size: 13px; }
.preview { font-size: 12px; color: var(--muted); background: var(--card); border-radius: 12px; padding: 10px 12px; line-height: 1.8; }

.footer { text-align: center; color: var(--muted); font-size: 11px; padding: 10px 14px calc(24px + var(--safe-bottom)); }
.footer button { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 11px; }
.hidden { display: none !important; }

/* ---- شاشة الإنشاء: الموقع التلقائي والجسم المرجعي ---- */
.hint { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.hint b { color: var(--text); }
.loc-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.loc-box.gps, .loc-box.network { border-color: rgba(120, 180, 255, 0.35); }
.loc-box.fail { border-color: rgba(255, 120, 120, 0.45); }
.loc-box.done { border-color: rgba(90, 200, 140, 0.45); }
.loc-main { font-size: 14px; line-height: 1.6; }
.loc-sub { font-size: 12px; color: var(--muted); }
.loc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.mini { background: transparent; color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; font: inherit; font-size: 12px; font-weight: 700; }
.mini:active { background: rgba(255, 255, 255, 0.06); }
.link { background: none; border: 0; color: #8fb7ff; font: inherit; font-size: 12px; font-weight: 700; padding: 8px 2px; text-decoration: underline; text-underline-offset: 3px; }
#body-manual { margin-top: 6px; }
.preview small { color: var(--muted); }
