/* CSS Variables - Pastel Sports Ground Theme (Pink/Green) */
:root {
  /* Primary: Soft grass green */
  --color-primary: #7cb798;
  --color-primary-dark: #5a9a78;
  /* Accent: Soft track pink */
  --color-accent: #e8a4b8;
  --color-accent-dark: #d68a9e;
  /* Backgrounds */
  --color-bg: #faf9f7;
  --color-surface: #ffffff;
  /* Text */
  --color-text: #3d3d3d;
  --color-text-secondary: #6b6b6b;
  /* Borders */
  --color-border: #e0ddd8;
  /* Semantic colors - pastels */
  --color-success: #7cb798;
  --color-warning: #f5d89a;
  --color-error: #e8a4b8;
  --color-info: #a4cce8;

  /* Status colors - Pastel palette */
  --status-A: #c5e8d2; /* Open - soft mint green */
  --status-L: #fef3c7; /* Limited - soft cream yellow */
  --status-B: #fcd5dc; /* Blocked - soft blush pink */
  --status-M: #e8e5e0; /* Closed - warm grey */

  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 12px rgba(0,0,0,0.10), 0 2px 6px rgba(0,0,0,0.08);

  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* Skip Link for Accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--color-primary);
  color: white;
  padding: 8px 16px;
  z-index: 1000;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
}

.skip-link:focus {
  top: 0;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.logo {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-primary);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  white-space: nowrap;
}

.logo-accent {
  color: var(--color-accent);
}

.logo-zh {
  color: var(--color-accent);
  font-size: inherit; /* Same size as parent logo for visual consistency */
  margin-left: 6px;
}

.lang-btn {
  background: var(--color-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.lang-btn:hover {
  background: var(--color-primary-dark);
}

/* Main Content */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
}

/* Intro */
.intro {
  text-align: center;
  padding: 24px 0;
}

.intro-text {
  font-size: 1.125rem;
  color: var(--color-text-secondary);
}

/* Filters */
.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
  background: var(--color-surface);
  padding: 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-secondary);
}

.select {
  padding: 10px 12px;
  font-size: 1rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: border-color 0.2s;
}

.select:hover:not(:disabled) {
  border-color: var(--color-primary);
}

.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.2);
}

.select:disabled {
  background: var(--color-bg);
  color: var(--color-text-secondary);
  cursor: not-allowed;
}

.select option:disabled {
  color: #999;
  background: #f5f5f5;
}

/* Search button in filters */
.filter-group-button {
  display: flex;
  align-items: flex-end;
}

.btn-search {
  background: var(--color-primary);
  color: white;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.btn-search:hover:not(:disabled) {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.btn-search:disabled {
  background: var(--color-border);
  color: var(--color-text-secondary);
  cursor: not-allowed;
}

/* Timetable Section */
.timetable-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.timetable-header {
  margin-bottom: 16px;
}

.table-last-updated {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.venue-title {
  font-size: 1.25rem;
  font-weight: 600;
}

/* Legend */
.legend {
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--color-bg);
  border-radius: var(--radius);
}

.legend h3 {
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--color-text-secondary);
}

.legend-items {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
}

.legend-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
}

/* Special Notes (e.g., turf maintenance with jogging track available) */
.special-notes-section {
  margin-bottom: 16px;
}

.special-notes-content {
  padding: 12px 16px;
  background: linear-gradient(135deg, #e8f5ec 0%, #d4f0de 100%);
  border-radius: var(--radius);
  border-left: 4px solid var(--color-primary);
}

.special-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--color-text);
  line-height: 1.5;
}

.special-note::before {
  content: "ℹ️";
  flex-shrink: 0;
}

.special-note + .special-note {
  margin-top: 8px;
}

/* Timetable */
.timetable-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.timetable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  min-width: 800px;
}

.timetable th,
.timetable td {
  padding: 6px 4px;
  text-align: center;
  border: 1px solid var(--color-border);
  white-space: nowrap;
}

.timetable th {
  background: var(--color-bg);
  font-weight: 500;
  position: sticky;
  top: 0;
}

.timetable th.time-header {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--color-bg);
}

.timetable td.time-cell {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  font-weight: 500;
  text-align: left;
  padding-left: 8px;
  z-index: 3; /* Higher than highlight overlay to ensure visibility */
}

.timetable .weekend {
  background: #f5f3f0;
}

