/* ===========================
   1. Custom Properties
   =========================== */
:root,
[data-theme="light"] {
  /* Brand Gradient */
  --gradient-brand: linear-gradient(135deg, #6366F1 0%, #8B5CF6 50%, #EC4899 100%);
  --gradient-brand-hover: linear-gradient(135deg, #4F46E5 0%, #7C3AED 50%, #DB2777 100%);

  /* Primary */
  --color-primary: #6366F1;
  --color-primary-hover: #4F46E5;
  --color-primary-active: #4338CA;
  --color-primary-light: #EEF2FF;
  --color-primary-100: #E0E7FF;
  --color-primary-200: #C7D2FE;

  /* Status */
  --color-success: #10B981;
  --color-warning: #F59E0B;
  --color-error: #EF4444;
  --color-info: #3B82F6;

  /* Neutrals */
  --color-bg-primary: #FFFFFF;
  --color-bg-secondary: #F8FAFC;
  --color-bg-tertiary: #F1F5F9;
  --color-border: #E2E8F0;
  --color-border-hover: #CBD5E1;
  --color-text-primary: #0F172A;
  --color-text-secondary: #475569;
  --color-text-tertiary: #94A3B8;

  /* Glass */
  --glass-bg: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(255, 255, 255, 0.3);
  --glass-shadow: 0 8px 32px rgba(99, 102, 241, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  --glass-shadow-hover: 0 12px 40px rgba(99, 102, 241, 0.12), 0 4px 12px rgba(0, 0, 0, 0.06);

  /* Fonts */
  --font-display: 'Plus Jakarta Sans', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  --space-3xl: 4rem;

  /* Radii */
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --radius-2xl: 1.5rem;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] {
  --color-bg-primary: #0F172A;
  --color-bg-secondary: #1E293B;
  --color-bg-tertiary: #334155;
  --color-border: #334155;
  --color-border-hover: #475569;
  --color-text-primary: #F8FAFC;
  --color-text-secondary: #CBD5E1;
  --color-text-tertiary: #64748B;
  --color-primary-light: rgba(99, 102, 241, 0.15);

  --glass-bg: rgba(15, 23, 42, 0.6);
  --glass-border: rgba(148, 163, 184, 0.1);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
  --glass-shadow-hover: 0 16px 48px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* ===========================
   2. Base / Reset
   =========================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent FOUC */
html:not([data-theme]) {
  visibility: hidden;
}

[data-theme] {
  transition: background-color 300ms ease, color 300ms ease;
}

body {
  font-family: var(--font-body);
  color: var(--color-text-primary);
  background: var(--color-bg-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ===========================
   3. Typography
   =========================== */
.font-display {
  font-family: var(--font-display);
}

.font-mono {
  font-family: var(--font-mono);
}

.gradient-text {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===========================
   4. Glass Components
   =========================== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--glass-shadow);
  transition: box-shadow var(--transition-slow), transform var(--transition-slow);
}

.glass-card:hover {
  box-shadow: var(--glass-shadow-hover);
}

.glass-1 {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.glass-3 {
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.4);
}

[data-theme="dark"] .glass-1 {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

[data-theme="dark"] .glass-3 {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid rgba(148, 163, 184, 0.15);
}

@supports not (backdrop-filter: blur(16px)) {
  .glass-card { background: rgba(255, 255, 255, 0.95); }
  [data-theme="dark"] .glass-card { background: rgba(15, 23, 42, 0.95); }
}

/* ===========================
   5. Buttons
   =========================== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--gradient-brand);
  color: #FFFFFF;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

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

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: transparent;
  color: var(--color-primary);
  border: 1.5px solid var(--color-border);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn-secondary:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1.5px solid var(--color-border);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-base);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-icon.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

.btn-icon-sm {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border-width: 1px;
}

/* ===========================
   6. Password Display
   =========================== */
.password-display {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--color-bg-tertiary);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-family: var(--font-mono);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  word-break: break-all;
  transition: border-color var(--transition-base);
  min-height: 64px;
}

.password-display:hover {
  border-color: var(--color-primary);
}

.password-text {
  flex: 1;
  line-height: 1.4;
}

/* Character color coding */
.char-upper { color: #6366F1; }
.char-lower { color: var(--color-text-primary); }
.char-digit { color: #10B981; }
.char-special { color: #EC4899; }

[data-theme="dark"] .char-upper { color: #818CF8; }
[data-theme="dark"] .char-digit { color: #34D399; }
[data-theme="dark"] .char-special { color: #F472B6; }

/* ===========================
   7. Range Slider
   =========================== */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--color-bg-tertiary);
  outline: none;
  transition: background var(--transition-base);
}

.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 3px solid var(--color-primary);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  cursor: pointer;
  transition: all var(--transition-base);
  margin-top: -8px;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #FFFFFF;
  border: 3px solid var(--color-primary);
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  cursor: pointer;
}

.slider::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: transparent;
}

.slider-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--color-primary);
  min-width: 3ch;
  text-align: right;
}

/* ===========================
   8. Checkboxes
   =========================== */
.checkbox-option {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition-fast);
  user-select: none;
}

.checkbox-option:hover {
  background: var(--color-bg-tertiary);
}

.checkbox-option input[type="checkbox"] {
  display: none;
}

.checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  flex-shrink: 0;
  position: relative;
}

.checkbox-option input:checked + .checkbox-custom {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.checkbox-option input:checked + .checkbox-custom::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid #FFF;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.checkbox-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

/* ===========================
   9. Strength Indicator
   =========================== */
.strength-bars {
  display: flex;
  gap: 4px;
  flex: 1;
}

.strength-bar {
  height: 4px;
  flex: 1;
  border-radius: 2px;
  background: var(--color-bg-tertiary);
  transition: all 300ms ease;
  transform-origin: left;
}

.strength-bar.active[data-strength="weak"] { background: #EF4444; }
.strength-bar.active[data-strength="fair"] { background: #F59E0B; }
.strength-bar.active[data-strength="good"] { background: #3B82F6; }
.strength-bar.active[data-strength="strong"] { background: #10B981; }
.strength-bar.active[data-strength="excellent"] { background: #6366F1; }

.strength-label {
  font-size: 0.875rem;
  font-weight: 600;
  min-width: 70px;
  text-align: right;
  transition: color var(--transition-base);
}

.strength-label[data-strength="weak"] { color: #EF4444; }
.strength-label[data-strength="fair"] { color: #F59E0B; }
.strength-label[data-strength="good"] { color: #3B82F6; }
.strength-label[data-strength="strong"] { color: #10B981; }
.strength-label[data-strength="excellent"] { color: #6366F1; }

/* ===========================
   10. Tabs
   =========================== */
.tabs {
  display: flex;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 4px;
}

.tab {
  flex: 1;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab.active {
  background: var(--color-bg-primary);
  color: var(--color-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ===========================
   11. Toast
   =========================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 12px 24px;
  background: var(--color-text-primary);
  color: var(--color-bg-primary);
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 500;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===========================
   12. Modal
   =========================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-slow);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: var(--color-bg-primary);
  border-radius: var(--radius-2xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.2);
  max-width: 440px;
  width: 100%;
  padding: var(--space-xl);
  transform: translateY(20px) scale(0.95);
  transition: all var(--transition-slow);
  z-index: 1000;
}

.modal-overlay.active .modal-content {
  transform: translateY(0) scale(1);
}

/* ===========================
   13. Input
   =========================== */
.input {
  width: 100%;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  outline: none;
  transition: all var(--transition-base);
}

.input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.input::placeholder {
  color: var(--color-text-tertiary);
}

/* ===========================
   14. History & Favorites Items
   =========================== */
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  border-bottom: 1px solid var(--color-border);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item:hover {
  background: var(--color-bg-tertiary);
}

.history-item-password {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  color: var(--color-text-primary);
  word-break: break-all;
  flex: 1;
  line-height: 1.3;
}

.history-item-meta {
  font-size: 0.7rem;
  color: var(--color-text-tertiary);
  white-space: nowrap;
}

.history-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.item-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: transparent;
  border: none;
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.item-action-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-primary);
}

.item-action-btn.delete:hover {
  color: var(--color-error);
}

/* Slide-out animation */
.history-item.removing {
  animation: slideOutLeft 200ms ease forwards;
}

/* ===========================
   15. Export Dropdown
   =========================== */
.export-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--color-bg-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 4px;
  z-index: 100;
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: all var(--transition-fast);
}

.export-dropdown.active {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.export-dropdown button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.export-dropdown button:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
}

/* ===========================
   16. Animations
   =========================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes charReveal {
  0% { opacity: 0; transform: translateY(-8px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes slideOutLeft {
  to {
    opacity: 0;
    transform: translateX(-30px);
    height: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin: 0;
    overflow: hidden;
  }
}

@keyframes barFill {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@keyframes bounceIn {
  0% { transform: scale(0.8); opacity: 0; }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

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

.animate-fade-in-up {
  animation: fadeInUp 500ms ease forwards;
}

.animate-delay-1 { animation-delay: 100ms; opacity: 0; }
.animate-delay-2 { animation-delay: 200ms; opacity: 0; }
.animate-delay-3 { animation-delay: 300ms; opacity: 0; }

/* ===========================
   17. Scrollbar
   =========================== */
.custom-scrollbar::-webkit-scrollbar {
  width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: transparent;
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

/* ===========================
   18. Empty State
   =========================== */
.empty-state {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
  color: var(--color-text-tertiary);
  font-size: 0.875rem;
}

.empty-state svg {
  opacity: 0.3;
  margin-bottom: 8px;
}

/* ===========================
   19. Responsive
   =========================== */
@media (max-width: 639px) {
  .password-display {
    font-size: 1.05rem;
    padding: 12px 14px;
    letter-spacing: 0.03em;
  }

  .slider-value {
    font-size: 1rem;
  }

  .btn-primary {
    width: 100%;
    padding: 14px 24px;
  }

  .secondary-grid {
    gap: 1rem;
  }
}

@media (min-width: 640px) {
  .password-display {
    font-size: 1.25rem;
  }
}

@media (min-width: 768px) {
  .password-display {
    font-size: 1.35rem;
  }
}

/* ===========================
   20. Accessibility
   =========================== */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

*:focus:not(:focus-visible) {
  outline: none;
}

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

/* ===========================
   21. Print
   =========================== */
@media print {
  #bgCanvas, .toast, .modal-overlay, header button {
    display: none !important;
  }
  .glass-card {
    backdrop-filter: none;
    background: white;
    box-shadow: none;
    border: 1px solid #ccc;
  }
}

/* ===========================
   22. Misc Utilities
   =========================== */
.truncate-password {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
  display: inline-block;
}

.favorite-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.strength-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.strength-dot[data-strength="weak"] { background: #EF4444; }
.strength-dot[data-strength="fair"] { background: #F59E0B; }
.strength-dot[data-strength="good"] { background: #3B82F6; }
.strength-dot[data-strength="strong"] { background: #10B981; }
.strength-dot[data-strength="excellent"] { background: #6366F1; }
