@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #14171f;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --input-bg: #ffffff;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;
  --success: #16a34a;
  --success-bg: #f0fdf4;
  --success-border: #bbf7d0;
  --shadow: 0 20px 45px -15px rgba(20, 23, 31, 0.15);
  --brand-grad: linear-gradient(155deg, #4f46e5 0%, #7c3aed 55%, #a855f7 100%);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0c10;
    --card: #15171e;
    --text: #f2f3f5;
    --text-muted: #9aa0ac;
    --border: #2c303b;
    --input-bg: #1c1f29;
    --primary: #818cf8;
    --primary-dark: #a5b4fc;
    --primary-light: #1e1b3a;
    --danger: #f87171;
    --danger-bg: #2a1618;
    --danger-border: #5c2327;
    --success: #4ade80;
    --success-bg: #142a1c;
    --success-border: #234f30;
    --shadow: 0 20px 45px -15px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

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

/* ---------- Auth screens (login / 2FA / 2FA setup) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(129, 140, 248, 0.35), transparent 45%),
    radial-gradient(circle at 85% 15%, rgba(217, 70, 239, 0.28), transparent 45%),
    radial-gradient(circle at 50% 100%, rgba(79, 70, 229, 0.3), transparent 55%),
    var(--auth-bg-base);
  --auth-bg-base: #eef0f6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-shell { --auth-bg-base: #0a0b0f; }
}
:root[data-theme="dark"] .auth-shell { --auth-bg-base: #0a0b0f; }

.auth-shell::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(120, 120, 150, 0.18) 1px, transparent 1px);
  background-size: 26px 26px;
  mask-image: radial-gradient(circle at 50% 40%, black, transparent 75%);
  pointer-events: none;
}

.auth-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  pointer-events: none;
  animation: float 14s ease-in-out infinite;
}
.auth-orb.o1 { width: 340px; height: 340px; top: -80px; left: -80px; background: radial-gradient(circle, #818cf8, transparent 70%); }
.auth-orb.o2 { width: 380px; height: 380px; bottom: -120px; right: -100px; background: radial-gradient(circle, #d946ef, transparent 70%); animation-delay: -6s; }
.auth-orb.o3 { width: 260px; height: 260px; bottom: 10%; left: 8%; background: radial-gradient(circle, #4f46e5, transparent 70%); animation-delay: -10s; }

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(20px, -25px) scale(1.05); }
}

@media (prefers-reduced-motion: reduce) {
  .auth-orb { animation: none; }
}

.auth-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 30px 60px -20px rgba(20, 15, 60, 0.35), 0 0 0 1px rgba(255,255,255,0.03);
  animation: rise 0.5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--brand-grad);
  box-shadow: 0 10px 24px -8px rgba(79, 70, 229, 0.55);
}

.auth-form { text-align: center; }

.auth-form h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}

.auth-form .subtitle {
  color: var(--text-muted);
  font-size: 0.92rem;
  margin: 0 0 28px;
}

.auth-form form { text-align: left; }

.auth-foot {
  margin-top: 24px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.qr-box {
  display: flex;
  justify-content: center;
  margin: 4px 0 20px;
  padding: 16px;
  background: #ffffff;
  border-radius: 14px;
  border: 1px solid var(--border);
}
.qr-box svg { width: 190px; height: 190px; }

/* ---------- Form elements ---------- */

.field { margin-bottom: 18px; }

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 7px;
  color: var(--text);
}

input[type=text],
input[type=email],
input[type=password] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.97rem;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-light);
}

input.otp-input {
  letter-spacing: 0.5em;
  font-size: 1.4rem;
  font-weight: 700;
  text-align: center;
  padding-left: 8px;
}

button[type=submit], .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.97rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
button[type=submit]:hover, .btn:hover { background: var(--primary-dark); }
button[type=submit]:active, .btn:active { transform: scale(0.99); }

.btn.secondary {
  background: transparent;
  color: var(--text);
  border: 1.5px solid var(--border);
}
.btn.secondary:hover { background: var(--primary-light); border-color: var(--primary); }

.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #b91c1c; }

.btn.block-auto { width: auto; }

/* ---------- Alerts ---------- */

.error, .success {
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 18px;
  font-size: 0.88rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}
.error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }

.muted { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Dashboard / admin layout (used by other pages) ---------- */

.wrap { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.wrap.wide { max-width: 960px; margin: 6vh auto; }

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

h1 { font-size: 1.4rem; margin: 0 0 20px; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; margin: 28px 0 12px; letter-spacing: -0.01em; }

table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); font-size: 0.88rem; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

nav.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
nav.top a { color: var(--text-muted); text-decoration: none; margin-left: 18px; font-size: 0.88rem; font-weight: 500; }
nav.top a:hover { color: var(--primary); }
nav.top strong { font-weight: 800; letter-spacing: -0.01em; }

.secret-box {
  background: var(--primary-light);
  border: 1px dashed var(--primary);
  padding: 12px 14px;
  border-radius: 10px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 0.9rem;
  word-break: break-all;
  margin-bottom: 16px;
}

/* ---------- Admin pro layout ---------- */

.admin-shell {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.admin-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 0.98rem;
  padding: 0 8px;
  margin-bottom: 28px;
}
.admin-logo .mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--brand-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.admin-nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}
.admin-nav a svg { flex-shrink: 0; opacity: 0.85; }
.admin-nav a:hover { background: var(--primary-light); color: var(--primary); }
.admin-nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.admin-nav-sublist {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 6px 34px;
  padding-left: 10px;
  border-left: 1.5px solid var(--border);
}
.admin-nav-sublist a {
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
}
.admin-nav-sublist a:hover { background: var(--primary-light); color: var(--primary); }

