/* Modern Design System for Key Recognition App */

:root {
  /* Light theme colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border-light: #e2e8f0;
  --border-medium: #cbd5e1;
  --accent-primary: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --success-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* Dark theme colors */
.dark-mode {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-light: #334155;
  --border-medium: #475569;
  --accent-primary: #60a5fa;
  --accent-hover: #3b82f6;
  --success: #34d399;
  --success-hover: #10b981;
  --warning: #fbbf24;
  --danger: #f87171;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.2), 0 2px 4px -2px rgb(0 0 0 / 0.2);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.2), 0 4px 6px -4px rgb(0 0 0 / 0.2);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.2), 0 8px 10px -6px rgb(0 0 0 / 0.2);
}

/* Image optimization */
.image-container img {
  max-width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 0.5rem;
}

.image-container img[data-bs-toggle="modal"] {
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.image-container img[data-bs-toggle="modal"]:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
}

/* Responsive image sizing */
@media (max-width: 768px) {
  .image-container img {
    max-height: 250px;
  }
}

@media (max-width: 576px) {
  .image-container img {
    max-height: 200px;
  }
}

/* Modal image styling */
#modalImage {
  transition: transform 0.1s ease;
}

/* Base styles */
* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  transition: none; /* Remove transition to prevent flash */
  font-size: 1rem; /* Increased from default 14px */
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 1rem;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.625rem; }
h4 { font-size: 1.375rem; }
h5 { font-size: 1.25rem; }
h6 { font-size: 1.125rem; }

/* Navigation */
.navbar {
  background-color: var(--bg-primary) !important;
  border-bottom: 1px solid var(--border-light);
  box-shadow: var(--shadow-sm);
  padding: 0.75rem 0;
  transition: all 0.3s ease;
}

.navbar-brand {
  font-weight: 600;
  font-size: 1.25rem;
  color: var(--text-primary) !important;
}

.dark-mode-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  cursor: pointer;
}

.dark-mode-toggle:hover {
  background: var(--border-light);
  transform: translateY(-1px);
}

