/* Import modern typography */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

/* Color Variables */
:root {
  --bg-color: #0d111d;
  --surface-color: rgba(22, 28, 45, 0.7);
  --surface-border: rgba(255, 255, 255, 0.08);
  --surface-hover: rgba(30, 41, 59, 0.8);
  --primary-color: #6366f1;
  --primary-glow: rgba(99, 102, 241, 0.15);
  --accent-color: #8b5cf6;
  --accent-glow: rgba(139, 92, 246, 0.3);
  --success-color: #10b981;
  --success-glow: rgba(16, 185, 129, 0.2);
  --danger-color: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.2);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-family: 'Outfit', sans-serif;
  --transition-speed: 0.25s;
}

/* Global Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(139, 92, 246, 0.05) 0%, transparent 40%);
  background-attachment: fixed;
  overflow-x: hidden;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-color);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Glassmorphic Container */
.app-container {
  max-width: 1100px;
  margin: 40px auto;
  padding: 24px;
  background: var(--surface-color);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  animation: fadeIn 0.6s ease-out;
}

/* Typography */
h1 {
  font-size: 2.25rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--text-main) 30%, var(--primary-color) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 16px;
}

/* Status Header Bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--surface-border);
  flex-wrap: wrap;
  gap: 16px;
}

.system-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 30px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--surface-border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--success-color);
  box-shadow: 0 0 10px var(--success-color);
}

.status-dot.connecting {
  background-color: #f59e0b;
  box-shadow: 0 0 10px #f59e0b;
  animation: pulse 1.5s infinite ease-in-out;
}

/* Dashboard Cards */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--surface-border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-speed) ease, border-color var(--transition-speed) ease;
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(99, 102, 241, 0.3);
}

.card-title {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-main);
}

.card-icon {
  position: absolute;
  right: 16px;
  bottom: 16px;
  color: rgba(255, 255, 255, 0.05);
  font-size: 3rem;
  pointer-events: none;
}

/* Controls (Search & Filters) */
.controls-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-wrapper {
  position: relative;
  flex-grow: 1;
  max-width: 400px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.search-input {
  width: 100%;
  padding: 12px 16px 12px 42px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--surface-border);
  border-radius: 12px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.95rem;
  transition: all var(--transition-speed) ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(255, 255, 255, 0.07);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.filter-buttons {
  display: flex;
  gap: 10px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: var(--font-family);
  font-size: 0.9rem;
  font-weight: 550;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-speed) ease;
  user-select: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--accent-color) 100%);
  color: #fff;
  box-shadow: 0 4px 14px 0 rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px 0 rgba(99, 102, 241, 0.4);
  filter: brightness(1.1);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--surface-border);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-secondary.active {
  background: var(--primary-color);
  border-color: var(--primary-color);
  box-shadow: 0 0 12px var(--primary-glow);
}

.btn-icon {
  padding: 8px;
  border-radius: 8px;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: #f87171;
}

.btn-danger:hover {
  background: var(--danger-color);
  color: #fff;
  box-shadow: 0 4px 12px var(--danger-glow);
}

.btn-success {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.2);
  color: #34d399;
}

.btn-success:hover {
  background: var(--success-color);
  color: #fff;
  box-shadow: 0 4px 12px var(--success-glow);
}

/* Pantry Table */
.table-wrapper {
  overflow-x: auto;
  border-radius: 14px;
  border: 1px solid var(--surface-border);
  background: rgba(255, 255, 255, 0.01);
  margin-bottom: 24px;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

th {
  background: rgba(255, 255, 255, 0.03);
  padding: 16px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--surface-border);
  user-select: none;
}

th.sortable {
  cursor: pointer;
}

th.sortable:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.sort-icon {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 4px;
  width: 14px;
  height: 14px;
}

td {
  padding: 16px 20px;
  border-bottom: 1px solid var(--surface-border);
  font-size: 0.95rem;
  color: var(--text-main);
  transition: background-color var(--transition-speed) ease;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: var(--surface-hover);
}

/* Editing State */
.edit-input {
  width: 100%;
  padding: 8px 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  color: var(--text-main);
  font-family: var(--font-family);
  font-size: 0.9rem;
  transition: border-color var(--transition-speed) ease;
}

.edit-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.barcode-badge {
  font-family: monospace;
  font-size: 0.85rem;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--surface-border);
}

.quantity-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
  background: rgba(99, 102, 241, 0.1);
  color: #a5b4fc;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.quantity-badge.zero {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.2);
}

.actions-cell {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.pagination-text {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

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

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  margin-bottom: 16px;
  width: 48px;
  height: 48px;
  color: var(--surface-border);
}

/* Modal styling */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

.modal-content {
  background: #151a2d;
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  max-width: 420px;
  width: 90%;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.modal-header-section {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-header-icon {
  width: 24px;
  height: 24px;
  color: var(--danger-color);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-body {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
  line-height: 1.6;
}

.modal-highlight {
  color: var(--text-main);
  font-weight: 600;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 200;
}

.toast {
  background: rgba(22, 28, 45, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid var(--surface-border);
  border-left: 4px solid var(--primary-color);
  border-radius: 12px;
  padding: 16px;
  width: 320px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.scan-toast {
  border-left-color: var(--success-color);
}

.toast.delete-toast {
  border-left-color: var(--danger-color);
}

@keyframes slideIn {
  from {
    transform: translateX(100%) translateY(0);
    opacity: 0;
  }
  to {
    transform: translateX(0) translateY(0);
    opacity: 1;
  }
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast-content {
  flex-grow: 1;
}

.toast-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.toast-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Mobile responsive styles */
@media (max-width: 600px) {
  .barcode-col, .desktop-only-card {
    display: none;
  }
  
  .app-container {
    margin: 10px;
    padding: 16px;
    border-radius: 12px;
  }

  h1 {
    font-size: 1.75rem;
  }

  .status-bar {
    margin-bottom: 20px;
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .card {
    padding: 16px;
  }

  .controls-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .search-wrapper {
    max-width: none;
  }

  .filter-buttons {
    width: 100%;
    justify-content: space-between;
  }

  .filter-buttons button {
    flex-grow: 1;
    font-size: 0.8rem;
    padding: 8px 10px;
  }

  td, th {
    padding: 10px 8px;
    font-size: 0.85rem;
  }

  .actions-cell {
    gap: 4px;
  }

  .btn {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  .btn-icon {
    padding: 6px;
  }
}

.search-link {
  color: var(--primary-color);
  text-decoration: underline;
  text-underline-offset: 4px;
  transition: color var(--transition-speed) ease;
}

.search-link:hover {
  color: var(--accent-color);
}

/* Custom Login Modal styling */
.login-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  min-height: 420px;
  animation: fadeIn 0.4s ease-out;
}

.login-box {
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--surface-border);
  border-radius: 20px;
  width: 100%;
  max-width: 400px;
  padding: 40px 30px;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: modalIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.login-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.login-lock-icon {
  width: 48px;
  height: 48px;
  color: var(--primary-color);
  filter: drop-shadow(0 0 8px var(--primary-glow));
  animation: pulse 2s infinite ease-in-out;
}

.login-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.input-group {
  position: relative;
  width: 100%;
  margin-bottom: 20px;
}

.input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 18px;
  height: 18px;
  pointer-events: none;
}

.login-input {
  padding-left: 42px !important;
}

.login-error-message {
  color: #f87171;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.error-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.login-btn {
  width: 100%;
  padding: 12px;
  margin-top: 10px;
}