:root {
  color-scheme: dark;
  --bg: #070709;
  --bg-card: #121216;
  --bg-card-hover: #17171c;
  --bg-elevated: #1c1c22;
  --border: rgba(255, 255, 255, 0.07);
  --border-light: rgba(255, 255, 255, 0.11);
  --text: #ffffff;
  --text-secondary: #d4d4d8;
  --muted: #9ca3af;
  --accent: #7c6cff;
  --accent-soft: rgba(124, 108, 255, 0.14);
  --accent-glow: rgba(124, 108, 255, 0.35);
  --ok: #34d399;
  --err: #f87171;
  --radius: 20px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --font: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --header-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body.mobile-app {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior-y: none;
}

body.mobile-app::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(124, 108, 255, 0.22), transparent 42%),
    radial-gradient(circle at 100% 0%, rgba(99, 102, 241, 0.1), transparent 30%);
  pointer-events: none;
  z-index: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(24px + var(--safe-bottom));
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  margin: 0 -16px;
  padding-top: var(--safe-top);
  background: rgba(7, 7, 9, 0.92);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--header-h);
  padding: 8px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #9b8cff, #6366f1);
  box-shadow: 0 0 16px var(--accent-glow);
}

.brand-dot.lg {
  width: 14px;
  height: 14px;
}

.brand-text {
  min-width: 0;
}

.brand-text strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.brand-text span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.header-btn {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border-light);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.03);
}

/* ── Main ── */
.app-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 14px;
}

/* ── Period filter card ── */
.filter-card .filter-head {
  padding-bottom: 10px;
}

.filter-card .period-bar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 0 14px 14px;
  margin: 0;
}

.filter-card .period-tab {
  background: rgba(255, 255, 255, 0.03);
}

.period-tab {
  min-height: 42px;
  padding: 6px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  hyphens: auto;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.period-tab.active {
  color: var(--text);
  border-color: rgba(124, 108, 255, 0.5);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(124, 108, 255, 0.15);
}

/* ── Main content spacing (continued) ── */
.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 500;
  margin-top: 4px;
}

/* ── Hero card ── */
.hero-card {
  padding: 24px 20px;
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(124, 108, 255, 0.12) 0%, var(--bg-card) 45%);
  border: 1px solid var(--border-light);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.hero-card.compact {
  padding-bottom: 20px;
}

.hero-label {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.hero-value {
  margin: 0;
  font-size: clamp(2.75rem, 12vw, 3.5rem);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.05em;
  color: var(--text);
}

.hero-desc {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 22px;
}

.stat-chip {
  padding: 14px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  text-align: center;
}

.stat-chip span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.stat-chip strong {
  display: block;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ── Section cards ── */
.section-card {
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.badge {
  flex-shrink: 0;
  min-width: 28px;
  height: 28px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #c4b5fd;
  font-size: 0.82rem;
  font-weight: 600;
}

.empty-state {
  margin: 0;
  padding: 28px 18px 32px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ── List items (banking style) ── */
.item-list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 16px 18px;
  border-top: 1px solid var(--border);
  min-height: 72px;
}

.list-item:first-child {
  border-top: 0;
}

.list-item.simple {
  align-items: center;
  min-height: 56px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.list-item-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 2px 0;
}

.list-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.35;
  word-break: break-word;
}

.list-item.simple .list-title {
  flex: 1;
  font-size: 1rem;
  color: var(--text);
}

.list-meta {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.3;
}

.list-side {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
}

.list-count {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  white-space: nowrap;
}

.list-item.simple .list-count,
.page-item .list-count {
  align-self: center;
  font-size: 1.15rem;
}

.page-item {
  align-items: center;
}

.btn-text-danger {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid rgba(248, 113, 113, 0.25);
  border-radius: 999px;
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.inline-reset {
  margin: 0;
}

/* ── Transaction feed ── */
.tx-list {
  display: flex;
  flex-direction: column;
}

.tx-item {
  padding: 18px;
  border-top: 1px solid var(--border);
}

.tx-item:first-child {
  border-top: 0;
}

.tx-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.tx-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #ddd6fe;
  font-size: 0.82rem;
  font-weight: 600;
}

.tx-time {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

.tx-phone {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.tx-link {
  display: block;
  color: #a5b4fc;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-all;
  margin-bottom: 8px;
}

.tx-site {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

/* ── Danger zone ── */
.danger-card {
  border-color: rgba(248, 113, 113, 0.2);
}

.danger-inner {
  padding: 0 18px 20px;
}

.danger-inner h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
  font-weight: 600;
}

.text-muted {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.danger-note {
  margin: 0 0 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

.danger-note strong {
  color: #fca5a5;
  font-weight: 700;
}

.reset-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.check-row input {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.btn-danger {
  min-height: 52px;
  padding: 0 20px;
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: var(--radius-sm);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
}

/* ── Toast / alerts ── */
.toast {
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  line-height: 1.45;
  font-weight: 500;
}

.toast-err {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #fecaca;
}

.toast-ok {
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: #a7f3d0;
}

/* ── Login ── */
.login-screen {
  min-height: calc(100dvh - var(--header-h) - var(--safe-top) - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
}

.login-box {
  width: 100%;
  padding: 28px 22px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.login-brand h1 {
  margin: 14px 0 6px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 22px;
}

.input-field span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 500;
}

.input-field input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.input-field input:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.55);
  box-shadow: 0 0 0 4px rgba(124, 108, 255, 0.12);
}

.btn-primary {
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #8b7cff, #6366f1);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(99, 102, 241, 0.3);
}

.btn-outline {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.95rem;
}

.page-item-full {
  align-items: start;
}

.page-item-full .list-count {
  margin-top: 4px;
}

.list-url {
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.45;
  word-break: break-all;
  color: #a5b4fc;
}

.page-item-full .list-meta {
  margin-top: 6px;
}

.settings-body {
  padding: 0 18px 20px;
}

.settings-body .form-stack {
  margin-top: 0;
}

.form-inline {
  margin-top: 10px;
}

.code-box {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.82rem;
  line-height: 1.5;
  color: #c4b5fd;
  white-space: pre-wrap;
  word-break: break-all;
}

.badge-ok {
  background: rgba(52, 211, 153, 0.14);
  color: #6ee7b7;
}

.badge-warn {
  background: rgba(251, 191, 36, 0.14);
  color: #fcd34d;
}

.settings-item {
  align-items: center;
}

.settings-item .list-item-link {
  pointer-events: none;
}

/* ── Desktop ── */
@media (min-width: 768px) {
  .app-shell {
    max-width: 720px;
    padding-left: calc(24px + var(--safe-left));
    padding-right: calc(24px + var(--safe-right));
  }

  .app-main {
    gap: 18px;
  }

  .hero-card {
    padding: 28px 26px;
  }

  .stat-chip strong {
    font-size: 1.25rem;
  }

  .list-item {
    padding: 18px 22px;
  }

  .section-head {
    padding: 20px 22px 16px;
  }
}

@media (max-width: 380px) {
  .stat-row {
    gap: 8px;
  }

  .stat-chip {
    padding: 12px 6px;
  }

  .stat-chip strong {
    font-size: 1rem;
  }

  .list-count {
    font-size: 1.05rem;
  }

  .filter-card .period-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .period-tab {
    min-height: 40px;
    font-size: 0.72rem;
    padding: 5px 3px;
  }
}

@media (min-width: 768px) {
  .filter-card .period-bar {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .period-tab {
    min-height: 44px;
    font-size: 0.84rem;
    padding: 8px 6px;
    white-space: nowrap;
  }
}
