/* Temple Scraper - Design System */
:root {
  --primary: #1D3557;
  --secondary: #457B9D;
  --light: #A8DADC;
  --background: #ffffff;
  --accent: #E63946;
  --sidebar-width: 280px;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 1rem;
  line-height: 1.6;
  margin: 0;
  background: var(--background);
  color: var(--primary);
  min-height: 100vh;
}

h1 {
  font-size: 2rem;
  font-weight: bold;
  margin: 0 0 1rem;
}

/* Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: linear-gradient(180deg, var(--primary) 0%, #0f1f35 100%);
  color: white;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease;
}

.sidebar-nav {
  padding: 1rem 0;
  flex: 1;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.1);
  color: white;
}

.sidebar-nav a.active {
  background: rgba(255,255,255,0.15);
  color: white;
  font-weight: 500;
}

.sidebar-nav .bi {
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: 1.5rem 2rem;
  min-height: 100vh;
}

/* Cards */
.card {
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  border-radius: 0.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 1rem;
  color: var(--primary);
}

.schedule-help {
  margin: 0 0 1rem;
  color: var(--secondary);
  font-size: 0.95rem;
}

/* Buttons - standard sizing (match Save/Reset Filters for consistency) */
.btn-primary-custom,
.btn-secondary-custom {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  min-height: 2.375rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.btn-primary-custom {
  background: var(--accent);
  color: white;
  border: 1px solid var(--accent);
}

.btn-primary-custom:hover {
  transform: scale(1.02);
  box-shadow: 0 2px 8px rgba(230,57,70,0.4);
}

.btn-secondary-custom {
  background: var(--secondary);
  color: white;
  border: 1px solid var(--secondary);
}

.btn-secondary-custom:hover {
  background: var(--light);
  color: var(--primary);
  border-color: var(--secondary);
  transform: scale(1.02);
}

.btn-unsubscribe {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  min-height: 2.375rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  background: #6c757d;
  color: white;
  border: 1px solid #6c757d;
}

.btn-unsubscribe:hover {
  background: #5a6268;
  border-color: #5a6268;
  transform: scale(1.02);
}

/* Page header with button on right */
.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-header-row h1 {
  margin-bottom: 0.25rem;
}

.page-header-row p {
  margin: 0;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop[aria-hidden="false"] {
  display: flex;
}

.modal-dialog {
  background: var(--background);
  border-radius: 0.5rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--primary);
  cursor: pointer;
  padding: 0.25rem;
  opacity: 0.7;
}

.modal-close:hover {
  opacity: 1;
}

.modal-body {
  padding: 1.5rem;
}

.notify-actions-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.notify-actions-row input {
  flex: 1;
  min-width: 0;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--primary);
}

.form-control,
input.form-control,
select.form-control,
textarea.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
}

/* Consistent select styling - match input appearance (white bg, same border, chevron) */
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-color: white;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 16 16'%3E%3Cpath fill='%23333' d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}

select.form-control:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 2px rgba(69,123,157,0.2);
}

input[type="date"],
input[type="time"],
input[type="number"],
input[type="text"],
select,
textarea {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Baptism sessions filters - consistent input sizing */
.filters-row .form-group {
  flex: 1 1 auto;
  min-width: 0;
}

@media (min-width: 769px) {
  .filters-row .form-group {
    min-width: 120px;
    max-width: 220px;
  }
  .filters-row-2 .filter-presaved {
    min-width: 340px;
    max-width: none;
    flex: 1 1 auto;
  }
  .filter-buttons {
    flex-direction: row;
    flex-wrap: nowrap;
  }
  .filter-actions-row .form-group {
    max-width: none;
    flex: 0 0 auto;
  }
}

.filters-row .filter-input,
.filters-row select.filter-input,
.filters-row input.filter-input,
.filters-row .multiselect-trigger.filter-input {
  width: 100%;
  min-height: 2.375rem;
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  line-height: 1.5;
}

.filter-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-reset-filters,
.btn-save-filters {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  min-height: 2.375rem;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

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

.btn-reset-filters:hover {
  background: rgba(69,123,157,0.1);
  border-color: var(--secondary);
}

.btn-save-filters {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
}

.btn-save-filters:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.filter-actions .filter-buttons {
  align-items: stretch;
}

.presaved-filter-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.presaved-filter-row select {
  flex: 1;
  min-width: 0;
}

.btn-delete-filter {
  padding: 0.5rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.5;
  min-height: 2.375rem;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  cursor: pointer;
  background: white;
  color: var(--primary);
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s;
}

.btn-delete-filter:hover:not(:disabled) {
  background: rgba(230,57,70,0.1);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-delete-filter:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.multiselect-dropdown {
  position: relative;
  min-width: 0;
}

.multiselect-panel {
  min-width: 10rem;
}

.multiselect-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
  background: white;
}

.multiselect-chevron {
  font-size: 0.75rem;
  opacity: 0.7;
  transition: transform 0.2s;
}

.multiselect-dropdown.open .multiselect-chevron {
  transform: rotate(180deg);
}

.multiselect-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background: white;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 100;
  padding: 0.5rem;
  max-height: 12rem;
  overflow-y: auto;
}

.multiselect-panel.open {
  display: block;
}

.multiselect-option {
  display: block;
  padding: 0.4rem 0.5rem;
  cursor: pointer;
  border-radius: 0.25rem;
  margin: 0;
  white-space: nowrap;
}

.multiselect-option:hover {
  background: rgba(69,123,157,0.1);
}

.multiselect-option input {
  margin-right: 0.5rem;
  cursor: pointer;
}

.form-control:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 2px rgba(69,123,157,0.2);
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  border-radius: 0.5rem;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
}

