/* Updated: 2025-11-14 16:30 - Søk renamed to Måltid, dynamic carbfree list */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  background: #f5f7fa;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
}

/* Header & Navigation */
header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 0;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (max-width: 768px) {
  .header-content {
    padding: 1.25rem 1rem;
  }
}

.logo {
  font-size: 1.8rem;
  font-weight: bold;
  flex-shrink: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

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

.user-info.logged-in {
  display: flex;
}

.user-name {
  font-size: 0.9rem;
  opacity: 0.9;
}

.logout-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Hamburger Menu */
.hamburger-menu {
  position: relative;
}

.menu-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: white;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.3rem;
  transition: all 0.2s ease;
  line-height: 1;
}

.menu-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  right: 0;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 200px;
  z-index: 1000;
  overflow: hidden;
}

.dropdown-menu a {
  display: block;
  padding: 0.75rem 1rem;
  color: #2d3748;
  text-decoration: none;
  transition: background 0.2s;
  border-bottom: 1px solid #e2e8f0;
}

.dropdown-menu a:last-child {
  border-bottom: none;
}

.dropdown-menu a:hover {
  background: #f7fafc;
  color: #667eea;
}

nav {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
}

nav ul {
  list-style: none;
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
}

nav li {
  flex: 1;
}

nav a {
  display: block;
  padding: 0.75rem 1rem;
  color: white;
  text-decoration: none;
  text-align: center;
  transition: all 0.3s ease;
  border-bottom: 3px solid transparent;
  font-weight: 500;
  font-size: 0.95rem;
  white-space: nowrap;
}

nav a:hover {
  background: rgba(255, 255, 255, 0.15);
  border-bottom-color: rgba(255, 255, 255, 0.8);
}

nav a.active {
  background: rgba(255, 255, 255, 0.2);
  border-bottom-color: white;
}

nav a.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

nav a.locked::after {
  content: " 🔒";
}

