* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px; line-height: 1.5;
  background: #0f172a; color: #e2e8f0;
}
a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

header {
  background: #1e293b; border-bottom: 1px solid #334155;
  padding: 12px 24px; display: flex; align-items: center; gap: 24px;
}
header h1 { font-size: 18px; margin: 0; color: #f1f5f9; }
header nav a {
  color: #cbd5e1; padding: 6px 12px; border-radius: 6px;
}
header nav a:hover { background: #334155; }
header nav a.active { background: #2563eb; color: #fff; }
header .spacer { flex: 1; }
header button {
  background: #334155; color: #e2e8f0; border: none;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
}

main { padding: 24px; margin: 0 auto; }

.card {
  background: #1e293b; border: 1px solid #334155;
  border-radius: 8px; padding: 16px; margin-bottom: 16px;
}
.card h2 { margin: 0 0 12px; font-size: 16px; color: #f1f5f9; }

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left; padding: 8px 12px;
  border-bottom: 1px solid #334155; font-size: 13px;
}
th { color: #94a3b8; font-weight: 600; }
td.actions { white-space: nowrap; }

button, .btn {
  background: #2563eb; color: #fff; border: none;
  padding: 6px 14px; border-radius: 6px; cursor: pointer;
  font-size: 13px;
  position: relative; overflow: hidden;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
  user-select: none;
}
button:hover, .btn:hover { background: #1d4ed8; }
button:active, .btn:active { transform: scale(0.96); }
button:disabled, .btn:disabled,
button.is-loading, .btn.is-loading {
  opacity: 0.7; cursor: progress;
  pointer-events: none;
}
button:disabled { background: #475569; cursor: not-allowed; }
button.danger { background: #dc2626; }
button.danger:hover { background: #b91c1c; }
button.secondary { background: #475569; }
button.secondary:hover { background: #334155; }

/* Ripple effect — pulse circle spawn từ click position */
.btn-ripple {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(0);
  background: rgba(255,255,255,0.45);
  pointer-events: none;
  animation: btn-ripple-anim 0.55s ease-out;
  width: 200px; height: 200px;
}
@keyframes btn-ripple-anim {
  to { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}

/* Spinner inline cho button is-loading */
button.is-loading::after, .btn.is-loading::after {
  content: '';
  display: inline-block;
  width: 10px; height: 10px;
  margin-left: 8px;
  border: 2px solid rgba(255,255,255,0.5);
  border-top-color: #fff;
  border-radius: 50%;
  vertical-align: middle;
  animation: btn-spin 0.6s linear infinite;
}
@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

input, select, textarea {
  background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 6px;
  padding: 8px 12px; font-size: 13px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #2563eb; }

.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }
.row > button { flex: none; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.badge.connected { background: #16a34a; color: #fff; }
.badge.dialing { background: #ca8a04; color: #fff; }
.badge.error { background: #dc2626; color: #fff; }
.badge.disconnected { background: #475569; color: #cbd5e1; }
.badge.running { background: #16a34a; color: #fff; }
.badge.stopped { background: #475569; color: #cbd5e1; }

.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-bg.open { display: flex; }
.modal {
  background: #1e293b; border: 1px solid #334155; border-radius: 8px;
  padding: 20px; min-width: 480px; max-width: 90vw;
  max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; }
.modal .form-row { margin-bottom: 12px; }
.modal .form-row label { display: block; font-size: 12px; color: #94a3b8; margin-bottom: 4px; }
.modal .actions { margin-top: 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ─── Custom Dialog (thay alert/confirm/prompt) ─── */
.dlg-bg {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 300;
  animation: dlg-fade-in 0.12s ease-out;
}
.dlg-bg.dlg-closing { animation: dlg-fade-out 0.12s ease-out forwards; }
.dlg {
  background: #1e293b; border: 1px solid #475569; border-radius: 10px;
  min-width: 360px; max-width: 560px; width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  animation: dlg-pop 0.14s ease-out;
}
.dlg-title {
  padding: 14px 20px 8px;
  font-size: 15px; font-weight: 600; color: #f1f5f9;
  border-bottom: 1px solid #334155;
}
.dlg-body { padding: 16px 20px; }
.dlg-msg { font-size: 13.5px; line-height: 1.6; color: #cbd5e1; word-break: break-word; }
.dlg-msg.dlg-warn   { color: #fbbf24; }
.dlg-msg.dlg-danger { color: #fca5a5; }
.dlg-msg.dlg-success{ color: #86efac; }
.dlg-msg .mono, .dlg-msg code {
  background: #0f172a; padding: 2px 6px; border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace; font-size: 12px;
}
.dlg-input {
  margin-top: 12px;
  width: 100%; box-sizing: border-box;
}
.dlg-actions {
  padding: 12px 20px 16px;
  display: flex; gap: 8px; justify-content: flex-end;
  border-top: 1px solid #334155;
}
.dlg-actions button { min-width: 80px; }
@keyframes dlg-fade-in  { from { opacity: 0; } to { opacity: 1; } }
@keyframes dlg-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes dlg-pop      { from { transform: scale(0.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.toast-area {
  position: fixed; top: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #1e293b; border: 1px solid #334155; border-left-width: 4px;
  padding: 10px 16px; border-radius: 6px; min-width: 240px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { border-left-color: #16a34a; }
.toast.error { border-left-color: #dc2626; }
.toast.info { border-left-color: #2563eb; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Dashboard stats cards ─────────────────────────────── */
.stats-grid {
  display: grid; gap: 16px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
}
.stat-card { padding: 14px 16px; margin-bottom: 0; }
.stat-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px; padding-bottom: 8px;
  border-bottom: 1px solid #334155;
}
.stat-title {
  font-size: 13px; font-weight: 700; color: #f1f5f9;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.stat-big {
  font-size: 32px; font-weight: 700; color: #f1f5f9;
  font-family: 'SF Mono', Monaco, monospace;
  line-height: 1.1;
}
.stat-row {
  display: grid; grid-template-columns: 80px 1fr 80px; gap: 10px;
  align-items: center; margin-bottom: 8px;
}
.stat-row .stat-label { font-size: 12px; color: #94a3b8; }
.stat-bar {
  height: 6px; background: #0f172a; border: 1px solid #334155;
  border-radius: 3px; overflow: hidden;
}
.stat-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #16a34a 0%, #16a34a 60%, #f59e0b 75%, #dc2626 90%);
  transition: width 0.4s ease;
}
.stat-bar-fill.warn { background: #f59e0b; }
.stat-bar-fill.danger { background: #dc2626; }
.stat-val {
  font-size: 12.5px; color: #cbd5e1; text-align: right;
}
.stat-mini-row {
  display: flex; justify-content: space-between; gap: 8px;
  margin-top: 6px; font-size: 12px;
}
.stat-mini-row > div { flex: 1; }
.stat-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.pill {
  display: inline-flex; gap: 4px; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: #334155; color: #cbd5e1;
}
.pill-ok   { background: #14532d; color: #86efac; }
.pill-info { background: #1e3a8a; color: #93c5fd; }
.pill-warn { background: #7c2d12; color: #fdba74; }
.pill-mute { background: #1f2937; color: #94a3b8; }

/* ─── Switch toggle (thay button Bật/Tắt) ─── */
.switch {
  position: relative; display: inline-block;
  width: 40px; height: 22px;
  vertical-align: middle; margin-right: 4px;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: #475569; border-radius: 22px;
  transition: background 0.18s ease;
}
.switch .slider::before {
  content: ''; position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: #f1f5f9; border-radius: 50%;
  transition: transform 0.18s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.switch input:checked + .slider { background: #16a34a; }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus + .slider { outline: 2px solid #2563eb; outline-offset: 2px; }
.switch input:disabled + .slider { opacity: 0.5; cursor: progress; }

/* ─── Badge với icon (status pill cải tiến) ─── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 10px;
  font-size: 11.5px; font-weight: 600;
  background: #334155; color: #cbd5e1;
}
.badge-icon {
  font-size: 11px; line-height: 1; display: inline-block;
}
.badge.connected, .badge.running { background: #14532d; color: #86efac; }
.badge.connected .badge-icon, .badge.running .badge-icon { color: #4ade80; }
.badge.dialing { background: #1e3a8a; color: #93c5fd; }
.badge.dialing .badge-icon {
  color: #60a5fa;
  display: inline-block;
  animation: spin 1.2s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.badge.error    { background: #7f1d1d; color: #fca5a5; }
.badge.error .badge-icon { color: #f87171; }
.badge.disconnected, .badge.stopped { background: #1f2937; color: #94a3b8; }

/* ─── Session type badges — màu khác nhau để dễ phân biệt ─── */
.badge.static {
  background: #155e75; color: #a5f3fc;
  border: 1px solid #0891b2;
}
.badge.static .badge-icon { color: #67e8f9; }
.badge.private {
  background: #581c87; color: #e9d5ff;
  border: 1px solid #9333ea;
}
.badge.private .badge-icon { color: #d8b4fe; }
.badge.rotating {
  background: #9a3412; color: #fed7aa;
  border: 1px solid #ea580c;
}
.badge.rotating .badge-icon { color: #fdba74; }

/* Nút "🏷 Loại" — phối màu trung tính nổi bật để phân biệt với button khác */
button.small.btn-type {
  background: #1e293b; color: #e0e7ff;
  border: 1px solid #6366f1;
}
button.small.btn-type:hover { background: #312e81; border-color: #818cf8; }

/* Context menu items đổi loại — icon màu theo type */
.ctx-item[data-act="type-static"]   .ctx-icon { color: #67e8f9; }
.ctx-item[data-act="type-private"]  .ctx-icon { color: #d8b4fe; }
.ctx-item[data-act="type-rotating"] .ctx-icon { color: #fdba74; }

/* ─── Auto-rotate preset chips ─── */
.ar-preset {
  background: #334155; color: #e2e8f0;
  border: 1px solid #475569;
  padding: 6px 14px; border-radius: 16px;
  font-size: 12.5px; cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.ar-preset:hover { background: #475569; }
.ar-preset.active {
  background: #2563eb; border-color: #2563eb; color: #fff;
  font-weight: 600;
}

.login-box {
  max-width: 380px; margin: 80px auto;
  background: #1e293b; padding: 32px; border-radius: 8px;
  border: 1px solid #334155;
}
.login-box h1 { margin: 0 0 24px; color: #f1f5f9; }
.login-box .form-row { margin-bottom: 16px; }
.login-box button { width: 100%; padding: 10px; }

.muted { color: #94a3b8; }
.small { font-size: 12px; }
.mono { font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Courier New', monospace; font-size: 12px; }
pre.export-text {
  background: #0f172a; border: 1px solid #334155; border-radius: 6px;
  padding: 12px; font-family: 'SF Mono', Monaco, monospace; font-size: 12px;
  max-height: 400px; overflow-y: auto; white-space: pre-wrap;
}

.creds-table { margin-top: 12px; font-size: 12px; }
.creds-table td { padding: 4px 8px; }

.nic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.nic-tile {
  background: #0f172a; border: 1px solid #334155; border-radius: 8px;
  padding: 10px 12px; position: relative;
}
.nic-tile.has-pado { border-color: #16a34a; }
.nic-tile.no-carrier { opacity: 0.55; }
.nic-tile .nic-name { font-weight: 600; font-family: 'SF Mono', Monaco, monospace; font-size: 13px; color: #f1f5f9; }
.nic-tile .nic-meta { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.nic-tile .nic-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.nic-tile .tag {
  font-size: 10px; padding: 2px 6px; border-radius: 4px; font-weight: 600;
}
.nic-tile .tag.up { background: #16a34a; color: #fff; }
.nic-tile .tag.carrier { background: #2563eb; color: #fff; }
.nic-tile .tag.no-link { background: #475569; color: #cbd5e1; }
.nic-tile .tag.pado { background: #f59e0b; color: #000; }
.nic-tile .tag.line { background: #7c3aed; color: #fff; }

/* Sessions selection */
#sessions-table tr.sel { background: rgba(37,99,235,0.18); }
#sessions-table tr.sel:hover { background: rgba(37,99,235,0.24); }
#sessions-table td.cb-cell { width: 28px; padding: 6px 8px 6px 12px; text-align: center; }
#sessions-table input.row-check, #sessions-table input.head-check {
  width: 14px; height: 14px; margin: 0; cursor: pointer; accent-color: #2563eb;
}
.sel-toolbar {
  display: flex; gap: 8px; align-items: center;
  padding: 6px 10px; background: rgba(37,99,235,0.12);
  border: 1px solid rgba(37,99,235,0.3); border-radius: 6px;
  margin-bottom: 10px;
}
.sel-toolbar .count { font-weight: 600; color: #93c5fd; }
.sel-toolbar button { padding: 4px 10px; font-size: 12px; }

/* Rubber-band */
#sel-band {
  position: fixed; pointer-events: none; z-index: 9000;
  border: 1.5px dashed #3b82f6;
  background: rgba(59,130,246,0.10); border-radius: 3px;
}

/* Context menu */
.ctx-menu {
  position: fixed; z-index: 9100; min-width: 240px;
  background: #1e293b; border: 1px solid #334155; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.45);
  padding: 4px; font-size: 13px; user-select: none;
  color: #e2e8f0;
}
.ctx-menu .ctx-header {
  padding: 6px 12px 4px; font-size: 11px; font-weight: 600;
  color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px;
}
.ctx-menu .ctx-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 6px; cursor: pointer;
  transition: background 0.12s;
}
.ctx-menu .ctx-item:hover { background: #334155; }
.ctx-menu .ctx-item.disabled { opacity: 0.45; pointer-events: none; }
.ctx-menu .ctx-item.danger { color: #fca5a5; }
.ctx-menu .ctx-item.danger:hover { background: #7f1d1d; color: #fff; }
.ctx-menu .ctx-sep { height: 1px; background: #334155; margin: 4px 6px; }
.ctx-menu .ctx-icon { width: 14px; text-align: center; opacity: 0.8; }

.api-group { margin-bottom: 24px; }
.api-group h3 { margin: 0 0 8px; font-size: 14px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.5px; }
.api-row {
  background: #0f172a; border: 1px solid #334155; border-radius: 6px;
  margin-bottom: 8px; padding: 10px 14px;
}
.api-row .method {
  display: inline-block; font-family: 'SF Mono', Monaco, monospace; font-weight: 700;
  padding: 2px 8px; border-radius: 4px; font-size: 11px; margin-right: 8px;
  min-width: 50px; text-align: center;
}
.api-row .method.GET { background: #16a34a; color: #fff; }
.api-row .method.POST { background: #2563eb; color: #fff; }
.api-row .method.PUT { background: #ca8a04; color: #fff; }
.api-row .method.DELETE { background: #dc2626; color: #fff; }
.api-row .path { font-family: 'SF Mono', Monaco, monospace; font-size: 13px; color: #f1f5f9; }
.api-row .desc { margin-top: 4px; font-size: 12px; color: #94a3b8; }
.api-row .extras { margin-top: 6px; }
.api-row pre {
  background: #020617; border: 1px solid #1e293b; border-radius: 4px;
  padding: 8px 10px; font-family: 'SF Mono', Monaco, monospace; font-size: 11px;
  overflow-x: auto; white-space: pre-wrap; margin: 4px 0;
}
.api-row .row-actions { display: flex; gap: 6px; margin-top: 4px; }
.api-row button { padding: 4px 10px; font-size: 11px; }
.api-search {
  width: 100%; max-width: 480px; margin-bottom: 16px;
}
