/* ServiceVault — Sleek Animated Workshop Theme (Windows Desktop + iPhone 11 PWA) */
:root {
  --bg: #0b0f16;
  --bg-glow: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(245, 158, 11, 0.11), transparent 65%);
  --surface: rgba(22, 27, 36, 0.92);
  --surface-solid: #161b24;
  --surface-2: #1f2735;
  --surface-hover: #263042;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #eef2f7;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-soft: rgba(245, 158, 11, 0.14);
  --ok: #22c55e;
  --danger: #ef4444;
  --private: #a855f7;
  --info: #38bdf8;
  --radius: 14px;
  --radius-sm: 10px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --shadow-card: 0 8px 24px rgba(0, 0, 0, 0.26), inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --shadow-hover: 0 14px 32px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
  color: var(--text);
  touch-action: manipulation;
}

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.22); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.38); }

/* Keyframes */
@keyframes tabFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes modalSlideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes backdropFade {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes pulseRec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.55); }
  50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 256px;
  background: rgba(18, 23, 32, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.brand img {
  width: 34px;
  height: 34px;
  filter: drop-shadow(0 2px 8px rgba(245, 158, 11, 0.3));
  transition: transform 0.35s var(--ease);
}

.brand:hover img {
  transform: rotate(-8deg) scale(1.06);
}

.brand-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.25px;
  background: linear-gradient(135deg, #fff 20%, #fde68a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  font-weight: 500;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), transform 0.16s var(--ease), border-color 0.2s var(--ease);
}

.nav-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateX(3px);
}

.nav-btn:active {
  transform: scale(0.98);
}

.nav-btn.active {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(245, 158, 11, 0.08));
  border-color: rgba(245, 158, 11, 0.42);
  color: #fde68a;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.12);
}

.sync-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sync-stamp {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.sync-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.7);
  flex-shrink: 0;
}

.sync-dot.idle {
  background: var(--muted);
  box-shadow: none;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(148, 163, 184, 0.14);
  color: #dbe4f0;
  letter-spacing: 0.15px;
  white-space: nowrap;
}

.badge.accent { background: linear-gradient(135deg, #f59e0b, #fbbf24); color: #0b0f16; }
.badge.ok { background: rgba(34, 197, 94, 0.18); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.25); }
.badge.danger { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.25); }
.badge.private { background: rgba(168, 85, 247, 0.2); color: #e9d5ff; border: 1px solid rgba(168, 85, 247, 0.3); }
.badge.info { background: rgba(56, 189, 248, 0.16); color: #bae6fd; border: 1px solid rgba(56, 189, 248, 0.26); }

.main-area {
  flex: 1;
  min-width: 0;
  padding: 22px 28px 96px;
  max-width: 1180px;
  margin: 0 auto;
  width: 100%;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.pill {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s var(--ease);
}

.pill.online { border-color: rgba(34, 197, 94, 0.4); color: #86efac; background: rgba(34, 197, 94, 0.08); }
.pill.offline { border-color: rgba(245, 158, 11, 0.5); color: #fde68a; background: rgba(245, 158, 11, 0.14); }

/* Tab animation */
.tab-view {
  animation: tabFadeIn 0.28s var(--ease);
}

/* Cards & Forms */
.card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-card);
  transition: border-color 0.22s var(--ease), transform 0.22s var(--ease), box-shadow 0.22s var(--ease);
}

.card.interactive:hover {
  border-color: rgba(245, 158, 11, 0.42);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.card h2, .card h3 {
  margin: 0 0 10px;
  font-size: 16.5px;
  font-weight: 650;
  letter-spacing: -0.1px;
}

.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row-nowrap { display: flex; align-items: center; gap: 8px; }
.space-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

label.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: #cbd5e1;
  margin: 10px 0 5px;
}

input[type="text"], input[type="password"], input[type="number"], input[type="search"], input[type="file"], textarea, select {
  width: 100%;
  background: rgba(11, 15, 22, 0.85);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

input:hover, textarea:hover, select:hover {
  border-color: var(--border-strong);
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.16);
  background: #0b0f16;
}

textarea { min-height: 112px; resize: vertical; line-height: 1.55; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 11px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease), transform 0.15s var(--ease), box-shadow 0.2s var(--ease);
  user-select: none;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: rgba(203, 213, 225, 0.42);
  transform: translateY(-1px);
}

.btn:active {
  transform: scale(0.975);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #0b0f16;
  border-color: transparent;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.28);
}

.btn.primary:hover {
  background: linear-gradient(135deg, #fbbf24, #fcd34d);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.38);
}

.btn.ok {
  background: rgba(34, 197, 94, 0.16);
  border-color: rgba(34, 197, 94, 0.45);
  color: #86efac;
}

.btn.ok:hover {
  background: rgba(34, 197, 94, 0.24);
}

.btn.danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn.danger:hover {
  background: rgba(239, 68, 68, 0.22);
}

.btn.sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 9px;
}

.btn.recording {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: transparent;
  color: #fff;
  animation: pulseRec 1.4s infinite;
}

/* Chips / Section Filters */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 4px;
}

