:root {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fa;
  --bg-input: #ffffff;
  --bg-card: #ffffff;
  --bg-elevated: #f1f8e9;

  --text-primary: #333333;
  --text-secondary: #666666;
  --text-tertiary: #999999;
  --border-color: #e0e0e0;

  --primary-color: #4caf50;
  --secondary-color: #2196f3;
  --accent-color: #ff9800;

  --success-color: #4caf50;
  --warning-color: #ff9800;
  --error-color: #f44336;
  --info-color: #2196f3;

  --toggle-bg: #b0b0b0;
  --toggle-border: #ddd;
  --toggle-slider-bg: #ccc;

  --table-header-bg: #4caf50;
  --table-header-text: #ffffff;
}

.dark-mode,
html.dark-mode,
body.dark-mode {
  --bg-primary: #121212;
  --bg-secondary: #1e1e1e;
  --bg-tertiary: #2d2d2d;
  --bg-input: #383838;
  --bg-card: #1e1e1e;
  --bg-elevated: #333333;

  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-tertiary: #808080;
  --border-color: #404040;

  --toggle-bg: #555555;
  --toggle-slider-bg: #4caf50;
  --table-header-bg: #2e7d32;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  width: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: "Poppins", "Inter", sans-serif;
  background: linear-gradient(135deg, var(--bg-primary) 0%, #c3cfe2 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  padding: 20px;
  transition:
    background-color 0.3s ease,
    color 0.3s ease;
  touch-action: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  transition: padding-bottom 0.3s ease;
}

/* إعدادات لشاشات الآيفون والهواتف الحديثة */
@viewport {
  orientation: portrait;
}

button,
.btn,
.action-btn,
input,
select,
.tab-btn,
.line-tab-btn {
  touch-action: manipulation;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  background-color: var(--bg-card);
  border-radius: 20px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
  padding: 20px;
  height: auto;
  min-height: auto;
  overflow: visible;
  transition: background-color 0.3s ease;
}

.loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: white;
}

.loading-spinner {
  width: 80px;
  height: 80px;
  border: 8px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
  margin-bottom: 20px;
}

#darkModeButton {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-dots::after {
  content: " ...";
  animation: dots 1.5s steps(5, end) infinite;
  color: var(--text-tertiary);
  font-style: italic;
}

@keyframes dots {
  0%,
  20% {
    content: " ...";
  }
  40% {
    content: " ....";
  }
  60% {
    content: " .....";
  }
  80%,
  100% {
    content: " ......";
  }
}

.loading-spinner-small {
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-left-color: #4caf50;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  animation: spin 0.8s linear infinite;
  display: block;
  margin: 0 auto;
}

.dark-mode .loading-spinner-small {
  border-left-color: #81c784;
}

.calculated-value.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
}

header {
  position: relative;
  text-align: center;
  padding: 30px 20px;
  background: linear-gradient(to right, #4caf50, #2e7d32);
  color: white;
  border-radius: 15px 15px 0 0;
  margin-bottom: 30px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.header-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: calc(100% - 120px);
  margin: 0 auto;
}

header h1 {
  font-size: 2.5rem;
  margin-top: 20px;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  flex-wrap: wrap;
  padding: 0;
}

.subtitle {
  font-size: 1.1rem;
  opacity: 0.9;
  font-weight: 300;
}

.credits-btn {
  position: absolute;
  top: 20px;
  left: 110px;
  width: 35px;
  height: 35px;
  background-color: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: all 0.3s ease;
  color: white;
  font-size: 16px;
}

.credits-btn:hover {
  background-color: white;
  color: #4caf50;
}

/* زر الرجوع — نفس نمط زر الإعدادات، أول يسار */
#flavor-home-btn {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 35px;
  height: 35px;
  min-width: 35px;
  max-width: 35px;
  min-height: 35px;
  max-height: 35px;
  background-color: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: all 0.3s ease;
  font-size: 16px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

#flavor-home-btn i {
  color: white;
  transition: all 0.3s ease;
}

#flavor-home-btn:hover {
  background-color: white;
}

#flavor-home-btn:hover i {
  color: #4caf50;
}

.dark-mode #flavor-home-btn i {
  color: white;
}

.dark-mode #flavor-home-btn:hover i {
  color: #4caf50;
}

.tabs,
.production-lines-tabs {
  display: flex;
  background-color: var(--bg-tertiary);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.tab-btn {
  flex: 1;
  padding: 15px 20px;
  border: 1px solid var(--border-color);
  border: none;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  border-radius: 10px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 200px;
  -webkit-user-select: none;
  user-select: none;
}

.tab-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
}
.tab-btn.active {
  background-color: #4caf50;
  color: white;
  border-color: #4caf50 !important;
}

.production-lines-tabs {
  background-color: var(--bg-tertiary) !important;
}

.line-tab-btn {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid var(--border-color);
  border: none;
  background: var(--bg-card);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  border-radius: 8px;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 150px;
  -webkit-user-select: none;
  user-select: none;
}

.line-tab-btn:hover {
  background-color: rgba(0, 0, 0, 0.05);
}
.line-tab-btn.active {
  background-color: #4caf50;
  color: white;
  border-color: #4caf50 !important;
}

.tab-pane {
  display: none !important;
  opacity: 0;
  will-change: display;
}
.tab-pane.active {
  display: block !important;
  opacity: 1;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Dark mode toggle alignment inside header */
header .hub-dark-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: white !important; /* Force text and icon to stay white */
  height: 35px;
  transition: all 0.3s ease;
}

header .hub-dark-toggle:hover {
  background-color: white !important;
  color: #4caf50 !important;
}

html.dark-mode header .hub-dark-toggle,
body.dark-mode header .hub-dark-toggle {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  color: white !important;
}

html.dark-mode header .hub-dark-toggle:hover,
body.dark-mode header .hub-dark-toggle:hover {
  background-color: white !important;
  color: #4caf50 !important;
}

