/* ── OberVPN Web Cabinet v2 ── */

/* CRITICAL: hidden attribute must always win */
[hidden] { display: none !important; }

:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #111827;
  --ink-soft: #6b7280;
  --ink-muted: #9ca3af;
  --line: #e5e7eb;
  --brand: #0d9488;
  --brand-dark: #0f766e;
  --brand-deeper: #0a5e57;
  --brand-light: #ccfbf1;
  --brand-surface: #f0fdfa;
  --accent: #f59e0b;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --radius: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 8px 28px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.03), 0 20px 50px rgba(0,0,0,0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 70px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  min-height: 100%;
  font-family: "Sora", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* hide the old ornament grid */
.bg-ornament { display: none; }

/* ═══════════ Layout Shell ═══════════ */
.app-shell {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px 16px calc(var(--nav-h) + 24px + var(--safe-bottom));
}

/* ═══════════ Topbar ═══════════ */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 32px;
  animation: slideUp .35s ease;
}

.brand-mark {
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: #fff;
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: .04em;
  flex-shrink: 0;
  box-shadow: 0 2px 10px rgba(13,148,136,.25);
}

.topbar > div:not(.brand-mark) { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 1.1rem; font-weight: 700; }
.topbar p  { margin: 2px 0 0; font-size: .78rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ═══════════ Views & Tabs ═══════════ */
.view {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* prevent nav from jumping when switching tabs with different content heights */
  min-height: calc(100vh - 200px);
  min-height: calc(100dvh - 200px);
}

/* ═══════════ Cards ═══════════ */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card[data-animate] {
  animation: slideUp .3s ease both;
}

.card-primary {
  background: linear-gradient(165deg, #ffffff 0%, var(--brand-surface) 100%);
  border-color: rgba(13,148,136,.12);
}

#auth-code-field {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card-balance {
  background: linear-gradient(160deg, var(--brand-surface) 0%, #ffffff 55%);
  border-color: rgba(13,148,136,.1);
}

/* ═══════════ Typography ═══════════ */
.eyebrow {
  margin: 0;
  color: var(--brand);
  letter-spacing: .1em;
  font-size: .7rem;
  text-transform: uppercase;
  font-weight: 700;
}

h2 { margin: 0; font-size: 1.45rem; line-height: 1.25; font-weight: 800; }
h3 { margin: 0; font-size: 1.15rem; font-weight: 700; }
h4 { margin: 0; font-size: 1rem; font-weight: 600; }

/* heading + description should be tighter than card gap */
.card h2 + .muted,
.card h3 + .muted,
.card .eyebrow + * { margin-top: -10px; }

.muted { color: var(--ink-soft); margin: 0; line-height: 1.6; }
.tiny  { font-size: .82rem; }

/* ═══════════ Form Fields ═══════════ */
.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span {
  font-size: .85rem;
  font-weight: 600;
  color: var(--ink);
}

input, select, button { font: inherit; }

input, select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
  color: var(--ink);
  padding: 14px 16px;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}

input:focus, select:focus {
  border-color: var(--brand);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(13,148,136,.1);
}

input::placeholder { color: var(--ink-muted); }

/* ═══════════ Buttons ═══════════ */
.btn, .ghost-btn, .chip, .link-btn, .nav-item {
  border: 0;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s ease, box-shadow .15s ease, color .15s ease, opacity .15s ease;
  -webkit-tap-highlight-color: transparent;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--brand);
  color: #fff;
  padding: 14px 28px;
  min-height: 52px;
  font-size: .95rem;
  border-radius: var(--radius-sm);
}

.btn:hover  { background: var(--brand-dark); box-shadow: 0 4px 16px rgba(13,148,136,.28); }
.btn:active { box-shadow: none; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

.btn-strong {
  background: linear-gradient(135deg, #0d9488, #0f766e);
  box-shadow: 0 3px 12px rgba(13,148,136,.3);
}
.btn-strong:hover { box-shadow: 0 6px 24px rgba(13,148,136,.35); }

.ghost-btn {
  background: var(--brand-surface);
  color: var(--brand-dark);
  padding: 12px 22px;
  min-height: 46px;
  font-size: .9rem;
  border-radius: var(--radius-sm);
}
.ghost-btn:hover { background: var(--brand-light); }

.chip {
  background: var(--brand-surface);
  color: var(--brand-dark);
  padding: 10px 18px;
  font-size: .85rem;
  font-weight: 600;
  min-height: 42px;
  border-radius: var(--radius-sm);
}
.chip:hover { background: var(--brand-light); }

.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: var(--brand-surface);
  color: var(--brand-dark);
  padding: 12px 20px;
  font-size: .9rem;
  border-radius: var(--radius-sm);
}
.link-btn:hover { background: var(--brand-light); }

.danger { color: var(--danger); background: var(--danger-bg); }
.danger:hover { background: #fee2e2; }

/* ═══════════ Flex Utilities ═══════════ */
.row     { display: flex; align-items: center; }
.wrap    { flex-wrap: wrap; }
.between { justify-content: space-between; }
.gap-sm  { gap: 12px; }

/* ═══════════ Balance Line ═══════════ */
.balance-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.balance-line span {
  font-size: clamp(2rem, 7vw, 2.8rem);
  font-weight: 800;
  letter-spacing: -.02em;
  color: var(--ink);
}

/* ═══════════ Quick Amounts ═══════════ */
.quick-amounts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

/* ═══════════ Feature List ═══════════ */
.feature-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: .92rem;
}

.feature-list li {
  padding-left: 28px;
  position: relative;
}

.feature-list li::before {
  content: "\2713";
  position: absolute;
  left: 0;
  color: var(--brand);
  font-weight: 700;
  font-size: 1rem;
}

/* ═══════════ Radio Pills ═══════════ */
.radio-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: #f8f9fb;
  border: 1.5px solid var(--line);
  font-size: .9rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.radio-pill:has(input:checked) {
  border-color: var(--brand);
  background: var(--brand-surface);
  box-shadow: 0 0 0 3px rgba(13,148,136,.08);
}

.radio-pill input { width: auto; margin: 0; padding: 0; accent-color: var(--brand); }

/* ═══════════ History & Subscriptions Lists ═══════════ */
.history-list, .subs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.history-item, .sub-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  background: #fafbfc;
  transition: box-shadow .2s;
}

