/* ═══════════════════════════════════════════════════════════════
   Bingy Key Manager — key-manager/css/style.css
   Design: Cinematic dark — matching the tvOS app aesthetic
   ═══════════════════════════════════════════════════════════════ */

/* ── Artdeco MN Brand font ────────────────────────────────────── */
@font-face {
  font-family: 'Artdeco MN';
  src: url('../../fonts/artdeco-mn.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ── Tokens ───────────────────────────────────────────────────── */
:root {
  --bg:          #09090f;
  --surface:     rgba(255,255,255,0.04);
  --surface-2:   rgba(255,255,255,0.07);
  --border:      rgba(255,255,255,0.08);
  --border-mid:  rgba(255,255,255,0.14);
  --fg:          #f2f2f7;
  --muted:       rgba(242,242,247,0.45);
  --faint:       rgba(242,242,247,0.18);
  --gold:        #C9A84C;
  --gold-bright: #e4c06e;
  --gold-dim:    rgba(201,168,76,0.15);
  --gold-glow:   rgba(201,168,76,0.28);
  --blue:        #0a84ff;
  --red:         #ff453a;
  --green:       #30d158;
  --glass:       rgba(12,12,20,0.78);
  --nav-bg:      rgba(9,9,15,0.92);
  --shadow:      0 24px 64px rgba(0,0,0,0.72);
  --font-brand:  'Artdeco MN', -apple-system, serif;
  --font-body:   'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius:      18px;
  --radius-sm:   10px;
  --max-w:       540px;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
img  { display: block; }
a    { text-decoration: none; }

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Page background (blurred image) ─────────────────────────── */
.page-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.page-bg-img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  filter: blur(32px) saturate(0.6);
  transform: scale(1.12);
}

.page-bg-overlay {
  position: absolute;
  inset: 0;
  background: rgba(9,9,15,0.86);
}

/* ── App shell ────────────────────────────────────────────────── */
#app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
}

/* ── Panel visibility ─────────────────────────────────────────── */
.panel { display: block; }
.panel[hidden] { display: none !important; }

/* ─────────────────────────────────────────────────────────────────
   AUTH SCREEN
   ──────────────────────────────────────────────────────────────── */
.auth-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px max(32px, env(safe-area-inset-bottom));
}

/* Back link */
.auth-back {
  position: fixed;
  top: 24px; left: 24px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  transition: color 0.15s, border-color 0.15s;
}
.auth-back:hover { color: var(--fg); border-color: var(--border-mid); }

/* Auth card */
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--glass);
  backdrop-filter: blur(40px) saturate(160%);
  -webkit-backdrop-filter: blur(40px) saturate(160%);
  border: 1px solid var(--border-mid);
  border-radius: 28px;
  padding: 44px 36px 36px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,0.03), inset 0 1px 0 rgba(255,255,255,0.06);
  animation: cardIn 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* Wordmark */
.auth-logo-wrap  { margin-bottom: 32px; }
.auth-wordmark {
  font-family: var(--font-brand);
  font-size: 2rem;
  letter-spacing: 0.04em;
  color: var(--gold);
}

/* Headlines */
.auth-headline {
  font-family: var(--font-brand);
  font-size: clamp(1.7rem, 5vw, 2rem);
  font-weight: normal;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: var(--fg);
  margin-bottom: 14px;
}

.auth-subtitle {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--muted);
  max-width: 300px;
  margin-bottom: 32px;
}

/* CloudKit button container */
#apple-sign-in-btn {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-bottom: 20px;
}

/* Security toggle */
.security-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  transition: color 0.15s;
  width: 100%;
  justify-content: center;
}
.security-toggle:hover,
.security-toggle.active { color: var(--fg); }

/* Security panel */
.security-panel {
  margin-top: 18px;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
}

.security-panel-heading {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.security-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.security-list li {
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--muted);
  padding-left: 14px;
  position: relative;
}
.security-list li::before {
  content: '\2022';
  position: absolute; left: 0;
  color: var(--gold);
}

/* Footer note */
.auth-note {
  margin-top: 24px;
  font-size: 0.68rem;
  line-height: 1.65;
  color: var(--faint);
  text-align: center;
}

/* ─────────────────────────────────────────────────────────────────
   MAIN PANEL (signed in)
   ──────────────────────────────────────────────────────────────── */

/* App nav */
.app-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(16px, 3vw, 32px);
  height: 60px;
  background: var(--nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.app-nav-brand {
  font-family: var(--font-brand);
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  color: var(--gold);
}

.app-nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-label {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-ghost {
  background: none;
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  padding: 6px 14px;
  transition: color 0.15s, border-color 0.15s;
}
.btn-ghost:hover { color: var(--fg); border-color: var(--fg); }

/* Panel body */
.panel-body {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 32px 16px max(40px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
}

.card h2 {
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: normal;
  letter-spacing: 0.02em;
  color: var(--fg);
  margin-bottom: 8px;
}

.hint {
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 20px;
  line-height: 1.55;
}

/* Keys list */
.keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 48px;
}

.empty-state {
  font-size: 0.82rem;
  color: var(--faint);
  text-align: center;
  padding: 16px 0;
}

/* Key row (generated by JS) */
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.key-row-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--fg);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-row-value {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: monospace;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-row-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--red);
  font-size: 0.75rem;
  padding: 4px;
  opacity: 0.6;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.key-row-del:hover { opacity: 1; }

/* Form */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 18px;
}
.form-group:first-child { margin-top: 0; }

label {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.04em;
}

input, select {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--fg);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
  -webkit-appearance: none;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus {
  border-color: var(--gold);
  background: rgba(201,168,76,0.05);
}

select option { background: #1a1a28; color: var(--fg); }

/* Service help */
.service-help {
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--gold-dim);
  border: 1px solid rgba(201,168,76,0.25);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  line-height: 1.55;
  color: var(--muted);
}
.service-help a { color: var(--gold); text-decoration: underline dotted; }
.service-help a:hover { color: var(--gold-bright); }

/* Form error */
.form-error {
  padding: 10px 14px;
  background: rgba(255,69,58,0.12);
  border: 1px solid rgba(255,69,58,0.28);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--red);
  margin-top: 6px;
}

/* Save button */
.btn-save {
  margin-top: 20px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--gold);
  border: none;
  border-radius: 999px;
  padding: 14px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: #09090f;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
  box-shadow: 0 0 0 0 var(--gold-glow);
}
.btn-save:hover {
  background: var(--gold-bright);
  box-shadow: 0 4px 20px var(--gold-glow);
  transform: translateY(-1px);
}
.btn-save:active { transform: translateY(0); }

/* ── Loading overlay ──────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(9,9,15,0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 0.875rem;
  color: var(--muted);
}

.loading-overlay[hidden] { display: none !important; }

/* ── Spinner ──────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.20);
  border-top-color: var(--fg);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner[hidden] { display: none !important; }
.spinner-lg { width: 36px; height: 36px; border-width: 3px; border-top-color: var(--gold); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toasts ───────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 20px;
  background: rgba(30,30,46,0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  font-size: 0.82rem;
  color: var(--fg);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease, toastOut 0.25s ease var(--duration, 3s) forwards;
  white-space: nowrap;
}
.toast.success { border-color: rgba(48,209,88,0.4); color: var(--green); }
.toast.error   { border-color: rgba(255,69,58,0.4);  color: var(--red);   }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateY(0);     } to { opacity: 0; transform: translateY(-8px); } }