.line-content {
  display: none;
  padding: 25px;
  background-color: var(--bg-tertiary);
  border-radius: 15px;
  border: 1px solid var(--border-color);
  will-change: display;
}
.line-content.active {
  display: block;
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 1.1rem;
  gap: 10px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  font-size: 16px;
  font-family: "Poppins", sans-serif;
  background-color: var(--bg-input);
  color: var(--text-primary);
  transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
  border-color: #4caf50;
  outline: none;
  box-shadow: 0 0 0 3px rgba(76, 175, 80, 0.2);
}

.range-indicator {
  margin-top: 8px;
  padding: 10px 15px;
  border-radius: 8px;
  font-weight: 600;
  display: none;
}

.range-indicator.valid {
  background-color: rgba(76, 175, 80, 0.1);
  color: #2e7d32;
  border-left: 4px solid #4caf50;
  display: none !important;
}

.range-indicator.invalid {
  background-color: rgba(244, 67, 54, 0.1);
  color: #d32f2f;
  border-left: 4px solid #f44336;
  display: block;
}

.samples-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
  gap: 30px;
  margin-bottom: 30px;
  margin-top: 10px !important;
}

.sample-group-card {
  background-color: var(--bg-card);
  border-radius: 15px;
  padding: 25px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  border: 2px solid var(--border-color);
}

.sample-group-card h3 {
  color: #2e7d32;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 3px solid #4caf50;
  display: flex;
  align-items: center;
  gap: 15px;
}

.sample-subgroup {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-top: 25px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.sample-card {
  background-color: var(--bg-tertiary);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border-color);
  transition: all 0.3s ease;
}

.sample-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
}

.sample-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

.sample-header h4 {
  color: #2196f3;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.1rem;
  flex: 1;
}

.applied-salt-field {
  background-color: rgba(33, 150, 243, 0.1);
  padding: 12px;
  border-radius: 8px;
  border-left: 4px solid #2196f3;
  margin-top: 10px;
}

.applied-salt-field label {
  color: var(--text-secondary) !important;
  font-weight: 600;
  font-size: 1rem;
}

.applied-salt-field .calculated-value {
  font-size: 1.2rem;
  font-weight: 700;
  padding: 10px;
  text-align: center;
  background-color: var(--bg-card);
  border-radius: 6px;
  margin-top: 8px;
  border: 2px solid #e0e0e0;
}

.applied-salt-field .calculated-value.waiting {
  color: #9e9e9e;
  font-style: italic;
  font-weight: 400;
  font-size: 1rem;
}

.applied-salt-field.status-green .calculated-value {
  color: #2e7d32 !important;
  border-color: #4caf50 !important;
  background-color: rgba(76, 175, 80, 0.1) !important;
}

.applied-salt-field.status-yellow .calculated-value {
  color: #000000 !important;
  border-color: #ffeb3b !important;
  background-color: rgba(255, 235, 59, 0.15) !important;
}

.applied-salt-field.status-red .calculated-value {
  color: #d32f2f !important;
  border-color: #f44336 !important;
  background-color: rgba(244, 67, 54, 0.1) !important;
}

.applied-salt-field.status-green {
  border-left-color: #4caf50 !important;
}
.applied-salt-field.status-yellow {
  border-left-color: #ffeb3b !important;
}
.applied-salt-field.status-red {
  border-left-color: #f44336 !important;
}

.result-field {
  background-color: var(--bg-tertiary);
  padding: 15px;
  border-radius: 10px;
  border-left: 4px solid #8bc34a;
  margin-top: 15px;
}

.result-field label {
  color: var(--text-secondary) !important;
  font-weight: 600;
  font-size: 1rem;
}

.calculated-value {
  font-size: 1.3rem;
  font-weight: 700;
  color: #2e7d32;
  padding: 10px;
  text-align: center;
  background-color: var(--bg-card);
  border-radius: 8px;
  margin-top: 5px;
  border: 2px solid #e0e0e0;
}

.result-field.status-green {
  border-left-color: #4caf50 !important;
  background-color: rgba(76, 175, 80, 0.1) !important;
}
.result-field.status-green .calculated-value {
  color: #2e7d32 !important;
}

.result-field.status-yellow {
  border-left-color: #ffeb3b !important;
  background-color: rgba(255, 235, 59, 0.15) !important;
}

.result-field.status-yellow .calculated-value {
  color: #000000 !important;
  border-color: #ffeb3b !important;
}

.dark-mode .result-field.status-yellow {
  border-left-color: #ffeb3b !important;
  background-color: rgba(255, 235, 59, 0.15) !important;
}

.dark-mode .result-field.status-yellow .calculated-value {
  color: #ffeb3b !important;
  border-color: #ffeb3b !important;
}

.result-field.status-red {
  border-left-color: #f44336 !important;
  background-color: rgba(244, 67, 54, 0.1) !important;
}
.result-field.status-red .calculated-value {
  color: #d32f2f !important;
}

.sample-status {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
  gap: 10px;
}

.result-container {
  background-color: var(--bg-tertiary);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  padding: 20px;
  margin: 30px 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}