.history-item:hover, .sub-item:hover {
  box-shadow: var(--shadow);
}

.history-item p, .sub-item p { margin: 0; }
.history-item .meta, .sub-item .meta { margin-top: 8px; font-size: .82rem; color: var(--ink-muted); }

.history-amount { font-weight: 700; color: var(--brand-dark); font-size: 1.1rem; }

.sub-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
}

.sub-status {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  background: var(--brand-surface);
  color: var(--brand-dark);
}

/* ═══════════ Profile ═══════════ */
.profile-grid {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  background: #f8f9fb;
  border: 1px solid var(--line);
}

.profile-row span { font-size: .88rem; color: var(--ink-soft); font-weight: 500; }

.profile-row code {
  font-family: "IBM Plex Mono", monospace;
  font-size: .85rem;
  color: var(--ink);
  font-weight: 500;
}

/* ═══════════ Bottom Navigation ═══════════ */
.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(12px + var(--safe-bottom));
  width: min(calc(100% - 24px), 460px);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px;
  border-radius: 22px;
  background: rgba(255,255,255,.88);
  border: 1px solid rgba(0,0,0,.05);
  backdrop-filter: blur(24px) saturate(1.6);
  -webkit-backdrop-filter: blur(24px) saturate(1.6);
  box-shadow: 0 4px 28px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  z-index: 20;
}

.nav-item {
  background: transparent;
  color: var(--ink-muted);
  font-size: .76rem;
  min-height: 46px;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 2px 12px rgba(13,148,136,.35);
}

/* ═══════════ Modal ═══════════ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
  z-index: 30;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: fadeIn .2s ease;
}

.modal-card {
  width: min(100%, 480px);
  max-height: 85vh;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--radius) var(--radius) var(--radius-md) var(--radius-md);
  border: 1px solid var(--line);
  padding: 28px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .3s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.modal-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .82rem;
  color: var(--ink-soft);
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 120px;
  overflow-y: auto;
}

/* ═══════════ Toast ═══════════ */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--nav-h) + 24px + var(--safe-bottom));
  background: var(--ink);
  color: #fff;
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  max-width: 90vw;
  text-align: center;
  animation: slideUp .25s ease;
}

/* ═══════════ Animations ═══════════ */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══════════ Onboarding Overlay ═══════════ */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn .25s ease;
}

.onboarding-card {
  width: min(100%, 440px);
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border-radius: var(--radius);
  padding: 36px 28px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .35s ease;
  display: flex;
  flex-direction: column;
  gap: 20px;
  text-align: center;
}

.onboarding-checkmark {
  font-size: 3.5rem;
  line-height: 1;
}

.onboarding-card h2 {
  margin: 0;
  font-size: 1.5rem;
}

/* ═══════════ Subscription Link Box ═══════════ */
.sub-link-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sub-link-box {
  background: #f8f9fb;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
}

.sub-link-text {
  font-family: "IBM Plex Mono", monospace;
  font-size: .82rem;
  color: var(--brand-dark);
  word-break: break-all;
  line-height: 1.5;
}

/* ═══════════ Traffic Bar ═══════════ */
.traffic-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.traffic-bar {
  height: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.traffic-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), #14b8a6);
  border-radius: 999px;
  transition: width .4s ease;
}

.traffic-bar-fill.traffic-bar-danger {
  background: linear-gradient(90deg, var(--danger), #f97316);
}

.traffic-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .8rem;
  color: var(--ink-soft);
}

/* ═══════════ Status Badges ═══════════ */
.sub-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: lowercase;
  flex-shrink: 0;
}

.badge-active {
  background: var(--brand-surface);
  color: var(--brand-dark);
}

