:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #17202c;
  --muted: #5b6878;
  --border: #dbe1e8;
  --primary: #1d5bbf;
  --primary-hover: #174a9c;
  --on-primary: #ffffff;
  --ok: #18703f;
  --ok-bg: #e2f3e9;
  --warn: #8a5a00;
  --warn-bg: #fcf0d9;
  --bad: #b3261e;
  --bad-bg: #fde6e4;
  --new-bg: #edf3ff;
  --you-bg: #1d5bbf;
  --net-bg: #eef1f5;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #1a2029;
    --text: #e6ebf1;
    --muted: #9aa6b5;
    --border: #2c3542;
    --primary: #5b93ee;
    --primary-hover: #7aa8f2;
    --on-primary: #0c1320;
    --ok: #6fd39a;
    --ok-bg: #173826;
    --warn: #f0c063;
    --warn-bg: #3a2d12;
    --bad: #f28b82;
    --bad-bg: #3d1c1a;
    --new-bg: #1c2a42;
    --you-bg: #3b6fc4;
    --net-bg: #252d39;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; }

button, input, select, textarea { font: inherit; color: inherit; }

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

textarea { resize: vertical; }

label { display: block; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; font-size: 15px; }

button {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

button:disabled { opacity: 0.55; cursor: wait; }

button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--primary-hover); }

button.link { border: 0; background: none; padding: 0; color: var(--primary); }
button.small { font-size: 0.85rem; }

.muted { color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.alert {
  background: var(--bad-bg);
  color: var(--bad);
  border-radius: 8px;
  padding: 8px 12px;
}

/* ---------- Sign-in ---------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login button { width: 100%; margin-top: 4px; }

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { font-weight: 700; font-size: 1.05rem; }

.sync { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.sync .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); }
.sync.ok .dot { background: var(--ok); }
.sync.bad .dot { background: var(--bad); }
.sync.bad { color: var(--bad); }

.who { margin-left: auto; display: flex; gap: 12px; align-items: center; font-size: 0.9rem; color: var(--muted); }

main { max-width: 960px; margin: 0 auto; padding: 16px; }

/* ---------- SIM cards ---------- */

.sims {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.sim {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--ok);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.sim.warn { border-left-color: var(--warn); }
.sim-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sim-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sim-meta { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 0.82rem; color: var(--muted); margin: 2px 0 4px; }
.sim.warn .reg { color: var(--warn); font-weight: 600; }
.sim-number { font-size: 0.85rem; margin-bottom: 4px; }

.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 14px; flex: none; }
.bars i { width: 4px; background: var(--border); border-radius: 1px; }
.bars i:nth-child(1) { height: 4px; }
.bars i:nth-child(2) { height: 7px; }
.bars i:nth-child(3) { height: 10px; }
.bars i:nth-child(4) { height: 14px; }
.bars i.on { background: var(--ok); }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }

.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  padding: 10px 14px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

.tabs button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 9px;
  background: var(--bad);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.5;
}

.badge[hidden] { display: none; }

/* ---------- Lists ---------- */

.toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.toolbar select { max-width: 220px; }

.messages { list-style: none; margin: 0; padding: 0; }

.msg {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}

.msg.new { background: var(--new-bg); border-color: var(--primary); }

.msg-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.msg-head time { margin-left: auto; font-size: 0.82rem; color: var(--muted); }
.sender { overflow-wrap: anywhere; }

.tag { font-size: 0.78rem; padding: 1px 8px; border-radius: 9px; background: var(--net-bg); color: var(--muted); }

.msg-body { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-foot { margin-top: 6px; font-size: 0.8rem; color: var(--muted); }

.status { font-size: 0.78rem; padding: 1px 8px; border-radius: 9px; font-weight: 600; background: var(--warn-bg); color: var(--warn); }
.status.s-sent_ok, .status.s-delivered, .status.s-replied { background: var(--ok-bg); color: var(--ok); }
.status.s-failed, .status.s-rejected, .status.s-error, .status.s-unavailable, .status.s-refused { background: var(--bad-bg); color: var(--bad); }
.status.s-cancelled, .status.s-unchanged { background: var(--net-bg); color: var(--muted); }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.more { display: block; margin: 8px auto 0; }

/* ---------- Forms ---------- */

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 8px; }
.row select { width: auto; }
.counter { font-size: 0.85rem; color: var(--muted); margin-right: auto; }
.counter.bad { color: var(--bad); }

.note { font-size: 0.88rem; color: var(--muted); }
.note.ok { color: var(--ok); }
.note.bad { color: var(--bad); }

/* ---------- USSD conversation ---------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.chat:empty { display: none; }

.bubble { max-width: 85%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.you { align-self: flex-end; background: var(--you-bg); color: #fff; border-bottom-right-radius: 4px; }
.bubble.net { align-self: flex-start; background: var(--net-bg); border-bottom-left-radius: 4px; }
.bubble.info { align-self: center; font-size: 0.85rem; color: var(--muted); background: none; }
.bubble small { display: block; margin-top: 4px; font-size: 0.78rem; color: var(--muted); }

@media (max-width: 560px) {
  .toolbar { flex-direction: column; }
  .toolbar select { max-width: none; }
  .row select { width: 100%; }
  .who span { display: none; }
}