.result-header h3 {
  color: #2e7d32;
  font-size: 1.3rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.result-value {
  text-align: center;
  padding: 20px;
  background-color: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  margin-top: 10px;
}

.result-label {
  display: block;
  font-size: 1.2rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}
.result-number {
  font-size: 3rem;
  font-weight: 800;
  color: #2e7d32;
  display: block;
}

.btn {
  padding: 16px 32px;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: "Poppins", sans-serif;
  min-width: 200px;
  min-height: 56px;
  -webkit-user-select: none;
  user-select: none;
}

.action-btn {
  padding: 16px 32px;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: "Poppins", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.btn:disabled,
.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.calculate-btn {
  background: linear-gradient(to right, #2196f3, #1976d2);
  color: white;
}
.calculate-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 7px 14px rgba(33, 150, 243, 0.3);
}

.whatsapp-btn,
.send-btn {
  background: linear-gradient(to right, #25d366, #128c7e);
  color: white;
}
.whatsapp-btn:hover:not(:disabled),
.send-btn:hover:not(:disabled) {
  transform: translateY(-3px);
  box-shadow: 0 7px 14px rgba(37, 211, 102, 0.3);
}

.add-btn,
.save-btn {
  background: linear-gradient(to right, #4caf50, #2e7d32);
  color: white;
}
.add-btn:hover,
.save-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 14px rgba(76, 175, 80, 0.3);
}
.add-btn,
.import-btn {
  margin-top: 20px !important;
}

.cancel-btn,
.reset-btn {
  background: linear-gradient(to right, #ff9800, #f57c00);
  color: white;
}
.cancel-btn:hover,
.reset-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 14px rgba(255, 152, 0, 0.3);
}

.delete-btn {
  background: #f44336;
  color: white;
}
.delete-btn:hover {
  background: #d32f2f;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.edit-btn {
  background: #2196f3;
  color: white;
}
.edit-btn:hover {
  background: #1976d2;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.action-buttons {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 30px;
  flex-wrap: wrap;
}

.action-buttons .btn {
  flex: none !important;
  width: auto !important;
  min-width: 200px;
}

.sample-actions {
  display: flex;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
  width: 100%;
}

.sample-actions .action-btn {
  flex: 1 !important;
  width: 100% !important;
  justify-content: center;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 25px;
  background-color: var(--bg-card);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
}

.action-required {
  background-color: #fff3cd;
  color: #856404;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  border: 1px solid #ffeeba;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.7;
  }
}

.table-container {
  overflow-x: auto;
  margin-bottom: 30px;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
  -webkit-overflow-scrolling: touch;
}

.flavors-table,
.contacts-table {
  width: 100%;
  min-width: 600px;
  table-layout: auto;
  border-collapse: collapse;
}
#add-flavor-btn {
  margin-bottom: 15px;
}

.contacts-table,
.contacts-table td {
  text-align: center;
}

.flavors-table th,
.contacts-table th {
  background-color: var(--table-header-bg);
  color: var(--table-header-text);
  padding: 12px 8px;
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
}

.flavors-table td {
  padding: 12px 5px;
  text-align: center;
  border-bottom: 1px solid var(--border-color);
  word-wrap: break-word;
}

.contacts-table td {
  padding: 15px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.flavors-table tr:nth-child(even),
.contacts-table tr:nth-child(even) {
  background-color: var(--bg-elevated);
}
.flavors-table tr:hover,
.contacts-table tr:hover {
  background-color: var(--bg-tertiary);
}

.contact-action-buttons-cell {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 60px;
}
.flavors-action-buttons-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.flavors-table .edit-btn,
.flavors-table .delete-btn,
.contacts-table .edit-btn,
.contacts-table .delete-btn {
  padding: 12px 16px !important;
  font-size: 1rem !important;
  line-height: 1.2;
  width: 100%;
  min-width: 100px !important;
  height: 40px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
  overflow: hidden !important;
}

.import-section {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 25px;
  padding: 15px;
  background-color: var(--bg-tertiary);
  border-radius: 10px;
}

.import-btn {
  background: linear-gradient(to right, #9c27b0, #7b1fa2);
  color: white;
  margin: 0 auto;
}
.note {
  color: #666;
  font-size: 0.85rem;
  margin-top: 5px;
}

.contacts-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 15px;
  margin-bottom: 40px;
  width: 100%;
}

.contact-card {
  background-color: var(--bg-card);
  border-radius: 12px;
  padding: 15px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}

.contact-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.contact-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  margin-bottom: 10px;
}

.contact-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #2e7d32;
}

.contact-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.contact-info {
  margin-bottom: 10px;
  min-height: 50px;
  display: flex;
  align-items: center;
}

.no-contact {
  color: #999;
  font-style: italic;
  text-align: left;
  padding: 10px;
  background-color: var(--bg-elevated);
  border-radius: 6px;
  width: 100%;
  font-size: 0.9rem;
}

.contact-details {
  padding: 10px;
  background-color: var(--bg-elevated);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
}

.contact-name {
  font-weight: 700;
  font-size: 1rem;
  color: #2e7d32;
  word-wrap: break-word;
}

.contact-phone {
  color: #555;
  font-size: 0.95rem;
  direction: ltr;
  word-wrap: break-word;
}