.chip {
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.6);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s var(--ease);
}

.chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.chip.active {
  background: var(--accent-soft);
  border-color: rgba(245, 158, 11, 0.55);
  color: #fde68a;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.15);
}

/* Key-Value Editor (replaces raw JSON!) */
.kv-box {
  background: rgba(11, 15, 22, 0.65);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kv-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(140px, 1.4fr) auto;
  gap: 8px;
  align-items: center;
}

/* Visual Link Picker */
.link-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.link-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #e0f2fe;
  font-size: 12.5px;
  font-weight: 500;
}

.link-chip button {
  border: none;
  background: transparent;
  color: #bae6fd;
  cursor: pointer;
  padding: 0 2px;
  font-size: 15px;
  line-height: 1;
}

/* Rich formatted Markdown output */
.md-view {
  background: rgba(11, 15, 22, 0.78);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 14px 16px;
  font-size: 14.5px;
  line-height: 1.62;
  word-break: break-word;
}

.md-view .md-section-title {
  display: block;
  color: #fde68a;
  font-weight: 700;
  margin-top: 12px;
  margin-bottom: 4px;
  font-size: 14.5px;
}

.md-view .md-section-title:first-child {
  margin-top: 0;
}

.md-view p {
  margin: 0 0 8px;
}

.md-view p:last-child {
  margin-bottom: 0;
}

.md-view strong {
  color: #ffffff;
  font-weight: 700;
}

.md-view code {
  background: rgba(148, 163, 184, 0.16);
  padding: 1px 6px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: #fde68a;
}

.md-view ul, .md-view ol {
  margin: 4px 0 10px 20px;
  padding: 0;
}

.md-view li {
  margin-bottom: 4px;
}

/* Progress bar */
.progress {
  width: 100%;
  height: 10px;
  background: rgba(11, 15, 22, 0.9);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24);
  transition: width 0.45s var(--ease);
  border-radius: 999px;
}

/* Previews & Reader */
.thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.thumb {
  width: 84px;
  height: 84px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  transition: transform 0.2s var(--ease);
}

.thumb:hover {
  transform: scale(1.04);
}

.reader-box {
  background: rgba(11, 15, 22, 0.8);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 14px 16px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.58;
}

.reader-img {
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 17, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 90;
  animation: backdropFade 0.25s var(--ease);
}

.auth-box {
  width: 100%;
  max-width: 400px;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 26px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: modalSlideUp 0.3s var(--ease);
}

/* Modal / Drawer */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 12, 0.76);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
  animation: backdropFade 0.2s var(--ease);
}

.modal-card {
  width: 100%;
  max-width: 880px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface-solid);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  animation: modalSlideUp 0.28s var(--ease);
}

.toast {
  position: fixed;
  top: calc(14px + var(--safe-top));
  right: 16px;
  background: rgba(22, 27, 36, 0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(245, 158, 11, 0.55);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  z-index: 100;
  max-width: 360px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  animation: toastIn 0.25s var(--ease);
}

.hidden { display: none !important; }

/* Mobile Bottom Nav (iPhone 11 PWA) */
.mobile-nav {
  display: none;
}

@media (max-width: 820px) {
  .sidebar { display: none; }
  .main-area {
    padding: calc(14px + var(--safe-top)) 12px calc(92px + var(--safe-bottom));
  }
  .topbar {
    margin-bottom: 14px;
    padding-bottom: 10px;
  }
  .topbar h1 { font-size: 19px; }
  .card { padding: 14px; border-radius: 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kv-row { grid-template-columns: 1fr 1fr auto; }

  /* Critical for iPhone 11 iOS Safari: >= 16px prevents automatic viewport zoom on input focus */
  input[type="text"], input[type="password"], input[type="number"], input[type="search"], textarea, select {
    font-size: 16px;
    padding: 11px 12px;
  }

  .modal-backdrop {
    align-items: flex-end;
    padding: 8px 8px calc(8px + var(--safe-bottom));
  }
  .modal-card {
    max-height: 88vh;
    border-radius: 20px 20px 14px 14px;
    padding: 16px;
  }

  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(18, 23, 32, 0.94);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid var(--border);
    padding: 6px 4px calc(8px + var(--safe-bottom));
    z-index: 70;
  }
  .mobile-nav button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    padding: 6px 2px;
    border-radius: 10px;
    position: relative;
    transition: color 0.18s var(--ease), background 0.18s var(--ease), transform 0.15s var(--ease);
  }
  .mobile-nav button:active {
    transform: scale(0.92);
  }
  .mobile-nav button.active {
    color: #fde68a;
    background: rgba(245, 158, 11, 0.14);
  }
  .mobile-nav .m-icon { font-size: 18px; line-height: 1; }
  .mobile-nav .m-badge {
    position: absolute;
    top: 2px;
    right: 6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 99px;
    background: var(--accent);
    color: #0b0f16;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

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