/* Extracted theme variables and utilities */
:root {
  --primary-50: rgb(238 242 255);
  --primary-100: rgb(224 231 255);
  --primary-200: rgb(199 210 254);
  --primary-300: rgb(165 180 252);
  --primary-400: rgb(129 140 248);
  --primary-500: rgb(99 102 241);
  --primary-600: rgb(79 70 229);
  --primary-700: rgb(67 56 202);
  --primary-800: rgb(55 48 163);
  --primary-900: rgb(49 46 129);
}

.bg-primary-50 { background-color: var(--primary-50); }
.bg-primary-100 { background-color: var(--primary-100); }
.bg-primary-500 { background-color: var(--primary-500); }
.bg-primary-600 { background-color: var(--primary-600); }
.bg-primary-700 { background-color: var(--primary-700); }
.text-primary-500 { color: var(--primary-500); }
.text-primary-600 { color: var(--primary-600); }
.text-primary-700 { color: var(--primary-700); }
.border-primary-500 { border-color: var(--primary-500); }
.ring-primary-500 { --tw-ring-color: var(--primary-500); }
.focus\:ring-primary-500:focus { --tw-ring-color: var(--primary-500); }
.dark .text-primary-300 { color: var(--primary-300); }
.dark .bg-primary-500\/20 { background-color: rgb(from var(--primary-500) r g b / 0.2); }

/* Base typography */
body { font-family: 'Inter', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
html { scroll-behavior: smooth; }

/* Back to top button */
#back-to-top-btn { position: fixed; bottom: 1.25rem; right: 1.1rem; z-index: 70; display: flex; transition: opacity .25s ease, transform .25s ease; opacity: 0.9; }
#back-to-top-btn:hover { opacity: 1; }
#back-to-top-btn svg { pointer-events: none; }
.dark #back-to-top-btn { backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }

/* Icon button */
.icon-btn { padding: 0.5rem; border-radius: 0.5rem; transition: background-color 0.2s ease-in-out; }
.icon-btn:hover { background-color: rgb(229 231 235); }
.dark .icon-btn:hover { background-color: rgb(55 65 81); }

/* Theme buttons */
.theme-btn.active { background-color: var(--primary-50) !important; }
.dark .theme-btn.active { background-color: rgb(from var(--primary-500) r g b / 0.25) !important; }
html.greyscale .theme-btn.active { filter: grayscale(0.2) brightness(1.05); }

/* Form accents */
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--primary-600); }
.dark input[type="checkbox"], .dark input[type="radio"], .dark input[type="range"] { accent-color: var(--primary-400); }

/* Input placeholder style - muted but consistent */
::placeholder { color: rgb(156 163 175); /* gray-400 */ opacity: 1; }
.dark ::placeholder { color: rgb(107 114 128); /* gray-500 */ opacity: 1; }

/* Password generator slider */
#generator-length-slider {
  height: 6px;
  background-color: #e5e7eb; /* gray-200 */
  border-radius: 9999px;
  outline: none;
}
#generator-length-slider::-webkit-slider-runnable-track {
  height: 6px;
  background-color: #e5e7eb; /* gray-200 */
  border-radius: 9999px;
}
#generator-length-slider::-moz-range-track {
  height: 6px;
  background-color: #e5e7eb;
  border-radius: 9999px;
}
#generator-length-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background-color: var(--primary-600);
  border-radius: 9999px;
  border: 2px solid white;
  margin-top: -6px; /* centers thumb on track */
}
#generator-length-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background-color: var(--primary-600);
  border: 2px solid white;
  border-radius: 9999px;
}
.dark #generator-length-slider {
  background-color: #374151; /* gray-700 */
}
.dark #generator-length-slider::-webkit-slider-runnable-track {
  background-color: #374151; /* gray-700 */
}
.dark #generator-length-slider::-moz-range-track {
  background-color: #374151; /* gray-700 */
}
.dark #generator-length-slider::-webkit-slider-thumb {
  background-color: var(--primary-400);
  border-color: #111827; /* gray-900 */
}
.dark #generator-length-slider::-moz-range-thumb {
  background-color: var(--primary-400);
  border-color: #111827;
}

/* Grid layouts */
.main-grid { grid-template-columns: 280px 1fr 2fr; }
.main-grid.three-column { grid-template-columns: 280px 1fr 1fr; }
.main-grid.two-column { grid-template-columns: 280px 1fr; }

