/* ============================================
   Common CSS for Daisypack Frontend Pages
   ============================================ */

/* Base Reset */
* {
  box-sizing: border-box;
}

/* Common Body Styles */
body {
  font-family: system-ui, -apple-system, sans-serif;
  max-width: 1400px;
  margin: 40px auto;
  padding: 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
}

/* Language Toggle - Standard Pattern (identical across all pages) */
#language-toggle {
  appearance: none;
  width: 40px;
  height: 20px;
  background: #ccc;
  border-radius: 20px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s;
}
#language-toggle:checked {
  background: #667eea;
}
#language-toggle::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: left 0.3s;
}
#language-toggle:checked::after {
  left: 22px;
}

/* Header Pattern - Standard across all pages */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 16px;
}

/* Common Container Pattern */
.container {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* Common Heading Styles */
h1 {
  margin: 0;
  color: #333;
}

/* Common Table Styles */
/* Exclude .table-container tables to allow sticky headers */
table:not(.table-container table) {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

table:not(.table-container table) th {
  background: #f8f9fa;
  padding: 12px;
  text-align: left;
  font-weight: 600;
  color: #333;
  border-bottom: 2px solid #dee2e6;
}

table:not(.table-container table) td {
  padding: 12px;
  border-bottom: 1px solid #e0e0e0;
}

table:not(.table-container table) tr:hover {
  background: #f8f9fa;
}

/* Sortable Table Headers - exclude .table-container tables */
table:not(.table-container table) th.sortable {
  position: relative;
  cursor: pointer;
  user-select: none;
  padding-right: 20px;
}

th.sortable:hover {
  background: #e9ecef;
}

th.sortable::after {
  content: ' ↕';
  position: absolute;
  right: 8px;
  opacity: 0.5;
  font-size: 12px;
}

th.sortable.asc::after {
  content: ' ↑';
  opacity: 1;
}

th.sortable.desc::after {
  content: ' ↓';
  opacity: 1;
}

th[colspan] {
  text-align: center;
  cursor: default;
}

th[colspan]::after {
  display: none;
}

/* Common Button Styles */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background: #667eea;
  color: white;
}

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

.btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.btn-secondary {
  background: #6c757d;
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-success {
  background: #28a745;
  color: white;
}

.btn-success:hover {
  background: #218838;
}

.btn-danger {
  background: #dc3545;
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

/* Common Status/Message Styles */
.status {
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.status.info {
  background: #d1ecf1;
  color: #0c5460;
  border: 1px solid #bee5eb;
}

.status.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.status.success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

/* Common Loading State */
.loading {
  text-align: center;
  padding: 20px;
  color: #666;
}

/* Common Controls/Button Groups */
.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  align-items: center;
}

/* Tab System (for pages with tabs) */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  border-bottom: 2px solid #e0e0e0;
}

.tab {
  padding: 12px 24px;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 16px;
  color: #666;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: #333;
  background: #f8f9fa;
}

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

.tab-content {
  display: none;
}

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

/* Table Container (for scrollable tables with sticky headers) */
/* overflow-y and max-height are critical for sticky positioning */
.table-container {
  overflow-x: auto;
  overflow-y: auto !important;
  max-height: calc(100vh - 200px) !important;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
}

/* Sticky header support: border-collapse: separate required for sticky positioning */
/* !important needed to override base table { border-collapse: collapse; } */
.table-container table {
  width: 100%;
  border-collapse: separate !important;
  border-spacing: 0;
  margin-top: 0;
}

/* Sticky table headers - match cdfa-scraper structure */
/* !important needed because base table/th styles may interfere */
.table-container thead {
  position: sticky !important;
  top: 0 !important;
  z-index: 10 !important;
}

.table-container th {
  padding: 12px;
  text-align: left;
  font-weight: 600;
  position: sticky !important;
  top: 0 !important;
  background-color: #f8f9fa; /* Prevent transparency when sticky */
  color: #333;
  border-bottom: 2px solid #dee2e6;
}

.table-container td {
  padding: 12px;
  border-bottom: 1px solid #e0e0e0;
}

.table-container tbody tr:hover {
  background: #f8f9fa;
}

/* Number Column Alignment */
.number-col {
  text-align: right;
}

/* Common Link Styles */
a {
  color: #0070f3;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Common Form Input Styles */
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.3s;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #667eea;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* Language Toggle Label */
.language-toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.language-toggle-label span {
  font-size: 14px;
  color: #666;
}

/* Navigation Bar */
.nav-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  position: relative;
}

.nav-link {
  padding: 8px 16px;
  text-decoration: none;
  color: #666;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border: 1px solid transparent;
}

.nav-link:hover {
  color: #333;
  background: #f8f9fa;
  border-color: #e0e0e0;
}

.nav-link.active {
  color: #667eea;
  background: #f0f2ff;
  border-color: #667eea;
  font-weight: 600;
}

/* Screen-reader-only (nav toggle label, etc.) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mobile hamburger: requires <button class="nav-menu-toggle"> + <div class="nav-bar-panel"> in each .nav-bar */
.nav-menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  color: #333;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.nav-menu-toggle:hover {
  background: #f8f9fa;
  border-color: #ced4da;
}

.nav-menu-toggle:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

.nav-menu-toggle-bars {
  display: block;
  width: 22px;
  height: 2px;
  background: #333;
  border-radius: 1px;
  position: relative;
  transition: background 0.2s ease;
}

.nav-menu-toggle-bars::before,
.nav-menu-toggle-bars::after {
  content: "";
  position: absolute;
  left: 0;
  width: 22px;
  height: 2px;
  background: #333;
  border-radius: 1px;
  transition: transform 0.2s ease, top 0.2s ease;
}

.nav-menu-toggle-bars::before {
  top: -7px;
}

.nav-menu-toggle-bars::after {
  top: 7px;
}

.nav-menu-toggle[aria-expanded="true"] .nav-menu-toggle-bars {
  background: transparent;
}

.nav-menu-toggle[aria-expanded="true"] .nav-menu-toggle-bars::before {
  top: 0;
  transform: rotate(45deg);
}

.nav-menu-toggle[aria-expanded="true"] .nav-menu-toggle-bars::after {
  top: 0;
  transform: rotate(-45deg);
}

.nav-bar-link-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

@media (min-width: 769px) {
  .nav-bar .nav-menu-toggle {
    display: none !important;
  }

  .nav-bar .nav-bar-panel {
    display: contents;
  }

  .nav-bar--split .nav-bar-link-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
  }
}

