/* ---------------------------------------------------------------------------
   Typography: Vercel "Geist" (bundled) with SF Pro Display / system fallback.
--------------------------------------------------------------------------- */
@font-face {
  font-family: 'Geist';
  src: url('/fonts/Geist-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/GeistMono-Variable.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --font-sans: 'Geist', -apple-system, 'SF Pro Display', BlinkMacSystemFont, 'Inter',
    'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --bg: #ffffff;
  --fg: #000000;
  --muted: #6b6b6b;
  --faint: #8f8f8f;
  --line: #ebebeb;
  --line-strong: #d4d4d4;
  --surface: #fafafa;
  --surface-2: #f4f4f4;
  --ok: #000000;
  --bad: #000000;
  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.04);
}

* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}
a {
  color: inherit;
}
button {
  font-family: inherit;
}

/* --------------------------------- layout -------------------------------- */
.app {
  min-height: 100%;
}
.app[data-view='loading'] {
  display: grid;
  place-items: center;
}

/* --------------------------------- login --------------------------------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 360px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}
.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--fg);
  display: grid;
  place-items: center;
}
.brand .logo svg {
  stroke: var(--bg);
}
.brand h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.02em;
}
.login h2 {
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.03em;
}
.login p.sub {
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 13.5px;
}

/* --------------------------------- forms --------------------------------- */
.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}
.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus {
  border-color: var(--fg);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06);
}
textarea.input {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  min-height: 40px;
}

.btn {
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--bg);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s, background 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover {
  opacity: 0.86;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn.full {
  width: 100%;
}
.btn.ghost {
  background: var(--bg);
  color: var(--fg);
  border-color: var(--line-strong);
}
.btn.ghost:hover {
  background: var(--surface-2);
  opacity: 1;
}
.btn.sm {
  height: 32px;
  padding: 0 11px;
  font-size: 12.5px;
}
.btn svg {
  width: 15px;
  height: 15px;
}

.error-msg {
  color: var(--fg);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  font-size: 12.5px;
  margin-bottom: 12px;
}

/* ------------------------------- dashboard ------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: saturate(180%) blur(12px);
}
.topbar .right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  display: inline-block;
}
.dot.live {
  background: var(--fg);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}
.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  font-weight: 600;
  margin: 32px 0 12px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
}
.stat .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.stat .value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat .value small {
  font-size: 13px;
  color: var(--faint);
  font-weight: 500;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  overflow: hidden;
}
.card .card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.card .card-head h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
}
.card .card-body {
  padding: 16px;
}

/* subscription url */
.sub-box {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.sub-box .url {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12.5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* sources list */
.src {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.src:last-child {
  border-bottom: none;
}
.src .meta {
  flex: 1;
  min-width: 0;
}
.src .meta .name {
  font-weight: 500;
  font-size: 13.5px;
}
.src .meta .url {
  color: var(--faint);
  font-size: 12px;
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.src .meta .badge {
  font-size: 11px;
  color: var(--muted);
}

/* toggle */
.toggle {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  border: none;
  cursor: pointer;
  transition: background 0.18s;
  flex: none;
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.18s;
}
.toggle.on {
  background: var(--fg);
}
.toggle.on::after {
  transform: translateX(16px);
}

.icon-btn {
  border: 1px solid var(--line-strong);
  background: var(--bg);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--fg);
  flex: none;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn svg {
  width: 15px;
  height: 15px;
}

/* keys table */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.segmented button {
  border: none;
  background: var(--bg);
  padding: 0 12px;
  height: 32px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--muted);
  border-right: 1px solid var(--line);
}
.segmented button:last-child {
  border-right: none;
}
.segmented button.active {
  background: var(--fg);
  color: var(--bg);
}
.search {
  flex: 1;
  min-width: 160px;
  height: 32px;
}

.keys {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.krow {
  display: grid;
  grid-template-columns: 18px 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.krow:last-child {
  border-bottom: none;
}
.krow .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.krow .status-dot.valid {
  background: #000;
}
.krow .status-dot.invalid {
  background: transparent;
  border: 1.5px solid var(--line-strong);
}
.krow .status-dot.unknown {
  background: var(--line-strong);
}
.krow .kname {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.krow .khost {
  color: var(--faint);
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.krow .lat {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12.5px;
}
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--faint);
  font-size: 13px;
}

.muted {
  color: var(--muted);
}
.row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.spread {
  justify-content: space-between;
}
.grow {
  flex: 1;
}

/* toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 50;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.spin {
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .krow {
    grid-template-columns: 16px 1fr auto;
  }
  .krow .khost {
    display: none;
  }
}