.admin-sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.admin-sidebar-foot a {
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}
.admin-sidebar-foot a:hover { background: var(--primary-light); color: var(--primary); }

.admin-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.admin-topbar h1 { margin: 0; font-size: 1.2rem; }

.admin-user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.86rem;
  color: var(--text-muted);
}
.admin-user-chip .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-grad);
  color: #fff;
  font-weight: 700;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.admin-content {
  padding: 28px 32px 48px;
  max-width: 1080px;
  width: 100%;
}

@media (max-width: 860px) {
  .admin-shell { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 12px 16px; gap: 12px; }
  .admin-logo { margin-bottom: 0; }
  .admin-nav { flex-direction: row; flex: 1; overflow-x: auto; }
  .admin-sidebar-foot { flex-direction: row; border-top: none; padding-top: 0; }
  .admin-content { padding: 20px; }
  .admin-topbar { padding: 16px 20px; }
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
}
.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.pill.green { background: var(--success-bg); color: var(--success); }
.pill.red { background: var(--danger-bg); color: var(--danger); }
.pill.gray { background: var(--border); color: var(--text-muted); }
.pill.purple { background: var(--primary-light); color: var(--primary); }
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}
.table-card .table-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.table-card .table-card-head h2 { margin: 0; }
.table-card table { margin-top: 0; }
.table-card th, .table-card td { padding: 12px 22px; }
.table-card tr:last-child td { border-bottom: none; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.small { width: auto; padding: 6px 12px; font-size: 0.8rem; }

.form-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px 28px;
  margin-bottom: 24px;
}
.form-card h2 { margin-top: 0; }
.form-row { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 200px; margin-bottom: 0; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.checkbox-row input { width: auto; margin: 0; }
.checkbox-row label { margin: 0; font-weight: 500; }

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- User dashboard (pro layout, no sidebar) ---------- */

.dash-shell {
  min-height: 100vh;
  background: var(--bg);
}

.dash-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}

.dash-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-size: 1rem;
}
.dash-logo .mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--brand-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dash-topbar-right {
  display: flex;
  align-items: center;
  gap: 18px;
}
.dash-topbar-right a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}
.dash-topbar-right a:hover { color: var(--primary); }

.nav-dropdown {
  position: relative;
}
.nav-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 5px;
}
.nav-dropdown-trigger::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
}
.nav-dropdown-panel {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 10px;
  min-width: 200px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 32px -12px rgba(20, 15, 60, 0.25);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
  z-index: 20;
}
.nav-dropdown:hover .nav-dropdown-panel,
.nav-dropdown:focus-within .nav-dropdown-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.nav-dropdown-heading {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 6px 10px 8px;
}
.nav-dropdown-panel a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--text) !important;
  text-decoration: none;
}
.nav-dropdown-panel a:hover {
  background: var(--primary-light);
  color: var(--primary) !important;
}

.dash-content {
  max-width: 880px;
  margin: 0 auto;
  padding: 36px 24px 60px;
}

.dash-hero {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}
.dash-hero .avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--brand-grad);
  color: #fff;
  font-weight: 700;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dash-hero h1 { margin: 0; font-size: 1.4rem; }
.dash-hero p { margin: 3px 0 0; color: var(--text-muted); font-size: 0.9rem; }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 20px;
  border-radius: 14px;
  margin-bottom: 24px;
}
.banner.warn { background: var(--danger-bg); border: 1px solid var(--danger-border); }
.banner.ok { background: var(--success-bg); border: 1px solid var(--success-border); }
.banner-text { font-size: 0.9rem; }
.banner.warn .banner-text { color: var(--danger); }
.banner.ok .banner-text { color: var(--success); }
.banner-text strong { display: block; margin-bottom: 2px; font-size: 0.95rem; }

.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.site-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
}
.site-card .site-name {
  font-weight: 700;
  margin-bottom: 4px;
}
.site-card .site-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.site-card .site-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

/* ---------- Modal (native <dialog>) ---------- */

dialog.modal {
  border: none;
  border-radius: 18px;
  padding: 32px;
  width: 100%;
  max-width: 380px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 30px 60px -20px rgba(20, 15, 60, 0.35);
}
dialog.modal::backdrop {
  background: rgba(10, 11, 15, 0.55);
  backdrop-filter: blur(2px);
}
dialog.modal[open] {
  animation: modal-rise 0.25s ease both;
}
@keyframes modal-rise {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--brand-grad);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
dialog.modal h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
  letter-spacing: -0.01em;
}
dialog.modal .subtitle {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0 0 20px;
}
dialog.modal form { margin: 0; }
dialog.modal button[type=submit] { margin-top: 4px; }
