/* Base Styles */
body {
  font-family: Arial, sans-serif;
  font-size: 13px;
  margin: 20px;
}

/* Header Layout */
#header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

#header-top h1 {
  margin: 0;
  font-size: 24px;
}

#auth-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#auth-controls input {
  padding: 4px 8px;
  font-size: 12px;
}

#auth-controls button {
  padding: 4px 12px;
  font-size: 12px;
}

#header-second {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 15px;
}

#export-import-controls {
  display: flex;
  gap: 8px;
}

/* Dropdown Styles */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  background: #388e3c;
  color: white;
  border: none;
  border-radius: 4px;
}

.dropdown-toggle:hover {
  background: #2e7d32;
}

.dropdown-menu {
  display: none !important;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 2px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  min-width: 200px;
  z-index: 1000;
}

.dropdown-menu a {
  display: block;
  padding: 10px 15px;
  text-decoration: none;
  color: #333;
  font-size: 13px;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

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

.dropdown-menu a:hover {
  background: #f5f5f5;
}

.dropdown-menu a[id*="Replace"] {
  color: #e57373;
  font-weight: bold;
}

.dropdown-menu a[id*="Replace"]:hover {
  background: #fff5f5;
}

.dropdown.open .dropdown-menu {
  display: block !important;
}

/* Autocomplete Dropdown Styles */
.autocomplete-dropdown {
  position: fixed;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10000;
}

.autocomplete-option {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.autocomplete-option:hover,
.autocomplete-option.selected {
  background: #e3f2fd;
}

.autocomplete-value {
  flex: 1;
  color: #333;
}

.autocomplete-count {
  color: #666;
  font-size: 11px;
  margin-left: 8px;
}

#search-filter-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

#search-filter-line input {
  padding: 4px 8px;
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  flex: 0 0 300px;
}

#search-filter-line button {
  padding: 4px 12px;
  font-size: 12px;
  min-width: 90px;
}

/* Filter Menu Panel */
#filterMenuPanel {
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.filter-section {
  margin-bottom: 15px;
}

.filter-section:last-child {
  margin-bottom: 0;
}

.filter-section-title {
  font-weight: bold;
  font-size: 11px;
  color: #555;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.filter-option {
  display: inline-block;
  padding: 3px 6px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 12px;
  color: #2e7d32;
  white-space: nowrap;
}

.filter-option:hover {
  text-decoration: underline;
}

.filter-option.active {
  background: #43a047;
  color: white;
  padding: 3px 6px;
  border-radius: 3px;
  font-weight: bold;
  text-decoration: none;
}

#add-entry-section {
  margin-bottom: 15px;
}

h1 {
  margin-bottom: 6px;
}

h2 {
  margin-bottom: 6px;
  padding: 10px 15px;
  background: linear-gradient(135deg, #2d5016 0%, #3d6b1f 100%);
  color: #e8f5e9;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  font-size: 16px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
  position: relative;
}

h2:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

h2::after {
  content: '▼';
  float: right;
  transition: transform 0.3s ease;
  font-size: 12px;
}

h2.collapsed::after {
  transform: rotate(-90deg);
}

/* Table Styles */
table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 25px;
  table-layout: fixed;
}

th, td {
  border-bottom: 1px solid #ddd;
  padding: 4px 6px;
  vertical-align: top;
  overflow-wrap: break-word;
}

th {
  background: #81c784;
  cursor: pointer;
  user-select: none;
}

tr:nth-child(even) {
  background: #f9f9f9;
}

tr:nth-child(odd) {
  background: white;
}

th:nth-child(1), td:nth-child(1) { width: 30%; }  /* Title - left-aligned */
th:nth-child(2), td:nth-child(2) { width: 6%; text-align: center; }   /* Media */
th:nth-child(3), td:nth-child(3) { width: 8%; text-align: center; }   /* Status */
th:nth-child(4), td:nth-child(4) { width: 15%; text-align: center; white-space: nowrap; }  /* Progress (includes unit) */
th:nth-child(5), td:nth-child(5) { width: 5%; text-align: center; }   /* Score */
th:nth-child(6), td:nth-child(6) { width: 9%; text-align: center; }   /* Start */
th:nth-child(7), td:nth-child(7) { width: 9%; text-align: center; }   /* End */
th:nth-child(8), td:nth-child(8) { width: 9%; }   /* Actions */

/* Actions column button wrapper - applies flex layout */
.action-buttons-wrapper {
  display: flex;
  flex-direction: row;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

/* Stack buttons vertically on medium-small screens (below 1200px) */
@media (max-width: 1200px) {
  .action-buttons-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 3px;
  }
  
  .action-buttons-wrapper button {
    width: 100%;
    margin: 0;
  }
}

