/*
 * Copyright (c) 2025 Davide Guerri <davide.guerri@gmail.com>
 *
 * This work is licensed under the Creative Commons Attribution-NonCommercial 4.0
 * International License. To view a copy of this license, visit
 * http://creativecommons.org/licenses/by-nc/4.0/
 */

/* ========================================
   DATABASE PAGE STYLES
   ======================================== */

/* Badge and grape ring styles */
.badge-grape {
  margin: 3px 8px 3px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ring {
  --p: 0;
  --ring-color: #28a745;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--p)*1%), rgba(255, 255, 255, 0.3) 0);
  position: relative;
  flex: 0 0 auto;
}

.ring::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: white;
  border-radius: 50%;
}

.ring.exact {
  --ring-color: #ffd700;
}

.ring.max {
  --ring-color: #ff1493;
}

.pct-text {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Filters */
.filters .form-select {
  width: 100%;
}

/* Custom multi-select styling */
.filter-dropdown {
  position: relative;
  width: 100%;
}

.filter-dropdown-toggle {
  width: 100%;
  text-align: left;
  background-color: white;
  border: 1px solid #ced4da;
  padding: 0.375rem 2.25rem 0.375rem 0.75rem;
  font-size: 1rem;
  border-radius: 0.375rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.filter-dropdown-toggle:hover {
  border-color: #86b7fe;
}

.filter-dropdown-toggle::after {
  content: "";
  border-top: 0.3em solid;
  border-right: 0.3em solid transparent;
  border-left: 0.3em solid transparent;
  margin-left: 0.5em;
}

.filter-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  z-index: 1000;
  display: none;
  min-width: 100%;
  max-height: 300px;
  overflow-y: auto;
  padding: 0.5rem 0;
  margin: 0.125rem 0 0;
  background-color: white;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.filter-dropdown-menu.show {
  display: block;
}

.filter-dropdown-item {
  display: flex;
  align-items: center;
  padding: 0.375rem 1rem;
  cursor: pointer;
  white-space: nowrap;
}

.filter-dropdown-item:hover {
  background-color: #e9ecef;
}

.filter-dropdown-item input[type="checkbox"] {
  margin-right: 0.5rem;
}

/* Selected filters display */
.selected-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  min-height: 2rem;
}

.selected-filter-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.35em 0.65em;
  font-size: 0.875rem;
  font-weight: 400;
  line-height: 1;
  color: #fff;
  background-color: #0d6efd;
  border-radius: 0.375rem;
  gap: 0.5rem;
}

.selected-filter-badge.grape-badge {
  background-color: #198754;
}

.selected-filter-badge.region-badge {
  background-color: #0dcaf0;
  color: #000;
}

.selected-filter-remove {
  cursor: pointer;
  font-weight: bold;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.selected-filter-remove:hover {
  opacity: 1;
}

.selected-filters-empty {
  color: #6c757d;
  font-style: italic;
  font-size: 0.875rem;
}

/* Action Buttons */
.database-actions {
  margin-top: 2rem;
}

#loadingMsg {
  padding: 40px;
  text-align: center;
}

/* Mobile responsive card styling */
@media screen and (max-width: 767px) {
  .badge-grape {
    margin: 2px 4px 2px 0;
    font-size: 0.85rem;
  }

  /* Make rows obviously clickable on mobile */
  #docgTable tbody tr:not(.child) {
    cursor: pointer;
  }

  #docgTable tbody tr:not(.child):hover {
    background-color: #e9ecef;
  }

  /* Improve card layout on mobile */
  table.dataTable.dtr-inline.collapsed>tbody>tr>td.dtr-control:before,
  table.dataTable.dtr-inline.collapsed>tbody>tr>th.dtr-control:before {
    background-color: #198754 !important;
    box-shadow: 0 0 3px rgba(0, 0, 0, 0.2) !important;
    border: 2px solid white !important;
    content: '+' !important;
    color: white !important;
    font-size: 14px !important;
    font-weight: bold !important;
    line-height: 20px !important;
    text-shadow: none !important;
    border-radius: 50% !important;
    width: 20px !important;
    height: 20px !important;
    margin-right: 8px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-align: center !important;
    vertical-align: middle !important;
  }

  table.dataTable.dtr-inline.collapsed>tbody>tr.parent>td.dtr-control:before,
  table.dataTable.dtr-inline.collapsed>tbody>tr.parent>th.dtr-control:before {
    background-color: #dc3545 !important;
    content: '−' !important;
  }

  /* Hide default DataTables responsive list on mobile - we use custom details */
  table.dataTable.dtr-inline.collapsed>tbody>tr.child ul.dtr-details {
    display: none !important;
  }

  /* Ensure custom wine details card is shown properly on mobile */
  table.dataTable.dtr-inline.collapsed>tbody>tr.child .wine-details {
    display: block !important;
    width: 100%;
    margin: 0;
  }

  /* Make wine details more readable on mobile */
  .wine-details {
    font-size: 0.9rem;
  }

  .wine-details .row>div {
    padding: 0.5rem 0;
  }
}

/* Tablet optimizations */
@media screen and (min-width: 576px) and (max-width: 991px) {
  .filter-dropdown-toggle span,
  .filters .form-select {
    font-size: 0.9rem;
  }
}

/* Wine details styling */
.wine-details {
  background-color: #f8f9fa;
  border-left: 3px solid #0d6efd;
  font-size: 0.95rem;
}

.wine-details strong {
  color: #495057;
  font-weight: 600;
}

.wine-details .row>div {
  line-height: 1.6;
}

/* DOCG name hover effect */
.docg-name:hover {
  font-weight: 500;
}

/* Expanded row indicator */
tr.details-shown td.docg-name {
  font-weight: 600;
}

/* Wine color classes for wine names */
.wine-color-rosso {
  color: #b71c1c !important;
}

.wine-color-bianco {
  color: #f57f17 !important;
}

.wine-color-rosato {
  color: #c2185b !important;
}

.wine-color-default {
  color: #0d6efd !important;
}
