:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --secondary: #f3f4f6;
  --secondary-hover: #e5e7eb;
  --secondary-text: #374151;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg-app: #f9fafb;
  --bg-card: #ffffff;
  --bg-header: #fcfcfc;
  --bg-input: #ffffff;
  --bg-code: #f3f4f6;
  --bg-nav: #ffffff;
  --border: #e5e7eb;
  --text-main: #111827;
  --text-muted: #6b7280;
  --text-code: #334155;
  --sidebar-bg: #1f2937;
  --sidebar-text: #e5e7eb;
  --sidebar-active: #374151;
  --toast-bg: #1f2937;
  --toast-text: #ffffff;
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', monospace;
  --radius: 8px;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --secondary: #374151;
    --secondary-hover: #4b5563;
    --secondary-text: #f3f4f6;
    --danger: #f87171;
    --danger-hover: #ef4444;
    --bg-app: #111827;
    --bg-card: #1f2937;
    --bg-header: #1f2937;
    --bg-input: #111827;
    --bg-code: #111827;
    --bg-nav: #1f2937;
    --border: #374151;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --text-code: #e5e7eb;
    --sidebar-bg: #111827;
    --sidebar-text: #e5e7eb;
    --sidebar-active: #374151;
    --toast-bg: #374151;
    --toast-text: #f9fafb;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3), 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.brand {
  padding: 24px;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
}

.logo-icon {
  width: 24px;
  height: 24px;
}

.nav-menu {
  flex: 1;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: #9ca3af;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: all 0.2s;
}

.nav-item svg {
  width: 18px;
  height: 18px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.05);
  color: #fff;
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6b7280;
}
.status-dot.ready { background: #10b981; box-shadow: 0 0 8px #10b98166; }
.status-dot.error { background: #ef4444; }
.status-dot.loading { animation: pulse 1.5s infinite; }

@keyframes pulse { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }

.btn-install {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.btn-install:hover { background: rgba(255,255,255,0.15); }

/* Content Area */
.content-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
}

.section-header {
  margin-bottom: 32px;
}
.section-header h2 { margin: 0 0 8px 0; font-size: 24px; font-weight: 700; }
.section-header p { margin: 0; color: var(--text-muted); }

.tab-content { display: none; animation: fadeIn 0.2s ease-out; }
.tab-content.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* Cards & Grid */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1024px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-header);
}
.card-header h3 { margin: 0; font-size: 16px; font-weight: 600; }

.card-body { padding: 20px; }

.badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--secondary);
  color: var(--text-muted);
  font-weight: 600;
}

/* Forms */
.form-group { margin-bottom: 16px; }
label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--font-sans);
  font-size: 16px; /* Prevents iOS zoom on focus */
  transition: border-color 0.15s, box-shadow 0.15s;
}
@media (min-width: 768px) {
  input, select, textarea { font-size: 14px; }
}
textarea { font-family: var(--font-mono); font-size: 13px; resize: vertical; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.select-wrapper { position: relative; }
.select-wrapper::after {
  content: '';
  position: absolute;
  right: 12px; top: 50%; transform: translateY(-50%);
  border: 5px solid transparent; border-top-color: var(--text-muted);
  pointer-events: none;
}
select { appearance: none; background: var(--bg-input); color: var(--text-main); }

.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.btn svg { width: 16px; height: 16px; }
.full-width { width: 100%; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary { background: var(--secondary); color: var(--secondary-text); border-color: var(--border); }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-danger { background: #fee2e2; color: var(--danger); }
.btn-danger:hover { background: #fecaca; }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--secondary); }

.btn-icon {
  padding: 4px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}
.btn-icon:hover { background: var(--secondary); color: var(--primary); }

.actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
  flex-wrap: wrap;
}

.textarea-wrapper { position: relative; }
.btn-icon-overlay {
  position: absolute;
  top: 8px; right: 8px;
  padding: 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
}
.btn-icon-overlay:hover { color: var(--primary); border-color: var(--primary); }

/* Results & Code */
.result-box {
  margin-top: 16px;
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  position: relative;
}
.result-content, .code-block {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: var(--text-code);
  max-height: 120px;
  overflow-y: auto;
}
.btn-copy {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  border-radius: 4px;
  cursor: pointer;
}
.btn-copy:hover { border-color: var(--primary); color: var(--primary); }

.hidden { display: none !important; }

/* Keys Tab Specifics */
.empty-state {
  text-align: center;
  padding: 40px 20px;
}
.empty-icon {
  width: 64px; height: 64px;
  background: var(--secondary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
  color: var(--text-muted);
}
.empty-icon svg { width: 32px; height: 32px; }

.key-field {
  margin-bottom: 24px;
}
.code-display {
  background: var(--bg-code);
  padding: 12px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  word-break: break-all;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  color: var(--text-code);
  max-height: 160px;
  overflow-y: auto;
  white-space: pre-wrap;
}
.code-display.blur code { filter: blur(4px); transition: filter 0.2s; cursor: pointer; }
.code-display.blur:hover code { filter: blur(0); }

.danger-zone {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px dashed var(--border);
}
.danger-zone h4 { color: var(--danger); margin: 0 0 16px 0; }

/* Contacts */
.split-view {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1024px) {
  .split-view { grid-template-columns: 350px 1fr; }
}

.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.contact-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.contact-info h4 { margin: 0 0 4px 0; font-size: 14px; }
.contact-key { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-actions { display: flex; gap: 8px; }

.divider {
  display: flex; align-items: center; text-align: center; color: var(--text-muted); font-size: 12px; margin: 20px 0;
}
.divider::before, .divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--border); }
.divider span { padding: 0 10px; }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 100;
}
.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease-out;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}
.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Verify Status */
.verify-status {
  margin-top: 16px;
  padding: 12px;
  border-radius: 6px;
  font-weight: 600;
  text-align: center;
}
.verify-status.valid { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.verify-status.invalid { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* Mode Switch */
.mode-switch {
  display: flex;
  gap: 16px;
  margin-bottom: 8px;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-main);
}
.radio-label input {
  width: auto;
  margin: 0;
}

/* Mobile Responsiveness */
.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .content-area {
    padding: 20px;
    padding-bottom: 80px; /* Space for bottom nav */
  }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-nav);
    border-top: 1px solid var(--border);
    padding: 8px 0;
    justify-content: space-around;
    z-index: 50;
    box-shadow: 0 -1px 3px rgba(0,0,0,0.05);
  }

  .bottom-nav .nav-item {
    flex-direction: column;
    gap: 4px;
    font-size: 10px;
    padding: 8px;
    color: var(--text-muted);
    background: transparent;
    border-radius: 8px;
    width: 64px;
    justify-content: center;
  }

  .bottom-nav .nav-item svg {
    width: 24px;
    height: 24px;
  }

  .bottom-nav .nav-item.active {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
  }

  .bottom-nav .nav-item:hover {
    background: rgba(0,0,0,0.05);
  }

  /* Adjust Toast position on mobile */
  .toast-container {
    bottom: 80px;
    left: 20px;
    right: 20px;
    width: auto;
  }
  
  .toast {
    min-width: 0;
    width: 100%;
  }

  /* Adjust Card Grid for very small screens if needed */
  .card-grid {
    gap: 16px;
  }
  
  .section-header h2 {
    font-size: 20px;
  }

  .actions {
    flex-direction: column;
  }
  .actions .btn {
    width: 100%;
  }
}

