:root {
  --bg: #f1f5f9;
  --card: #fff;
  --text: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --ok: #16a34a;
  --danger: #dc2626;
  --dark: #0f172a;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}
a { color: var(--brand); }
.wrap { width: min(1100px, calc(100% - 24px)); margin: 16px auto 32px; }
.wrap-narrow { width: min(600px, calc(100% - 24px)); }
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}
.card-form { padding: 20px 22px 22px; }
.card + .card { margin-top: 14px; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); font-size: 12px; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar.dark { background: var(--dark); color: #fff; }
.topbar.dark .muted { color: #cbd5e1; }
.topbar-brand { display: flex; flex-direction: column; gap: 2px; }
.nav { display: flex; flex-wrap: wrap; gap: 6px; }
.nav a {
  text-decoration: none;
  background: #f8fafc;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: bold;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.topbar.dark .nav a { background: #1e293b; color: #e2e8f0; }
.nav a.on { background: #dbeafe; color: #1d4ed8; }
.nav a.danger { background: #fee2e2; color: #991b1b; }
label { display: block; font-size: 13px; font-weight: bold; margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-family: Tahoma, Arial, sans-serif;
  font-size: 14px;
  background: #fff;
}
.btn, button.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 14px;
  border: 0;
  border-radius: 8px;
  text-decoration: none;
  font-weight: bold;
  font-family: Tahoma, Arial, sans-serif;
  cursor: pointer;
  font-size: 13px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-ghost { background: #e2e8f0; color: #334155; }
.btn-danger { background: #fee2e2; color: #991b1b; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row .btn { flex: 1; }
.alert { padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; font-size: 13px; text-align: center; }
.alert.danger { background: #fee2e2; color: #991b1b; }
.alert.ok { background: #dcfce7; color: #166534; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { background: #fff; border-radius: 12px; padding: 14px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: middle; }
th { background: #f8fafc; color: #475569; }
.grid-2 { display: grid; grid-template-columns: 280px 1fr; gap: 14px; }
.login-box { width: min(420px, calc(100% - 24px)); margin: 8vh auto; }
.prefix-box { display: flex; gap: 8px; align-items: center; }
.prefix-box .pre {
  background: #e2e8f0;
  padding: 11px;
  border-radius: 8px;
  font-family: monospace;
  white-space: nowrap;
}
.chips { display: flex; flex-direction: column; gap: 8px; }
.chips-row {
  flex-direction: row;
  flex-wrap: wrap;
}
.chips-row .chip {
  flex: 1 1 140px;
  min-width: 120px;
}
.chip {
  border: 2px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  font-size: 13px;
}
.chip.on { border-color: var(--brand); background: #eff6ff; color: #1d4ed8; }
.add-client-form .tpl-block { margin-bottom: 4px; }
.add-client-form .inbounds-block { margin-top: 8px; }
.username-row { display: flex; gap: 8px; align-items: stretch; }
.username-row input {
  flex: 1;
  direction: ltr;
  text-align: left;
  font-family: ui-monospace, Consolas, monospace;
}
.username-row .btn { flex: 0 0 auto; white-space: nowrap; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-line { display: flex; align-items: center; gap: 8px; font-weight: normal; margin-top: 14px; }
.inbound-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.inbound-card {
  display: flex;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}
.hint { font-size: 12px; color: var(--muted); }
.switch { position: relative; display: inline-block; width: 42px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .3s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: #2563eb; }
input:checked + .slider:before { transform: translateX(-20px); }
.login-container { width: min(420px, calc(100% - 24px)) !important; }
/* Seller / admin client dashboards */
.dash-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.credit-badge {
  background: #eef2ff;
  color: #1d4ed8;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: bold;
  font-size: 13px;
  white-space: nowrap;
}
.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat-box {
  background: #fff;
  padding: 12px 10px;
  border-radius: 10px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
  border-top: 3px solid #94a3b8;
}
.stat-box.active { border-top-color: #16a34a; }
.stat-box.online { border-top-color: #2563eb; }
.stat-box.disabled { border-top-color: #dc2626; }
.stat-box.expired { border-top-color: #f59e0b; }
.stat-box .title { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat-box .value { font-size: 20px; font-weight: bold; color: #0f172a; }
.main-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  padding: 12px;
}
.action-bar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.clients-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  font-size: 12.5px;
  min-width: 980px;
}
.clients-table th {
  background: #f8fafc;
  padding: 10px 8px;
  color: #475569;
  border-bottom: 2px solid var(--line);
  white-space: nowrap;
  font-size: 12px;
}
.clients-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.clients-table tr:hover { background: #fafbfc; }
.client-id-cell {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 700;
  direction: ltr;
  text-align: left;
  white-space: nowrap;
}
.client-id-meta {
  font-size: 10px;
  color: #94a3b8;
  font-family: ui-monospace, Consolas, monospace;
  margin-top: 2px;
  direction: ltr;
  text-align: left;
}
.col-nowrap, .col-traffic, .col-remain, .col-expiry {
  white-space: nowrap;
  min-width: 110px;
}
.col-remain { color: #16a34a; font-weight: 700; min-width: 130px; }
.col-expiry { min-width: 160px; }
.expiry-pending { color: #0ea5e9; font-weight: 500; white-space: nowrap; }
.expiry-dead { color: #dc2626; font-weight: bold; white-space: nowrap; }
.inbound-cell { position: relative; white-space: nowrap; }
.inbound-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: default;
}
.inbound-count.empty {
  background: #f8fafc;
  color: #94a3b8;
  border-color: #e2e8f0;
  font-weight: 500;
}
.inbound-popover {
  display: none;
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  right: 0;
  min-width: 200px;
  max-width: 280px;
  max-height: 220px;
  overflow: auto;
  background: #0f172a;
  color: #e2e8f0;
  padding: 8px 10px;
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.28);
  font-size: 11px;
  line-height: 1.55;
  text-align: right;
}
.inbound-popover div { padding: 2px 0; border-bottom: 1px solid #1e293b; }
.inbound-popover div:last-child { border-bottom: 0; }
.inbound-cell:hover .inbound-popover { display: block; }
.progress-container {
  width: 72px;
  background: #e2e8f0;
  border-radius: 10px;
  height: 6px;
  overflow: hidden;
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
}
.progress-bar { height: 100%; background: #16a34a; border-radius: 10px; }
.progress-bar.warning { background: #f59e0b; }
.progress-bar.danger { background: #dc2626; }
.traffic-text { font-size: 11px; color: var(--muted); white-space: nowrap; }
.badge-online { color: #16a34a; font-weight: bold; white-space: nowrap; }
.badge-offline { color: #94a3b8; white-space: nowrap; }
.action-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  min-width: 140px;
}
.op-btn {
  text-decoration: none;
  font-size: 14px;
  padding: 5px 8px;
  border-radius: 4px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  color: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.op-btn:hover { background: #e2e8f0; }
.op-delete { background: #fff5f5; border-color: #fecaca; color: #dc2626; }
.sub-link-btn {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1d4ed8;
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  white-space: nowrap;
}
.readonly-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 600;
}
@media (max-width: 800px) {
  .header, .admin-header, .title-bar, .action-bar { flex-direction: column; align-items: stretch !important; }
  .header > div, .admin-header > div { display: flex; flex-wrap: wrap; gap: 8px; }
  .container { max-width: 100% !important; padding: 8px !important; }
  body { padding: 8px !important; }
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .grid-2 { grid-template-columns: 1fr; }
  .wrap, .wrap-narrow { width: calc(100% - 16px); margin: 10px auto 24px; }
  .topbar { position: static; }
  .nav a { flex: 1 1 calc(50% - 6px); justify-content: center; }
  table, .clients-table { min-width: 720px; }
  .prefix-box { flex-wrap: wrap; }
  .prefix-box .pre { width: 100%; }
  .fields-2 { grid-template-columns: 1fr; }
  .username-row { flex-wrap: wrap; }
  .username-row .btn { width: 100%; }
  .dash-toolbar { flex-direction: column; align-items: stretch; }
  .dash-toolbar .btn { width: 100%; }
}
