﻿/* Theme colors */
/* Theme color variables. */
:root {
  --base-color: #ffffff;
  --base-variant: #e8e9ed;
  --border-color: #d0d4dd;
  --text-color: #111528;
  --secondary-text: #232738;
  --primary-color: #3a435d;
  --accent-color: #0071ff;
  --plot-bg: #fbfcff;
  --plot-text: #111528;
  --shadow-strong: 0 4px 20px rgba(0, 0, 0, 0.05);
  --shadow-soft: 0 2px 6px rgba(0, 0, 0, 0.03);
  --danger: #b00000;
  --header-color: #035751;
}

body.darkmode,
/* Dark theme color variables. */
body.darkemode {
  --base-color: #0d1226;
  --base-variant: #121a33;
  --border-color: #2c3752;
  --text-color: #f5f7ff;
  --secondary-text: #aeb7d9;
  --primary-color: #5aa0ff;
  --accent-color: #ffd166;
  --plot-bg: #c1cbea;
  --plot-text: #0f1c3f;
  --shadow-strong: 0 6px 28px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 3px 10px rgba(0, 0, 0, 0.28);
  --danger: #ff8f9a;
}

/* Base page colors and font. */
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: Arial, sans-serif;
  background: var(--base-variant);
  color: var(--text-color);
}

/* Default button look. */
button {
  padding: 9px 14px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--base-variant);
  cursor: pointer;
  font-size: 14px;
  color: var(--primary-color);
}

/* Button hover background. */
button:hover {
  background: var(--base-color);
}

/* Main page layout. */
.page {
  margin: 40px auto;
  padding: 0 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

/* Header */
#pageHeader {
  background-color: var(--header-color);
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  width: 100%;
  box-sizing: border-box;
  position: relative;
}

.header-content {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.2rem;
}

.header-content img {
  width: clamp(6em, 15vw, 10em);
  height: auto;
  object-fit: contain;
  display: block;
  cursor: pointer;
}
/* Round button to toggle theme. */
#theme-switch {
  position: absolute;
  right: 1.2rem;
  top: 50%;
  transform: translateY(-50%);
  height: 50px;
  width: 50px;
  padding: 0;
  border-radius: 50%;
  background-color: var(--base-color);
  box-shadow: var(--shadow-soft);
  flex-shrink: 0;
}

#header-container {
  width: 100%;
  display: contents;
}


/* Color theme icon. */
#theme-switch svg {
  fill: var(--primary-color);
}

/* Hide second icon by default. */
#theme-switch svg:last-child {
  display: none;
}

/* Hide first icon in dark mode. */
.darkmode #theme-switch svg:first-child {
  display: none;
}

/* Show second icon in dark mode. */
.darkmode #theme-switch svg:last-child {
  display: block;
}

/* Card container for the form. */
.form-card {
  background: var(--base-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  max-width: 1500px;
  margin: auto;
  padding: 20px 24px;
  box-shadow: var(--shadow-strong);
}

/* Grid layout for form fields. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(200px, 1fr));
  gap: 16px 20px;
  align-items: center;
}

/* Label row layout. */
.form-grid label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-weight: 600;
}

/* Input field style. */
.form-grid input {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  font-weight: 400;
  background: var(--base-color);
  color: var(--secondary-text);
}

body.darkmode input[type="datetime-local"] {
  color-scheme: dark;
}

body.darkmode input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(1.1);
}

/* Wrapper to position autocomplete list. */
.autocomplete-wrap {
  position: relative;
  display: inline-flex;
  flex: 1;
}

/* Make autocomplete input full width. */
.autocomplete-wrap input {
  width: 100%;
}

/* Dropdown list for suggestions. */
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--base-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  box-shadow: var(--shadow-soft);
  max-height: 200px;
  overflow-y: auto;
  display: none;
  z-index: 20;
}

/* Show suggestions list. */
.autocomplete-list.open {
  display: block;
}

/* Single suggestion row. */
.autocomplete-item {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--secondary-text);
}

/* Hover background for suggestion. */
.autocomplete-item:hover {
  background: var(--base-variant);
}

/* Layout for plots section. */
.plots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
}

/* Center and bold the plots title. */
.plots-title {
  font-weight: 700;
  text-align: center;
}

/* Grid container for plot cards. */
.plot-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

/* Two-column plot grid. */
.plot-list.two {
  grid-template-columns: repeat(2, minmax(360px, 1fr));
}

/* Three-column plot grid. */
.plot-list.three {
  grid-template-columns: repeat(3, minmax(280px, 1fr));
}

