/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-base:       #0a0a0f;
  --bg-surface:    #111118;
  --bg-elevated:   #1a1a26;
  --bg-card:       #1e1e2e;
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(108,99,255,0.6);

  --text-primary:  #f0f0ff;
  --text-secondary:#9898b8;
  --text-muted:    #5a5a78;

  --accent:        #6c63ff;
  --accent-hover:  #7c73ff;
  --accent-glow:   rgba(108,99,255,0.25);
  --cyan:          #48cae4;
  --danger:        #ff5a5a;
  --success:       #4ade80;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-md: 0 8px 32px rgba(0,0,0,0.5);
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.7);

  --transition: 200ms cubic-bezier(0.4,0,0.2,1);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ─── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 99px; }

/* ─── App Shell ────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ─── Top Bar ──────────────────────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
  -webkit-app-region: drag;
}

#topbar .logo {
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-app-region: no-drag;
  text-decoration: none;
}

#topbar .logo img { width: 28px; height: 28px; border-radius: 6px; }

#topbar .logo-text {
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(135deg, #6c63ff, #48cae4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}

#topbar .spacer { flex: 1; }

.topbar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  -webkit-app-region: no-drag;
  flex-shrink: 0;
}
.topbar-btn:hover { background: var(--bg-elevated); color: var(--text-primary); }
.topbar-btn svg { width: 18px; height: 18px; }

#url-bar {
  flex: 1;
  max-width: 340px;
  height: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 14px;
  color: var(--text-secondary);
  font-size: 12px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), color var(--transition);
  -webkit-app-region: no-drag;
}
#url-bar:focus { border-color: var(--border-focus); color: var(--text-primary); }

/* ─── Frame Container ──────────────────────────────────────────────────────── */
#frame-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#site-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: var(--bg-base);
}

/* ─── Loading Screen ───────────────────────────────────────────────────────── */
#loading-screen {
  position: absolute;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 200;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
#loading-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.loader-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: linear-gradient(135deg, #1a1a2e, #0a0a0f);
  border: 2px solid rgba(108,99,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse-icon 2s ease-in-out infinite;
}
.loader-icon img { width: 48px; height: 48px; }

@keyframes pulse-icon {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50%       { box-shadow: 0 0 0 16px transparent; }
}

.loader-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-elevated);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#loading-screen p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* ─── Error Screen ─────────────────────────────────────────────────────────── */
#error-screen {
  position: absolute;
  inset: 0;
  background: var(--bg-base);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 32px;
  text-align: center;
  z-index: 200;
}
#error-screen.visible { display: flex; }

.error-icon {
  font-size: 48px;
  line-height: 1;
}
#error-screen h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
}
#error-screen p {
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 380px;
  line-height: 1.6;
}
.error-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }

/* ─── Overlay (Login Modal) ────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
#overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.92) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 28px;
}
.modal-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #1a1a3e, #0f0f2a);
  border: 1px solid rgba(108,99,255,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.modal-icon img { width: 32px; height: 32px; }
.modal-header h1 { font-size: 20px; font-weight: 700; }
.modal-header p  { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* ─── Form Elements ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  height: 44px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 40px 0 14px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-text-security: none;
}
.input-wrap input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.input-wrap input[type="password"] { font-family: 'Courier New', monospace; letter-spacing: 2px; }
.input-wrap input::placeholder { font-family: var(--font); letter-spacing: 0; color: var(--text-muted); }

.toggle-pw {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  line-height: 0;
  transition: color var(--transition);
}
.toggle-pw:hover { color: var(--text-secondary); }
.toggle-pw svg { width: 18px; height: 18px; }

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  margin-top: -4px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  user-select: none;
}
.checkbox-label input[type="checkbox"] { display: none; }
.checkbox-box {
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition), background var(--transition);
  flex-shrink: 0;
}
.checkbox-label:has(input:checked) .checkbox-box {
  background: var(--accent);
  border-color: var(--accent);
}
.checkbox-box svg { width: 12px; height: 12px; display: none; }
.checkbox-label:has(input:checked) .checkbox-box svg { display: block; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  font-family: var(--font);
  transition: color var(--transition);
}
.link-btn:hover { color: var(--accent-hover); text-decoration: underline; }

/* ─── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 44px;
  padding: 0 22px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--accent), #5a52ef);
  color: #fff;
  box-shadow: 0 4px 16px rgba(108,99,255,0.35);
}
.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #6a62ff);
  box-shadow: 0 4px 24px rgba(108,99,255,0.5);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card); border-color: rgba(255,255,255,0.14); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-danger {
  background: rgba(255,90,90,0.12);
  color: var(--danger);
  border: 1px solid rgba(255,90,90,0.25);
}
.btn-danger:hover { background: rgba(255,90,90,0.2); }

/* ─── Credential Vault Panel ───────────────────────────────────────────────── */
#vault-panel {
  position: fixed;
  top: 52px;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border);
  z-index: 250;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
}
#vault-panel.open { transform: translateX(0); }

.vault-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.vault-header h2 { font-size: 16px; font-weight: 700; }
.vault-header p  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.vault-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

.cred-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.cred-item .cred-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.cred-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cred-row span {
  flex: 1;
  font-size: 14px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: 'Courier New', monospace;
}
.cred-row span.masked { letter-spacing: 3px; color: var(--text-muted); }
.copy-btn {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 12px;
  height: 28px;
  border-radius: var(--radius-sm);
}

.vault-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.security-note {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(108,99,255,0.08);
  border: 1px solid rgba(108,99,255,0.2);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.security-note .note-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }

/* ─── Toast Notifications ──────────────────────────────────────────────────── */
#toast-area {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
  pointer-events: auto;
  max-width: 320px;
}
.toast.success { border-color: rgba(74,222,128,0.3); }
.toast.error   { border-color: rgba(255,90,90,0.3); }
.toast.info    { border-color: var(--border-focus); }
.toast-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.toast.success .toast-dot { background: var(--success); }
.toast.error   .toast-dot { background: var(--danger); }
.toast.info    .toast-dot { background: var(--accent); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(20px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.toast.out {
  animation: toast-out 0.25s ease forwards;
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(20px) scale(0.9); }
}

/* ─── Focus Ring ───────────────────────────────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
button:focus:not(:focus-visible) { outline: none; }

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .modal { padding: 24px 20px; border-radius: var(--radius-lg); }
  #vault-panel { width: 100%; }
  #url-bar { display: none; }
  #toast-area { right: 12px; bottom: 16px; }
}
