@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Sans+Arabic:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --ink: #14171C;
  --panel: #1B1F26;
  --panel-raised: #21262F;
  --line: #2A2F38;
  --text: #E8E6E1;
  --text-dim: #8A8F98;
  --amber: #E8A33D;
  --amber-dim: #B37F2E;
  --ok: #5FB88A;
  --danger: #D9634B;
  --font-ui: 'IBM Plex Sans Arabic', 'IBM Plex Sans', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
}

body {
  direction: rtl;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

::selection { background: var(--amber-dim); color: #14171C; }

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.brand .mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background .3s;
}

.brand .mark.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.brand .mark.off { background: var(--danger); }

.brand h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .2px;
}

.brand .status-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
}

.icon-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-dim); }

/* ---------- Layout ---------- */

.main {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 90px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; animation: fade-in .18s ease-out; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Tab bar ---------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  border-top: 1px solid var(--line);
  background: rgba(20,23,28,.92);
  backdrop-filter: blur(10px);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  font-size: 11px;
  position: relative;
}

.tab svg { width: 20px; height: 20px; stroke: currentColor; fill: none; }
.tab.active { color: var(--amber); }
.tab .badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 6px);
  background: var(--amber);
  color: #14171C;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  border-radius: 8px;
  min-width: 15px;
  height: 15px;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}
.tab .badge.show { display: flex; }

/* ---------- Section headers ---------- */

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 12px;
}

.section-head h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.refresh-btn {
  background: none;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-ui);
}
.refresh-btn:hover { color: var(--amber); border-color: var(--amber-dim); }
.refresh-btn svg { width: 14px; height: 14px; }
.refresh-btn.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.gateway-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
}

.gateway-card .label { font-size: 14px; font-weight: 500; }
.gateway-card .sub { font-size: 12px; color: var(--text-dim); font-family: var(--font-mono); margin-top: 3px; }

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  border-radius: 20px;
  background: var(--line);
  border: none;
  flex-shrink: 0;
  transition: background .2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .2s, background .2s;
}
.switch.on { background: rgba(95,184,138,.25); }
.switch.on::after { transform: translateX(-19px); background: var(--ok); }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.stat .n { font-family: var(--font-mono); font-size: 22px; font-weight: 500; color: var(--amber); }
.stat .l { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

/* ---------- List items ---------- */

.list-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
}

.list-item .row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.list-item .addr {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  direction: ltr;
  text-align: right;
}

.list-item .time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.list-item .body {
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.55;
  word-break: break-word;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  border: 1px solid var(--line);
  color: var(--text-dim);
}
.pill.in { color: var(--ok); border-color: rgba(95,184,138,.35); }
.pill.out { color: var(--amber); border-color: rgba(232,163,61,.35); }
.pill.pending { color: var(--amber); border-color: rgba(232,163,61,.35); }
.pill.sent { color: var(--ok); border-color: rgba(95,184,138,.35); }
.pill.sending { color: var(--text-dim); }
.pill.missed { color: var(--danger); border-color: rgba(217,99,75,.35); }

.empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
}
.empty svg { width: 34px; height: 34px; stroke: var(--line); margin-bottom: 12px; }
.empty p { font-size: 13px; margin: 0; line-height: 1.6; }

/* ---------- Compose ---------- */

.fab {
  position: fixed;
  bottom: 86px;
  left: 18px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  color: #14171C;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(232,163,61,.35);
  z-index: 5;
}
.fab svg { width: 22px; height: 22px; stroke: #14171C; stroke-width: 2.2; }

/* ---------- Modal / sheet ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,12,15,.6);
  backdrop-filter: blur(2px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}
.overlay.show { display: flex; }

.sheet {
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 18px 18px calc(20px + env(safe-area-inset-bottom));
  animation: sheet-up .2s ease-out;
}
@keyframes sheet-up { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.sheet .sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.sheet h3 { font-size: 15px; margin: 0; font-weight: 600; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input, .field textarea, .field select {
  width: 100%;
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}
.field input[dir="ltr"], .field textarea[dir="ltr"] { font-family: var(--font-mono); text-align: left; }
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--amber-dim);
}

.sim-choice { display: flex; gap: 8px; }
.sim-choice button {
  flex: 1;
  background: var(--ink);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-family: var(--font-ui);
}
.sim-choice button.selected { border-color: var(--amber); color: var(--amber); background: rgba(232,163,61,.08); }

.btn-primary {
  width: 100%;
  background: var(--amber);
  border: none;
  color: #14171C;
  border-radius: 8px;
  padding: 13px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-ui);
  margin-top: 4px;
}
.btn-primary:disabled { opacity: .5; }

.btn-ghost {
  width: 100%;
  background: none;
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 11px;
  font-size: 13px;
  font-family: var(--font-ui);
  margin-top: 8px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--panel-raised);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 30px;
  font-size: 12.5px;
  opacity: 0;
  transition: opacity .2s, transform .2s;
  z-index: 30;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { border-color: rgba(217,99,75,.4); color: #F0A493; }

/* ---------- Setup screen ---------- */

.setup-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.setup-card { width: 100%; max-width: 380px; }
.setup-card .mark-lg {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 18px;
}
.setup-card .mark-lg svg { width: 22px; height: 22px; stroke: var(--amber); }
.setup-card h2 { font-size: 19px; margin: 0 0 6px; }
.setup-card p.desc { font-size: 13px; color: var(--text-dim); margin: 0 0 22px; line-height: 1.6; }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(20,23,28,.3);
  border-top-color: #14171C;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

@media (min-width: 720px) {
  .main { padding-top: 24px; }
}