/* Status colors - Pastel palette */
.status-A { background: var(--status-A); } /* Mint green - open */
.status-L { background: var(--status-L); } /* Cream yellow - limited lanes */
.status-B { background: var(--status-B); } /* Blush pink - blocked */
.status-M { background: var(--status-M); } /* Warm grey - closed */
.status-T { background: #ffc99c; } /* Orange - turf maintenance, jogging track available */
.status-S { background: #e8d4f0; } /* Soft lavender - sports booking */
.status-F { background: #d4eaf5; } /* Soft sky blue - football */
.status-R { background: #deecd4; } /* Soft sage - rugby */
.status-G { background: #d4c0f0; } /* Purple - grass pitch booked (Causeway Bay) */
.status-GL { background: #fdd8a8; } /* Soft orange - both lanes and grass booked (Causeway Bay) */

.timetable td.status-A,
.timetable td.status-L,
.timetable td.status-B,
.timetable td.status-M,
.timetable td.status-T,
.timetable td.status-S,
.timetable td.status-F,
.timetable td.status-R,
.timetable td.status-G,
.timetable td.status-GL {
  font-weight: 500;
}

/* Today's column highlight */
.timetable th.today-column,
.timetable td.today-column {
  border-left: 3px solid var(--color-primary);
  border-right: 3px solid var(--color-primary);
}

.timetable th.today-column {
  background: linear-gradient(to bottom, var(--color-primary), var(--color-primary-dark));
  color: white;
  font-weight: 600;
  border-top: 3px solid var(--color-primary);
}

.timetable tr:last-child td.today-column {
  border-bottom: 3px solid var(--color-primary);
}

/* Past days - greyed out and muted */
.timetable th.past-day,
.timetable td.past-day {
  opacity: 0.5;
}

.timetable th.past-day {
  background: #e0e0e0;
  color: var(--color-text-secondary);
}

.timetable td.past-day:not(.time-cell) {
  background: #f2f0ed !important;
  color: var(--color-text-secondary);
}

/* Double height for today's cells */
.timetable td.today-column {
  padding-top: 12px;
  padding-bottom: 12px;
}

/* Cells with notices - clickable link style */
.timetable td.has-notice {
  cursor: pointer;
  text-decoration: underline;
}

.timetable td.status-B.has-notice:hover {
  background: #f5b8c3;
}

.timetable td.status-L.has-notice:hover {
  background: #fceaa8;
}

.timetable td.status-M.has-notice:hover {
  background: #d5d2cd;
}

.timetable td.status-T.has-notice:hover {
  background: #f5d4a8;
}

.timetable td.status-S.has-notice:hover {
  background: #d8c0e5;
}

.timetable td.status-F.has-notice:hover {
  background: #b8d8ed;
}

.timetable td.status-R.has-notice:hover {
  background: #c8dcc0;
}

.timetable td.status-G.has-notice:hover {
  background: #c0a8e0;
}

.timetable td.status-GL.has-notice:hover {
  background: #f5c888;
}

/* Notices */
.notices-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

.notices-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.notices-content {
  font-size: 0.875rem;
}

.notice-item {
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.notice-item:last-child {
  margin-bottom: 0;
}

.notice-item.highlight {
  animation: highlight-pulse 2s ease-out;
}

@keyframes highlight-pulse {
  0% { background: var(--color-primary); color: white; }
  100% { background: var(--color-bg); color: inherit; }
}

.notice-datetime {
  font-weight: 500;
  color: var(--color-primary);
}

.notice-facility {
  color: var(--color-text-secondary);
  margin: 4px 0;
}

.notice-reason {
  font-style: italic;
}

/* Loading */
.loading {
  text-align: center;
  padding: 48px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error */
.error {
  text-align: center;
  padding: 24px;
  background: #fff3f3;
  border-radius: var(--radius);
  color: var(--color-error);
}

/* Footer */
.footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 24px 16px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-top: auto;
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
}

.footer a {
  color: var(--color-primary);
  text-decoration: none;
}

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

.footer-source {
  margin-bottom: 8px;
}

.last-updated {
  font-size: 0.75rem;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.footer-feedback {
  font-size: 0.8rem;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--color-border);
}

.footer-disclaimer {
  font-size: 0.75rem;
  color: var(--color-text-secondary);
  font-style: italic;
  margin-bottom: 8px;
}

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

/* Quick Actions */
.quick-actions {
  margin-bottom: 24px;
  text-align: center;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
}

.quick-actions-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 12px;
}

.quick-actions-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.btn {
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.btn-region {
  background: var(--color-bg);
  color: var(--color-text);
  border: 2px solid var(--color-border);
  flex: 1;
  min-width: 140px;
  max-width: 200px;
}

.btn-region:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-hover);
}

.btn-region.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

/* Today Section */
.today-section {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 24px;
}

.today-legend {
  margin: 12px 0 16px 0;
  padding: 8px 12px;
  background: var(--color-bg);
}

.section-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.today-date {
  color: var(--color-text-secondary);
  margin-bottom: 16px;
}

.today-venues {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.today-venue-card {
  background: var(--color-bg);
  border-radius: var(--radius);
  padding: 16px;
}

.today-venue-name {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--color-text);
}

.today-venue-district {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
}

.today-timeline-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.today-timeline {
  display: flex;
  gap: 2px;
  min-width: max-content;
}

.today-slot {
  min-width: 50px;
  padding: 8px 4px;
  text-align: center;
  border-radius: 4px;
  font-size: 0.75rem;
}

.today-slot-time {
  font-weight: 500;
  margin-bottom: 2px;
}

.today-slot-status {
  font-weight: 600;
}

.today-slot.current-time {
  border: 2px solid var(--color-primary);
  box-shadow: 0 0 8px rgba(124, 183, 152, 0.5);
}

.today-no-venues {
  text-align: center;
  color: var(--color-text-secondary);
  padding: 24px;
}

/* Row and column highlight on hover/touch */
.timetable tr.highlight-row td:not(.time-cell) {
  background-color: rgba(0, 0, 0, 0.06) !important;
}

.timetable tr.highlight-row td.time-cell {
  background-color: #e8f5ec !important; /* Soft mint - matches primary green */
  font-weight: 600;
  z-index: 3; /* Higher z-index to stay above highlight overlay */
}

.timetable th.highlight-col,
.timetable td.highlight-col {
  background-color: rgba(0, 0, 0, 0.06) !important;
}

.timetable th.highlight-col {
  background-color: rgba(124, 183, 152, 0.15) !important; /* Soft green tint */
  font-weight: 600;
}

/* Highlighted cell itself gets stronger highlight */
.timetable td.highlight-cell {
  outline: 2px solid var(--color-primary);
  outline-offset: -2px;
  z-index: 1;
  position: relative;
}

/* Preserve status colors with overlay effect - pastel tones */
.timetable tr.highlight-row td.status-A:not(.highlight-cell) { background-color: #a8dbb8 !important; }
.timetable tr.highlight-row td.status-L:not(.highlight-cell) { background-color: #fceaa8 !important; }
.timetable tr.highlight-row td.status-B:not(.highlight-cell) { background-color: #f5b8c3 !important; }
.timetable tr.highlight-row td.status-M:not(.highlight-cell) { background-color: #d5d2cd !important; }
.timetable tr.highlight-row td.status-T:not(.highlight-cell) { background-color: #f5d4a8 !important; }
.timetable tr.highlight-row td.status-S:not(.highlight-cell) { background-color: #d8c0e5 !important; }
.timetable tr.highlight-row td.status-F:not(.highlight-cell) { background-color: #b8d8ed !important; }
.timetable tr.highlight-row td.status-R:not(.highlight-cell) { background-color: #c8dcc0 !important; }
.timetable tr.highlight-row td.status-G:not(.highlight-cell) { background-color: #c0a8e0 !important; }
.timetable tr.highlight-row td.status-GL:not(.highlight-cell) { background-color: #f5c888 !important; }

.timetable td.highlight-col.status-A:not(.highlight-cell) { background-color: #a8dbb8 !important; }
.timetable td.highlight-col.status-L:not(.highlight-cell) { background-color: #fceaa8 !important; }
.timetable td.highlight-col.status-B:not(.highlight-cell) { background-color: #f5b8c3 !important; }
.timetable td.highlight-col.status-M:not(.highlight-cell) { background-color: #d5d2cd !important; }
.timetable td.highlight-col.status-T:not(.highlight-cell) { background-color: #f5d4a8 !important; }
.timetable td.highlight-col.status-S:not(.highlight-cell) { background-color: #d8c0e5 !important; }
.timetable td.highlight-col.status-F:not(.highlight-cell) { background-color: #b8d8ed !important; }
.timetable td.highlight-col.status-R:not(.highlight-cell) { background-color: #c8dcc0 !important; }
.timetable td.highlight-col.status-G:not(.highlight-cell) { background-color: #c0a8e0 !important; }
.timetable td.highlight-col.status-GL:not(.highlight-cell) { background-color: #f5c888 !important; }

/* Utility */
.hidden {
  display: none !important;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .header-content {
    padding: 10px 12px;
  }

  .logo {
    font-size: 1.25rem;
  }

  .main {
    padding: 12px;
  }

  .filters {
    padding: 16px;
  }

  .timetable-section {
    padding: 16px;
  }

  .timetable {
    font-size: 0.75rem;
  }

  /* Wider columns on mobile for better readability */
  .timetable th:not(.time-header),
  .timetable td:not(.time-cell) {
    min-width: 50px;
  }

  .timetable th,
  .timetable td {
    padding: 4px 2px;
  }

  .legend-items {
    flex-direction: column;
    gap: 8px;
  }
}