.badge-inactive {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ═══════════ Device Cards ═══════════ */
.devices-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafbfc;
}

.device-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}

.device-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-name {
  font-size: .9rem;
  font-weight: 600;
  color: var(--ink);
}

.device-meta {
  font-size: .78rem;
  color: var(--ink-muted);
}

.device-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--ink-muted);
  padding: 6px 8px;
  border-radius: 8px;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}

.device-delete-btn:hover {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ═══════════ Instruction Accordion ═══════════ */
.instruction-platform {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.instruction-platform + .instruction-platform {
  margin-top: -1px;
}

.instruction-summary {
  padding: 14px 16px;
  font-weight: 600;
  font-size: .92rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fafbfc;
  transition: background .15s;
}

.instruction-summary::-webkit-details-marker { display: none; }
.instruction-summary::marker { content: ""; }

.instruction-summary::after {
  content: "▸";
  margin-left: auto;
  transition: transform .2s;
  color: var(--ink-muted);
}

details[open] > .instruction-summary::after {
  transform: rotate(90deg);
}

.instruction-summary:hover {
  background: var(--brand-surface);
}

.instruction-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border-top: 1px solid var(--line);
}

.instruction-body h4 {
  margin: 4px 0 0;
  font-size: .88rem;
  color: var(--brand-dark);
}

.instruction-steps {
  margin: 0;
  padding-left: 20px;
  font-size: .85rem;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ═══════════ Modal Action Sections ═══════════ */
.modal-action-section {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.modal-action-title {
  padding: 14px 16px;
  font-weight: 600;
  font-size: .9rem;
  cursor: pointer;
  list-style: none;
  background: #fafbfc;
  transition: background .15s;
}

.modal-action-title::-webkit-details-marker { display: none; }
.modal-action-title::marker { content: ""; }

.modal-action-title::after {
  content: " ▸";
  color: var(--ink-muted);
}

details[open] > .modal-action-title::after {
  content: " ▾";
}

.modal-action-title:hover {
  background: var(--brand-surface);
}

.modal-action-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-top: 1px solid var(--line);
}

/* ═══════════ Dashboard Grid ═══════════ */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.dash-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 12px;
  border-radius: var(--radius-sm);
  background: var(--brand-surface);
  border: 1px solid rgba(13,148,136,.1);
}

.dash-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--brand-dark);
  line-height: 1;
}

.dash-label {
  font-size: .78rem;
  color: var(--ink-soft);
  text-align: center;
}

/* ═══════════ Subscription Cards (list) ═══════════ */
.sub-card {
  padding: 18px 20px;
  border: 1.5px solid rgba(13,148,136,.25);
  border-radius: var(--radius-md);
  background: linear-gradient(165deg, #fff 0%, var(--brand-surface) 100%);
  cursor: pointer;
  transition: box-shadow .2s, transform .1s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sub-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.sub-card:active {
  transform: translateY(0);
}

.sub-card-inactive {
  border-color: var(--line);
  background: #fafbfc;
}

.sub-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sub-card-name {
  font-weight: 700;
  font-size: 1rem;
}

.sub-card-id {
  font-size: .78rem;
  color: var(--ink-muted);
  font-family: "IBM Plex Mono", monospace;
}

.sub-card-meta {
  display: flex;
  justify-content: space-between;
  font-size: .82rem;
  color: var(--ink-soft);
}

/* ═══════════ Create Sub Toggle ═══════════ */
.sub-create-details {
  border-radius: var(--radius-md);
}

.sub-create-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  font-weight: 600;
  font-size: .92rem;
  color: var(--brand-dark);
  cursor: pointer;
  list-style: none;
  border: 1.5px dashed var(--brand);
  border-radius: var(--radius-md);
  background: var(--brand-surface);
  transition: background .15s, box-shadow .15s;
}

.sub-create-toggle::-webkit-details-marker { display: none; }
.sub-create-toggle::marker { content: ""; }

.sub-create-toggle:hover {
  background: var(--brand-light);
  box-shadow: var(--shadow-sm);
}

.sub-create-details[open] > .sub-create-toggle {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-style: solid;
}

.sub-create-details > .card {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 0;
}

/* ═══════════ Modal Body Layout ═══════════ */
#modal-sub-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#modal-sub-body > .divider {
  margin: -4px 0;
}

.modal-plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-plan-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.modal-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-block-label {
  font-size: .75rem;
  font-weight: 700;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
}

.modal-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.modal-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  color: var(--ink-soft);
  padding: 8px 12px;
  background: #f8f9fb;
  border-radius: 8px;
}

.modal-meta-accent {
  font-weight: 700;
  color: var(--ink);
}

/* ═══════════ Desktop ═══════════ */
@media (min-width: 640px) {
  .app-shell {
    max-width: 540px;
    padding: 36px 24px calc(var(--nav-h) + 32px + var(--safe-bottom));
  }

  .card { padding: 32px; }
  .modal-card { padding: 32px; }
}