.select-contact-btn {
  width: 100%;
  background: linear-gradient(to right, #2196f3, #1976d2);
  color: white;
  padding: 10px;
  font-size: 0.95rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  margin-top: auto;
}

.select-contact-btn:hover {
  background: linear-gradient(to right, #1976d2, #1565c0);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(33, 150, 243, 0.3);
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 3000;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.3s cubic-bezier(0.19, 1, 0.22, 1);
  display: flex;
  flex-direction: column;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(50px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 25px;
  background: linear-gradient(to right, #4caf50, #2e7d32);
  color: white;
  flex-shrink: 0;
}

.modal-header h3 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.3rem;
  margin: 0;
}

.close-modal {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  line-height: 1;
}

.close-modal:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: rotate(90deg);
}

.modal-body {
  padding: 0;
  overflow-y: auto;
  flex-grow: 1;
  background-color: var(--bg-card);
}

.contact-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 25px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s ease;
  width: 100%;
  box-sizing: border-box;
}

.contact-item:hover {
  background-color: var(--bg-tertiary);
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-item.selected {
  background-color: var(--bg-elevated);
  border-left: 4px solid #4caf50;
}

.contact-item-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 1rem;
}

.contact-item-phone {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-family: "Inter", sans-serif;
}

.contact-item-line {
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  padding: 5px 12px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.modal-actions {
  padding: 20px 25px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  text-align: center;
  flex-shrink: 0;
}

.add-new-contact-btn {
  width: 100%;
  max-width: 300px;
  display: block;
  margin: 0 auto;
}

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1001;
  max-width: 350px;
}

.toast {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 15px 20px;
  margin-bottom: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  gap: 15px;
  transform: translateX(400px);
  transition: transform 0.3s ease;
  border-left: 5px solid #4caf50;
  color: var(--text-primary);
}
.toast.show {
  transform: translateX(0);
}

.toast.success {
  border-left-color: #4caf50;
}
.toast.warning {
  border-left-color: #ff9800;
}
.toast.error {
  border-left-color: #f44336;
}
.toast.info {
  border-left-color: #2196f3;
}

.toast-icon {
  font-size: 1.5rem;
}
.toast.success .toast-icon {
  color: #4caf50;
}
.toast.warning .toast-icon {
  color: #ff9800;
}
.toast.error .toast-icon {
  color: #f44336;
}
.toast.info .toast-icon {
  color: #2196f3;
}

.toast-content h4 {
  margin: 0 0 5px 0;
  font-size: 1rem;
  color: var(--text-primary);
}
.toast-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.flavor-form-container,
.contact-form-container {
  background-color: var(--bg-tertiary);
  padding: 20px;
  border-radius: 15px;
  margin-top: 30px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
  width: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
}

.flavor-form-container h3 {
  color: #2e7d32;
  margin-bottom: 25px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-row {
  display: flex;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.form-row .form-group {
  flex: 1;
  min-width: 250px;
  margin-bottom: 0;
}
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 15px;
  margin-top: 30px;
  width: 100%;
}

.auth-section {
  max-width: 500px;
  margin: 40px auto;
  padding: 40px;
  background-color: var(--bg-tertiary);
  border-radius: 15px;
  text-align: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}
.auth-section h2 {
  color: #2e7d32;
  margin-bottom: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
}
.login-btn {
  background: linear-gradient(to right, #ff9800, #f57c00);
  color: white;
  margin-top: 20px;
}
.password-hint {
  margin-top: 20px;
  color: #666;
  font-size: 0.9rem;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #555;
}

.dark-mode ::-webkit-scrollbar-track {
  background: #2d2d2d;
}
.dark-mode ::-webkit-scrollbar-thumb {
  background: #555;
}

@media (max-width: 768px) {
  body {
    padding: 5px;
  }

  .container {
    padding: 10px;
    border-radius: 15px;
  }

  header {
    padding: 20px 15px;
    overflow: hidden;
  }

  .line-content {
    padding: 10px !important;
  }

  .header-content {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 50px;
    box-sizing: border-box;
  }

  header h1 {
    font-size: 1.5rem !important;
    width: 100%;
    justify-content: center !important;
    text-align: center !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  header .subtitle {
    font-size: 0.85rem !important;
    padding: 0 10px;
  }

  .tabs {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    overflow-x: visible;
  }

  .production-lines-tabs {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    overflow-x: visible;
  }

  .tab-btn,
  .line-tab-btn {
    flex: 1 1 140px;
    min-width: 120px;
    white-space: normal;
    text-align: center;
    padding: 10px;
    font-size: 0.9rem;
  }

  .samples-container {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
    overflow-x: hidden;
  }
  .sample-group-card {
    width: 100%;
  }
  .sample-subgroup {
    grid-template-columns: 1fr;
  }

  .action-buttons {
    flex-direction: column;
    gap: 10px;
  }
  .action-buttons .btn {
    width: 100%;
    max-width: none;
  }

  .dark-mode-toggle .fa-moon {
    color: #313131;
    font-size: 13px;
    margin-left: 9px;
  }
  .dark-mode-toggle .fa-sun {
    color: #fdc468;
    font-size: 13px;
  }

  .dark-mode-toggle {
    width: 54px;
    height: 28px;
  }
  .dark-mode-toggle .slider {
    width: 20px;
    height: 20px;
    left: 5px;
  }
  .dark-mode .dark-mode-toggle .slider {
    transform: translateX(22px) !important;
  }

  .dark-mode-toggle,
  .credits-btn {
    min-height: unset !important;
    min-width: unset !important;
  }

  .flavors-table .edit-btn,
  .flavors-table .delete-btn,
  .contacts-table .edit-btn,
  .contacts-table .delete-btn {
    padding: 10px 12px !important;
    font-size: 0.9rem !important;
    height: 44px !important;
    min-width: 90px !important;
  }

  .flavors-table th,
  .contacts-table th {
    padding: 10px 5px;
    font-size: 0.9rem;
  }

  .flavors-table td,
  .contacts-table td {
    padding: 10px 5px;
    font-size: 0.9rem;
  }

  .flavor-form-container,
  .contact-form-container {
    padding: 15px;
    margin-left: -10px;
    margin-right: -10px;
    border-radius: 10px;
    width: calc(100% + 20px);
  }

  .form-actions {
    display: flex;
    flex-direction: column-reverse;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
  }

  .form-actions .btn {
    width: 100%;
    max-width: none;
    min-width: auto;
    font-size: 1rem;
  }

  .contacts-container {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .contact-card {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px !important;
    border-radius: 8px;
    min-width: 150px;
    justify-content: space-between !important;
    overflow: hidden !important;
  }

  .contact-header h3 {
    font-size: 1rem;
  }

  .contact-name {
    font-size: 0.9rem !important;
  }

  .contact-phone {
    font-size: 0.85rem !important;
  }

  .select-contact-btn {
    width: 100% !important;
    box-sizing: border-box !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    margin-bottom: 0 !important;
    padding: 8px 10px !important;
    margin-top: auto !important;
    font-size: 0.85rem !important;
    text-align: center;
    max-width: 100% !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    height: 50px;
  }

  .contact-name,
  .contact-phone {
    word-break: break-word !important;
  }

  .btn,
  .select-contact-btn {
    min-width: unset !important;
    min-height: unset !important;
  }

  .close-credits {
    top: 15px;
    right: 15px;
    width: 35px !important;
    height: 35px !important;
  }

  .close-modal {
    width: 35px !important;
    height: 35px !important;
    font-size: 1.2rem !important;
  }

  #contact-selector-modal .close-modal {
    /* --- التعديل: جعل الحجم 45 --- */
    width: 35px !important;
    height: 35px !important;
    font-size: 1.2rem !important;
  }
}

.credits-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 2000;
  display: none;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.credits-modal-overlay.show {
  display: flex;
  opacity: 1;
}

.credits-modal {
  background: var(--bg-card);
  border-radius: 20px;
  padding: 0;
  max-width: 370px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  position: relative;
  transform: translateY(20px);
  transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
  border: 1px solid var(--border-color);
}

.credits-modal-overlay.show .credits-modal {
  transform: translateY(0);
}

.close-credits {
  position: absolute;
  top: 15px;
  right: 15px;
  border: none;
  width: 35px;
  height: 35px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  transition: all 0.3s ease;
  z-index: 2;
  font-size: 1.2rem;
}

.close-credits:hover {
  transform: rotate(90deg);
}

.credits-header {
  padding: 25px 20px 10px;
}

.credits-icon-wrapper {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 15px;
  color: white;
  font-size: 24px;
  box-shadow: 0 8px 16px rgba(76, 175, 80, 0.3);
}

.credits-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.3rem;
  font-weight: 700;
}

.credits-body {
  padding: 10px 25px 25px;
}

.dev-name {
  font-size: 1.1rem;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 20px;
}

.contact-links {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.contact-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 15px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: all 0.2s ease;
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.contact-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.contact-btn i {
  font-size: 1.1rem;
}

.phone-btn:hover {
  background: rgba(33, 150, 243, 0.1);
  color: #2196f3;
  border-color: #2196f3;
}
.whatsapp-btn:hover {
  background: rgba(37, 211, 102, 0.1);
  color: #25d366;
  border-color: #25d366;
}
.email-btn:hover {
  background: rgba(244, 67, 54, 0.1);
  color: #f44336;
  border-color: #f44336;
}

.progress-container {
  width: 80%;
  height: 4px;
  margin: 15px auto 20px;
  background: var(--bg-tertiary);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(to right, #4caf50, #81c784);
  width: 0%;
  transition: width 5s linear;
}

.dark-mode .credits-modal {
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  border-color: #333;
}

.dark-mode .close-credits {
  background: rgba(255, 255, 255, 0.05);
}

.dark-mode .contact-btn:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

#tc .samples-container {
  display: grid;

  grid-template-columns: 1fr 1fr;
  gap: 20px;
  width: 100%;
}

#tc .sample-group-card {
  width: 100%;
  box-sizing: border-box;
  min-width: 0;
}

#tc .sample-subgroup {
  display: block;
  grid-template-columns: 1fr;
}

.tab-pane {
  display: none !important;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease;
}

.tab-pane.active {
  display: block !important;
  opacity: 1;
  visibility: visible;
  animation: fadeIn 0.3s ease;
}

.input-needed {
  position: relative !important;

  border: 2px solid #dbdbdbea !important;

  background-image: linear-gradient(
    to right,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0) 40%,
    rgba(76, 175, 80, 0.25) 50%,
    rgba(255, 255, 255, 0) 60%,
    rgba(255, 255, 255, 0) 100%
  ) !important;

  background-size: 200% 100% !important;
  background-repeat: no-repeat !important;

  animation: scanner-horizontal 1s infinite linear !important;

  will-change: background-position;
}

@keyframes scanner-horizontal {
  0% {
    background-position: 100% 0%;
  }
  100% {
    background-position: 0% 0%;
  }
}

/* Ensure specific glow animations override general input rules */
input.input-needed,
select.input-needed {
  animation: scanner-horizontal 1s infinite linear !important;
  background-image: linear-gradient(
    to right,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0) 40%,
    rgba(76, 175, 80, 0.25) 50%,
    rgba(255, 255, 255, 0) 60%,
    rgba(255, 255, 255, 0) 100%
  ) !important;
  background-size: 200% 100% !important;
  background-repeat: no-repeat !important;
}

