*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --primary-dark: #1b4332;
  --bg: #f8f9fa;
  --card-bg: #fff;
  --text: #212529;
  --text-light: #6c757d;
  --border: #dee2e6;
  --danger: #dc3545;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* Ensure hidden attribute works even with other display styles */
[hidden] {
  display: none !important;
}

/* Login Page */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  background: var(--card-bg);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 380px;
}

.login-container h1 {
  text-align: center;
  color: var(--primary);
  margin-bottom: 1.5rem;
  font-size: 1.8rem;
}

/* Header */
header {
  background: var(--primary);
  color: #fff;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.4rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

#user-info {
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, opacity 0.2s;
}

.btn:hover {
  opacity: 0.9;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-light);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}

.btn-small:hover {
  background: rgba(255,255,255,0.3);
}

.btn-full {
  width: 100%;
  padding: 0.65rem;
}

.btn-cancel {
  background: var(--border);
  color: var(--text);
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.3rem;
  font-size: 1rem;
  color: var(--text-light);
}

.btn-icon:hover {
  color: var(--text);
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(45,106,79,0.15);
}

.form-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.form-row .form-group {
  flex: 1;
  min-width: 150px;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: #f8d7da;
  border-radius: var(--radius);
}

/* Main */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Controls */
.controls {
  margin-bottom: 1rem;
}

#search-input {
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
  background: var(--card-bg);
}

#search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(45,106,79,0.15);
}

.category-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.tab {
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card-bg);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* Recipe Count */
.recipe-count {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 0.75rem;
}

/* Recipe Grid */
.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.recipe-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.recipe-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.recipe-card-img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: #e9ecef;
}

.recipe-card-img-placeholder {
  width: 100%;
  height: 160px;
  background: linear-gradient(135deg, #e9ecef 0%, #dee2e6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 2rem;
}

.recipe-card-body {
  padding: 0.75rem;
}

.recipe-card-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 12px;
  font-size: 0.75rem;
  background: #e9ecef;
  color: var(--text-light);
}

.badge-fruehstueck { background: #ffeaa7; color: #6c5c00; }
.badge-hauptmahlzeiten { background: #dfe6e9; color: #2d3436; }
.badge-desserts { background: #fab1a0; color: #6b2d1e; }
.badge-kleinigkeiten { background: #a29bfe; color: #2d1b69; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal:not([hidden]) {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 550px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal-large {
  max-width: 700px;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-light);
  line-height: 1;
  padding: 0.25rem;
}

.modal-close:hover {
  color: var(--text);
}

/* Detail view */
.detail-image {
  width: 100%;
  max-height: 350px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.detail-title {
  font-size: 1.4rem;
  margin-bottom: 0.5rem;
}

.detail-meta {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.detail-section {
  margin-bottom: 1.25rem;
}

.portion-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
  margin-bottom: 0.5rem;
}

.portion-row h3 {
  font-size: 1rem;
  color: var(--primary);
  margin: 0;
  border: none;
  padding: 0;
}

.portion-control {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.portion-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  color: var(--text);
  transition: background 0.15s;
}

.portion-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.portion-count {
  font-weight: 700;
  font-size: 1rem;
  min-width: 1.5rem;
  text-align: center;
}

.portion-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

.detail-section h3 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}

.detail-section ul {
  padding-left: 1.25rem;
}

.detail-section li {
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.detail-steps {
  white-space: pre-line;
  font-size: 0.9rem;
  line-height: 1.6;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.detail-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.9rem;
}

.detail-link:hover {
  text-decoration: underline;
}

/* Users list */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child {
  border-bottom: none;
}

.user-info-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge-admin {
  background: var(--primary);
  color: #fff;
}

/* Admin button spacing */
#btn-add-recipe {
  margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .recipe-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  .modal-content {
    padding: 1rem;
  }

  .form-row {
    flex-direction: column;
  }
}
