/* ============================================================
   CHRONIC — black & gold, RTL-first (Arabic default)
   ============================================================ */
:root {
  --bg:        #080808;
  --surface:   #131313;
  --surface-2: #1b1b1b;
  --line:      #262626;
  --gold:      #c9a24b;
  --gold-soft: #e6c87a;
  --text:      #f2efe8;
  --muted:     #8f8a80;
  --green:     #3ecf6e;
  --red:       #e5484d;
  --blue:      #4f8ff7;
  --purple:    #8b5cf6;
  --orange:    #f59e0b;
  --radius:    18px;
  --nav-h:     64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Tajawal', 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
}


[dir="ltr"] body, [dir="ltr"] { font-family: 'Outfit', 'Tajawal', system-ui, sans-serif; }

#app { max-width: 480px; margin: 0 auto; min-height: 100dvh; margin-top:35px;
       padding-bottom: calc(var(--nav-h) + 16px); position: relative; }

a { color: var(--gold); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; transition: opacity .6s ease; }
.splash.hide { opacity: 0; pointer-events: none; }
.splash .logo-c {
  width: 96px; height: 96px; border-radius: 50%;
  border: 3px solid var(--gold); border-inline-start-color: transparent;
  display: grid; place-items: center;
  font-family: 'Outfit', sans-serif; font-size: 42px; font-weight: 300;
  color: var(--gold); letter-spacing: 2px;
  animation: ringGlow 2.4s ease-in-out infinite; }
@keyframes ringGlow {
  0%,100% { box-shadow: 0 0 0 rgba(201,162,75,0); }
  50%     { box-shadow: 0 0 34px rgba(201,162,75,.35); } }
.splash h1 { font-family: 'Outfit', sans-serif; letter-spacing: .5em;
             font-weight: 300; font-size: 22px; color: var(--text); padding-inline-start: .5em; }
.splash p  { color: var(--muted); font-size: 12px; letter-spacing: .2em; }
.splash .bar { width: 140px; height: 3px; border-radius: 3px; background: var(--surface-2);
               overflow: hidden; margin-top: 8px; }
.splash .bar i { display: block; height: 100%; width: 40%;
                 background: linear-gradient(90deg, var(--gold), var(--gold-soft));
                 animation: load 1.4s ease-in-out infinite; }
@keyframes load { 0% {transform: translateX(-100%);} 100% {transform: translateX(350%);} }
[dir="rtl"] .splash .bar i { animation-name: loadRtl; }
@keyframes loadRtl { 0% {transform: translateX(100%);} 100% {transform: translateX(-350%);} }

/* ---------- Header ---------- */
.header { display: flex; align-items: center; gap: 12px; padding: 18px 18px 8px; }
.header h2 { font-size: 19px; font-weight: 700; flex: 1; text-align: center; }
.header .spacer { width: 38px; }
.icon-btn { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
            background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
[dir="rtl"] .flip-rtl { transform: scaleX(-1); }

/* ---------- Cards / layout ---------- */
.page { padding: 8px 18px 24px; display: flex; flex-direction: column; gap: 14px;
        animation: pageIn .25s ease; }
@keyframes pageIn { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none;} }

.card { background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius); padding: 16px; }
.card.tap { transition: border-color .15s, transform .1s; }
.card.tap:active { transform: scale(.985); border-color: var(--gold); }

.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.title-sm  { font-size: 13px; color: var(--muted); }
.value-xl  { font-size: 40px; font-weight: 800; line-height: 1.1; }
.value-xl small { font-size: 15px; font-weight: 500; color: var(--muted); }
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px;
         font-size: 11px; font-weight: 700; }
.badge.good    { color: var(--green); background: rgba(62,207,110,.12); }
.badge.gold    { color: var(--gold-soft); background: rgba(201,162,75,.14); }
.badge.danger  { color: var(--red); background: rgba(229,72,77,.12); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 12px; }
.stat .k { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .v { font-size: 20px; font-weight: 800; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--muted); }

/* status pill (ring connected) */
.conn-pill { display: flex; align-items: center; gap: 10px;
             background: var(--surface); border: 1px solid var(--line);
             border-radius: 14px; padding: 12px 14px; }
.conn-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--red); }
.conn-pill.on .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.conn-pill .grow { font-size: 13px; font-weight: 600; }
.batt { font-size: 12px; color: var(--green); font-weight: 700; }

/* ---------- List items (settings style) ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { display: flex; align-items: center; gap: 12px;
        background: var(--surface); border: 1px solid var(--line);
        border-radius: 14px; padding: 13px 14px; width: 100%; text-align: start;
        transition: border-color .15s; }
.item:active { border-color: var(--gold); }
.item .ic { width: 36px; height: 36px; border-radius: 10px; flex: none;
            display: grid; place-items: center;
            background: rgba(201,162,75,.1); color: var(--gold); }
.item .ic svg { width: 18px; height: 18px; }
.item .grow b { display: block; font-size: 14px; }
.item .grow span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.item .chev { color: var(--muted); flex: none; }
.item .val { color: var(--muted); font-size: 13px; flex: none; }

/* toggle */
.toggle { width: 44px; height: 25px; border-radius: 20px; background: var(--surface-2);
          border: 1px solid var(--line); position: relative; flex: none; transition: background .2s; }