/* Responsive tweaks */
@media (max-width: 1024px) {
  .main-grid { grid-template-columns: 1fr 1.5fr; }
  .main-grid.three-column { grid-template-columns: 1fr 1fr; }
  #third-panel-container { display: none !important; }
  #nav-sidebar { position: fixed; left: -280px; top: 0; height: 100%; z-index: 40; transition: left 0.3s ease-in-out; box-shadow: 0 0 15px rgba(0,0,0,0.2); }
  #nav-sidebar.is-open { left: 0; }
}
@media (max-width: 767px) {
  .main-grid { grid-template-columns: 1fr; }
  #item-list-container.mobile-hidden { display: none; }
  #details-pane-container:not(.mobile-hidden) { display: block; }
  #details-pane-container.mobile-hidden { display: none; }
}

/* Scrollbars */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 10px; }
.dark ::-webkit-scrollbar-track { background: #2d3748; }
::-webkit-scrollbar-thumb { background: #888; border-radius: 10px; }
.dark ::-webkit-scrollbar-thumb { background: #555; }
::-webkit-scrollbar-thumb:hover { background: #555; }
.dark ::-webkit-scrollbar-thumb:hover { background: #777; }

/* Hide scrollbars completely */
.scrollbar-hidden { -ms-overflow-style: none; scrollbar-width: none; }
.scrollbar-hidden::-webkit-scrollbar { display: none; }

/* Scroll isolation */
.scroll-isolated { overscroll-behavior: contain; overscroll-behavior-y: contain; }

/* Hide number spinners */
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { appearance: textfield; -moz-appearance: textfield; }

/* Flash highlight */
@keyframes flashHighlight { 0% { box-shadow: 0 0 0 3px var(--primary-500); background-color: var(--primary-50); } 60% { box-shadow: 0 0 0 0 var(--primary-500); background-color: transparent; } 100% { box-shadow: none; background-color: transparent; } }
.flash-highlight { animation: flashHighlight 1.6s ease-out 1; }

/* Shake animation for errors */
@keyframes shake { 0%, 100% { transform: translateX(0); } 10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); } 20%, 40%, 60%, 80% { transform: translateX(4px); } }
.shake { animation: shake 0.8s ease-in-out; }

/* Shake animation for inline button - maintains position */
@keyframes shakeInline { 
  0%, 100% { transform: translateX(0) translateY(-50%); } 
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px) translateY(-50%); } 
  20%, 40%, 60%, 80% { transform: translateX(4px) translateY(-50%); } 
}
#unlock-button.shake { animation: shakeInline 0.8s ease-in-out; }
#create-vault-button.shake { animation: shakeInline 0.8s ease-in-out; }

/* Error state styling */
.error-state { border-color: #ef4444 !important; box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2) !important; }
.dark .error-state { border-color: #f87171 !important; box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.2) !important; }

/* Enhanced validation message styling */
.validation-message {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  margin-top: 0.5rem;
  transition: all 0.3s ease;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
  box-sizing: border-box;
  line-height: 1.4;
}

.validation-message span {
  flex: 1;
  min-width: 0;
}

.validation-message.error {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.1), rgba(220, 38, 38, 0.05));
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #dc2626;
}

.validation-message.success {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(22, 163, 74, 0.05));
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #16a34a;
}

.validation-message.warning {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(217, 119, 6, 0.05));
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: #d97706;
}

.dark .validation-message.error {
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.15), rgba(239, 68, 68, 0.08));
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

.dark .validation-message.success {
  background: linear-gradient(135deg, rgba(74, 222, 128, 0.15), rgba(34, 197, 94, 0.08));
  border-color: rgba(74, 222, 128, 0.4);
  color: #86efac;
}

.dark .validation-message.warning {
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.08));
  border-color: rgba(251, 191, 36, 0.4);
  color: #fbbf24;
}

/* Invalid master password message - white text in dark mode */
.dark .validation-message.error span {
  color: #ffffff !important;
}

.validation-icon {
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
}

/* Password error container styling */
#password-error {
  min-height: auto;
  overflow: visible;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

#password-error .validation-message {
  margin-top: 0;
  margin-bottom: 0;
  width: 100%;
}

