:root {
  --yellow: #ffd700;
  --yellow-dim: #c9a800;
  --yellow-glow: rgba(255, 215, 0, 0.15);
  --black: #0a0a0a;
  --black-elevated: #141414;
  --black-surface: #1c1c1c;
  --black-border: rgba(255, 215, 0, 0.18);

  --bg: var(--black);
  --text: #f5f5f5;
  --text-secondary: #9a9a9a;
  --surface: var(--black-surface);
  --surface-elevated: var(--black-elevated);
  --accent: var(--yellow);
  --accent-text: var(--black);
  --border: var(--black-border);
  --danger: #ff4d4d;
  --danger-bg: rgba(255, 77, 77, 0.12);
  --warning: var(--yellow);
  --warning-bg: rgba(255, 215, 0, 0.12);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, 0.12);
  --info: var(--yellow);
  --info-bg: var(--yellow-glow);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --tab-bar-height: 64px;
  --header-height: 72px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

#app {
  min-height: 100dvh;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

/* ── App header ── */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 16px;
  background: var(--bg);
}

.app-header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.logout-btn {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s;
  white-space: nowrap;
}

.logout-btn:hover {
  color: var(--yellow);
}

.app-header__logo {
  height: 36px;
  width: auto;
  max-width: 200px;
  object-fit: contain;
  display: block;
}

.app-header__subtitle {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.app-header--login {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: static;
  flex-shrink: 0;
  width: 100%;
  padding: max(12px, env(safe-area-inset-top)) 0 0;
}

.app-header--login .app-header__logo {
  margin: 0;
}

/* ── Language switcher ── */

.lang-switcher {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.lang-switcher__btn {
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.lang-switcher__btn--active {
  background: var(--yellow);
  color: var(--black);
}

/* ── Login ── */

.login-page {
  width: 100%;
  min-height: 100dvh;
  min-height: var(--tg-viewport-stable-height, 100dvh);
  padding: 0 max(16px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left));
  overflow-x: hidden;
}

.login-page__content {
  width: min(360px, 100%);
  margin-inline: auto;
}

.login-page__spacer {
  height: 10vh;
  height: calc(var(--tg-viewport-stable-height, 100dvh) * 0.1);
}

.login-block {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 0;
}

.login-block__title {
  margin: 0;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
  color: var(--yellow);
}

.login-block__input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--black-elevated);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  box-sizing: border-box;
  -webkit-appearance: none;
  appearance: none;
}

.login-block__input:focus {
  outline: none;
  border-color: var(--yellow);
}

.login-block__input--error {
  border-color: var(--danger);
}

.login-block__error {
  margin: 0;
  text-align: center;
  font-size: 13px;
  color: var(--danger);
}

.login-block__submit {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  justify-content: center;
  margin: 0;
}

/* ── Fields ── */

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

.field-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--yellow);
}

.field-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--black-elevated);
  color: var(--text);
  resize: none;
  transition: border-color 0.15s;
}

.field-input:focus {
  outline: none;
  border-color: var(--yellow);
}

.field-input--mono {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-all;
}

.field-input--error {
  border-color: var(--danger);
}

.field-hint {
  font-size: 12px;
  color: var(--text-secondary);
}

.field-error {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

/* ── Cabinet layout ── */

.cabinet {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--tab-bar-height) + var(--safe-bottom));
}

.cabinet-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 16px 16px;
}

/* ── Tab bar ── */

.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: calc(var(--tab-bar-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.tab-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 500;
  transition: color 0.15s;
}

.tab-bar__item--active {
  color: var(--yellow);
}

.tab-bar__icon {
  font-size: 18px;
  line-height: 1;
}

.tab-bar__label {
  font-size: 11px;
  font-weight: 500;
}

/* ── Section ── */

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

.section--overview {
  flex: 1;
}

.section--share {
  flex: 1;
}

.share-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.share-tabs__btn {
  flex: 1;
  min-width: 0;
  padding: 10px 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--black-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.25;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.share-tabs__btn--active {
  border-color: var(--yellow);
  background: var(--yellow-glow);
  color: var(--yellow);
}

.share-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.section-desc {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--text-secondary);
}

.empty-state {
  margin: 0;
  text-align: center;
  color: var(--text-secondary);
  padding: 8px 0;
}

/* ── Card ── */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card--highlight {
  border-color: var(--yellow);
  background: var(--yellow-glow);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.card-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--yellow);
}

.card-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Account card ── */

.account-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.account-card__main {
  min-width: 0;
}

.account-card__expiry {
  flex-shrink: 0;
  text-align: right;
}

.account-card__expiry-badge {
  margin-bottom: 4px;
}

.account-card__expiry-date {
  font-size: 16px;
}

.account-card__identity {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.account-card__identity--plan-only {
  justify-content: flex-end;
}

.account-card__identity-value {
  min-width: 0;
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-card__plan {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--yellow);
}

/* ── Limits ── */

.limits-card .card-header {
  justify-content: center;
}

.limits-card .card-header > div {
  text-align: center;
}

.limits-card .limits-section {
  text-align: center;
}

.limits-card .traffic-stats {
  justify-content: center;
}

.limits-card .traffic-stat {
  align-items: center;
}

.limits-card .expiry-hint {
  text-align: center;
}

.limits-section + .limits-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.limits-section__label {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Overview actions ── */

.overview-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
  padding-top: 4px;
}

.share-qr-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 8px 0 16px;
}