/* Metadata Row Styles */
.metadata-row {
  border-top: none !important;
}

.metadata-row td {
  border-bottom: 2px solid #999 !important;
  padding-top: 2px !important;
  padding-bottom: 6px !important;
}

/* Remove bold from metadata labels */
.metadata-row strong {
  font-weight: normal;
}

/* Entry Content Styles */
.title {
  font-weight: bold;
}

.comments {
  font-size: 0.85em;
  color: #666;
  white-space: pre-wrap;
}

.tag {
  color: #2e7d32;
  cursor: pointer;
  margin-right: 0;
}

.tag:hover {
  text-decoration: underline;
}

.tag-active {
  background: #43a047;
  color: white;
  padding: 2px 4px;
  border-radius: 3px;
  font-weight: bold;
}

.media-type {
  color: #2e7d32;
}

/* Form Elements */
button {
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

select, input {
  font-size: 12px;
}

textarea {
  font-size: 12px;
  font-family: Arial, sans-serif;
}

/* Compact buttons in actions column when stacked */
@media (max-width: 1200px) {
  .btn-edit,
  .btn-history,
  .btn-delete {
    padding: 3px 6px;
    font-size: 11px;
  }
}

/* Authentication Styles */
.auth-status {
  padding: 5px 10px;
  background: #f0f0f0;
  border-radius: 3px;
  font-size: 12px;
}

.auth-status.authenticated {
  background: #a5d6a7;
  color: #1b5e20;
}

.auth-status.unauthenticated {
  background: #ffcc80;
  color: #e65100;
}

/* Edit Row Styles */
.edit-row {
  background: #e8f5e9 !important;
}

.edit-row td {
  padding: 8px 6px;
}

.edit-row input,
.edit-row select,
.edit-row textarea {
  width: 100%;
  padding: 4px;
  margin: 2px 0;
  box-sizing: border-box;
}

.edit-row .edit-controls {
  text-align: right;
}

.edit-row .edit-controls button {
  margin-left: 5px;
  padding: 4px 10px;
}

/* Button Styles */
.btn-confirm {
  background: #43a047;
  color: white;
  border: none;
  border-radius: 3px;
}

.btn-confirm:hover {
  background: #2e7d32;
}

.btn-cancel {
  background: #e57373;
  color: white;
  border: none;
  border-radius: 3px;
}

.btn-cancel:hover {
  background: #ef5350;
}

.btn-edit {
  background: #66bb6a;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 8px;
  margin-right: 5px;
}

.btn-edit:hover {
  background: #4caf50;
}

.btn-delete {
  background: #e57373;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 8px;
  cursor: pointer;
}

.btn-delete:hover {
  background: #ef5350;
}

.delete-btn {
  color: #900;
  cursor: pointer;
  font-weight: bold;
}

/* Progress Styles */
.progress-text {
  cursor: pointer;
}

.progress-btn {
  cursor: pointer;
  color: #66bb6a;
  font-size: 11px;
  padding: 0 3px;
  user-select: none;
}

.progress-btn:hover {
  color: #4caf50;
}

/* Filter Styles */
.filter-active {
  background: #e3f2fd;
  padding: 2px 6px;
  border-radius: 3px;
}

.clear-filter {
  cursor: pointer;
  color: #e57373;
  margin-left: 5px;
  font-weight: bold;
}

/* Editable Styles */
.editable {
  cursor: pointer;
}

.editable:hover {
  background: #f0f0f0;
}

/* New Entry Form */
#new-entry-form {
  margin-bottom: 20px;
  padding: 15px;
  background: #f1f8e9;
  border: 2px solid #7cb342;
  border-radius: 4px;
}

/* Collapsible Section Styles */
.section-content {
  transition: max-height 0.3s ease, opacity 0.3s ease;
  overflow: hidden;
}

.section-content.collapsed {
  max-height: 0 !important;
  opacity: 0;
  margin: 0 !important;
  padding: 0 !important;
}

.section-wrapper {
  margin-bottom: 25px;
}