/* Inline unlock button styling */
#unlock-button {
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: background-color 0.3s ease, border-color 0.3s ease;
  transform: translateY(-50%);
}

#unlock-button:active {
  transform: translateY(-50%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#unlock-button:focus {
  transform: translateY(-50%);
}

/* Button error state during shake animation */
#unlock-button.shake {
  background-color: #ef4444 !important;
  border: 2px solid #dc2626 !important;
  box-shadow: 0 0 0 2px #dc2626 !important;
}

#create-vault-button.shake {
  background-color: #ef4444 !important;
  border: 2px solid #dc2626 !important;
  box-shadow: 0 0 0 2px #dc2626 !important;
}

.dark #unlock-button.shake {
  background-color: #f87171 !important;
  border: 2px solid #ef4444 !important;
  box-shadow: 0 0 0 2px #ef4444 !important;
}

.dark #create-vault-button.shake {
  background-color: #f87171 !important;
  border: 2px solid #ef4444 !important;
  box-shadow: 0 0 0 2px #ef4444 !important;
}

/* Error state for lock screen elements */
.error-red {
  color: #ef4444 !important;
}

.dark .error-red {
  color: #f87171 !important;
}

/* Specific rule for banner with text-white class */
#inactivity-banner.error-red {
  color: #dc2626 !important;
  background-color: rgba(239, 68, 68, 0.2) !important;
  border-color: #dc2626 !important;
  backdrop-filter: blur(6px) !important;
  -webkit-backdrop-filter: blur(6px) !important;
}

.dark #inactivity-banner.error-red {
  color: #ffffff !important;
  background-color: rgba(248, 113, 113, 0.2) !important;
  border-color: #f87171 !important;
  backdrop-filter: blur(6px) !important;
  -webkit-backdrop-filter: blur(6px) !important;
}

/* Verify and Import button error state during shake animation */
#verify-and-import-btn.shake {
  background-color: #ef4444 !important;
  border-color: #dc2626 !important;
}

.dark #verify-and-import-btn.shake {
  background-color: #f87171 !important;
  border-color: #ef4444 !important;
}

/* Ensure input padding accounts for button */
#master-password {
  padding-right: 4rem !important;
}

/* Inactivity banner: transparent primary glass with subtle reflection */
#inactivity-banner {
  position: relative;
  background-color: rgb(from var(--primary-600) r g b / 0.12) !important;
  border-color: rgb(from var(--primary-600) r g b / 0.35) !important;
  color: var(--primary-700) !important;
  backdrop-filter: saturate(120%) blur(6px);
  -webkit-backdrop-filter: saturate(120%) blur(6px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
#inactivity-banner::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(135deg, rgba(255,255,255,0.35) 0%, rgba(255,255,255,0.12) 20%, rgba(255,255,255,0) 45%);
  pointer-events: none;
}
.dark #inactivity-banner {
  background-color: rgb(from var(--primary-700) r g b / 0.25) !important;
  border-color: rgb(from var(--primary-600) r g b / 0.5) !important;
  color: #ffffff !important;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.dark #inactivity-banner::before {
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, rgba(255,255,255,0.06) 20%, rgba(255,255,255,0) 45%);
}

/* Greyscale theme - desaturate entire UI while keeping readability */
html.greyscale body {
  filter: grayscale(1) contrast(0.95) brightness(0.97);
}
/* Allow opt-out for specific elements (e.g., logos, strength bar if desired) */
html.greyscale .no-greyscale, html.greyscale .no-greyscale * { filter: none !important; }
/* Slightly reduce desaturation for toast container so feedback remains clear */
html.greyscale #toast-container { filter: grayscale(0.25) brightness(1); }

/* Profile completion banner (ensures good contrast in dark mode) */
.profile-complete-banner {
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  color: var(--primary-700);
}
.dark .profile-complete-banner {
  background: rgb(from var(--primary-600) r g b / 0.18);
  border: 1px solid rgb(from var(--primary-400) r g b / 0.35);
  color: var(--primary-100);
  backdrop-filter: saturate(140%) blur(4px);
  -webkit-backdrop-filter: saturate(140%) blur(4px);
}
.profile-complete-banner svg { color: var(--primary-600); }
.dark .profile-complete-banner svg { color: var(--primary-300); }