/* Sidebar */
.sidebar-custom {
  background-color: var(--bg-primary) !important;
  border-right: 1px solid var(--border-light) !important;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.sidebar-custom {
  padding: 1.5rem 1rem;
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Folder tree */
.explorer-folder {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  color: var(--text-primary);
}

.explorer-folder:hover {
  background-color: var(--bg-tertiary);
}

.explorer-arrow {
  width: 1rem;
  height: 1rem;
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.folder-icon {
  width: 1rem;
  height: 1rem;
  color: var(--accent-primary);
}

.folder-add {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.25rem;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 0;
  font-size: 0.875rem;
}

.explorer-folder:hover .folder-add {
  opacity: 1;
}

.folder-add:hover {
  color: var(--accent-primary);
  background-color: var(--bg-tertiary);
}

/* Key items */
.key-item {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  border-left: 2px solid transparent;
}

.key-item:hover {
  background-color: var(--bg-tertiary);
  border-left-color: var(--accent-primary);
  color: var(--text-primary);
  text-decoration: none;
  transform: translateX(2px);
}

/* Main content */
.main-content {
  padding: 2rem 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

@media (min-width: 1200px) {
  .main-content {
    padding: 2rem 2.5rem;
  }
}

@media (min-width: 1400px) {
  .main-content {
    padding: 2rem 3rem;
  }
}

/* Cards */
.modern-card {
  background-color: var(--bg-primary);
  border-radius: 0.75rem;
  border: 1px solid var(--border-light);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: all 0.3s ease;
}

.modern-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-header {
  border-bottom: 1px solid var(--border-light);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

/* Forms */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-primary);
  font-size: 0.875rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border-medium);
  border-radius: 0.5rem;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.form-control:disabled {
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
}

/* File input styling */
.file-input-wrapper {
  position: relative;
  display: inline-block;
  cursor: pointer;
  width: 100%;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

.file-input-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 2px dashed var(--border-medium);
  border-radius: 0.5rem;
  background-color: var(--bg-secondary);
  transition: all 0.2s ease;
  min-height: 3rem;
}

.file-input-display:hover {
  border-color: var(--accent-primary);
  background-color: var(--bg-tertiary);
}

.file-input-icon {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--text-muted);
}

.file-input-text {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.file-selected .file-input-display {
  border-color: var(--success);
  background-color: var(--bg-primary);
}

.file-selected .file-input-text {
  color: var(--success);
  font-weight: 500;
}

/* Radio buttons */
.radio-group {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-medium);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: var(--bg-primary);
}

.radio-option:hover {
  border-color: var(--accent-primary);
  background-color: var(--bg-tertiary);
}

.radio-option input[type="radio"] {
  margin: 0;
  accent-color: var(--accent-primary);
}

.radio-option.selected {
  border-color: var(--accent-primary);
  background-color: rgb(59 130 246 / 0.05);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 500;
  font-size: 1rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

/* Center content only for specific form buttons, not navigation buttons */
.btn[type="submit"],
input[type="submit"].btn,
.modal .btn,
form .btn {
  justify-content: center;
  text-align: center;
}

/* Ensure sidebar navigation buttons stay left-aligned */
.sidebar-custom .btn {
  justify-content: flex-start;
  text-align: left;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-secondary:hover {
  background-color: var(--border-light);
  transform: translateY(-1px);
}

.btn-success {
  background-color: var(--success);
  color: white;
  border-color: var(--success);
}

.btn-success:hover {
  background-color: var(--success-hover);
  border-color: var(--success-hover);
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
}

/* Images */
.image-container {
  position: relative;
  border-radius: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all 0.3s ease;
}

.image-container:hover {
  box-shadow: var(--shadow-lg);
  transform: scale(1.02);
}

.image-container img {
  width: 100%;
  height: auto;
  display: block;
}

/* List groups */
.list-group {
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.list-group-item {
  background-color: var(--bg-primary);
  border-color: var(--border-light);
  color: var(--text-primary);
  padding: 1rem;
  border-bottom: 1px solid var(--border-light);
}

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

.list-group-item strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  margin-bottom: 1.5rem;
}

.alert-success {
  background-color: rgb(16 185 129 / 0.1);
  border-color: var(--success);
  color: var(--success);
}

.alert-warning {
  background-color: rgb(245 158 11 / 0.1);
  border-color: var(--warning);
  color: var(--warning);
}

.alert-danger {
  background-color: rgb(239 68 68 / 0.1);
  border-color: var(--danger);
  color: var(--danger);
}

/* Accordion */
.accordion {
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.accordion-item {
  border: none;
  background-color: var(--bg-primary);
}

.accordion-header {
  margin: 0;
}

.accordion-button {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: none;
  padding: 1rem 1.25rem;
  font-weight: 500;
  border-bottom: 1px solid var(--border-light);
}

.accordion-button:not(.collapsed) {
  background-color: var(--bg-tertiary);
  color: var(--accent-primary);
}

.accordion-button:focus {
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.accordion-body {
  padding: 1.25rem;
  background-color: var(--bg-primary);
}

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-muted-dark {
  color: var(--text-muted);
  opacity: 0.85;
}
.dark-mode .text-muted-dark {
  color: #cbd5e1;
  opacity: 1;
}
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-3 { margin-top: 1rem; }
.mt-4 { margin-top: 1.5rem; }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }

/* Responsive design */
@media (max-width: 768px) {
  .main-content {
    padding: 1rem;
  }
  
  .modern-card {
    padding: 1rem;
  }
  
  .radio-group {
    flex-direction: column;
  }
  
  .btn {
    width: 100%;
    justify-content: center;
  }
}

/* Additional utilities and fixes */
.bg-tertiary {
  background-color: var(--bg-tertiary) !important;
}

/* Sidebar styling improvements */
.sidebar-custom {
  padding: 1.5rem 1rem;
}

/* Form control improvements */
.form-control {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
}

.form-control:focus {
  background-color: var(--bg-primary);
  border-color: var(--accent-primary);
  color: var(--text-primary);
  box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

/* Pre/code styling */
pre {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 0.875rem;
  line-height: 1.4;
}

/* Dark mode improvements for Bootstrap overrides */
.dark-mode .list-group-item {
  background-color: var(--bg-primary);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.dark-mode .accordion-button {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.dark-mode .accordion-button:not(.collapsed) {
  background-color: var(--bg-tertiary);
  color: var(--accent-primary);
  border-color: var(--border-light);
  box-shadow: none;
}

.dark-mode .accordion-button:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.25);
}

.dark-mode .accordion-body {
  background-color: var(--bg-primary);
  border-color: var(--border-light);
}

/* Custom scrollbar for dark mode */
.dark-mode ::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.dark-mode ::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.dark-mode ::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}

.dark-mode ::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Loading states */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

/* Focus states */
.btn:focus,
.form-control:focus,
.radio-option:focus-within {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Animation improvements */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.modern-card {
  animation: fadeIn 0.3s ease-out;
}

/* Mobile improvements */
@media (max-width: 768px) {
  .sidebar-custom {
    position: fixed;
    top: 73px;
    left: -300px;
    width: 300px;
    height: calc(100vh - 73px);
    transition: left 0.3s ease;
    z-index: 1000;
    box-shadow: var(--shadow-xl);
  }
  
  .sidebar-custom.show {
    left: 0;
  }
  
  .main-content {
    padding: 1rem;
  }
  
  .row > .col-md-6,
  .row > .col-md-7,
  .row > .col-md-5 {
    margin-bottom: 1.5rem;
  }
  
  .d-flex.justify-content-between {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
  
  .card-title {
    font-size: 1.125rem;
  }
}

/* Print styles */
@media print {
  .sidebar-custom,
  .btn,
  .accordion-button {
    display: none !important;
  }
  
  .main-content {
    padding: 0;
  }
  
  .modern-card {
    box-shadow: none;
    border: 1px solid #000;
  }
}

/* Dark mode improvements and folder hierarchy fixes */
.folder-add-root {
  background: var(--bg-primary) !important;
  border: 1px solid var(--border-medium) !important;
  color: var(--text-secondary) !important;
  padding: 0.375rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  opacity: 1;
}

.folder-add-root:hover,
.folder-add-root:focus {
  color: var(--accent-primary) !important;
  background-color: var(--bg-tertiary) !important;
  border-color: var(--accent-primary) !important;
  transform: scale(1.05);
}

.folder-add {
  background: var(--bg-primary) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text-secondary) !important;
}

.folder-add:hover,
.folder-add:focus {
  color: var(--accent-primary) !important;
  background-color: var(--bg-tertiary) !important;
  border-color: var(--accent-primary) !important;
}

/* Improved folder alignment */
.explorer-folder {
  display: flex;
  align-items: center;
  min-height: 2rem;
}

.explorer-arrow {
  width: 16px;
  height: 16px;
  margin-right: 0.5rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.folder-spacer {
  width: 16px;
  height: 16px;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.folder-icon {
  width: 16px !important;
  height: 16px !important;
  margin-right: 0.5rem;
  flex-shrink: 0;
}

.folder-label {
  flex-grow: 1;
  color: var(--text-primary);
  font-size: 0.875rem;
}

/* Ensure dark mode visibility for all interactive elements */
.dark-mode .btn-close {
  filter: invert(1);
}

.dark-mode .modal-content {
  background-color: var(--bg-primary);
  border-color: var(--border-medium);
}

.dark-mode .modal-header {
  border-bottom-color: var(--border-medium);
}

/* Image modal improvements - proper initial sizing */
.modal-body {
  background: var(--bg-primary);
}

#zoomContainer {
  background: var(--bg-primary) !important;
  display: flex;
  align-items: center;
  justify-content: center;
}

#modalImage {
  background: var(--bg-primary);
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.dark-mode .sidebar-custom {
  background-color: var(--bg-secondary) !important;
  border-right: 1px solid var(--border-medium) !important;
}
.dark-mode .key-item {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}
.dark-mode .key-item:hover {
  background-color: var(--bg-tertiary);
}
.dark-mode .folder-header {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
}
.dark-mode .folder-item {
  background-color: transparent !important;
  color: var(--text-primary) !important;
}
.dark-mode .folder-header:hover {
  background-color: rgba(255, 255, 255, 0.12) !important;
  border-color: rgba(108, 117, 125, 0.5) !important;
}
.dark-mode .modern-card,
.dark-mode .card {
  background-color: var(--bg-primary) !important;
  color: var(--text-primary) !important;
}
.dark-mode .breadcrumb-item.active {
  color: var(--accent-primary) !important;
  opacity: 1;
}

/* Removed custom #deleteKeyModal styles for stability */

#keyList {
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  padding: 0.5rem 0;
}
.dark-mode #keyList {
  background: var(--bg-secondary);
}
