/* ============================================
   BatSound — App-specific styles
   Extends pibico.css
   ============================================ */

/* --- Layout --- */
body {
  background: linear-gradient(135deg, #2c5171 0%, #4682b4 50%, #6a9bc3 100%);
  background-attachment: fixed;
  min-height: 100vh;
}

.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  box-sizing: border-box;
}

/* --- Floating Navbar --- */
.navbar {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: 12px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(70, 130, 180, 0.15);
  padding: 12px 20px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.navbar-title {
  font-family: var(--pibico-font-heading);
  font-weight: 700;
  font-size: 18px;
  background: linear-gradient(135deg, #4682b4 0%, #6a9bc3 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.navbar-title svg {
  width: 20px;
  height: 20px;
  vertical-align: -3px;
  stroke: #4682b4;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.navbar-nav {
  list-style: none;
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 0;
  align-items: center;
}

.navbar-nav .btn {
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}

.navbar-nav .btn:hover {
  background: rgba(255, 255, 255, 0.8);
}

.navbar-nav .btn svg {
  width: 18px;
  height: 18px;
  stroke: #4682b4;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.navbar-nav .nav-link {
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #4682b4;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.2s ease;
}

.navbar-nav .nav-link:hover {
  background: rgba(255, 255, 255, 0.8);
}

.navbar-nav .nav-link svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Main Content --- */
.app-main {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  max-width: 1400px;
  margin: 0 auto;
  margin-top: calc(58px + env(safe-area-inset-top, 0px));
  margin-bottom: 50px;
  width: 100%;
}

/* --- Upload Zone --- */
.upload-zone {
  border: 2px dashed var(--pibico-grey-mid);
  border-radius: var(--pibico-radius);
  padding: 32px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  margin: 8px 0;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--pibico-steel-blue);
  background: var(--pibico-steel-pale);
}

.upload-zone svg {
  width: 48px;
  height: 48px;
  stroke: var(--pibico-steel-blue);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 8px;
}

.upload-zone h3 {
  margin-bottom: 4px;
}

.upload-zone p {
  color: var(--pibico-grey-dark);
  font-size: 0.85rem;
}

.file-input {
  display: none;
}

/* --- File Queue — responsive grid --- */
.file-queue-list {
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.file-queue-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 24px 4px 6px;
  background: var(--pibico-light-grey);
  border-radius: var(--pibico-radius-sm);
  font-size: 0.75rem;
  transition: background 0.2s ease;
}

.file-queue-item .fq-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.file-queue-item .fq-meta {
  padding-left: 24px;
  gap: 8px;
}

.file-queue-item.processing {
  background: var(--pibico-steel-pale);
}

.file-queue-item.done {
  background: rgba(40, 167, 69, 0.1);
}

.file-queue-item.error {
  background: var(--pibico-brick-pale);
}

.file-queue-item .fq-icon {
  width: 16px;
  height: 16px;
  stroke: var(--pibico-steel-blue);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.file-queue-item .fq-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.file-queue-item .fq-size {
  color: var(--pibico-grey-dark);
  font-size: 0.7rem;
}

.file-queue-item .fq-status {
  font-size: 0.7rem;
  font-weight: 600;
}

.file-queue-item .fq-remove {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  background: var(--pibico-red-brick);
  border: none;
  border-radius: 50%;
  color: var(--pibico-white);
  font-size: 0.65rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.file-queue-item:hover .fq-remove {
  opacity: 1;
}

.file-queue-item .fq-remove:hover {
  background: var(--pibico-brick-dark);
}

/* Hide remove during processing */
.file-queue-item.processing .fq-remove,
.file-queue-item.done .fq-remove,
.file-queue-item.error .fq-remove {
  display: none;
}

/* --- Control Buttons --- */
.controls-buttons {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* --- Progress --- */
.progress-section {
  display: none;
  margin-top: 12px;
  padding: 8px 12px;
  background: var(--pibico-steel-pale);
  border-radius: var(--pibico-radius-sm);
}

.progress-section.show {
  display: block;
}

.progress-bar {
  height: 6px;
  background: var(--pibico-light-grey);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--pibico-steel-blue);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

.progress-text {
  text-align: center;
  margin-top: 4px;
  color: var(--pibico-grey-dark);
  font-size: 0.85rem;
  font-weight: 500;
}

/* --- Error Message --- */
.error-message {
  background: var(--pibico-brick-pale);
  color: var(--pibico-brick-dark);
  padding: 6px 12px;
  border-radius: var(--pibico-radius-sm);
  margin-top: 8px;
  display: none;
  font-weight: 500;
  font-size: 0.9rem;
}

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

/* --- Results Section --- */
.results-section {
  display: none;
  margin-top: 16px;
}

.results-section.show {
  display: block;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.results-header h3 {
  display: flex;
  align-items: center;
  gap: 6px;
}

.results-header h3 svg {
  width: 20px;
  height: 20px;
  stroke: var(--pibico-steel-blue);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.detection-count {
  background: var(--pibico-steel-blue);
  color: var(--pibico-white);
  padding: 2px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
}

/* --- Detection Cards — responsive grid --- */
.detections-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.detection-card {
  background: var(--pibico-white);
  border: none;
  border-radius: var(--pibico-radius);
  padding: 8px 12px;
  box-shadow: var(--pibico-card-shadow);
  transition: box-shadow 0.2s ease;
  cursor: pointer;
}

.detection-card:hover {
  box-shadow: var(--pibico-card-shadow-hover);
}

.detection-header {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.species-image {
  width: 60px;
  height: 60px;
  border-radius: var(--pibico-radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--pibico-light-grey);
}

.species-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.species-info {
  flex: 1;
  min-width: 0;
}

.species-info h4 {
  color: var(--pibico-steel-dark);
  margin-bottom: 2px;
}

.species-info .common-name-es {
  display: block;
  color: var(--pibico-grey-dark);
  font-size: 0.85rem;
}

.species-info .scientific-name {
  font-style: italic;
  color: var(--pibico-grey-dark);
  font-size: 0.8rem;
}

.detection-badges {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  flex-shrink: 0;
}

.detection-count-badge {
  background: var(--pibico-steel-blue);
  color: var(--pibico-white);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8rem;
}

/* --- Confidence Badges --- */
.confidence-badge {
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8rem;
}

.confidence-high {
  background: rgba(40, 167, 69, 0.15);
  color: #1b7a34;
}

.confidence-medium {
  background: rgba(255, 183, 77, 0.2);
  color: #b86e00;
}

.confidence-low {
  background: var(--pibico-brick-pale);
  color: var(--pibico-brick-dark);
}

/* --- Detection Details (compact) --- */
.detection-details {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  font-size: 0.75rem;
  flex-wrap: wrap;
}

.detail-item .label {
  color: var(--pibico-grey-dark);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-weight: 500;
}

.detail-item .value {
  font-weight: 600;
  color: var(--pibico-near-black);
  font-size: 0.8rem;
}

/* --- File source label on detection card --- */
.detection-source {
  font-size: 0.7rem;
  color: var(--pibico-grey-dark);
  background: var(--pibico-light-grey);
  padding: 1px 6px;
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
  margin-bottom: 4px;
  display: inline-block;
}

/* --- No Results --- */
.no-results {
  text-align: center;
  padding: 32px 16px;
  color: var(--pibico-grey-dark);
}

.no-results svg {
  width: 48px;
  height: 48px;
  stroke: var(--pibico-grey-mid);
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  margin-bottom: 8px;
}

/* --- Toast --- */
.toast-notification {
  position: fixed;
  bottom: -80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--pibico-white);
  color: var(--pibico-near-black);
  padding: 8px 16px;
  border-radius: 999px;
  box-shadow: var(--pibico-card-shadow);
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 1100;
  transition: bottom 0.4s ease;
  font-weight: 500;
  font-size: 0.85rem;
}

.toast-notification.show {
  bottom: 16px;
}

.toast-notification svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toast-notification.error {
  background: var(--pibico-red-brick);
  color: var(--pibico-white);
}

/* --- Detail Panel extras --- */
.detail-spectrogram {
  width: 100%;
  border-radius: var(--pibico-radius-sm);
}

.detail-audio {
  width: 100%;
}

.detail-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.detail-row .label {
  color: var(--pibico-grey-dark);
  font-size: 0.8rem;
  font-weight: 500;
}

.detail-row .value {
  font-weight: 600;
  font-size: 0.9rem;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: var(--pibico-light-grey);
}

::-webkit-scrollbar-thumb {
  background: var(--pibico-grey-mid);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--pibico-grey-dark);
}

/* --- Responsive --- */
@media (max-width: 1400px) {
  .detections-list,
  .file-queue-list {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1024px) {
  .detections-list,
  .file-queue-list {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .detections-list,
  .file-queue-list {
    grid-template-columns: 1fr;
  }

  .app-main {
    padding: 8px;
  }

  .controls-buttons {
    flex-direction: column;
  }

  .controls-buttons .pibico-btn {
    width: 100%;
    justify-content: center;
  }
}

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid var(--pibico-steel-blue);
  outline-offset: 2px;
  border-radius: var(--pibico-radius-sm);
}

/* --- Dark Mode --- */
@media (prefers-color-scheme: dark) {
  body {
    background: var(--pibico-near-black);
  }

  .detection-card,
  .pibico-card {
    background: #2a2a3e;
  }

  .detection-instance {
    background: #1e1e30;
  }

  .detection-instance:hover {
    background: #2a2a3e;
  }

  .upload-zone {
    border-color: #3a3a50;
  }

  .upload-zone:hover,
  .upload-zone.dragover {
    background: rgba(70, 130, 180, 0.1);
    border-color: var(--pibico-steel-blue);
  }

  .file-info {
    background: rgba(70, 130, 180, 0.1);
  }

  .progress-section {
    background: rgba(70, 130, 180, 0.1);
  }
}

/* --- Footer --- */
.app-footer {
  position: fixed;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  left: 12px;
  right: 12px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(70, 130, 180, 0.15);
  padding: 10px 20px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-size: 13px;
  color: var(--pibico-grey-dark);
}

.app-footer a {
  color: var(--pibico-steel-blue);
  text-decoration: none;
  font-weight: 500;
}

.app-footer a:hover {
  text-decoration: underline;
}

.footer-separator {
  color: rgba(0, 0, 0, 0.2);
}