@media (max-width: 768px) {
  .nav-bar .nav-menu-toggle {
    display: inline-flex;
  }

  .nav-bar:not(.nav-bar--split) {
    justify-content: flex-end;
    flex-wrap: nowrap;
    align-items: center;
  }

  .nav-bar:not(.nav-bar--split) .nav-bar-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 10px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 2000;
  }

  .nav-bar:not(.nav-bar--split).nav-menu-open .nav-bar-panel {
    display: flex;
  }

  .nav-bar:not(.nav-bar--split) .nav-bar-panel .nav-link {
    text-align: center;
    padding: 10px 12px;
  }

  /* Nav row + language toggle (emails, email-history) */
  .nav-bar--split {
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
  }

  .nav-bar--split .nav-menu-toggle {
    order: 0;
  }

  .nav-bar--split .language-toggle-label {
    order: 1;
    margin: 0 !important;
  }

  .nav-bar--split .nav-bar-panel {
    display: none;
    order: 2;
    flex: 0 0 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 10px;
    margin-top: 4px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
    z-index: 2000;
  }

  .nav-bar--split.nav-menu-open .nav-bar-panel {
    display: flex;
  }

  .nav-bar--split .nav-bar-link-group {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .nav-bar--split .nav-bar-panel .nav-link {
    text-align: center;
    padding: 10px 12px;
  }
}

/* Responsive Design - Common Breakpoints */
@media (max-width: 768px) {
  body {
    margin: 10px auto;
    padding: 10px;
  }
  .container {
    padding: 15px;
  }
  h1 {
    font-size: 24px;
  }
  table {
    font-size: 14px;
  }
  th, td {
    padding: 8px 4px;
  }
  .nav-bar {
    margin-bottom: 12px;
  }
  .nav-link {
    padding: 6px 12px;
    font-size: 13px;
  }
}

@media (max-width: 480px) {
  table {
    font-size: 12px;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  th, td {
    padding: 6px 2px;
    white-space: nowrap;
  }
  .btn {
    padding: 10px 16px;
    font-size: 14px;
  }
  h1 {
    font-size: 20px;
  }
}

