/* =========================================================
   whenworks4u — main.css
   Layout, components, and responsive styles
   ========================================================= */

/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  outline: none;
}

button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

/* ── Layout ───────────────────────────────────────────── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ── Header ───────────────────────────────────────────── */
#app-header {
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  height: 4rem;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.brand-tagline {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

/* Visually hidden but accessible to screen readers */
.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;
}

#theme-toggle {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  transition: background 0.2s, transform 0.2s;
}

#theme-toggle:hover {
  background: var(--border);
  transform: rotate(20deg);
}

#theme-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
}

/* ── Main ─────────────────────────────────────────────── */
#app-main {
  padding: 1.5rem 1rem 3rem;
  max-width: 1200px;
  margin: 0 auto;
}

/* ── Section headings ─────────────────────────────────── */
.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
}

/* ── City Search ──────────────────────────────────────── */
#city-search-section {
  margin-bottom: 1.5rem;
}

.search-wrapper {
  position: relative;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
  width: 1rem;
  height: 1rem;
}

#city-search-input {
  width: 100%;
  padding: 0.65rem 0.75rem 0.65rem 2.25rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.95rem;
  box-shadow: 0 1px 3px var(--shadow);
}

#city-search-input::placeholder { color: var(--text-secondary); }

#city-search-input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#search-dropdown {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px var(--shadow-md);
  max-height: 260px;
  overflow-y: auto;
  z-index: 200;
  display: none;
}

#search-dropdown.open { display: block; }

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-primary);
  gap: 0.5rem;
}

.dropdown-item:hover,
.dropdown-item.focused {
  background: var(--bg-secondary);
}

.dropdown-item.disabled {
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.55;
}

.dropdown-item .city-name-dd { font-weight: 500; }
.dropdown-item .country-dd   { color: var(--text-secondary); font-size: 0.8rem; }
.dropdown-item .tz-dd        { color: var(--text-secondary); font-size: 0.78rem; font-family: monospace; }

.max-cities-msg {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--yellow);
  font-weight: 500;
  display: none;
}

.max-cities-msg.visible { display: block; }

/* ── City Cards Grid ──────────────────────────────────── */
#city-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── City Card ────────────────────────────────────────── */
.city-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 8px var(--shadow);
  position: relative;
  animation: slideIn 0.25s ease forwards;
  overflow: hidden;
}

.city-card.removing {
  animation: fadeOut 0.25s ease forwards;
}

.city-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.city-card-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.city-card-country {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.city-card-remove {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.1rem;
  border-radius: 0.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.city-card-remove:hover {
  color: var(--red);
  background: var(--red-bg);
}

.city-card-remove svg { width: 1rem; height: 1rem; }

.city-card-clock {
  font-size: 1.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--accent);
  margin: 0.5rem 0 0.2rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
}

.city-card-date {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.city-card-offset {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  padding: 0.1rem 0.4rem;
  color: var(--text-secondary);
  font-family: monospace;
}

.city-card-home-badge {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.65rem;
  background: var(--accent);
  color: #fff;
  border-radius: 0.25rem;
  padding: 0.1rem 0.35rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}

/* ── Date Picker ──────────────────────────────────────── */
#date-picker-section {
  margin-bottom: 1.5rem;
}

.date-picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.date-input-wrapper input[type="date"] {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  box-shadow: 0 1px 3px var(--shadow);
  cursor: pointer;
}

.date-input-wrapper input[type="date"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.date-quick-btns {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.date-quick-btn {
  padding: 0.45rem 0.8rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.date-quick-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.date-quick-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.date-display {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-height: 1.2em;
}

.date-display strong {
  color: var(--text-primary);
}

.date-display .dst-note {
  color: var(--yellow);
  font-weight: 600;
}

/* ── One-city prompt ──────────────────────────────────── */
#one-city-prompt {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  margin-bottom: 1rem;
  display: none;
}

#one-city-prompt.visible { display: block; }

/* ── Timeline Grid Section ────────────────────────────── */
#grid-section {
  margin-bottom: 2rem;
  display: none;
}

#grid-section.visible { display: block; }

.grid-scroll-wrapper {
  overflow-x: auto;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px var(--shadow);
}

/* Grid table */
#timeline-grid {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  font-size: 0.78rem;
  position: relative;
}

#timeline-grid th,
#timeline-grid td {
  border: 1px solid var(--border);
  text-align: center;
  padding: 0;
}

/* Header row */
#timeline-grid thead th {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 0.3rem 0.2rem;
  min-width: 2.6rem;
  position: sticky;
  top: 0;
  z-index: 2;
}

#timeline-grid thead th.row-header-cell {
  min-width: 7rem;
  text-align: left;
  padding-left: 0.5rem;
  position: sticky;
  left: 0;
  z-index: 3;
}