input.field-highlight-active,
select.field-highlight-active {
  animation: continuousGlow 1.5s ease-in-out infinite !important;
  box-shadow: 0 0 15px 3px rgba(76, 175, 80, 0.6) !important;
  border-color: #4caf50 !important;
}

.dark-mode .input-needed {
  background-image: linear-gradient(
    to right,
    transparent 0%,
    transparent 40%,
    rgba(110, 128, 111, 0.35) 50%,
    transparent 60%,
    transparent 100%
  ) !important;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

/* Onboarding Modal Styles */
.onboarding-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6); /* لون الخلفية مطابق للاعتمادات */
  z-index: 10000;
  display: none; /* مخفي افتراضياً */
  justify-content: center;
  align-items: center;
  padding: 20px;
  backdrop-filter: blur(4px); /* مطابق للاعتمادات */
  opacity: 0;
  transition: opacity 0.3s ease;
}

.onboarding-overlay.show {
  display: flex;
  opacity: 1;
}

.onboarding-modal {
  background: var(--bg-card); /* استخدام متغير اللون من التطبيق */
  border-radius: 20px;
  max-width: 370px; /* نفس عرض نافذة الاعتمادات */
  width: 90%;
  /* إزالة الارتفاع الثابت ليتناسب مع المحتوى فقط */
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  /* تحريك من الأسفل قليلاً للوسط مثل الاعتمادات */
  transform: translateY(20px);
  transition:
    transform 0.4s cubic-bezier(0.19, 1, 0.22, 1),
    opacity 0.3s ease;
  opacity: 0;
  position: relative;
}

/* عند التفعيل: تعود لمكانها الطبيعي */
.onboarding-overlay.show .onboarding-modal {
  transform: translateY(0);
  opacity: 1;
}

.onboarding-header {
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  color: white;
  padding: 15px; /* تقليل البادينج قليلاً */
  text-align: center;
  border-radius: 20px 20px 0 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.onboarding-header h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.onboarding-body {
  padding: 20px; /* تقليل البادينج لتقليل الفراغات */
  overflow-y: auto;
  max-height: 70vh; /* حد أقصى للارتفاع في حال كان المحتوى طويلاً */
}

.onboarding-step {
  display: flex;
  align-items: flex-start;
  margin-bottom: 15px; /* تقليل المسافة بين الخطوات */
}

.step-number {
  background: #4caf50;
  color: white;
  width: 28px; /* تصغير الدائرة قليلاً */
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  flex-shrink: 0;
  margin-right: 12px;
  margin-top: 2px;
  font-size: 0.9rem;
}

.step-content h4 {
  margin: 0 0 3px 0;
  color: var(--text-primary);
  font-size: 0.95rem;
}
.step-content p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
}

.onboarding-footer {
  padding: 15px; /* تقليل البادينج السفلي لإزالة الفراغ */
  text-align: center;
  border-top: 1px solid var(--border-color);
  background: var(--bg-tertiary);
}