.share-qr-view__title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--yellow);
}

.share-qr-view__hint {
  margin: 0;
  max-width: 280px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.share-qr-view .qr-wrap {
  margin-bottom: 0;
}

/* ── Traffic ── */

.traffic-stats {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.traffic-stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.traffic-stat__value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--yellow);
}

.traffic-stat__label {
  font-size: 12px;
  color: var(--text-secondary);
}

.traffic-stat__divider {
  width: 1px;
  height: 36px;
  background: var(--border);
}

.expiry-date {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.expiry-hint {
  margin: 0;
  font-size: 14px;
  color: var(--text-secondary);
}

.new-key {
  display: block;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--black-elevated);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  word-break: break-all;
  line-height: 1.6;
  border: 1px solid var(--yellow);
  color: var(--yellow);
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Progress ── */

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

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-track {
  height: 8px;
  background: var(--black-elevated);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: var(--yellow);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.progress-fill--warning {
  background: var(--yellow-dim);
}

.progress-fill--danger {
  background: var(--danger);
}

/* ── Badge ── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

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

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

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

.badge--info {
  background: var(--info-bg);
  color: var(--yellow);
}

.badge--neutral {
  background: var(--black-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

/* ── Button ── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--md {
  padding: 10px 16px;
  font-size: 15px;
}

.btn--sm {
  padding: 8px 12px;
  font-size: 14px;
}

.btn--primary {
  background: var(--yellow);
  color: var(--black);
}

.btn--secondary {
  background: transparent;
  color: var(--yellow);
  border: 1.5px solid var(--yellow);
}

.btn--danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1.5px solid rgba(255, 77, 77, 0.3);
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn--block {
  width: 100%;
}

.btn-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Lists ── */

.device-list,
.subscription-list,
.transaction-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.collapse-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.collapse-header:hover {
  border-color: var(--accent);
  background: var(--surface-elevated);
}

.collapse-header__title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.collapse-header__count {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
}

.collapse-header__chevron {
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--accent);
  transform: rotate(0deg);
  transition: transform 0.15s;
}

.collapse-header__chevron--open {
  transform: rotate(90deg);
}

.collapse-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.collapse-empty {
  margin: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
}

.device-group .card-header {
  margin-bottom: 0;
}

/* ── Device item ── */

.device-card {
  position: relative;
  padding-right: 40px;
}

.device-card__unlink {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #ff2d2d;
  font-size: 26px;
  font-weight: 400;
  line-height: 1;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.device-card__unlink:hover:not(:disabled) {
  color: #ff5555;
  background: rgba(255, 45, 45, 0.12);
}

.device-card__unlink:disabled {
  cursor: wait;
  opacity: 0.7;
}

.device-card__unlink-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 45, 45, 0.25);
  border-top-color: #ff2d2d;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.device-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.device-item__icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.device-item__info {
  flex: 1;
  min-width: 0;
}

.device-item__header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.device-item__name {
  font-weight: 600;
  font-size: 15px;
}

.device-item__meta {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.devices-bulk-action {
  width: 100%;
}

/* ── Detail list ── */

.detail-list {
  margin: 0 0 12px;
}

.detail-list__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.detail-list__row:last-child {
  border-bottom: none;
}

.detail-list__row dt {
  color: var(--text-secondary);
}

.detail-list__row dd {
  margin: 0;
  font-weight: 500;
}

/* ── Subscription actions ── */

.subscription-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.plan-picker {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plan-picker__title {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  color: var(--yellow);
}

.plan-option {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--black-elevated);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s;
}

.plan-option:hover:not(:disabled) {
  border-color: var(--yellow);
}

.plan-option--current {
  border-color: var(--yellow);
  background: var(--yellow-glow);
  cursor: default;
}

.plan-option:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.plan-option__name {
  font-weight: 600;
  font-size: 14px;
}

.plan-option__price {
  font-size: 14px;
  font-weight: 500;
  color: var(--yellow);
}

.plan-option__traffic {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Transaction item ── */

.transaction-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.transaction-item__main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.transaction-item__desc {
  font-weight: 500;
  font-size: 15px;
}

.transaction-item__date {
  font-size: 13px;
  color: var(--text-secondary);
}

.transaction-item__side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.transaction-item__amount {
  font-weight: 600;
  font-size: 15px;
  color: var(--yellow);
}

/* ── Spinner ── */

.spinner-wrap,
.app-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 0;
}

.app-loading {
  min-height: 100svh;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Modal ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
}

.modal {
  width: 100%;
  max-width: 360px;
  padding: 20px;
  background: var(--black-surface);
  border: 1px solid var(--yellow);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.modal__title {
  margin: 0 0 12px;
  font-size: 18px;
  font-weight: 600;
  color: var(--yellow);
}

.modal__message {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal__actions--center {
  justify-content: center;
}

.modal--qr {
  text-align: center;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  padding: 20px;
  margin-bottom: 20px;
  background: var(--black);
  border: 1.5px solid var(--yellow);
  border-radius: var(--radius-sm);
}

.share-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.share-picker__option {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--black-elevated);
  color: var(--yellow);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.share-picker__option:hover {
  border-color: var(--yellow);
  background: var(--yellow-glow);
}

.share-picker__name {
  font-weight: 600;
  font-size: 15px;
  text-align: center;
}