/* Row header (city name) */
.row-header {
  background: var(--bg-secondary) !important;
  font-weight: 600;
  font-size: 0.8rem;
  text-align: left !important;
  padding: 0.4rem 0.5rem !important;
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 7rem;
  color: var(--text-primary);
  white-space: nowrap;
}

/* Hour cells */
.hour-cell {
  min-width: 2.6rem;
  height: 2.4rem;
  font-size: 0.68rem;
  font-weight: 500;
  vertical-align: middle;
  position: relative;
  cursor: default;
  transition: filter 0.15s;
}

.hour-cell:hover { filter: brightness(0.92); }

.hour-cell .cell-label {
  display: block;
  line-height: 1;
}

/* Cell colour classes */
.hour-core  { background: var(--cell-core-bg);  color: var(--cell-core-text); }
.hour-early { background: var(--cell-early-bg); color: var(--cell-early-text); }
.hour-night { background: var(--cell-night-bg); color: var(--cell-night-text); }

/* Golden column (all cities in core hours) */
.hour-golden {
  background: var(--cell-golden-bg) !important;
  color: var(--cell-golden-text) !important;
  box-shadow: inset 0 0 0 2px var(--accent);
  font-weight: 700;
}

/* NOW indicator */
.now-col-header {
  background: var(--accent) !important;
  color: #fff !important;
  border-radius: 0.2rem;
}

.now-cell {
  border-left: 3px solid var(--accent) !important;
  border-right: 3px solid var(--accent) !important;
}

.now-cell:first-of-type { border-top: 3px solid var(--accent) !important; }

/* ── Suggestions Section ──────────────────────────────── */
#suggestions-section {
  margin-bottom: 2rem;
  display: none;
}

#suggestions-section.visible { display: block; }

#suggestion-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

/* ── Suggestion Card ──────────────────────────────────── */
.suggestion-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.1rem;
  box-shadow: 0 2px 8px var(--shadow);
  animation: fadeInUp 0.3s ease forwards;
  opacity: 0;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.suggestion-card:nth-child(1) { animation-delay: 0.05s; }
.suggestion-card:nth-child(2) { animation-delay: 0.10s; }
.suggestion-card:nth-child(3) { animation-delay: 0.15s; }

.suggestion-quality {
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.6rem;
}

.suggestion-times {
  list-style: none;
  margin-bottom: 0.7rem;
}

.suggestion-times li {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 0.15rem 0;
  color: var(--text-primary);
}

.suggestion-times li .sug-city  { color: var(--text-secondary); }
.suggestion-times li .sug-time  { font-weight: 600; font-family: monospace; }

.score-bar-wrapper {
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  height: 0.45rem;
  margin-bottom: 0.8rem;
  overflow: hidden;
}

.score-bar {
  height: 100%;
  border-radius: 0.5rem;
  background: var(--accent);
  transition: width 0.6s ease;
}

.suggestion-actions {
  display: flex;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  border: 1px solid transparent;
}

.btn:active { transform: scale(0.96); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover { background: var(--border); }

/* ── Export Modal / Inline Form ───────────────────────── */
#export-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  display: none;
}

#export-overlay.open { display: flex; }

#export-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1.5rem;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 16px 48px var(--shadow-md);
  animation: slideIn 0.2s ease;
}

#export-modal h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.form-group {
  margin-bottom: 0.9rem;
}

.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.1rem;
}

/* ── No overlap message ───────────────────────────────── */
#no-overlap-msg {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-radius: 0.5rem;
  display: none;
}

#no-overlap-msg.visible { display: block; }

/* ── Footer ───────────────────────────────────────────── */
#app-footer {
  text-align: center;
  padding: 2rem 1.5rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.footer-brand {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.footer-privacy {
  font-size: 0.78rem;
  max-width: 620px;
  margin: 0 auto;
  line-height: 1.6;
  color: var(--text-secondary);
}

.footer-copy {
  font-size: 0.73rem;
  color: var(--text-secondary);
  opacity: 0.75;
}

/* ── Animations ───────────────────────────────────────── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)     scale(1); }
}

@keyframes fadeOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.92); max-height: 0; padding: 0; margin: 0; }
}

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 639px) {
  .brand-tagline { font-size: 1.2rem; }

  #city-cards-grid {
    grid-template-columns: 1fr;
  }

  #suggestion-cards {
    grid-template-columns: 1fr;
  }

  .header-inner { padding: 0.6rem 0.75rem; }

  #app-main { padding: 1rem 0.75rem 2.5rem; }
}

@media (min-width: 640px) and (max-width: 1023px) {
  #city-cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  #city-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

/* ── Scrollbar styling ────────────────────────────────── */
.grid-scroll-wrapper::-webkit-scrollbar { height: 6px; }
.grid-scroll-wrapper::-webkit-scrollbar-track { background: var(--bg-secondary); }
.grid-scroll-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
