:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242d;
  --border: #262c37;
  --text: #e6e9ef;
  --muted: #8892a6;
  --accent: #5b8dff;
  --accent-2: #4878ee;
  --green: #4ade80;
  --red: #f87171;
  --yellow: #fbbf24;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.9rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.logo {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #5b8dff, #7c5bff);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white;
}
.brand h1 { margin: 0; font-size: 1rem; }
.brand .sub { color: var(--muted); font-size: 0.72rem; }

.nav { display: flex; gap: 0.25rem; margin-left: 1rem; }
.nav a {
  padding: 0.45rem 0.85rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.85rem;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { background: var(--surface-2); color: var(--text); }

.balance-pill {
  margin-left: auto;
  display: flex; flex-direction: column; align-items: flex-end;
  padding: 0.35rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--mono);
}
.balance-pill .label { font-size: 0.62rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.balance-pill .value { font-size: 0.9rem; font-weight: 600; }

/* ---- Layout ---- */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem; }
.card h2 { margin: 0; font-size: 0.95rem; }

.row { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; min-width: 180px; }
.field label { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
select, input[type="text"] {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  outline: none;
}
select:focus, input[type="text"]:focus { border-color: var(--accent); }

/* ---- Searchable Combobox ---- */
.combobox { position: relative; width: 100%; }
.combobox-display {
  width: 100%;
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}
.combobox-display:hover { border-color: var(--muted); }
.combobox-display[aria-expanded="true"] { border-color: var(--accent); }
.combobox-icon { color: var(--muted); font-size: 0.85rem; }
.combobox-current { flex: 1; }
.combobox-arrow { color: var(--muted); font-size: 0.75rem; transition: transform 0.15s; }
.combobox-display[aria-expanded="true"] .combobox-arrow { transform: rotate(180deg); }

.combobox-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  z-index: 50;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  padding: 0.5rem;
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 380px;
}
.combobox-search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  font-size: 0.88rem;
  outline: none;
  width: 100%;
}
.combobox-search:focus { border-color: var(--accent); }
.combobox-list { overflow-y: auto; max-height: 300px; }
.combobox-section {
  font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); padding: 0.55rem 0.5rem 0.25rem; font-weight: 600;
}
.combobox-item {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
}
.combobox-item:hover, .combobox-item.highlighted { background: var(--surface-2); }
.combobox-item.selected { background: rgba(91, 141, 255, 0.12); color: var(--accent); }
.combobox-item .item-name { flex: 1; }
.combobox-item .item-price {
  font-family: var(--mono); font-size: 0.72rem; color: var(--muted);
}
.favorite-btn {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font-size: 1rem;
  padding: 0; line-height: 1; width: 18px;
  transition: color 0.15s, transform 0.1s;
}
.favorite-btn:hover { transform: scale(1.15); }
.favorite-btn.on { color: var(--yellow); }
.combobox-empty {
  text-align: center; padding: 1.25rem 0.5rem;
  color: var(--muted); font-size: 0.82rem;
}
.combobox-status {
  font-size: 0.68rem; color: var(--muted); font-family: var(--mono);
  padding: 0.35rem 0.5rem 0; text-align: center;
}

.meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.6rem; font-family: var(--mono); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.65rem 1.1rem;
  font-size: 0.88rem; font-weight: 500;
  border-radius: 8px; border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--red); border-color: #5b2929; }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.1); }

.spinner {
  width: 12px; height: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Active list ---- */
.active-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.85rem; }
.active-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.active-item .svc {
  display: inline-block;
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted);
}
.active-item .mdn {
  font-family: var(--mono); font-size: 1.25rem; font-weight: 600;
  display: flex; align-items: center; gap: 0.5rem;
}
.active-item .copy {
  font-size: 0.7rem; padding: 0.2rem 0.5rem;
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 5px; cursor: pointer;
}
.active-item .copy:hover { color: var(--text); border-color: var(--muted); }
.active-item .otp {
  font-family: var(--mono); font-size: 1.15rem; font-weight: 700;
  color: var(--green);
  padding: 0.5rem 0.65rem;
  background: rgba(74, 222, 128, 0.08);
  border: 1px dashed rgba(74, 222, 128, 0.4);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: space-between;
}
.active-item .sms-text { font-size: 0.78rem; color: var(--muted); font-family: var(--mono); }
.active-item .countdown { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); }
.active-item .countdown.warn { color: var(--yellow); }
.active-item .actions { display: flex; gap: 0.5rem; margin-top: 0.25rem; }
.active-item .waiting {
  font-size: 0.78rem; color: var(--muted);
  padding: 0.5rem 0.65rem;
  background: var(--surface); border-radius: 6px;
  display: flex; align-items: center; gap: 0.4rem;
}
.active-item .waiting .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--yellow); animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.3; } }

.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; font-size: 0.85rem; }

/* ---- Live dot ---- */
.hint {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--muted); display: inline-block;
}
.hint.online { background: var(--green); box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.2); }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.5rem; min-width: 320px; max-width: 90%;
  display: flex; flex-direction: column; align-items: center; gap: 0.85rem;
  text-align: center;
}
.modal-icon {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700;
  background: rgba(251, 191, 36, 0.12); color: var(--yellow);
}
.modal-icon.error { background: rgba(248, 113, 113, 0.12); color: var(--red); }
.modal-title { font-size: 1rem; font-weight: 600; }
.modal-body { color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.7rem 1.1rem;
  font-size: 0.82rem; font-family: var(--mono);
  transform: translateY(20px); opacity: 0; pointer-events: none;
  transition: all 0.25s;
  z-index: 200;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: rgba(74, 222, 128, 0.4); color: var(--green); }
.toast.error { border-color: rgba(248, 113, 113, 0.4); color: var(--red); }

/* ---- History table ---- */
.filters { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pill {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  padding: 0.4rem 0.85rem; border-radius: 20px; font-size: 0.8rem; cursor: pointer;
}
.pill:hover { color: var(--text); }
.pill.active { background: var(--accent); color: white; border-color: var(--accent); }

.table-wrap { overflow-x: auto; }
.history-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.history-table th { text-align: left; padding: 0.65rem; color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 0.68rem; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.history-table td { padding: 0.7rem 0.65rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.history-table td.num, .history-table td.otp-cell { font-family: var(--mono); }
.history-table td.otp-cell { color: var(--green); font-weight: 600; }
.history-table td.sms { color: var(--muted); font-size: 0.78rem; max-width: 280px; }
.history-table tr:last-child td { border-bottom: none; }

.status-badge {
  display: inline-block; padding: 0.18rem 0.55rem; border-radius: 12px;
  font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.05em;
  font-family: var(--mono);
}
.status-badge.active { background: rgba(91, 141, 255, 0.15); color: var(--accent); }
.status-badge.otp_received { background: rgba(74, 222, 128, 0.15); color: var(--green); }
.status-badge.rejected { background: rgba(136, 146, 166, 0.15); color: var(--muted); }
.status-badge.expired { background: rgba(251, 191, 36, 0.15); color: var(--yellow); }

.pager { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1rem; font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 0.75rem 1rem; }
  .balance-pill { margin-left: 0; }
  .container { padding: 1rem; }
  .card { padding: 1rem; }
}
.combobox-panel[hidden] { display: none; }