.start-btn {
  background: linear-gradient(to right, #4caf50, #2e7d32);
  color: white;
  border: none;
  padding: 10px 30px;
  border-radius: 25px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
  width: 100%;
}

#contact-phone {
  touch-action: auto;
  -webkit-user-select: text;
  user-select: text; /* ضمان صريح للنسخ واللصق */
}

.start-btn:hover {
  transform: scale(1.02);
}

/* Dark Mode Support for Onboarding */
.dark-mode .onboarding-modal {
  background: #2c2c2c;
  color: white;
}
.dark-mode .onboarding-footer {
  background: #333;
  border-top-color: #444;
}
.dark-mode .step-content h4 {
  color: #e0e0e0;
}
.dark-mode .step-content p {
  color: #b0b0b0;
}

@media (max-width: 768px) {
  body {
    padding: 10px;
  }
  .container {
    padding: 8px;
    border-radius: 15px;
  }

  .header-content {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    /* تغيير الـ padding من 50px إلى 25px لاستغلال المساحة خلف الأزرار */
    padding: 0 25px !important;
    box-sizing: border-box;
  }

  header {
    padding: 26px 15px 15px 15px;
    margin-bottom: 15px !important;
  }

  header h1 {
    font-size: 1.8rem;
    flex-direction: column;
    text-align: center;
    gap: 10px;
    padding-right: 70px;
  }

  header .subtitle {
    font-size: 0.9rem !important;
    padding: 0 5px !important; /* تقليل الحواف الداخلية لاستغلال العرض */
    line-height: 1.3 !important; /* تقليل المسافة بين الأسطر */
    max-width: 100% !important;
  }

  .tabs,
  .production-lines-tabs {
    display: flex;
    background-color: var(--bg-tertiary);
    border-radius: 12px;
    padding: 8px;
    margin-bottom: 15px;
    flex-wrap: wrap;
  }
  .tab-btn,
  .line-tab-btn {
    flex: 1 1 140px;
    white-space: normal;
    text-align: center;
    padding: 10px;
    font-size: 0.9rem;
  }

  .line-content .calculator-form > .form-group > label {
    font-size: 1rem !important;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px !important;
    margin-top: 8px !important;
  }

  .form-group label {
  font-size: 1rem !important;
  }

  .sample-group-card h3 {
    margin-bottom: 10px !important;
    padding-bottom: 8px !important;
    font-size: 1.2rem !important;
  }

  .sample-group-card .form-group {
    margin-bottom: 10px !important;
  }

  .sample-subgroup {
    margin-top: 8px !important;
    padding-top: 8px !important;
    border-top: 1px solid #eee;
  }

  .sample-header {
    margin-bottom: 20px !important;
    justify-content: center;
    text-align: center;
  }

  .line-content > .calculator-form > .form-group:first-of-type {
    margin-bottom: 8px !important;
  }

  .samples-container {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 15px !important;
    overflow-x: hidden;
  }

  .sample-group-card label {
    font-size: 0.9rem !important;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-secondary);
  }

  .sample-group-card {
    width: 100%;
    padding: 8px !important;
    border-radius: 10px;
  }

  .sample-subgroup {
    grid-template-columns: 1fr 1fr !important;
    gap: 15px !important;
    margin-top: 7px;
  }

  .sample-card {
    background-color: var(--bg-tertiary);
    border-radius: 8px;
    padding: 7px !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    min-width: 0 !important;
  }

  .sample-header {
    margin-bottom: 5px !important;
    margin-top: 5px !important;
    justify-content: center;
    text-align: center;
  }

  .sample-header h4 {
    font-size: 1.25rem !important;
    margin: 0;
    line-height: 1.2;
    color: #2196f3;
  }

  .form-group input,
  .form-group select {
    font-size: 16px !important;
    height: 40px !important;
    padding: 0 5px !important;
    border-radius: 4px;
    width: 100% !important;
    box-sizing: border-box;
    color: var(--text-primary) !important;
    background-color: var(--bg-input) !important;
  }

  .form-group select {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
    padding-right: 5px !important;
  }

  input[type="number"]::-webkit-outer-spin-button,
  input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }

  .sample-card label {
    font-size: 0.9rem !important;
    margin-bottom: 4px !important;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .result-field {
    padding: 3px !important;
    margin-top: 4px !important;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    color: #2e7d32;
  }

  .applied-salt-field {
    padding: 4px !important;
    border-radius: 4px;
  }

  .calculated-value {
    font-size: 1.1rem !important;
    padding: 5px !important;
    border-radius: 4px;
    font-weight: 700;
    color: #2e7d32;
    background-color: var(--bg-card);
    border: 2px solid var(--border-color);
    text-align: center;
  }

  .sample-actions {
    margin-top: 7px !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 5px !important;
    width: 100% !important;
  }

  .action-btn {
    padding: 8px !important;
    font-size: 1.1rem !important;
    width: 100% !important;
    min-width: auto !important;
    height: 48px !important;
    border-radius: 8px;
  }

  .action-required {
    display: none !important;
  }

  .contacts-container {
    grid-template-columns: 1fr;
  }

  .table-container {
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
  }

  .flavors-table,
  .contacts-table {
    min-width: 600px;
  }

  #tc .samples-container {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    width: 100% !important;
    margin: 10px 0 !important;
  }

  #tc .sample-group-card {
    width: 100% !important;
    padding: 5px !important;
    margin: 0 !important;
    box-sizing: border-box;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 1.5rem;
  }
  .btn {
    font-size: 1rem;
    padding: 14px 24px;
  }
  .samples-container {
    display: flex !important;
    flex-direction: column;
  }

  .sample-subgroup {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .sample-card {
    padding: 3px !important;
  }

  .sample-card label {
    font-size: 0.85rem !important;
  }
  .sample-header h4 {
    font-size: 1.05rem !important;
  }

  .table-container {
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
  }
  .flavors-table,
  .contacts-table {
    min-width: 600px;
  }

  #tc .samples-container {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .btn,
  .select-contact-btn {
    min-width: unset !important;
    min-height: unset !important;
  }

  .close-modal {
    width: 35px !important;
    height: 35px !important;
    font-size: 1.2rem !important;
  }

  #contact-selector-modal .close-modal {
    width: 35px !important; /* ← للشاشات الصغيرة */
    height: 35px !important;
    font-size: 1.2rem !important;
  }
}