/* History table: fit viewport on desktop, word wrap for long content */
.history-table {
  table-layout: fixed;
  width: 100%;
}

.history-table .temples-cell,
.history-table .error-cell {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  min-width: 0;
}

.history-table th:nth-child(5),
.history-table td:nth-child(5),
.history-table th:nth-child(8),
.history-table td:nth-child(8) {
  max-width: 10rem;
}

/* Settings page table wrapper - enable horizontal scroll */
#page-scraper .table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th {
  background: var(--primary);
  color: white;
  font-weight: 500;
}

th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th.sortable:hover {
  background: #162a47;
}

th.sortable .sort-icon {
  margin-left: 0.25rem;
  opacity: 0.7;
  font-size: 0.85rem;
}

tr:hover {
  background: rgba(168,218,220,0.2);
}

/* Page sections */
.page-section {
  display: none;
}

.page-section.active {
  display: block;
}

/* Filters row */
.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.5rem;
  align-items: flex-end;
}

.filters-row .form-group {
  margin-bottom: 0;
}

/* Buttons row - minimal top margin for tighter vertical spacing */
.filter-actions-row {
  margin-bottom: 0.75rem;
  margin-top: 0.25rem;
}

/* Mobile top bar - hidden on desktop, contains hamburger on mobile */
.mobile-top-bar {
  display: none;
}

.hamburger {
  display: none;
}

/* Mobile */
@media (max-width: 768px) {
  html, body {
    overflow-x: hidden;
    max-width: 100vw;
  }

  .app-layout, .main-content {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .main-content {
    margin-left: 0;
    padding: 56px 1rem 1.5rem 1rem;
  }

  .page-section {
    max-width: 100%;
  }

  .card {
    max-width: 100%;
  }

  .table-wrapper {
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
  }

  /* Settings page: allow horizontal scroll, limit wrapping */
  #page-scraper .table-wrapper {
    overflow-x: auto;
  }

  #page-scraper .history-table {
    table-layout: auto;
    min-width: 600px;
  }

  #page-scraper .history-table th,
  #page-scraper .history-table td {
    white-space: nowrap;
  }

  #page-scraper .history-table .temples-cell,
  #page-scraper .history-table .error-cell {
    white-space: nowrap;
    max-width: none;
  }

  #page-scraper .history-table th:nth-child(5),
  #page-scraper .history-table td:nth-child(5),
  #page-scraper .history-table th:nth-child(8),
  #page-scraper .history-table td:nth-child(8) {
    max-width: none;
  }

  .filters-row {
    max-width: 100%;
    flex-direction: column;
  }

  .filters-row .form-group {
    min-width: 0;
    flex: 1 1 100%;
    width: 100%;
  }

  .filters-row .filter-presaved,
  .filters-row .filter-actions {
    width: 100%;
  }

  .presaved-filter-row {
    flex-wrap: wrap;
  }

  .presaved-filter-row .btn-delete-filter {
    flex: 0 0 auto;
  }

  /* Keep Save/Reset buttons side by side on all screen sizes */
  .filter-buttons {
    flex-direction: row;
    flex-wrap: nowrap;
  }

  .filter-buttons .btn-reset-filters,
  .filter-buttons .btn-save-filters {
    width: auto;
    flex: 0 0 auto;
  }

  .form-control,
  select,
  input,
  textarea,
  .multiselect-trigger {
    font-size: 16px !important;
  }

  select option {
    font-size: 16px;
  }

  .multiselect-panel {
    position: fixed !important;
    z-index: 1100;
    font-size: 1rem !important;
    left: 1rem !important;
    right: 1rem !important;
    width: auto !important;
    max-width: calc(100vw - 2rem);
  }

  .multiselect-option {
    font-size: 1rem !important;
  }

  .multiselect-dropdown {
    min-width: 100%;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar .sidebar-nav {
    padding-top: 56px;
  }

  body.sidebar-open .main-content {
    margin-left: var(--sidebar-width) !important;
  }

  .main-content {
    transition: margin-left 0.2s ease;
  }

  .table-wrapper table,
  .table-wrapper th,
  .table-wrapper td {
    font-size: 0.8rem;
  }

  .table-wrapper th,
  .table-wrapper td {
    padding: 0.5rem 0.6rem;
  }

  .mobile-top-bar {
    display: flex !important;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 48px;
    z-index: 1001;
    background: linear-gradient(180deg, var(--primary) 0%, #0f1f35 100%);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  }

  .hamburger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: transparent;
    color: white;
    border: none;
    padding: 0;
    border-radius: 0;
    cursor: pointer;
  }

  .hamburger .bi {
    font-size: 1.5rem;
  }
}

/* Pagination */
.pagination-wrapper {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid #eee;
}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.pagination-info {
  color: var(--secondary);
  font-size: 0.95rem;
}

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

.btn-pagination {
  padding: 0.4rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  background: white;
  color: var(--primary);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-pagination:hover:not(:disabled) {
  background: rgba(69,123,157,0.1);
  border-color: var(--secondary);
}

.btn-pagination:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pagination-page {
  font-size: 0.95rem;
  color: var(--primary);
}

/* Toast notification */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  background: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease;
}

.toast.success {
  border-left: 4px solid #28a745;
}

.toast.error {
  border-left: 4px solid var(--accent);
}

.notification-message {
  font-size: 0.95rem;
}
.notification-message.success {
  color: #28a745;
}
.notification-message.error {
  color: var(--accent);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Accessibility */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--secondary);
  outline-offset: 2px;
}