/* Grid for many plots. */
.plot-list.fourplus {
  grid-template-columns: repeat(3, minmax(240px, 1fr));
}

/* Card style for each plot. */
.plot-card {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  background: var(--plot-bg);
  color: var(--plot-text);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Header row in plot card. */
.plot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  gap: 12px;
}

/* Wrap plot action buttons. */
.plot-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Small buttons inside plot actions. */
.plot-actions button {
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  white-space: nowrap;
}

/* Extra space before delete button. */
.plot-actions .delete-plot {
  margin-left: 6px;
}

/* Image sizing and border. */
.plot-image {
  width: auto;
  max-width: 90%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 6px;
  align-self: center;
  background: var(--plot-bg);
  padding: 6px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
}

#wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  top: 1rem;
  width: 900px;
  max-width: 100vw;
}

#img {
  display: block;
  width: 900px;
  max-width: 100vw;
  height: auto;
  background-color: white;
}

#plot {
  display: block;
  width: 900px;
  max-width: 100vw;
  height: auto;
  margin-top: 2rem;
}

/* place where rectangle can be drawn */
#overlay {
  position: absolute;
  cursor: crosshair;
  left: 48%;
  transform: translateX(-50%);
  width: 72%;
  top: 10.2%;
  height: 60%;
}

/* rectangle itself */
#selectionBox {
  position: absolute;
  border: 2px solid blue;
  background: rgba(0, 0, 255, 0.15);
  display: none;
  box-sizing: border-box;
  pointer-events: none;
}

/* Loading overlay during request */
#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 999;
}

/* Loading dots */
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  animation: bounce 1.2s ease-in-out infinite;
}

.dot:nth-child(2) {
  animation-delay: 0.2s;
}
.dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Status text under plot. */
.plot-status {
  font-size: 12px;
  color: var(--secondary-text);
  text-align: center;
}

/* Error color for status. */
.plot-status.error {
  color: var(--danger);
}

/* Right-align footer content. */
.plot-footer {
  display: flex;
  justify-content: flex-end;
}

/* Single plot card full width. */
.plot-card:only-child {
  grid-column: 1 / -1;
  width: 100%;
  max-width: 1200px;
  justify-self: center;
}

/* Larger image when only one plot. */
.plot-card:only-child .plot-image {
  width: 90%;
  max-height: 60vh;
}

/* Row layout for time inputs. */
.time-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
}

/* Align label with time input. */
.time-row label {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Layout for add-time controls. */
.time-add-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px 10px;
  grid-column: 1 / -1;
  margin-top: 16px;
}

/* Inner time row in add section. */
.time-add-row .time-row {
  flex: 0 1 auto;
  justify-content: center;
}

/* Place delete-all button. */
.time-add-row #delete-all {
  justify-self: start;
}

/* Group time action buttons. */
.time-add-row .time-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: 10px;
}

/* Small screens: stack add-time controls. */
@media only screen and (max-width: 720px) {
  /* Layout for add-time controls. */
  .time-add-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 12px;
  }

  /* Inner time row in add section. */
  .time-add-row .time-row {
    order: 1;
    width: 100%;
    justify-content: center;
  }

  /* Place delete-all button. */
  .time-add-row #delete-all {
    order: 2;
  }

  /* Group time action buttons. */
  .time-add-row .time-actions {
    order: 3;
    margin-left: 6px;
  }
}

/* Small screens: single-column plot grid. */
@media only screen and (max-width: 779px) {
  .plot-list.two,
    .plot-list.three,
    /* Grid for many plots. */
    .plot-list.fourplus {
    grid-template-columns: 1fr;
  }
}

/* Tablet and up: wider grids. */
@media only screen and (min-width: 780px) {
  .plot-list.two,
    .plot-list.three,
    /* Grid for many plots. */
    .plot-list.fourplus {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Grid layout for form fields. */
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop and up: 3-column plots. */
@media only screen and (min-width: 1024px) {
  .plot-list.three,
    /* Grid for many plots. */
    .plot-list.fourplus {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Row layout for time inputs. */
  .time-row {
    justify-content: center;
  }
}

/* Wide screens: 4-column form grid. */
@media (min-width: 1100px) {
  /* Grid layout for form fields. */
  .form-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Large screens: 3-column plots, 4-column form. */
@media only screen and (min-width: 1200px) {
  /* Grid for many plots. */
  .plot-list.fourplus {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Grid layout for form fields. */
  .form-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Very wide screens: 3-column plot grid. */
@media (min-width: 1400px) {
  /* Grid container for plot cards. */
  .plot-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
