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

:root {
  --primary: #ff6b6b;
  --primary-dark: #ee5a52;
  --secondary: #4ecdc4;
  --bg: #f8f9fa;
  --card: #ffffff;
  --text: #2d3436;
  --text-light: #636e72;
  --border: #dfe6e9;
  --shadow: rgba(0, 0, 0, 0.1);
  --success: #00b894;
  --danger: #d63031;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* Header */
.header {
  background: var(--card);
  box-shadow: 0 2px 10px var(--shadow);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 2rem;
}

.header h1 {
  font-size: 1.5rem;
  color: var(--primary);
  white-space: nowrap;
}

/* Desktop Navigation */
.desktop-nav {
  display: none;
  gap: 1rem;
  flex: 1;
}

.desktop-nav .nav-link {
  color: var(--text);
  text-decoration: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  transition: all 0.3s;
  font-weight: 500;
  white-space: nowrap;
}

.desktop-nav .nav-link:hover {
  background: var(--bg);
  color: var(--primary);
}

.desktop-nav .nav-link.active {
  background: var(--primary);
  color: white;
}

@media (min-width: 768px) {
  .desktop-nav {
    display: flex;
  }
  
  .hamburger {
    display: none;
  }
}

.hamburger {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  display: block;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-name {
  font-weight: 600;
  color: var(--text);
}

.login-btn {
  padding: 0.5rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.login-btn:hover {
  background: var(--primary-dark);
}

/* Mobile Menu */
.mobile-menu {
  position: fixed;
  top: 0;
  left: -100%;
  width: 280px;
  height: 100vh;
  background: var(--card);
  box-shadow: 2px 0 20px var(--shadow);
  z-index: 200;
  transition: left 0.3s;
  padding: 2rem;
}

.mobile-menu.active {
  left: 0;
}

.close-menu {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  float: right;
  color: var(--text);
}

.menu-nav {
  margin-top: 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.menu-nav a {
  padding: 1rem;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
  transition: background 0.3s;
  font-weight: 500;
}

.menu-nav a:hover,
.menu-nav a.active {
  background: var(--bg);
}

.logout-btn {
  margin-top: 2rem;
  padding: 0.75rem;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

/* Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 300;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  max-width: 400px;
  width: 90%;
  position: relative;
  box-shadow: 0 10px 40px var(--shadow);
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
}

.modal-content h2 {
  margin-bottom: 1.5rem;
  color: var(--primary);
}

.modal-content form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-content input {
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.modal-content button[type="submit"] {
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
}

.error-message {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.success-message {
  color: var(--success);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* Search Section */
.search-section {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
  margin-bottom: 2rem;
}

.search-section h2 {
  margin-bottom: 1.5rem;
  color: var(--text);
}

.search-type-toggle {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.toggle-btn {
  padding: 0.5rem 1.5rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s;
}

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

.search-box {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.search-box input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.search-box button {
  padding: 0.75rem 2rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

.search-box button:hover {
  background: var(--primary-dark);
}

.search-hint {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Results Section */
.results-section {
  margin-top: 2rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.results-header h3 {
  color: var(--text);
}

.results-count {
  color: var(--text-light);
  font-size: 0.9rem;
}

/* Recipe Cards */
.recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.5rem;
  overflow-anchor: none; /* Prevent scroll anchoring issues */
  margin-bottom: 2rem;
}

.recipe-card {
  background: var(--card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 10px var(--shadow);
  transition: transform 0.3s, box-shadow 0.3s;
  position: relative;
}

.recipe-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 5px 20px var(--shadow);
}

.recipe-image {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--bg);
}

.recipe-content {
  padding: 1.25rem;
}

.recipe-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
  line-height: 1.4;
}

.recipe-ingredients {
  color: var(--text-light);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}

.recipe-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}

.btn-view {
  flex: 1;
  padding: 0.5rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}

.btn-favorite {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 2px solid var(--primary);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.2rem;
  transition: all 0.3s;
}

.btn-favorite.active {
  background: var(--primary);
}

.btn-share {
  padding: 0.5rem 1rem;
  background: transparent;
  border: 2px solid var(--text-light);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.3s;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-top: 2rem;
}

.pagination button {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.pagination button:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.pagination span {
  font-weight: 600;
  color: var(--text);
}

/* Favorites */
.favorites-section,
.shopping-list-section {
  background: var(--card);
  padding: 2rem;
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
}

.favorites-header {
  margin-bottom: 2rem;
}

.favorites-header h2 {
  margin-bottom: 0.5rem;
}

.favorites-header p {
  color: var(--text-light);
}

.empty-state,
.login-prompt {
  text-align: center;
  padding: 3rem 1rem;
}

.empty-state h3,
.prompt-card h3 {
  margin-bottom: 0.5rem;
  color: var(--text);
}

.empty-state p,
.prompt-card p {
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.btn-primary {
  display: inline-block;
  padding: 0.75rem 2rem;
  background: var(--primary);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
}

/* Shopping List */
.list-selector {
  margin-bottom: 2rem;
}

.list-selector h2 {
  margin-bottom: 1rem;
}

.list-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.btn-primary,
.btn-secondary {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.3s;
}

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

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 2px solid var(--border);
}

.lists-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.list-item {
  background: var(--bg);
  padding: 1.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s;
  border: 2px solid transparent;
}

.list-item:hover {
  border-color: var(--primary);
  background: white;
}

.list-item h4 {
  margin-bottom: 0.5rem;
}

.list-item p {
  color: var(--text-light);
  font-size: 0.85rem;
}

.active-list {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 2px solid var(--border);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.list-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-danger {
  padding: 0.5rem 1rem;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.add-item-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.add-item-form input {
  flex: 1;
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.add-item-form button {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.5rem;
}

.shopping-items {
  list-style: none;
}

.shopping-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

.shopping-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

.shopping-item span {
  flex: 1;
}

.shopping-item.checked span {
  text-decoration: line-through;
  color: var(--text-light);
}

.shopping-item button {
  padding: 0.25rem 0.5rem;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.share-code-box {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin-top: 1rem;
}

.share-code-box code {
  flex: 1;
  padding: 1rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 1.2rem;
  font-weight: bold;
}

.copy-btn {
  padding: 0.75rem 1.5rem;
  background: var(--secondary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

/* Admin */
.admin-panel {
  padding: 2rem;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 2px 10px var(--shadow);
}

.add-user-form {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg);
  border-radius: 8px;
}

.add-user-form h3 {
  margin-bottom: 1rem;
}

.add-user-form form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 1rem;
}

.add-user-form input,
.add-user-form select {
  padding: 0.75rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.add-user-form button {
  padding: 0.75rem 1.5rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
}

.users-list h3 {
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th {
  background: var(--bg);
  padding: 1rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

.access-denied {
  text-align: center;
  padding: 3rem 1rem;
}

.access-denied h2 {
  color: var(--danger);
  margin-bottom: 1rem;
}

.access-denied p {
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

/* Mobile */
@media (max-width: 768px) {
  .hamburger {
    display: block;
  }

  .header h1 {
    font-size: 1.2rem;
  }

  .container {
    padding: 1rem;
  }

  .search-box {
    flex-direction: column;
  }

  .recipes-grid {
    grid-template-columns: 1fr;
  }

  .add-user-form form {
    grid-template-columns: 1fr;
  }

  .list-header {
    flex-direction: column;
    align-items: flex-start;
  }
}
