/* gap gives the stacked cards (hero/link/usage/expiry/auto-renew/cta) a
   consistent rhythm — without it they butt together, since none carry margins. */
.sub-detail-screen { gap: 12px; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px 0;
}
.detail-header .title { font-size: 20px; font-weight: 700; }
.detail-header .back-btn, .detail-header .spacer {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.detail-header .back-btn svg { width: 18px; height: 18px; }
.detail-header .spacer { background: transparent; border: 0; }

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.hero-card .top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hero-card .status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}
.hero-card .status .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--success);
}
/* Non-active states recolor the pill so a green badge never sits on an
   expired or traffic-exhausted subscription. */
.hero-card .status.expiring { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.hero-card .status.expiring .dot { background: var(--warning); }
.hero-card .status.expired { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.hero-card .status.expired .dot { background: var(--danger); }
.hero-card .name { font-size: 18px; font-weight: 700; text-align: start; }
.hero-card .sub-label { font-size: 12px; color: var(--text-muted); text-align: start; margin-top: 2px; }

.link-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.link-card .head { font-size: 12px; color: var(--text-secondary); text-align: start; }
.link-card .row { display: flex; gap: 12px; align-items: center; }
.link-card .qr-wrap {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 6px;
  flex-shrink: 0;
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.link-card .qr-wrap svg { width: 100%; height: 100%; display: block; }
.link-card .right { flex: 1; display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.link-card .right code {
  font-family: monospace;
  font-size: 11px;
  word-break: break-all;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  color: var(--text-primary);
  direction: ltr;
  text-align: end;
}
.link-card .right .actions { display: flex; gap: 6px; }
.link-card .right .actions button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}
.link-card .right .actions button:hover { border-color: var(--accent); color: var(--accent); }

.link-card .add-to-app {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  padding: 11px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.link-card .add-to-app:hover { border-color: var(--accent); color: var(--accent); }

.link-card .alt-link {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.link-card .alt-head { font-size: 12px; color: var(--text-secondary); text-align: start; }
.link-card .alt-row { display: flex; gap: 6px; align-items: stretch; }
.link-card .alt-row code {
  flex: 1;
  font-family: monospace;
  font-size: 11px;
  word-break: break-all;
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 8px 10px;
  color: var(--text-primary);
  direction: ltr;
  text-align: end;
}
.link-card .alt-row button {
  flex-shrink: 0;
  width: 38px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.link-card .alt-row button:hover { border-color: var(--accent); color: var(--accent); }
.link-card .alt-hint { font-size: 11px; color: var(--text-muted); text-align: start; }

/* Add-to-app sheet */
.app-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  color: var(--text-primary);
  font-family: inherit;
}
.app-item:hover { border-color: var(--accent); }
.app-logo {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Lettered fallback shown when the brand asset is missing. */
.app-logo::before {
  content: attr(data-letter);
  position: absolute;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
}
.app-logo img {
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.app-name { font-size: 11px; font-weight: 600; }

.usage-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.usage-card .row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.usage-card .label { font-size: 11px; color: var(--text-muted); }
.usage-card .value { font-size: 15px; font-weight: 700; }
.usage-card .extra-vol { font-size: 11px; font-weight: 600; color: var(--success); text-align: start; margin-top: 6px; }
.usage-card .track {
  height: 10px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.usage-card .track > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: var(--radius-full);
}

.expiry-row { display: flex; gap: 12px; }
.expiry-row .box {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}
.expiry-row .box .label { font-size: 11px; color: var(--text-muted); }
.expiry-row .box .value { font-size: 16px; font-weight: 700; }

.auto-renew {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
/* flex:1 lets the label fill the row so the toggle sits beside it instead of
   being shoved to the far edge with a big empty gap between. */
.auto-renew .text { flex: 1; text-align: start; }
.auto-renew .text .title { font-size: 14px; font-weight: 600; }
.auto-renew .text .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.auto-renew .switch {
  position: relative;
  width: 46px;
  height: 26px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s;
}
.auto-renew .switch::after {
  content: '';
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--text-secondary);
  /* Slide the knob with the logical inset (not a physical translateX) so it
     moves toward the END edge under both ltr and rtl. translateX always pushes
     right, which in rtl shoved the knob clean outside the track. */
  transition: inset-inline-start 0.18s, background 0.18s;
}
.auto-renew .switch.on { background: var(--accent); border-color: var(--accent); }
.auto-renew .switch.on::after {
  background: #FFFFFF;
  inset-inline-start: 25px;
}
.auto-renew .switch.busy { opacity: 0.5; pointer-events: none; }

.name-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.name-edit button {
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  padding: 4px;
}
.name-edit button:hover { color: var(--accent); }
.name-edit input {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 6px 10px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: inherit;
  text-align: start;
  direction: rtl;
  max-width: 220px;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-end;
  z-index: 100;
  animation: sheet-fade 0.18s ease-out;
}
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }

.sheet {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-3xl) var(--radius-3xl) 0 0;
  padding: 18px 16px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 80vh;
  overflow-y: auto;
  animation: sheet-slide 0.22s ease-out;
}
@keyframes sheet-slide { from { transform: translateY(20px); } to { transform: translateY(0); } }

.sheet .handle {
  width: 44px;
  height: 4px;
  background: var(--border);
  border-radius: var(--radius-full);
  margin: 0 auto;
}
.sheet .title { font-size: 16px; font-weight: 700; text-align: center; }
.sheet .sub { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: -8px; }
.sheet .balance {
  background: var(--surface-2);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}
.sheet .balance b { color: var(--text-primary); }

.sheet-plan {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  text-align: start;
  color: var(--text-primary);
  font-family: inherit;
}
.sheet-plan:hover { border-color: var(--accent); }
.sheet-plan.insufficient { opacity: 0.55; }
.sheet-plan .meta .name { font-weight: 600; font-size: 14px; }
.sheet-plan .meta .stats { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.sheet-plan .price { text-align: end; }
.sheet-plan .price .now { font-weight: 700; }
.sheet-plan .price .strike { font-size: 11px; color: var(--text-muted); text-decoration: line-through; }

.sheet .cancel {
  background: transparent;
  color: var(--text-secondary);
  padding: 10px;
  text-align: center;
  font-size: 13px;
}

.sheet-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--danger);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-size: 12px;
  text-align: center;
}

.cta-primary {
  width: 100%;
  background: var(--accent);
  color: var(--on-accent);
  border-radius: var(--radius-full);
  padding: 14px;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 6px 18px rgba(255, 106, 0, 0.35);
}
.cta-primary:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* "Generate new link" — icon tile + the 24h-cooldown locked state. */
.new-link .nl-ic {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.new-link .nl-ic svg { width: 20px; height: 20px; }
.new-link.locked {
  opacity: 0.6;
  pointer-events: none;
  cursor: default;
}
.new-link.locked .nl-ic { filter: blur(1.5px); }
.new-link.locked .sub { color: var(--warning); font-weight: 600; }