.tab-pane {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  transition:
    opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    visibility 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(10px);
  will-change: opacity, transform;
}

.tab-pane.active {
  opacity: 1;
  visibility: visible;
  position: relative;
  transform: translateY(0);
}

.line-content {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 100%;
  transition:
    opacity 0.25s ease-in-out,
    visibility 0.25s ease-in-out,
    transform 0.25s ease-in-out;
  transform: translateX(-20px);
  will-change: opacity, transform;
}

.line-content.active {
  opacity: 1;
  visibility: visible;
  position: relative;
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .tab-pane,
  .line-content,
  .sample-card,
  .modal,
  .toast {
    transition: none !important;
    animation: none !important;
  }
}

.tab-btn,
.line-tab-btn {
  position: relative;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

.tab-btn::before,
.line-tab-btn::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 3px;
  background: var(--primary-color);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateX(-50%);
}

.tab-btn.active::before,
.line-tab-btn.active::before {
  width: 80%;
}

.tab-btn:hover:not(.active)::before,
.line-tab-btn:hover:not(.active)::before {
  width: 40%;
  opacity: 0.5;
}

*:focus {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

button:focus,
input:focus,
select:focus,
textarea:focus,
.tab-btn:focus,
.line-tab-btn:focus {
  outline: 3px solid var(--primary-color);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.15);
}

*:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 3px;
  box-shadow: 0 0 0 4px rgba(76, 175, 80, 0.2);
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--primary-color);
  color: white;
  padding: 10px 20px;
  text-decoration: none;
  border-radius: 0 0 5px 0;
  z-index: 10000;
  transition: top 0.3s;
}

.skip-link:focus {
  top: 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

:root {
  --focus-color: #2e7d32;
  --error-focus: #c62828;
  --success-focus: #2e7d32;
}

.dark-mode {
  --focus-color: #66bb6a;
  --error-focus: #ef5350;
  --success-focus: #66bb6a;
}

.container {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.sample-card,
.result-field,
.calculator-form {
  will-change: auto;
  transform: translateZ(0);
}

img {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 0%,
    var(--bg-elevated) 50%,
    var(--bg-tertiary) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.loading-spinner-small {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 3px solid rgba(76, 175, 80, 0.3);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to {
    transform: rotate(360deg);
  }
}

@media (min-width: 1200px) {
  .tab-pane,
  .line-content {
    transition-duration: 0.35s;
  }

  .sample-card {
    transition:
      transform 0.2s ease,
      box-shadow 0.2s ease;
  }

  .sample-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  }
}

@media (max-width: 768px) {
  .tab-pane,
  .line-content {
    transition-duration: 0.2s;
  }

  button:not(.close-modal):not(.settings-close):not(.close-credits),
  .tab-btn,
  .line-tab-btn,
  .btn {
    min-height: 45px;
    min-width: 45px;
  }

  .tabs,
  .production-lines-tabs {
    gap: 8px;
  }
}

body,
.container,
.sample-card,
.modal-content,
input,
select,
button {
  transition:
    background-color 0.3s ease,
    color 0.3s ease,
    border-color 0.3s ease;
}

html:not(.hydrated) {
  visibility: hidden;
}

html.hydrated {
  visibility: visible;
}

@media print {
  .tabs,
  .production-lines-tabs,
  button,
  .toast-container,
  .modal,
  .dark-mode-toggle,
  .credits-btn {
    display: none !important;
  }

  .tab-pane {
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
  }

  .line-content {
    opacity: 1 !important;
    visibility: visible !important;
    position: relative !important;
    page-break-inside: avoid;
  }

  .sample-card {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ccc;
  }

  * {
    background: white !important;
    color: black !important;
  }

  .result-field.status-green {
    border: 2px solid #4caf50 !important;
  }

  .result-field.status-yellow {
    border: 2px solid #ff9800 !important;
  }

  .result-field.status-red {
    border: 2px solid #f44336 !important;
  }
}

@media (prefers-contrast: high) {
  :root {
    --primary-color: #2e7d32;
    --text-primary: #000000;
    --text-secondary: #333333;
    --border-color: #000000;
  }

  .dark-mode {
    --primary-color: #66bb6a;
    --text-primary: #ffffff;
    --text-secondary: #e0e0e0;
    --border-color: #ffffff;
  }

  button,
  .tab-btn,
  .btn {
    border: 2px solid currentColor;
  }
}

.toast,
.modal,
.credits-modal {
  transform: translateZ(0);
  backface-visibility: hidden;
  perspective: 1000px;
}

.tab-content,
.line-content-container {
  contain: layout style;
}

.tab-pane:not(.active),
.line-content:not(.active) {
  content-visibility: hidden;
}

.no-focus-outline:focus {
  outline: none;
}

.error-text {
  color: var(--error-color);
  font-weight: 500;
}

.warning-text {
  color: var(--warning-color);
  font-weight: 500;
}

.success-text {
  color: var(--success-color);
  font-weight: 500;
}

.is-loading {
  pointer-events: none;
  opacity: 0.6;
  cursor: wait;
}

.is-disabled {
  pointer-events: none;
  opacity: 0.5;
  cursor: not-allowed;
}

@media (hover: none) and (pointer: coarse) {
  .sample-card:hover {
    transform: none !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05) !important;
  }
}

/* ========================================
   شاشة تنبيه دوران الشاشة (تم التعديل ليتوافق مع HTML)
   ========================================= */

#rotation-alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* خلفية فاتحة أنيقة */
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  z-index: 999999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

/* خلفية الوضع الليلي */
.dark-mode #rotation-alert-overlay {
  background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
}

#rotation-alert-overlay.show {
  opacity: 1;
  pointer-events: all;
}

.rotation-alert-content {
  text-align: center;
  padding: 40px;
  max-width: 90%;
}

