/* KyClick VPN admin — Tailscale/Linear-style dark dashboard.
   Inter as the primary, JetBrains Mono only for tabular data. */

@import url('https://rsms.me/inter/inter.css');

:root {
  --bg:          #0a0e14;
  --surface:     #0f1620;
  --surface-2:   #141d2a;
  --surface-3:   #1a2434;
  --border:      #1f2937;
  --border-2:    #2a3441;

  --text:        #e8edf3;
  --text-muted:  #94a3b8;
  --text-dim:    #64748b;

  --primary:     #3b82f6;
  --primary-h:   #60a5fa;
  --primary-bg:  rgba(59,130,246,0.08);
  --primary-bd:  rgba(59,130,246,0.35);

  --success:     #10b981;
  --success-bg:  rgba(16,185,129,0.10);
  --success-bd:  rgba(16,185,129,0.35);

  --danger:      #ef4444;
  --danger-bg:   rgba(239,68,68,0.10);
  --danger-bd:   rgba(239,68,68,0.35);

  --warning:     #f59e0b;
  --warning-bg:  rgba(245,158,11,0.10);
  --warning-bd:  rgba(245,158,11,0.35);

  --shadow-sm:   0 1px 2px rgba(0,0,0,0.5);
  --shadow:      0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg:   0 12px 40px rgba(0,0,0,0.5);

  --radius:      6px;
  --radius-lg:   10px;
}

* , *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

@supports (font-variation-settings: normal) {
  body { font-family: 'Inter var', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; }
}

.mono { font-family: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace; font-feature-settings: "tnum"; }

a { color: var(--primary-h); text-decoration: none; }
a:hover { color: var(--primary); }

::selection { background: var(--primary-bg); color: var(--text); }