/* Main Content */
main {
  max-width: 1200px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.page {
  display: none;
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.page.active {
  display: block;
  animation: fadeIn 0.3s ease-in;
}

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

h1 {
  display: none;
}

/* Login Page */
.login-container {
  max-width: 400px;
  margin: 4rem auto;
  background: white;
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.login-container h1 {
  border: none;
  text-align: center;
  color: #667eea;
}

/* Cards */
.card {
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1rem 0;
}

.card h3 {
  color: #667eea;
  margin-bottom: 0.5rem;
}

/* Buttons */
.btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.2s ease;
  font-weight: 500;
  width: 100%;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Forms */
.form-group {
  margin: 1rem 0;
}

label {
  display: block;
  color: #4a5568;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

input, select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 1rem;
}

input:focus, select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.error-message {
  color: #ff6b6b;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  display: none;
}

.error-message.show {
  display: block;
}

/* Status indicator */
.status {
  background: white;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #4a5568;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  border-left: 4px solid #cbd5e0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.status.connected {
  border-left-color: #51cf66;
  color: #2d3748;
}

.status.error {
  border-left-color: #ff6b6b;
  color: #2d3748;
}

.sugar-level {
  background: white;
  padding: 0.5rem 0.8rem;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #4a5568;
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  border-left: 4px solid #f59f0b;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

/* System bottom button */
.system-bottom-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem;
  text-align: center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  margin-top: 2rem;
}

.system-bottom-btn a {
  display: block;
  color: white;
  text-decoration: none;
  font-weight: 500;
  font-size: 1rem;
  padding: 0.5rem;
}

.system-bottom-btn a.locked::after {
  content: " 🔒";
}

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

.access-denied h2 {
  color: #ff6b6b;
  margin-bottom: 1rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 2px solid #e2e8f0;
}

.tab {
  padding: 0.75rem 1.5rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: #718096;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.tab:hover {
  color: #667eea;
  background: #f7fafc;
}

.tab.active {
  color: #667eea;
  border-bottom-color: #667eea;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Food Input Rows */
.food-row {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 1rem;
  margin-bottom: 0.5rem;
  align-items: end;
  padding: 0.75rem;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.food-row.has-value {
  background: #f7fafc;
  border: 2px solid #e2e8f0;
  border-left: 4px solid #667eea;
  padding: 0.75rem;
  margin-bottom: 1rem;
}

.desktop-only {
  display: block;
}

.food-row input {
  margin: 0;
}

.remove-btn {
  background: #ff6b6b;
  color: white;
  border: none;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.remove-btn:hover {
  background: #ff5252;
}

.add-row-btn {
  background: #51cf66;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  margin-top: 0.5rem;
  transition: all 0.2s ease;
}

.add-row-btn:hover {
  background: #40c057;
}

.total-display {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1.5rem;
  border-radius: 8px;
  margin-top: 1.5rem;
  text-align: center;
}

.total-display h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
}

.total-display .total-number {
  font-size: 2.5rem;
  font-weight: bold;
}

.total-display .total-unit {
  font-size: 1rem;
  opacity: 0.9;
}

/* Autocomplete dropdown */
.autocomplete-dropdown {
  position: absolute;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Search Results */
.search-results {
  margin-top: 1rem;
  max-height: 400px;
  overflow-y: auto;
}

.search-item {
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 1rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-item:hover {
  background: #edf2f7;
  border-color: #667eea;
}

.search-item-info {
  flex: 1;
}

.search-item-name {
  font-weight: 600;
  color: #2d3748;
  margin-bottom: 0.25rem;
}

.search-item-carbs {
  color: #667eea;
  font-size: 0.9rem;
}

.add-item-btn {
  background: #667eea;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.add-item-btn:hover {
  background: #5568d3;
}

.calculator-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

/* Food Database Management */
.food-db-item {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 1rem;
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 1rem;
}

.food-db-item input {
  margin: 0;
}

.food-db-item .delete-btn {
  background: #ff6b6b;
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.food-db-item .delete-btn:hover {
  background: #ff5252;
}

/* ==================== MOBILE OPTIMIZATIONS ==================== */
@media (max-width: 768px) {
  /* Compact header */
  .header-content {
    padding: 0.4rem 0.5rem !important;
  }

  .logo {
    font-size: 1rem;
    font-weight: 700;
  }

  /* Ultra-compact navigation */
  nav a {
    padding: 0.4rem 0.15rem;
    font-size: 0.65rem;
    font-weight: 600;
  }

  /* Hide "Hjem" on mobile to save space */
  nav ul li:first-child {
    display: none;
  }

  /* Compact status indicators */
  .header-right {
    gap: 0.3rem;
  }

  .status, .sugar-level {
    font-size: 0.6rem;
    padding: 0.25rem 0.4rem;
    border-left-width: 2px;
    gap: 0.25rem;
  }

  .status span:first-child,
  .sugar-level span:first-child {
    font-size: 0.75rem;
  }

  /* Minimal main padding */
  main {
    margin: 0;
    padding: 0.5rem 0.5rem 1rem 0.5rem;
  }

  .page {
    padding: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }

  /* Hide page titles */
  h1 {
    display: none;
  }

  /* Compact cards with modern shadows */
  .card {
    background: #fff;
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 0.75rem;
    margin: 0.5rem 0;
    border-radius: 10px;
  }

  .card h3 {
    font-size: 0.95rem;
    margin-bottom: 0.4rem;
    font-weight: 700;
  }

  .card > p {
    font-size: 0.8rem;
    margin-bottom: 0.5rem !important;
    line-height: 1.4;
  }

  /* Compact form elements */
  .form-group {
    margin: 0.5rem 0;
  }

  .form-group label {
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
    font-weight: 600;
  }

  .form-group small {
    font-size: 0.7rem !important;
    line-height: 1.3;
    margin-bottom: 0.25rem !important;
    display: block;
  }

  input, select {
    padding: 0.6rem 0.7rem;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  /* Single column grid */
  .calculator-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem !important;
  }

  .calculator-grid .form-group {
    margin-bottom: 0.5rem;
  }

  /* Compact food rows */
  .food-row {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    padding: 0.6rem;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 0.5rem;
  }

  .food-row .form-group {
    margin: 0;
  }

  .food-row label {
    font-size: 0.8rem;
  }

  .remove-btn {
    width: 100%;
    padding: 0.6rem;
    font-size: 0.8rem;
    border-radius: 8px;
  }

  /* Compact total display */
  .total-display {
    padding: 0.75rem;
    margin-top: 0.75rem;
    border-radius: 10px;
  }

  .total-display h3 {
    font-size: 0.85rem;
  }

  /* Buttons */
  .btn {
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    border-radius: 8px;
  }

  /* Compact database items */
  .food-db-item {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: 8px;
  }

  .food-db-item .delete-btn {
    width: 100%;
    padding: 0.6rem;
    font-size: 0.85rem;
  }

  /* Selected food items - compact */
  .selected-food-item {
    padding: 0.6rem !important;
    margin-bottom: 0.5rem !important;
    border-radius: 8px;
  }

  .selected-food-item > div {
    grid-template-columns: 1fr !important;
    gap: 0.4rem !important;
  }

  .selected-food-controls {
    justify-content: space-between !important;
    gap: 0.5rem !important;
  }

  /* Autocomplete - show above on mobile */
  .autocomplete-dropdown {
    bottom: 100%;
    margin-bottom: 0.25rem;
    top: auto;
    max-height: 180px;
    border-radius: 8px;
  }

  /* Search items - compact */
  .search-item {
    padding: 0.7rem;
    margin-bottom: 0.4rem;
    border-radius: 8px;
  }

  .search-item-name {
    font-size: 0.9rem;
  }

  .search-item-carbs {
    font-size: 0.8rem;
  }

  .add-item-btn {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    border-radius: 6px;
  }

  /* System button - compact */
  .system-bottom-btn {
    padding: 0.6rem;
    margin-top: 1rem;
  }

  .system-bottom-btn a {
    font-size: 0.9rem;
    padding: 0.3rem;
  }

  /* Toggle sections - compact */
  .toggle-section {
    margin-bottom: 1rem;
    border-radius: 10px;
  }

  .toggle-header {
    padding: 0.7rem 0.9rem;
  }

  .toggle-header h3 {
    font-size: 0.95rem;
  }

  .toggle-icon {
    font-size: 1.2rem;
  }

  .toggle-content {
    padding: 0.75rem;
  }

  /* Tabs - compact */
  .tabs {
    margin-bottom: 1rem;
    gap: 0.3rem;
  }

  .tab {
    padding: 0.5rem 0.8rem;
    font-size: 0.85rem;
  }

  /* Hide desktop-only elements */
  .desktop-only {
    display: none !important;
  }

  /* Category filters - compact */
  #category-filters {
    gap: 0.4rem !important;
  }

  #category-filters button {
    padding: 0.4rem 0.7rem;
    font-size: 0.75rem;
    border-radius: 6px;
  }
}

/* Extra small devices (< 400px) - even more compact */
@media (max-width: 400px) {
  nav a {
    font-size: 0.6rem;
    padding: 0.35rem 0.1rem;
  }

  .logo {
    font-size: 0.9rem;
  }

  .status, .sugar-level {
    font-size: 0.55rem;
    padding: 0.2rem 0.3rem;
  }

  .card {
    padding: 0.6rem;
  }

  .card h3 {
    font-size: 0.9rem;
  }

  input, select {
    font-size: 0.85rem;
    padding: 0.55rem 0.6rem;
  }
}

/* ==================== DATABASE PAGE GRID FIX ==================== */
.food-db-item {
  overflow-x: auto;
  max-width: 100%;
}

/* Ensure database grid header and items have same width */
#food-database-list > div {
  min-width: 900px; /* Minimum width to prevent squishing */
}

/* Make database page scrollable horizontally on small screens */
@media (max-width: 1024px) {
  #food-database-list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  #food-database-list > div {
    min-width: 800px;
  }
}

@media (max-width: 768px) {
  #food-database-list > div {
    min-width: 700px;
    font-size: 0.8rem;
  }

  #food-database-list input,
  #food-database-list select,
  #food-database-list button {
    font-size: 0.75rem;
    padding: 0.4rem 0.5rem;
  }
}

/* ==================== MÅLTID PAGE REMOVE BUTTON ==================== */
.remove-food-btn:hover {
  background: #c53030 !important;
  transform: scale(1.05);
}

/* ==================== RESPONSIVE FOOD ITEM LAYOUT ==================== */
/* Desktop: show single-row layout, hide two-row mobile layout */
.selected-food-desktop {
  display: flex !important;
}

.selected-food-mobile {
  display: none !important;
}

/* Mobile: hide single-row layout, show two-row mobile layout */
@media (max-width: 768px) {
  .selected-food-desktop {
    display: none !important;
  }

  .selected-food-mobile {
    display: block !important;
  }
}

/* ==================== RECIPE INGREDIENT ROWS ==================== */
/* Recipe page needs 4-column grid: ingredient, amount, carbs, remove */
#recipe-ingredients-list .food-row {
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
}

@media (max-width: 768px) {
  #recipe-ingredients-list .food-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
  }

  #recipe-ingredients-list .food-row .form-group:first-child {
    grid-column: 1 / -1;
  }
}

/* ==================== ERSTATNINGSMAT PAGE HORIZONTAL LAYOUT ==================== */
/* Desktop: horizontal layout for the two input boxes */
.erstatningsmat-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* Mobile: vertical layout */
@media (max-width: 768px) {
  .erstatningsmat-inputs {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}