.rotation-icon-container {
  position: relative;
  margin: 0 auto 30px;
  width: 120px;
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* تطبيق حركة الاهتزاز على الحاوية */
  animation: phoneShake 1.5s ease-in-out infinite;
}

/* تصميم الأيقونة للوضع الفاتح */
.rotation-icon-container .fa-mobile-alt {
  font-size: 80px;
  color: #4caf50; /* اللون الأخضر الأساسي */
}

/* تصميم الأيقونة للوضع الداكن */
.dark-mode .rotation-icon-container .fa-mobile-alt {
  color: #66bb6a; /* أخضر أفتح للوضع الداكن */
}

/* حركة الاهتزاز (محاكاة طلب الدوران) */
@keyframes phoneShake {
  0%,
  100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-20deg);
  }
  75% {
    transform: rotate(20deg);
  }
}

/* تنسيق العناوين للوضع الفاتح */
.rotation-alert-content h2 {
  font-size: 2rem;
  color: #333; /* نص داكن */
  margin-bottom: 15px;
  font-weight: 700;
  font-family: "Poppins", sans-serif;
}

/* تنسيق العناوين للوضع الداكن */
.dark-mode .rotation-alert-content h2 {
  color: #e0e0e0; /* نص فاتح */
}

/* تنسيق الفقرات للوضع الفاتح */
.rotation-alert-content p {
  font-size: 1.2rem;
  color: #555; /* نص رمادي */
  margin-bottom: 10px;
  font-family: "Poppins", sans-serif;
}

/* تنسيق الفقرات للوضع الداكن */
.dark-mode .rotation-alert-content p {
  color: #b0b0b0; /* نص رمادي فاتح */
}

/* النص الفرعي للوضع الفاتح */
.rotation-alert-content .rotation-sub-text {
  font-size: 1rem;
  color: #777;
  font-style: italic;
  margin-top: 20px;
}

/* النص الفرعي للوضع الداكن */
.dark-mode .rotation-alert-content .rotation-sub-text {
  color: #909090;
}

/* =========================================
   تفعيل الشاشة (المنطق البرمجي)
   ========================================= */

/* هذا الشرط يفعل الشاشة فقط في وضع أفقي وشاشة صغيرة (موبايل) */
@media screen and (orientation: landscape) and (max-height: 500px) {
  /* إظهار التنبيه */
  #rotation-alert-overlay {
    opacity: 1 !important;
    pointer-events: all !important;
  }

  /* إخفاء باقي التطبيق خلف التنبيه */
  body > .container,
  body > .toast-container,
  .custom-keyboard {
    display: none !important;
  }

  /* منع التمرير */
  body {
    overflow: hidden !important;
  }
}

/* ============================================================
   Header Reveal Manager v3.1
   ============================================================ */

#header-tabs-wrapper {
  overflow: hidden;
  max-height: 600px;
  opacity: 1;
  transition:
    max-height 0.44s cubic-bezier(0.4, 0, 0.2, 1),
    opacity    0.36s ease;
}

#header-tabs-wrapper.no-transition {
  transition: none !important;
}

#header-tabs-wrapper.header-collapsed {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
}

/* --- مؤشر السحب --- */
#pull-indicator {
  display: flex;
  justify-content: center;
  padding: 6px 0 4px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.3s ease;
  position: relative;
  z-index: 200;
}

#pull-indicator.pi-hidden {
  opacity: 0;
  pointer-events: none;
  height: 0;
  padding: 0;
  overflow: hidden;
}

#pull-indicator.pi-visible {
  opacity: 1;
  pointer-events: auto;
}

/* الـ Pill */
.pi-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px 9px 14px;
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.18);
  border: 1.5px solid rgba(76, 175, 80, 0.4);
  backdrop-filter: blur(12px) saturate(160%);
  -webkit-backdrop-filter: blur(12px) saturate(160%);
  box-shadow:
    0 4px 16px rgba(76, 175, 80, 0.12),
    0 1px 3px rgba(0,0,0,0.06),
    inset 0 1px 0 rgba(255,255,255,0.28);
  color: #2e7d32;
  transition: background 0.22s ease, box-shadow 0.22s ease,
              border-color 0.22s ease, transform 0.18s ease, color 0.22s ease;
  position: relative;
  overflow: hidden;
}

/* شريط التقدم داخل الـ Pill */
.pi-pill::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  height: 2.5px;
  width: calc(var(--pp, 0) * 100%);
  background: #4caf50;
  border-radius: 0 2px 2px 0;
  transition: none;
}

.dark-mode .pi-pill {
  background: rgba(20, 20, 20, 0.38);
  border-color: rgba(129, 199, 132, 0.45);
  color: #81c784;
  box-shadow:
    0 4px 16px rgba(76, 175, 80, 0.18),
    inset 0 1px 0 rgba(255,255,255,0.07);
}

/* السهم */
.pi-arrow {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
  animation: piArrowBounce 1.5s ease-in-out infinite;
}

@keyframes piArrowBounce {
  0%, 100% { transform: translateY(-2px); opacity: 0.65; }
  50%       { transform: translateY(3px);  opacity: 1;   }
}

.pi-text {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  white-space: nowrap;
  font-family: 'Poppins', 'Inter', sans-serif;
}

/* حالة السحب النشط */
#pull-indicator.pi-pulling .pi-pill {
  border-color: rgba(76, 175, 80, 0.65);
  box-shadow: 0 6px 20px rgba(76, 175, 80, 0.2);
}

#pull-indicator.pi-pulling .pi-arrow {
  animation: none;
  transform: translateY(2px);
  opacity: 1;
}

/* حالة "جاهز" — بعد تجاوز العتبة */
#pull-indicator.pi-ready .pi-pill {
  background: linear-gradient(135deg, #4caf50, #2e7d32);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 6px 24px rgba(76, 175, 80, 0.42);
  transform: scale(1.06);
}

#pull-indicator.pi-ready .pi-pill::before {
  display: none; /* نخفي شريط التقدم عند الاكتمال */
}

#pull-indicator.pi-ready .pi-arrow {
  animation: piArrowReady 0.5s ease infinite alternate;
}

@keyframes piArrowReady {
  from { transform: translateY(0); }
  to   { transform: translateY(4px); }
}