/* History Modal Styles */
.history-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.history-content {
  background: white;
  padding: 20px;
  border-radius: 8px;
  max-width: 700px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.history-content h3 {
  margin: 0 0 15px 0;
  padding-bottom: 10px;
  border-bottom: 2px solid #ddd;
  font-size: 18px;
  color: #333;
}

.history-list {
  margin-bottom: 15px;
}

.history-group {
  margin-bottom: 12px;
  padding: 10px;
  background: #f9f9f9;
  border-left: 4px solid #388e3c;
  border-radius: 4px;
}

.history-timestamp {
  font-weight: bold;
  font-size: 13px;
  color: #333;
  margin-bottom: 2px;
}

.history-user {
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
}

.history-create-label {
  font-weight: bold;
  color: #28a745;
  margin-bottom: 10px;
  font-size: 13px;
}

.history-delete-label {
  font-weight: bold;
  color: #dc3545;
  margin-bottom: 10px;
  font-size: 13px;
}

.history-changes {
  margin-top: 5px;
}

.history-change-item {
  margin-bottom: 4px;
  padding: 5px;
  background: white;
  border-radius: 3px;
  font-size: 12px;
  line-height: 1.4;
}

.history-field-label {
  font-weight: bold;
  color: #555;
  display: inline-block;
  min-width: 100px;
}

.history-old-value {
  color: #dc3545;
  text-decoration: line-through;
  font-style: italic;
}

.history-new-value {
  color: #28a745;
  font-weight: bold;
}

.history-arrow {
  color: #666;
  margin: 0 5px;
}

.btn-history {
  background: #64b5f6;
  color: white;
  border: none;
  border-radius: 3px;
  padding: 2px 8px;
  margin-right: 5px;
  cursor: pointer;
  font-size: 12px;
}

.btn-history:hover {
  background: #42a5f5;
}

.history-content > button {
  width: 100%;
  padding: 10px;
  font-size: 14px;
  margin-top: 10px;
}

/* ========================================
   MOBILE-ONLY STYLES (768px and below)
   DESKTOP CODE ABOVE IS UNTOUCHED
   ======================================== */

@media (max-width: 768px) {
  /* Hide desktop table on mobile */
  table {
    display: none !important;
  }
  
  /* Adjust body margins for mobile */
  body {
    margin: 10px;
    font-size: 14px;
  }
  
  /* Header adjustments for mobile */
  #header-top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  
  #header-top h1 {
    font-size: 18px;
    text-align: center;
  }
  
  #auth-controls {
    flex-direction: column;
    gap: 5px;
  }
  
  #auth-controls input,
  #auth-controls button {
    width: 100%;
    padding: 8px;
  }
  
  #header-second {
    justify-content: center;
  }
  
  #export-import-controls {
    width: 100%;
    flex-direction: column;
  }
  
  #export-import-controls .dropdown {
    width: 100%;
  }
  
  #export-import-controls button {
    width: 100%;
    padding: 10px;
  }
  
  .dropdown-menu {
    right: auto;
    left: 0;
    width: 100%;
  }
  
  #search-filter-line {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 5px;
  }
  
  #search-filter-line input {
    grid-column: 1 / -1;
    flex: none;
    width: 100%;
  }
  
  #search-filter-line button {
    width: 100%;
    padding: 10px;
  }
  
  #filterMenuBtn {
    grid-column: 1;
  }
  
  #search-filter-line button:last-child {
    grid-column: 2;
  }
  
  /* Filter menu panel on mobile */
  #filterMenuPanel {
    padding: 12px;
  }
  
  .filter-section {
    margin-bottom: 12px;
  }
  
  .filter-section-title {
    font-size: 12px;
    margin-bottom: 6px;
  }
  
  .filter-options {
    flex-direction: column;
    gap: 4px;
  }
  
  .filter-option {
    display: block;
    padding: 8px 12px;
    font-size: 13px;
    text-align: left;
  }
  
  .filter-option.active {
    padding: 8px 12px;
  }
  
  #add-entry-section button {
    width: 100%;
    padding: 10px;
  }
  
  /* Header adjustments */
  h1 {
    font-size: 18px;
    text-align: center;
    margin-bottom: 10px;
  }
  
  h2 {
    font-size: 15px;
    text-align: center;
    margin: 15px 0 10px 0;
    padding: 12px 15px;
  }
  
  /* Auth status on mobile */
  .auth-status {
    display: block;
    text-align: center;
    margin: 0;
    padding: 8px;
  }
  
  /* Mobile card container */
  .mobile-cards-container {
    display: block;
    width: 100%;
  }
  
  /* Mobile card styles */
  .mobile-card {
    display: block;
    width: 100%;
    margin-bottom: 10px;
    padding: 10px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
  }
  
  .mobile-card:nth-child(even) {
    background: #f9f9f9;
  }
  
  /* Card title - LEFT aligned, bold */
  .card-title {
    text-align: left;
    font-weight: bold;
    font-size: 15px;
    margin-bottom: 4px;
    color: #333;
    line-height: 1.3;
  }
  
  /* Card status and progress line - LEFT aligned */
  .card-status-progress {
    text-align: left;
    font-size: 13px;
    color: #333;
    margin-bottom: 4px;
    line-height: 1.4;
  }
  
  /* Progress buttons in mobile */
  .card-status-progress .progress-btn {
    cursor: pointer;
    color: #66bb6a;
    font-size: 12px;
    padding: 0 2px;
    user-select: none;
    font-weight: bold;
  }
  
  .card-status-progress .progress-btn:hover {
    color: #4caf50;
  }
  
  /* Card meta line - LEFT aligned */
  .card-meta-line {
    text-align: left;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    line-height: 1.4;
  }
  
  /* Card tags line - LEFT aligned */
  .card-tags-line {
    text-align: left;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
    line-height: 1.4;
  }
  
  /* Clickable tags in mobile */
  .card-meta-line .tag,
  .card-tags-line .tag {
    display: inline;
    color: #2e7d32;
    cursor: pointer;
    margin: 0;
  }
  
  .card-meta-line .tag:hover,
  .card-tags-line .tag:hover {
    text-decoration: underline;
  }
  
  .card-meta-line .tag-active,
  .card-tags-line .tag-active {
    background: #43a047;
    color: white;
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: bold;
  }
  
  /* Card comments - LEFT aligned for readability */
  .card-comments {
    text-align: left;
    font-size: 12px;
    color: #666;
    margin-bottom: 6px;
    white-space: pre-wrap;
    line-height: 1.4;
  }
  
  /* Card actions - CENTERED */
  .card-actions {
    text-align: center;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #ddd;
  }
  
  .card-actions button {
    margin: 0 4px;
    padding: 6px 10px;
    font-size: 12px;
  }
  
  /* Mobile edit card */
  .mobile-edit-card {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 12px;
    background: #e8f5e9;
    border: 2px solid #7cb342;
    border-radius: 6px;
  }
  
  .mobile-edit-card h3 {
    text-align: center;
    margin: 0 0 15px 0;
    font-size: 16px;
  }
  
  .mobile-edit-card label {
    display: block;
    font-weight: bold;
    margin-top: 10px;
    margin-bottom: 3px;
    font-size: 13px;
  }
  
  .mobile-edit-card input,
  .mobile-edit-card select,
  .mobile-edit-card textarea {
    width: 100%;
    padding: 8px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
  }
  
  .mobile-edit-card textarea {
    min-height: 80px;
    font-family: Arial, sans-serif;
  }
  
  .mobile-edit-card .edit-controls {
    margin-top: 15px;
    text-align: center;
  }
  
  .mobile-edit-card .edit-controls button {
    width: 48%;
    margin: 0 1%;
    padding: 10px;
    font-size: 14px;
  }
  
  /* Filter styles for mobile */
  #filters {
    font-size: 11px;
    text-align: center;
  }
  
  .filter-active {
    display: inline-block;
    margin: 3px;
    padding: 4px 8px;
    font-size: 11px;
  }
  
  /* New entry form on mobile */
  #new-entry-form {
    padding: 12px;
  }
  
  #new-entry-form h3 {
    text-align: center;
    font-size: 16px;
  }
  
  #new-entry-form input,
  #new-entry-form select,
  #new-entry-form textarea {
    width: 100%;
    margin: 5px 0;
    padding: 8px;
    font-size: 14px;
  }
  
  #new-entry-form label {
    display: block;
    margin-top: 10px;
    font-size: 13px;
  }
  
  /* Search bar on mobile */
  #search-container {
    text-align: center;
  }
  
  #searchInput {
    width: 100% !important;
    display: block;
    margin-bottom: 8px;
    padding: 10px !important;
    font-size: 15px !important;
  }
  
  #search-container button {
    width: 100%;
    padding: 10px;
    font-size: 14px;
  }
  
  /* History modal on mobile */
  .history-modal {
    padding: 10px;
  }
  
  .history-content {
    padding: 15px;
    max-height: 90vh;
  }
  
  .history-content h3 {
    font-size: 16px;
    margin-bottom: 15px;
  }
  
  .history-group {
    padding: 12px;
    margin-bottom: 15px;
  }
  
  .history-timestamp {
    font-size: 13px;
  }
  
  .history-change-item {
    font-size: 12px;
    padding: 6px;
  }
  
  .history-field-label {
    display: block;
    margin-bottom: 3px;
    min-width: auto;
  }
  
  .btn-history {
    padding: 6px 12px;
    font-size: 13px;
    margin: 0 3px;
  }
}