/* ===== top nav ===== */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,14,20,0.85);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
}
.brand .brand-mark {
  width: 24px; height: 24px;
  background: linear-gradient(135deg, var(--primary), #2563eb);
  border-radius: 6px;
  display: grid; place-items: center;
  color: #fff;
  box-shadow: 0 0 0 1px var(--primary-bd), 0 4px 12px rgba(59,130,246,0.25);
}
.brand .brand-mark svg { width: 14px; height: 14px; }

.topbar-right { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.nav-link {
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.who {
  color: var(--text-muted); padding: 6px 12px; font-size: 13px;
  border-left: 1px solid var(--border); margin-left: 8px;
  border-radius: var(--radius); cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
  text-decoration: none;
}
.who:hover { color: var(--text); background: var(--surface-2); }
.who em { color: var(--primary-h); font-style: normal; font-size: 11px; font-weight: 500; margin-left: 4px; }

/* ===== flash ===== */
.flash-stack { max-width: 1280px; margin: 16px auto 0; padding: 0 24px; }
.flash {
  padding: 10px 14px; margin-bottom: 8px; border-radius: var(--radius);
  font-size: 13px; display: flex; align-items: center; gap: 10px;
  border: 1px solid; background: var(--surface);
}
.flash-error   { color: #fca5a5; border-color: var(--danger-bd);  background: var(--danger-bg); }
.flash-success { color: #6ee7b7; border-color: var(--success-bd); background: var(--success-bg); }

/* ===== layout ===== */
.page { max-width: 1280px; margin: 0 auto; padding: 24px; }
.page-narrow { max-width: 560px; }

.page-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-head h2 {
  margin: 0; font-size: 20px; font-weight: 600; color: var(--text);
  letter-spacing: -0.01em;
}
.page-head h2 .muted { font-weight: 400; color: var(--text-dim); margin-left: 6px; font-size: 14px; }
.muted { color: var(--text-dim); font-size: 13px; }

/* ===== forms ===== */
input[type="text"],
input[type="password"],
input[type="email"] {
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 9px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
  width: 100%;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}
input[readonly] { color: var(--text-dim); background: var(--surface); cursor: not-allowed; }
input::placeholder { color: var(--text-dim); }

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

/* ===== buttons ===== */
.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 7px 12px;
  border-radius: var(--radius);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
  white-space: nowrap;
}
.btn:hover, button:hover { background: var(--surface-3); border-color: #3a4859; }
.btn svg, button svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
  padding: 6px 8px;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { color: var(--danger); border-color: var(--border-2); }
.btn-danger:hover { color: #fff; background: var(--danger); border-color: var(--danger); }

.btn-warn { color: var(--warning); border-color: var(--border-2); }
.btn-warn:hover { color: var(--bg); background: var(--warning); border-color: var(--warning); }

button:disabled, .btn:disabled { opacity: 0.4; cursor: not-allowed; }
button:disabled:hover, .btn:disabled:hover { background: var(--surface-2); border-color: var(--border-2); }

.inline { display: inline; }

/* icon-only round button (for table actions) */
.icon-btn {
  width: 28px; height: 28px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid transparent;
  color: var(--text-muted); border-radius: var(--radius);
  cursor: pointer; transition: all 150ms ease;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border-2); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger-bd); background: var(--danger-bg); }
.icon-btn.warn:hover { color: var(--warning); border-color: var(--warning-bd); background: var(--warning-bg); }
.icon-btn svg { width: 16px; height: 16px; }

/* ===== peers table ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.peers { width: 100%; border-collapse: collapse; font-size: 13px; }
.peers th, .peers td { padding: 10px 14px; text-align: left; }
.peers thead { background: var(--surface-2); }
.peers th {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.peers tbody tr { border-bottom: 1px solid var(--border); transition: background 100ms ease; }
.peers tbody tr:last-child { border-bottom: none; }
.peers tbody tr:hover { background: var(--surface-2); }
.peers .row-disabled { opacity: 0.55; }
.peers .actions { white-space: nowrap; text-align: right; }
.peers .actions > * { margin-left: 2px; }

.peers form.rename input {
  background: transparent;
  border: 1px solid transparent;
  padding: 5px 8px;
  margin-left: -8px;
  width: 100%;
  min-width: 120px;
  font-weight: 500;
}
.peers form.rename input:hover { border-color: var(--border-2); }
.peers form.rename input:focus { border-color: var(--primary); background: var(--surface); }

/* ===== status badges (pills) ===== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-online  { color: #6ee7b7; border-color: var(--success-bd); background: var(--success-bg); }
.badge-online  .dot { background: var(--success); animation: pulseDot 1.8s ease-in-out infinite; }
.badge-offline { color: var(--text-muted); border-color: var(--border-2); background: var(--surface-2); }
.badge-offline .dot { background: #4b5563; }
.badge-disabled{ color: #fca5a5; border-color: var(--danger-bd); background: var(--danger-bg); }
.badge-disabled .dot { background: var(--danger); }

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  50%      { box-shadow: 0 0 0 5px rgba(16,185,129,0); }
}

.status-cell .status-sub {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

.th-hint {
  display: inline-flex;
  width: 14px; height: 14px;
  align-items: center; justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border-2);
  color: var(--text-dim);
  font-size: 9px;
  font-weight: 600;
  margin-left: 4px;
  cursor: help;
  vertical-align: middle;
  text-transform: none;
}
.th-hint:hover { color: var(--text-muted); border-color: var(--text-dim); }

/* ===== email cell ===== */
.email-cell { max-width: 220px; }
.email-current {
  display: inline-block;
  max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle;
  color: var(--text-muted);
}
.inline-email { display: flex; gap: 4px; align-items: center; }
.inline-email input { flex: 1; min-width: 0; padding: 5px 8px; font-size: 12px; }

/* ===== new peer header form ===== */
.new-peer { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.new-peer input { width: 220px; }
.new-peer input[type="email"] { width: 260px; }

/* ===== empty state ===== */
.empty {
  padding: 48px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px dashed var(--border-2);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

/* ===== user form ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.user-form { display: flex; flex-direction: column; gap: 16px; }
.user-form label.checkbox {
  display: flex; flex-direction: row; align-items: center; gap: 10px;
  font-size: 13px; color: var(--text); margin-bottom: 0;
}
.user-form label.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
.user-form button { align-self: flex-start; margin-top: 8px; }

/* ===== peer detail (QR view) ===== */
.qr-stage {
  display: flex; flex-direction: column; align-items: center;
  padding: 24px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); margin: 24px 0;
}
.qr { max-width: 280px; width: 100%; height: auto;
      background: #fff; padding: 12px; border-radius: 8px; box-shadow: var(--shadow); }
.actions-center { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }

/* ============================================================
   LOGIN PAGE — minimal, centered, professional
   ============================================================ */
body.login-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 800px 600px at 50% -10%, rgba(59,130,246,0.10), transparent 60%),
    radial-gradient(ellipse 600px 400px at 50% 110%, rgba(59,130,246,0.04), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
body.login-page::before {
  content: "";
  position: fixed; inset: 0;
  background-image:
    radial-gradient(circle, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

.login-shell {
  position: relative; z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 32px 24px;
  display: flex; flex-direction: column; align-items: stretch;
}

.login-logo {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), #2563eb);
  border-radius: 10px;
  display: grid; place-items: center;
  color: #fff;
  margin: 0 auto 24px;
  box-shadow: 0 0 0 1px var(--primary-bd), 0 12px 32px rgba(59,130,246,0.25);
}
.login-logo svg { width: 22px; height: 22px; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  margin: 0 0 4px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
  text-align: center;
}
.login-card .subtitle {
  margin: 0 0 24px 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}
.login-card .field { margin-bottom: 14px; }
.login-card button[type="submit"] {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  margin-top: 6px;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

/* ===== responsive ===== */
@media (max-width: 700px) {
  .topbar { padding: 10px 14px; }
  .page { padding: 16px 12px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .new-peer { flex-direction: column; align-items: stretch; }
  .new-peer input { width: 100%; }
  .peers { font-size: 12px; }
  .peers th, .peers td { padding: 8px 8px; }
  .peers .actions { text-align: left; padding-top: 4px; }
}

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

/* ---- Protocol badges (extends existing .badge) ---- */
.badge-wg   { color: #93c5fd; border-color: rgba(59,130,246,0.35); background: rgba(59,130,246,0.10); }
.badge-ovpn { color: #c4b5fd; border-color: rgba(139,92,246,0.35); background: rgba(139,92,246,0.10); }
.badge-revoked { color: #fca5a5; border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.10); margin-left: 4px; }

.peers .row-revoked { opacity: 0.5; }
.peers .row-revoked td { font-style: italic; }

/* ---- Filter chips (above the peers table) ---- */
.filter-chips {
  display: flex;
  gap: 8px;
  margin: 0 0 16px 0;
  flex-wrap: wrap;
}
.filter-chips .chip {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}
.filter-chips .chip:hover { color: var(--text); background: var(--surface-3); }
.filter-chips .chip.is-active {
  color: var(--primary-h);
  background: var(--primary-bg);
  border-color: var(--primary-bd);
}

/* ---- Picker grid (used by peer_picker.html from Phase 2c) ---- */
.picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}
@media (max-width: 600px) {
  .picker-grid { grid-template-columns: 1fr; }
}
.picker-card {
  display: block;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  transition: background 100ms ease, border-color 100ms ease;
}
.picker-card:hover {
  background: var(--surface-2);
  border-color: var(--primary-bd);
}
.picker-card h3 { margin: 0 0 6px 0; font-size: 16px; }
.picker-card p { margin: 0; font-size: 13px; }

/* ---- OVPN show page detail list ---- */
.peer-detail { margin: 0; }
.peer-detail dt {
  float: left;
  clear: left;
  width: 110px;
  color: var(--text-muted);
  font-size: 13px;
  padding-bottom: 6px;
}
.peer-detail dd {
  margin: 0 0 6px 130px;
  font-size: 13px;
}
