:root {
  color-scheme: dark;
  --bg: #0b1120;
  --panel: #111827;
  --panel-2: #0f172a;
  --line: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --indigo: #6366f1;
  --indigo-strong: #4f46e5;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--indigo); }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 104px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 12px;
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  font-size: 19px;
}
.brand h1 { margin: 0; font-size: 17px; line-height: 1.15; letter-spacing: -0.02em; }
.brand p {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 190px;
}

.role-pill {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 6px 9px;
  border-radius: 999px;
  color: #c7d2fe;
  background: rgba(79, 70, 229, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.35);
}

.view { padding-top: 16px; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.avatar {
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 21px;
  font-weight: 800;
}
.profile-info { flex: 1; min-width: 0; }
.profile-info h2 {
  margin: 0 0 3px;
  font-size: 18px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.profile-info p { margin: 0; font-size: 12px; color: var(--muted); }

.badge {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  color: #a5b4fc;
  background: rgba(79, 70, 229, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.badge.free { color: var(--muted); background: rgba(148, 163, 184, 0.1); border-color: var(--line); }
.badge.active { color: #6ee7b7; background: rgba(16, 185, 129, 0.12); border-color: rgba(16, 185, 129, 0.3); }

.usage-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.label { margin: 0; font-size: 12px; color: var(--muted); }
.big { margin: 3px 0 0; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }
.big span { font-size: 15px; font-weight: 600; color: var(--muted); }

.ring {
  width: 60px;
  height: 60px;
  flex: 0 0 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: conic-gradient(var(--indigo) 0deg, var(--line) 0deg);
}
.ring::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--panel);
}
.ring b { position: relative; z-index: 1; font-size: 12px; color: var(--muted); }

.bar {
  height: 6px;
  margin: 14px 0 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--indigo), #8b5cf6);
  transition: width 0.4s ease;
}
.hint { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.45; }

.btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 700;
  margin-top: 12px;
}
.btn-primary { background: var(--indigo-strong); color: #fff; }
.btn-primary:disabled { opacity: 0.5; }
.btn-ghost { background: transparent; color: #c7d2fe; border: 1px solid var(--line); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 18px;
}
.stat { padding: 13px 8px; text-align: center; }
.stat b { display: block; font-size: 19px; line-height: 1.2; }
.stat span { font-size: 10px; color: var(--muted); }
.stat b.small-value { font-size: 13px; line-height: 1.35; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 2px 9px;
}
.section-head h3 { margin: 0; font-size: 15px; letter-spacing: -0.01em; }
.section-head span { font-size: 11px; color: var(--muted); }

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

.report-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 12px 14px;
}
.report-row:active { transform: scale(0.995); }
.report-main { flex: 1; min-width: 0; }
.report-title {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.report-sub { margin-top: 3px; font-size: 11px; color: var(--muted); }
.score {
  flex: 0 0 auto;
  min-width: 50px;
  text-align: center;
  padding: 7px 8px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 800;
}
.score.good { color: var(--green); background: rgba(52, 211, 153, 0.1); }
.score.mid { color: var(--amber); background: rgba(251, 191, 36, 0.1); }
.score.low { color: var(--red); background: rgba(248, 113, 113, 0.1); }

.empty {
  border: 1px dashed var(--line);
  border-radius: 15px;
  padding: 24px 16px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.plan-hero {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.35), transparent 55%),
    linear-gradient(160deg, #151d33, #0f172a);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 12px;
}
.plan-hero h2 { margin: 4px 0 2px; font-size: 29px; letter-spacing: -0.03em; }
.plan-hero h2 span { font-size: 14px; color: var(--muted); font-weight: 600; }
.plan-hero p { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.plan-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 5px 9px;
  border-radius: 999px;
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.12);
}
.plan-status.off { color: var(--muted); background: rgba(148, 163, 184, 0.1); }

.features { margin: 0; padding: 0; list-style: none; }
.features li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  padding: 9px 0;
  font-size: 12px;
  border-bottom: 1px solid var(--line);
  line-height: 1.4;
}
.features li:last-child { border-bottom: 0; }
.features .check {
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #a5b4fc;
  background: rgba(79, 70, 229, 0.18);
}

.tabs {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  z-index: 30;
  display: flex;
  gap: 4px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: rgba(11, 17, 32, 0.97);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 7px 4px 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab .icon { font-size: 18px; line-height: 1; }
.tab.active { color: #c7d2fe; background: rgba(79, 70, 229, 0.14); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
  backdrop-filter: blur(4px);
}
.modal-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  padding: 20px 18px calc(24px + env(safe-area-inset-bottom));
  animation: slideUp 0.22s ease;
}
@keyframes slideUp { from { transform: translateY(26px); opacity: 0; } }

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.modal-close { position: absolute; top: 10px; right: 10px; }

.report-head { text-align: center; padding: 6px 24px 14px; }
.score-big {
  width: 86px;
  height: 86px;
  margin: 0 auto 9px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 27px;
  font-weight: 800;
}
.score-big.good { color: var(--green); background: rgba(52, 211, 153, 0.1); }
.score-big.mid { color: var(--amber); background: rgba(251, 191, 36, 0.1); }
.score-big.low { color: var(--red); background: rgba(248, 113, 113, 0.1); }
.report-head h3 { margin: 0 0 3px; font-size: 17px; }
.report-head p { margin: 0; font-size: 11px; color: var(--muted); }
.report-summary { margin: 0 0 6px; font-size: 12px; color: var(--muted); text-align: center; line-height: 1.5; }

.block-title { margin: 18px 0 9px; font-size: 13px; }

.criteria { display: flex; flex-direction: column; gap: 10px; }
.criterion-top { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.criterion-top span:last-child { color: var(--muted); }
.criterion-bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; }
.criterion-bar i { display: block; height: 100%; border-radius: 999px; background: var(--indigo); }
.criterion p { margin: 4px 0 0; font-size: 11px; color: var(--muted); line-height: 1.45; }

.error-item {
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 11px;
  margin-bottom: 7px;
  background: var(--panel-2);
}
.error-item b { font-size: 12px; }
.error-item .quote {
  margin: 6px 0;
  padding-left: 9px;
  border-left: 2px solid var(--indigo);
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  line-height: 1.45;
}
.error-item .fix { font-size: 11px; line-height: 1.45; }

.action-item {
  display: flex;
  gap: 9px;
  padding: 8px 0;
  font-size: 12px;
  line-height: 1.45;
  border-bottom: 1px solid var(--line);
}
.action-item:last-child { border-bottom: 0; }
.action-num {
  flex: 0 0 21px;
  width: 21px;
  height: 21px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: #a5b4fc;
  background: rgba(79, 70, 229, 0.18);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 80;
  max-width: 90vw;
  padding: 10px 15px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #0f172a;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.loading {
  min-height: 45vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}
.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--indigo);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.fatal {
  margin-top: 24px;
  padding: 20px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.fatal h2 { margin: 0 0 8px; font-size: 16px; }
.fatal p { margin: 0 0 12px; font-size: 12px; color: var(--muted); line-height: 1.5; }

.hidden { display: none !important; }

@media (min-width: 640px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 22px; max-width: 560px; }
}