.toggle i { position: absolute; top: 2px; inset-inline-start: 2px; width: 19px; height: 19px;
            border-radius: 50%; background: var(--muted); transition: all .2s; }
.toggle.on { background: rgba(201,162,75,.3); border-color: var(--gold); }
.toggle.on i { inset-inline-start: 21px; background: var(--gold); }

/* ---------- Score rings ---------- */
.score-wrap { display: flex; align-items: center; justify-content: center; padding: 8px 0; position: relative; }
.score-center { position: absolute; text-align: center; }
.score-center .n { font-size: 44px; font-weight: 800; }
.score-center .l { font-size: 13px; color: var(--gold-soft); font-weight: 700; }

/* ---------- Segmented (Day/Week/Month) ---------- */
.seg { display: flex; background: var(--surface); border: 1px solid var(--line);
       border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 9px; font-size: 13px;
              color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--surface-2); color: var(--gold-soft); }

/* ---------- Charts ---------- */
canvas.chart { width: 100%; height: 120px; display: block; }
.legend { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.legend .lr { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .lr b { margin-inline-start: auto; font-weight: 700; }
.legend .lr .pct { color: var(--muted); width: 42px; text-align: end; }

/* ---------- Buttons ---------- */
.btn { display: block; width: 100%; text-align: center; padding: 14px;
       border-radius: 14px; font-weight: 700; font-size: 15px; transition: transform .1s; }
.btn:active { transform: scale(.98); }
.btn.gold   { background: linear-gradient(120deg, var(--gold), var(--gold-soft)); color: #14100a; }
.btn.danger { background: var(--red); color: #fff; }
.btn.ghost  { background: var(--surface); border: 1px solid var(--line); color: var(--text); }
.warn-text  { text-align: center; color: var(--red); font-size: 12px; font-weight: 600; }

/* ---------- SOS ---------- */
.sos-btn { width: 150px; height: 150px; border-radius: 50%; margin: 18px auto;
           display: grid; place-items: center; font-size: 30px; font-weight: 800;
           color: var(--red); background: rgba(229,72,77,.08);
           border: 2px solid var(--red); position: relative; user-select: none; }
.sos-btn::after { content: ''; position: absolute; inset: -12px; border-radius: 50%;
                  border: 1px solid rgba(229,72,77,.35); animation: sosPulse 1.6s ease-out infinite; }
@keyframes sosPulse { 0% { transform: scale(.9); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }
.sos-btn.arming { background: rgba(229,72,77,.25); }

/* ---------- Ring hero (device page) ---------- */
.ring-hero { text-align: center; padding: 10px 0 4px; }
.ring-hero .img { width: 150px; height: 150px; margin: 0 auto; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #3a3a3a, #0c0c0c 70%);
  border: 1px solid var(--line); display: grid; place-items: center; position: relative; }
.ring-hero .img::before { content: ''; width: 96px; height: 96px; border-radius: 50%;
  border: 10px solid #1f1f1f; border-top-color: #2e2a20;
  box-shadow: 0 0 0 2px #0a0a0a, inset 0 0 0 2px var(--gold); }
.ring-hero .led { position: absolute; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 8px var(--green);
  bottom: 42px; }
.ring-hero h3 { margin-top: 12px; letter-spacing: .12em; font-family: 'Outfit', sans-serif; }

/* ---------- Bottom nav ---------- */
nav.tabbar { position: fixed; bottom: 0; inset-inline: 0; margin: 0 auto; max-width: 480px;
  height: var(--nav-h); background: rgba(10,10,10,.92); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line); display: flex; z-index: 50; }
nav.tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600; }
nav.tabbar button svg { width: 21px; height: 21px; }
nav.tabbar button.on { color: var(--gold-soft); }

/* ---------- Toast ---------- */
#toast { position: fixed; bottom: calc(var(--nav-h) + 18px); inset-inline: 0;
  display: flex; justify-content: center; pointer-events: none; z-index: 90; }
#toast span { background: var(--surface-2); border: 1px solid var(--gold);
  color: var(--text); padding: 10px 20px; border-radius: 30px; font-size: 13px;
  opacity: 0; transform: translateY(10px); transition: all .25s; }
#toast.show span { opacity: 1; transform: none; }

/* ---------- Test-mode banner ---------- */
.testbar { display: flex; align-items: center; gap: 10px; padding: 9px 14px;
  background: rgba(201,162,75,.1); border: 1px dashed var(--gold);
  border-radius: 12px; font-size: 12px; color: var(--gold-soft); }
.testbar kbd { background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px; font-family: monospace; }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 80;
  display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 480px; background: var(--surface);
  border-radius: 22px 22px 0 0; border: 1px solid var(--line); border-bottom: 0;
  padding: 22px 18px 28px; animation: sheetUp .25s ease; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal h3 { margin-bottom: 6px; }
.modal p  { color: var(--muted); font-size: 13.5px; margin-bottom: 16px; }
.modal .btn + .btn { margin-top: 10px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.field input, .field select {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 12px 14px; font: inherit; outline: none; }
.field input:focus, .field select:focus { border-color: var(--gold); }

/* lang list */
.lang-row { justify-content: space-between; }
.lang-row .check { color: var(--gold); }

/* keyboard focus + reduced motion */
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
