:root {
  --bg-abyss: #090e18;
  --bg-surface: #0f1726;
  --bg-elevated: #152035;
  --bg-input: #0b1220;
  --border-subtle: #21304a;
  --border-focus: #3b82f6;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Cascadia Code", "Menlo", "Consolas", monospace;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background-color: var(--bg-abyss);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #60a5fa;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

/* --- Portal Layout (Friend View) --- */
.portal-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px 48px;
}

.portal-container {
  width: 100%;
  max-width: 460px;
}

.brand-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.brand-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #60a5fa;
  flex-shrink: 0;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 24px;
}

.panel-subtitle {
  margin: 0 0 18px;
  color: var(--text-secondary);
  font-size: 14px;
}

/* --- Forms & Controls --- */
.field {
  margin-bottom: 16px;
}

.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: #cbd5e1;
}

.field-hint {
  margin-top: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.input {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input.mono {
  font-family: var(--font-mono);
  font-size: 14px;
}

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

.input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
  padding: 6px 12px;
  font-size: 13px;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: #33486b;
  background: rgba(255, 255, 255, 0.03);
}

.btn-full {
  width: 100%;
}

.search-row {
  display: flex;
  gap: 10px;
}

.search-row .input {
  flex: 1;
}

.search-row .btn {
  flex-shrink: 0;
  padding: 10px 18px;
}

/* --- Alerts & Notices --- */
.notice {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: 9px;
  font-size: 13.5px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-secondary);
}

.notice-error {
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.08);
  color: #fca5a5;
}

.notice-success {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.08);
  color: #6ee7b7;
}

/* --- Bitwarden-Faithful TOTP Authenticator Card --- */
.results-stack {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.totp-card {
  background: #0d1422;
  border: 1px solid #24334d;
  border-radius: 12px;
  overflow: hidden;
}

.totp-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px 10px;
  border-bottom: 1px solid #19253a;
  background: rgba(255, 255, 255, 0.015);
}

.totp-service {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.totp-account {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.totp-body {
  padding: 15px 18px 17px;
}

.totp-label {
  font-size: 14.5px;
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 10px;
}

.totp-main-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.totp-code {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 26px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: #f8fafc;
  cursor: pointer;
  user-select: all;
  transition: color 0.18s ease, opacity 0.18s ease;
}

.totp-code.refreshing {
  opacity: 0.45;
}

.totp-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.countdown-wrap {
  position: relative;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.countdown-svg {
  width: 30px;
  height: 30px;
  transform: rotate(-90deg);
}

.countdown-track {
  fill: none;
  stroke: #24334d;
  stroke-width: 2.5;
}

.countdown-progress {
  fill: none;
  stroke: #e2e8f0;
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.35s linear, stroke 0.25s ease;
}

.countdown-wrap.expiring .countdown-progress {
  stroke: var(--danger);
}

.countdown-num {
  position: absolute;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 600;
  color: #e2e8f0;
}

.countdown-wrap.expiring .countdown-num {
  color: #fca5a5;
}

.copy-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #cbd5e1;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.copy-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.copy-btn.copied {
  color: var(--success);
}

.copy-toast {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

/* --- Admin Console Layout --- */
.admin-shell {
  max-width: 820px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

.admin-grid {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.section-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.status-badge.ok {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
  color: #6ee7b7;
}

.status-badge.warn {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.1);
  color: #fcd34d;
}

.form-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 16px;
  font-size: 13.5px;
  color: #cbd5e1;
  cursor: pointer;
}

.seg-tabs {
  display: inline-flex;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 9px;
  padding: 3px;
  margin-bottom: 16px;
}

.seg-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.seg-tab.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.items-table-wrap {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-input);
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.items-table th,
.items-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid #182338;
}

.items-table th {
  position: sticky;
  top: 0;
  background: #10192b;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 12.5px;
}

.items-table tr:last-child td {
  border-bottom: none;
}

/* Switch toggle */
.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 21px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #293853;
  border-radius: 21px;
  transition: 0.2s;
}

.slider::before {
  position: absolute;
  content: "";
  height: 15px;
  width: 15px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .slider {
  background-color: var(--accent);
}

.switch input:checked + .slider::before {
  transform: translateX(17px);
}

@media (max-width: 600px) {
  .form-two-col {
    grid-template-columns: 1fr;
  }
  .search-row {
    flex-direction: column;
  }
  .totp-code {
    font-size: 23px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
  }
}
