:root {
  --bg: #0b0f14;
  --surface: #151b24;
  --surface-2: #1c2430;
  --border: #2a3444;
  --text: #eef2f7;
  --muted: #8b97a8;
  --primary: #4f8cff;
  --primary-pressed: #3a73e0;
  --success: #22c55e;
  --success-bg: #102818;
  --danger: #ef4444;
  --danger-bg: #2a1212;
  --radius: 14px;
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overscroll-behavior: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: 100%;
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(12px + var(--safe-top))
    16px
    calc(var(--nav-h) + var(--safe-bottom) + 20px);
  position: relative;
}

.app-shell.no-nav {
  padding-bottom: calc(24px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.page-head {
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0 0 6px;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.page-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.page-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.card.success {
  background: var(--success-bg);
  border-color: #1f6b3a;
}

.card.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
}

label {
  display: block;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

input[type="text"],
input[type="password"],
input[type="number"],
.copy-input {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 14px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  appearance: none;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.98);
}

.btn.block {
  display: flex;
  width: 100%;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.btn.danger {
  background: var(--danger-bg);
  border-color: #7f1d1d;
  color: #fecaca;
}

.btn.small {
  min-height: 42px;
  padding: 0 14px;
  font-size: 0.88rem;
}

.btn.icon {
  min-width: 48px;
  padding: 0;
}

.chip-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.chip input:checked + span {
  border-color: var(--primary);
  background: rgba(79, 140, 255, 0.14);
  color: #dbeafe;
}

.chip.full {
  grid-column: 1 / -1;
}

.alert.error {
  background: var(--danger-bg);
  border: 1px solid #7f1d1d;
  color: #fecaca;
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-size: 0.92rem;
}

.copy-block {
  margin-top: 12px;
}

.copy-block label {
  margin-bottom: 8px;
}

.copy-row {
  display: flex;
  gap: 8px;
}

.copy-row .copy-input {
  margin-top: 0;
  font-size: 0.82rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 12px 0;
}

.meta-item {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 12px;
}

.meta-item .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.meta-item .value {
  font-size: 0.98rem;
  font-weight: 600;
}

.config-card {
  padding: 0;
  overflow: hidden;
}

.config-card-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.config-card-head code {
  display: block;
  font-size: 0.82rem;
  color: #cbd5e1;
  word-break: break-all;
}

.config-card-body {
  padding: 12px 16px 16px;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.qr-wrap img {
  width: min(220px, 70vw);
  height: auto;
  background: #fff;
  padding: 10px;
  border-radius: 12px;
}

.protocol-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.protocol-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.tunnel-block {
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 4px;
}

.tunnel-block:last-of-type {
  border-bottom: none;
}

.tunnel-block .protocol-item {
  border-bottom: none;
  padding-bottom: 0;
}

.usage-row {
  margin: 0 0 4px;
}

.usage-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 0.78rem;
  color: var(--muted);
}

.usage-meta strong {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.usage-spark {
  display: block;
  width: 100%;
  height: 36px;
  border-radius: 8px;
  background: var(--surface-2);
}

.usage-spark-fill {
  fill: rgba(79, 140, 255, 0.22);
}

.usage-spark-line {
  stroke: var(--primary);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.protocol-info {
  min-width: 0;
  flex: 1;
}

.protocol-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.protocol-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.switch-form {
  flex-shrink: 0;
}

.switch {
  position: relative;
  width: 52px;
  height: 32px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  background: #334155;
  border-radius: 999px;
  transition: background 0.2s;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 26px;
  height: 26px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .switch-slider {
  background: var(--success);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 430px;
  min-height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  background: rgba(11, 15, 20, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.bottom-nav a {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 600;
  padding: 8px 2px;
  text-align: center;
}

.bottom-nav a.active {
  color: var(--primary);
}

.bottom-nav .icon {
  font-size: 1.15rem;
  line-height: 1;
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-brand .logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, #4f8cff, #2563eb);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
}

.login-brand h1 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: #1e293b;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.summary-card {
  text-align: center;
}

.summary-total {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--primary);
}

.summary-sub {
  margin-top: 4px;
}

.traffic-row {
  padding: 14px 16px;
}

.traffic-row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.traffic-row-title {
  min-width: 0;
  flex: 1;
}

.traffic-name {
  display: block;
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.3;
}

.traffic-value {
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.92rem;
  color: #dbeafe;
}

.traffic-bar-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.traffic-bar {
  flex: 1;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

.traffic-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2563eb, #4f8cff);
  min-width: 0;
  transition: width 0.35s ease;
}

.traffic-bar-fill-mid {
  background: linear-gradient(90deg, #d97706, #f59e0b);
}

.traffic-bar-fill-high {
  background: linear-gradient(90deg, #dc2626, #ef4444);
}

.traffic-pct {
  flex-shrink: 0;
  min-width: 44px;
  text-align: right;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
}

.traffic-usage-block {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.traffic-meta {
  font-size: 0.74rem;
  line-height: 1.35;
}

.badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-off {
  background: #3f1d1d;
  color: #fecaca;
}

.badge-on {
  background: #132a1f;
  color: #86efac;
}

.search-bar {
  margin-bottom: 12px;
}

.search-input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.search-empty {
  text-align: center;
  padding: 8px 0 12px;
}

.config-card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.config-card-head-row code {
  word-break: break-all;
}

.config-card-disabled {
  opacity: 0.72;
  border-color: #4b5563;
}

.config-actions {
  margin-top: 14px;
}

.config-actions form {
  margin: 0;
}

.badge-cf {
  background: #dc2626;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(254, 202, 202, 0.35);
}

.cf-bubble {
  position: relative;
  background: linear-gradient(145deg, #7f1d1d, #991b1b 45%, #b91c1c);
  border: 1px solid #fecaca;
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 8px 24px rgba(127, 29, 29, 0.35);
  color: #fff;
}

.cf-bubble-inline {
  margin-bottom: 12px;
}

.cf-bubble-tag {
  display: inline-block;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.cf-bubble-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.cf-bubble-title {
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
}

.cf-bubble-domain {
  margin-top: 4px;
  font-size: 0.82rem;
  color: #fecaca;
}

.cf-bubble-traffic {
  flex-shrink: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #fff;
}

.cf-bubble .traffic-bar {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.25);
}

.cf-bubble .traffic-bar-fill {
  background: linear-gradient(90deg, #fff, #fecaca);
}

.cf-bubble-pct {
  color: #fff !important;
  font-size: 0.88rem !important;
}

.cf-bubble-meta {
  margin-top: 8px;
  font-size: 0.78rem;
  color: #fecaca;
}

.tag-chip {
  display: inline-block;
  background: #1e3a5f;
  color: #93c5fd;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
}

.tag-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.tag-form label {
  flex: 1;
  min-width: 140px;
  margin: 0;
}

.tag-form .btn {
  flex-shrink: 0;
}

.card-title {
  margin: 0 0 14px;
  font-size: 1rem;
}

.reseller-card {
  padding: 0;
  overflow: hidden;
  margin-bottom: 12px;
}

.reseller-card-link {
  display: block;
  width: 100%;
  padding: 16px;
  color: inherit;
  text-decoration: none;
}

.reseller-card-link:active {
  background: rgba(255, 255, 255, 0.03);
}

.reseller-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.reseller-card-head > div:first-child {
  flex: 1;
  min-width: 0;
}

.reseller-card-head strong {
  display: block;
  font-size: 1rem;
  line-height: 1.3;
}

.reseller-card-head .muted {
  display: block;
  font-size: 0.82rem;
  margin-top: 2px;
}

.reseller-card-head .badge {
  flex-shrink: 0;
  margin-top: 0;
  white-space: nowrap;
}

.reseller-card .meta-grid {
  margin: 14px 0 0;
}

.reseller-period {
  margin: 12px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  line-height: 1.4;
}

.billing-card .stat-value {
  font-size: 1.2rem;
  font-weight: 700;
}

.admin-actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.password-form label {
  margin-bottom: 8px;
}

.settlement-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.settlement-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.settlement-table th,
.settlement-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.settlement-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

/* Public status page — mobile first */
body.status-body {
  font-family: "Vazirmatn", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(79, 140, 255, 0.22), transparent 55%),
    radial-gradient(80% 50% at 100% 100%, rgba(34, 197, 94, 0.08), transparent 50%),
    var(--bg);
}

body.status-body .app-shell.no-nav {
  justify-content: flex-start;
  padding-top: calc(28px + var(--safe-top));
  max-width: 420px;
}

.status-page {
  width: 100%;
}

.status-hero {
  text-align: center;
  margin-bottom: 20px;
}

.status-kicker {
  margin: 0 0 10px;
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #7eb0ff;
  font-weight: 700;
}

.status-hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.55rem, 6vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.03em;
}

.status-sub {
  margin: 0 auto;
  max-width: 16rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.status-alert {
  margin-bottom: 14px;
  text-align: center;
}

.status-result {
  text-align: center;
  padding: 22px 18px 20px;
  margin-bottom: 16px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background:
    linear-gradient(180deg, rgba(28, 36, 48, 0.95), rgba(21, 27, 36, 0.98));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

.status-pill {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.status-pill.status-active {
  color: #4ade80;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.25);
}

.status-pill.status-expired,
.status-pill.status-inactive,
.status-pill.status-exhausted {
  color: #f87171;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.25);
}

.status-days-ring {
  --p: 100;
  width: min(210px, 58vw);
  aspect-ratio: 1;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(
    #4f8cff calc(var(--p) * 1%),
    rgba(255, 255, 255, 0.08) 0
  );
  position: relative;
}

.status-days-ring::before {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: #121821;
}

.status-days-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
}

.status-days-num {
  font-size: clamp(2.6rem, 12vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.status-days-unit {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.status-plan-line {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
}

.status-expire {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.status-expire strong {
  color: var(--text);
  font-weight: 700;
  margin-right: 4px;
}

.status-form-card {
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(21, 27, 36, 0.92);
  margin-bottom: 0;
}

.status-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.status-form-card textarea {
  width: 100%;
  margin: 0 0 12px;
  padding: 14px;
  min-height: 120px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #0e141c;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.45;
  resize: vertical;
}

.status-form-card textarea:focus {
  outline: none;
  border-color: rgba(79, 140, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.18);
}

.status-submit {
  min-height: 48px;
  font-size: 1rem;
  font-weight: 700;
  border-radius: 14px;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}

@media (max-width: 380px) {
  .status-days-ring {
    width: min(190px, 64vw);
  }
}
