:root {
    --bg-gradient-start: #f5f7fa;
    --bg-gradient-end: #e8ecf1;
    --card-bg: white;
    --text-color: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --input-bg: white;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-light: rgba(0, 0, 0, 0.05);
    --accent-bg: #f3f4f6;
    --accent-border: #3b82f6;
    --success-bg: #d1fae5;
    --success-text: #065f46;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --zones-bg: #f9fafb;
    --zones-text: #374151;
    --zones-border: #e5e7eb;
    --sunset-input-border: rgba(0,0,0,0.15);
    /* compatibility variables used elsewhere in the stylesheet */
    --paper-bg: white;
    --paper-fg: #111827;
    --muted: #6b7280;
    --logs-bg: #f9fafb;
    --logs-fg: #374151;
    --logs-border: #e5e7eb;
}


/* Backup preview tooltip (used by static/js/index.js) */
.backup-preview-tooltip {
  position: fixed;
  display: none;
  z-index: 9999;
  background: var(--card-bg);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  padding: 12px;
  border-radius: 8px;
  max-width: min(720px, 92vw);
  max-height: 72vh;
  overflow: auto;
  box-shadow: 0 8px 32px rgba(16,24,40,0.12);
  font-size: 0.95em;
  line-height: 1.35;
  pointer-events: auto;
}

/* Visible state */
.backup-preview-tooltip.show { display: block; }

.backup-preview-tooltip .preview-title { font-weight: 700; margin-bottom: 6px; }
.backup-preview-tooltip .preview-content { display: block; }
.backup-preview-tooltip .preview-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 6px; flex-wrap: wrap; }
.backup-preview-tooltip .preview-ward { font-weight: 800; margin-right: 8px; color: var(--accent-border); min-width: 44px; }
.backup-preview-tooltip .preview-pair { color: var(--text-secondary); margin-right: 8px; display: inline-block; min-width: 46px; }
.backup-preview-tooltip .preview-ellipsis { color: var(--muted); margin-left: 6px; }
.backup-preview-tooltip .preview-note { margin-top: 8px; font-size: 0.85em; color: var(--text-secondary); }

/* Hide preview tooltips on touch devices */
@media (hover: none) and (pointer: coarse) {
  .backup-preview-tooltip { display: none !important; }
}

/* Theme-aware Bootstrap dropdown overrides */
.dropdown-menu {
  background: var(--card-bg) !important;
  color: var(--text-color) !important;
  border: 1px solid var(--border-color) !important;
  box-shadow: 0 8px 24px rgba(16,24,40,0.06) !important;
  border-radius: 8px !important;
  padding: 6px 0 !important;
}
.dropdown-menu li { list-style: none; }
.dropdown-item {
  color: var(--text-color) !important;
  background: transparent !important;
  padding: 8px 16px !important;
}
.dropdown-item.disabled { color: var(--text-secondary) !important; }
.dropdown-item:hover, .dropdown-item:focus, .dropdown-item.active {
  background: var(--accent-bg) !important;
  color: var(--text-color) !important;
}

/* Ensure dropdown dividers respect theme */
.dropdown-divider { border-top: 1px solid var(--border-color) !important; }
[data-theme="dark"] {
    --bg-gradient-start: #2c3e50;
    --bg-gradient-end: #34495e;
    --card-bg: #2c3e50;
    --text-color: #ecf0f1;
    --text-secondary: #bdc3c7;
    --border-color: #34495e;
    --input-bg: #34495e;
    --shadow: rgba(0, 0, 0, 0.4);
    --shadow-light: rgba(0, 0, 0, 0.2);
    --accent-bg: #34495e;
    --accent-border: #3498db;
    --success-bg: #27ae60;
    --success-text: #ecf0f1;
    --error-bg: #e74c3c;
    --error-text: #ecf0f1;
    --sunset-input-border: rgba(255,255,255,0.18);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    color: var(--text-color);
    transition: all 0.3s ease;
}

a {
    color: var(--accent-border);
    text-decoration: none;
    transition: all 0.3s ease;
}

/* Ensure Bootstrap's muted text follows the theme */
.muted, .text-muted { color: var(--text-secondary) !important; }

a:hover {
    color: var(--accent-border);
    text-decoration: underline;
    opacity: 0.8;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.header {
    position: relative;
    text-align: center;
    color: white;
    margin-bottom: 30px;
    padding-top: 18px;
}

/* Small branding image in the top-left of the header (legacy selectors) */
.header img.logo,
.header img.branding,
.header .brand-img,
.header img:first-child {
  position: absolute;
  top: 12px;
  left: 12px;
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}

/* Target header markup used in templates: #spkrLogo / .header-logo inside the flex header */
.header-logo,
#spkrLogo,
.d-flex.align-items-center > img.header-logo,
.d-flex.align-items-center > img#spkrLogo {
  position: relative;
  width: 64px !important;
  height: 64px !important;
  max-width: 64px !important;
  max-height: 64px !important;
  object-fit: contain !important;
  margin-right: 12px !important;
  vertical-align: middle;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.12);
}

/* When the logo exists next to the title, keep the title offset to avoid overlap */
.d-flex.align-items-center > img.header-logo + h1,
.d-flex.align-items-center > img#spkrLogo + h1 {
  margin: 0; /* reset default */
}

@media (max-width: 768px) {
  .header-logo, #spkrLogo, .d-flex.align-items-center > img.header-logo { width:48px !important; height:48px !important; max-width:48px !important; max-height:48px !important; margin-right:10px !important; }
}

/* Keep header text offset to avoid overlapping the small logo on wider screens */
@media (min-width: 600px) {
  .header h1, .header p {
    margin-left: 88px;
    text-align: left;
  }
}

@media (max-width: 480px) {
  .header img.logo,
  .header img.branding,
  .header .brand-img,
  .header img:first-child {
    width: 40px;
    height: 40px;
    top: 8px;
    left: 8px;
  }
  .header h1, .header p { margin-left: 56px; text-align: left; }
}

.card h3 {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 0;
    margin-bottom: 12px;
}

.card-title-left {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}
.card-title-right {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
}

.pattern-name {
    margin-left: 8px;
    color: #27ae60;
    font-weight: 600;
    font-size: 0.95em;
    white-space: nowrap;
}

.header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.header p {
    font-size: 1.2em;
    opacity: 0.9;
}

.nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    margin-bottom: 18px;
}

.nav-row { display: flex; align-items: center; gap: 20px; }
.nav-row.nav-links { justify-content: center; }

.nav-menu { display:flex; gap:15px; width:100%; }

@media (hover: none) and (pointer: coarse) {
    .hamburger-btn:hover { transform: none; background: rgba(255,255,255,0.2); }
    .hamburger-btn:active { background: rgba(255,255,255,0.4); transform: scale(0.95); }
}
.nav-row.nav-links { flex:1; justify-content:center; }
.nav-row.nav-controls { flex:0; justify-content:flex-end; }

.nav a {
    color: white;
    text-decoration: none;
    padding: 10px 20px;
    background: rgba(255,255,255,0.2);
    border-radius: 25px;
    transition: all 0.3s ease;
}

.nav a:hover, .nav a.active { background: rgba(255,255,255,0.3); transform: translateY(-2px); }
.nav a:active { transform: translateY(0); background: rgba(255,255,255,0.4); }

.theme-toggle {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    width: 40px; height: 40px; display:flex; align-items:center; justify-content:center;
}
.theme-toggle:hover { background: rgba(255,255,255,0.3); transform: translateY(-2px) rotate(180deg); }

#about-toggle-btn, .nav-about-link {
    display: inline-block; color: white; text-decoration: none; padding: 8px 14px; background: rgba(255,255,255,0.16); border-radius:20px; transition: all 0.18s ease; cursor:pointer; font-size:0.95em;
}
#about-toggle-btn:hover, .nav-about-link:hover { background: rgba(255,255,255,0.28); transform: translateY(-2px); }

@media (prefers-color-scheme: light) {
    #about-toggle-btn, .nav-about-link { color: black; background: rgba(0,0,0,0.06); }
    #about-toggle-btn:hover, .nav-about-link:hover { background: rgba(0,0,0,0.1); }
}

#controller-status-toggle.btn-compact { padding:6px 10px; font-size:13px; border-radius:12px; background: rgba(255,255,255,0.16); color: white; }
#controller-status-toggle.btn-compact:hover { transform: translateY(-2px); background: rgba(255,255,255,0.28); }

.card { background: var(--card-bg); border-radius:15px; padding:25px; margin-bottom:20px; box-shadow: 0 10px 30px var(--shadow); transition: transform 0.3s ease; border:1px solid var(--border-color); }
.card:hover { transform: translateY(-5px); }

.status-grid { display:grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap:20px; margin-bottom:30px; }

.status-indicator { display:inline-block; width:12px; height:12px; border-radius:50%; margin-right:8px; }
.status-connected { background-color:#4CAF50; }
.status-disconnected { background-color:#f44336; }

.btn { background: linear-gradient(135deg, var(--accent-border) 0%, var(--bg-gradient-end) 100%); color: white; border: none; padding: 12px 24px; border-radius:25px; cursor:pointer; font-size:16px; transition: all 0.3s ease; margin:5px; }
.btn:hover { transform: translateY(-2px); box-shadow: 0 5px 15px var(--shadow-light); }
.btn-compact { padding:6px 10px; font-size:12px; border-radius:6px; margin:0 6px; height:auto; line-height:1; }
.btn-danger { background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%); }
.btn-success { background: linear-gradient(135deg, #51cf66 0%, #40c057 100%); }

/* Light theme: use gray buttons for default buttons (including btn-secondary) */
html:not([data-theme="dark"]) .btn:not(.btn-danger):not(.btn-success) { 
    background: linear-gradient(135deg, #d1d5db 0%, #c4c9d0 100%);
    color: #1f2937;
}
html:not([data-theme="dark"]) .btn:not(.btn-danger):not(.btn-success):hover { 
    background: linear-gradient(135deg, #b8bdc5 0%, #9ca3af 100%); 
}

/* Light theme: use light green for success button (Generate Schedule) */
html:not([data-theme="dark"]) .btn-success {
    background: linear-gradient(135deg, #86efac 0%, #6ee7b7 100%);
    color: #1f2937;
}
html:not([data-theme="dark"]) .btn-success:hover {
    background: linear-gradient(135deg, #6ee7b7 0%, #4ade80 100%);
}

/* Modal Cancel button: subdued gray styling in both themes */
.modal-buttons .btn-secondary {
    background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
    color: #1f2937;
}
.modal-buttons .btn-secondary:hover {
    background: linear-gradient(135deg, #d1d5db 0%, #9ca3af 100%);
}

/* Dark theme: keep modal Cancel button gray/muted */
[data-theme="dark"] .modal-buttons .btn-secondary {
    background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
    color: #e5e7eb;
}
[data-theme="dark"] .modal-buttons .btn-secondary:hover {
    background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
}

.pattern-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap:15px; margin-top:20px; }
.pattern-item { background: var(--accent-bg); padding:15px; border-radius:10px; border-left:4px solid var(--accent-border); transition: all 0.3s ease; }
.pattern-item:hover { background: var(--border-color); transform: translateX(5px); }

.event-badge { display:inline-block; background: var(--accent-border); color: white; padding:4px 12px; border-radius:15px; font-size:0.9em; margin-bottom:10px; }

.controls { display:flex; gap:10px; flex-wrap:wrap; align-items:center; justify-content:center; margin-top:20px; }
.form-group { margin:10px 0; }
.form-group label { display:block; margin-bottom:5px; font-weight:bold; }
label[for="manual-args"] { font-weight:400; font-size:0.9em; color: var(--text-secondary); }
.form-group input, .form-group select { width:100%; padding:10px; border:1px solid var(--border-color); border-radius:5px; font-size:16px; background: var(--input-bg); color: var(--text-color); }

/* Apply theme to all form controls (covers inputs generated without .form-group) */
.form-control,
input,
select,
textarea {
  background: var(--input-bg) !important;
  color: var(--text-color) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 6px;
  padding: 8px 10px;
  box-shadow: none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent-border) !important;
  box-shadow: 0 0 0 6px rgba(102,126,234,0.06);
  outline: none;
}

/* Slightly darker header row */
.table thead tr {
  background-color: rgba(0, 0, 0, 0.15) !important;
}

/* Zebra-stripe every other row starting on row 2 (skip if only 1 row) */
.table tbody tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Table and panel theming to keep headers/rows consistent with the site theme */
.panel { background: var(--card-bg); border: 1px solid var(--border-color); padding: 12px; border-radius: 8px; }
.table { border-color: var(--border-color); background: transparent; }
.table thead th {
  background: var(--card-bg) !important;
  color: var(--text-color) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

/* Logs panel styling (used on main page) */
#logs {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 14px;
  border-radius: 8px;
  min-height: 84px;
  box-shadow: 0 8px 24px rgba(16,24,40,0.04);
  color: var(--text-color);
  white-space: pre-wrap;
}

/* Slightly tighter, small variant used inside .paper */
.paper #logs { min-height: 56px; padding: 10px; box-shadow: none; border-radius: 6px; }

/* Stronger specificity to override Bootstrap defaults when theme toggles */
html[data-theme="dark"] .table thead th,
html .panel .table thead th {
  background-color: var(--card-bg) !important;
  background-image: none !important;
  color: var(--text-color) !important;
}
.table thead th:first-child { border-top-left-radius: 6px; }
.table thead th:last-child { border-top-right-radius: 6px; }
.table tbody td {
  background: transparent;
  color: var(--text-color) !important;
  vertical-align: middle;
}
/* Inputs inside tables should match themed controls */
.table .form-control {
  background: var(--input-bg) !important;
  color: var(--text-color) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 8px;
  padding: 10px 12px;
}

/* Make small table badges / number cells use the accent but remain theme-aware */
.table .btn, .table .badge {
  background: linear-gradient(135deg, var(--accent-border) 0%, var(--bg-gradient-end) 100%);
  color: #fff;
  border: none;
}

/* High Council speakers: constrain the Name column input width so it isn't too wide */
#speakersTable .speaker-num {
  width: 56px;
  max-width: 56px;
  padding: 10px 12px;
  border-radius: 10px;
}
#speakersTable .speaker-name {
  width: 280px;
  max-width: 280px;
  padding: 10px 14px;
  border-radius: 10px;
}

/* Ensure speaker row layout respects the constrained widths when JS uses flex */
#speakersTable td[style] { display: table-cell; }
#speakersTable td > .form-control { box-sizing: border-box; }

/* Speaking months layout: align like Additional Lodge Speaking Months */
#monthsList .input-group {
  display: block;
}
#monthsList .input-group > div {
  display: flex;
  gap: 8px;
  align-items: center;
  width: 100%;
}
#monthsList .month-input {
  flex: 0 0 150px; /* match lodge date width */
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-color);
}
#monthsList .month-weekday {
  flex: 0 0 50px; /* match lodge weekday width */
  text-align: center; /* center like Additional Lodge */
  color: var(--muted); /* lighter muted color to match lodge */
  font-weight: 600;
  padding-left: 0;
}
#monthsList .month-display {
  flex: 0 0 100px; /* match lodge formatted date width */
  color: var(--muted);
  padding-left: 8px;
}

/* Adjust the header column sizing for the Speaking Months panel so Day aligns with lodge */
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-2 {
  flex: 0 0 50px;
  max-width: 50px;
  width: 50px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
}

/* Ensure the Speaking Date header column keeps its intended width */
#months_panel_headers {
  /* marker class (no DOM element) to group header overrides */
}

/* Make the header row use the same internal layout as the input rows (no bootstrap gutters) */
.panel > .mb-2 > .row.fw-bold.text-muted.small {
  margin-left: 0;
  margin-right: 0;
  display: flex;
  gap: 8px;
  align-items: center;
}
.panel > .mb-2 > .row.fw-bold.text-muted.small > div {
  padding-left: 0;
  padding-right: 0;
}

/* Fixed widths to match the input row flex children */
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-4 {
  flex: 0 0 150px;
  max-width: 150px;
  width: 150px;
  text-align: left;
  color: var(--text-color);
  font-weight: 700;
}
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-2 {
  /* span the weekday (50px) + gap (8px) + formatted date (100px) = 158px */
  flex: 0 0 158px;
  max-width: 158px;
  width: 158px;
  text-align: left;
  color: var(--text-color);
  font-weight: 700;
  padding-left: 8px; /* align header text with month-display spacing */
}
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-3 {
  /* Additional Lodge Day header: span weekday + formatted date width */
  flex: 0 0 158px;
  max-width: 158px;
  width: 158px;
  text-align: left;
  color: var(--text-color);
  font-weight: 700;
  padding-left: 8px;
}
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-5 {
  /* Speaker header: fixed width to align with speaker input values (JS uses ~80px) */
  flex: 0 0 100px;
  max-width: 100px;
  width: 100px;
  text-align: left;
  color: var(--text-color);
  font-weight: 700;
  padding-left: 8px;
}
.panel > .mb-2 > .row.fw-bold.text-muted.small > .col-6 {
  flex: 1 1 auto;
}

/* Restore compact, neutral delete buttons for months and lodge entries
   — they should only appear red on hover. Overrides Bootstrap's .btn-danger. */
.btn-remove-month, .btn-remove-lodge {
  background: transparent !important;
  color: var(--text-color) !important;
  border: 1px solid var(--border-color) !important;
  width: 36px !important;
  height: 36px !important;
  padding: 6px !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 50% !important;
  font-size: 14px !important;
  box-shadow: none !important;
  transition: background .16s ease, transform .12s ease, box-shadow .12s ease, color .12s ease;
}

.btn-remove-month:hover, .btn-remove-lodge:hover,
.btn-remove-month:active, .btn-remove-lodge:active {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a24 100%) !important;
  color: #fff !important;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.16) !important;
  border-color: transparent !important;
}

/* Make Add month button match lodge add button spacing */
#monthsList > button {
  margin-top: 8px;
}

/* Lodge inputs: ensure consistent sizing with months */
.lodge-date-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-color);
}
.lodge-speaker-input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-color);
}

.alert { padding:15px; border-radius:10px; margin:10px 0; }
.alert-success { background: var(--success-bg); color: var(--success-text); border:1px solid var(--success-bg); }
.alert-error { background: var(--error-bg); color: var(--error-text); border:1px solid var(--error-bg); }

/* Custom modal/dialog styling that respects theme */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.modal-overlay.show {
  opacity: 1;
}
.modal-dialog {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.9);
  transition: transform 0.2s ease;
}
.modal-overlay.show .modal-dialog {
  transform: scale(1);
}
.modal-title {
  font-size: 1.3em;
  font-weight: 600;
  color: var(--text-color);
  margin: 0 0 12px 0;
}
.modal-message {
  color: var(--text-color);
  line-height: 1.5;
  margin-bottom: 20px;
  white-space: pre-wrap;
}
.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}
.modal-buttons .btn {
  min-width: 80px;
  cursor: pointer;
  pointer-events: auto;
}
.modal-dialog {
  pointer-events: auto;
}

.scheduler-status { background: var(--accent-bg); border-radius:8px; padding:15px; border:1px solid var(--accent-border); }
.status-row { display:flex; justify-content:space-between; align-items:center; padding:8px 0; border-bottom:.1px solid var(--accent-border); }
.status-row-noline { display:flex; justify-content:space-between; align-items:center; padding:8px 0; border-bottom:none; }
.status-row-bold { display:flex; justify-content:space-between; align-items:center; padding:8px 0; font-weight:600; border-bottom:2px solid var(--accent-border); }
.status-row:last-child { border-bottom:none; }
.status-label { font-weight:600; color: var(--text-secondary); }
.status-label .icon { margin-right:8px; font-size:0.95em; vertical-align:middle; color: var(--text-secondary); }
.status-value { color: var(--text-color); font-family: 'Courier New', monospace; }
#next-moon-phase { display:inline-block; min-width:160px; text-align:right; }
.status-value-right { margin-left:auto; text-align:right; min-width:140px; }

.power-badge { display:inline-block; padding:6px 10px; border-radius:12px; font-weight:600; font-size:0.9em; min-width:46px; text-align:center; }
.zones-status { margin-right:8px; vertical-align:middle; display:inline-block; }
.power-on { background: linear-gradient(135deg, #2ecc71 0%, #27ae60 100%); color: white; }
.power-off { background: rgba(0,0,0,0.08); color: var(--text-color); }

#watch-status.running { color: #51cf66; }
#watch-status.stopped { color: #fa5252; }

@media (max-width: 768px) {
    .container { padding:10px; }
    .header h1 { font-size:1.8em; margin-bottom:8px; }
    .header p { font-size:0.9em; margin-bottom:5px; }
    .header { margin-bottom:15px; }
    .nav { flex-direction:column; align-items:center; gap:12px; margin-bottom:15px; }
    .nav-row.nav-links { flex-direction:row; flex-wrap:wrap; justify-content:center; gap:8px; }
    .nav-row.nav-controls { justify-content:center; }
    .nav a { padding:8px 14px; font-size:0.85em; min-width:44px; min-height:44px; display:flex; align-items:center; justify-content:center; }
    .theme-toggle { width:44px; height:44px; font-size:18px; padding:8px; }
    .status-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .container { padding:8px; }
    .header h1 { font-size:1.6em; }
    .header p { font-size:0.85em; margin-bottom:3px; }
    .header { margin-bottom:10px; }
    .nav { gap:0; margin-bottom:10px; }
    .nav-row.nav-links { gap:6px; }
    .nav a { padding:8px 12px; font-size:0.85em; min-width:40px; min-height:40px; }
    .theme-toggle { width:40px; height:40px; font-size:16px; padding:6px; }
    .card { padding:12px 8px; border-radius:8px; margin:0 2px; overflow:hidden; }
}

.emergency-row .status-value { display:inline-flex; align-items:center; gap:8px; white-space:nowrap; }
/* Ensure text inside the paper contrasts with the paper background */
.paper, .paper h2, .paper h5, .paper p, .paper li, .paper strong { color: var(--paper-fg); }
.paper .muted { color: var(--muted); }
.header-left h2 { font-size: 1.05rem; font-weight:700; margin:0; }
.schedule-meta { font-size: 0.78rem; line-height: 1.05; }
.paper .paper-body { height: calc(11in - 1rem); overflow: auto; padding: 0.5in; box-sizing: border-box; }
@media (max-width:900px){
  .page-viewport { padding: 1rem; }
  .paper { width: calc(100% - 2rem); height: auto; aspect-ratio: 8.5 / 11; }
}

.page-viewport {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #efefef;
  padding: 2rem 1rem;
  min-height: 100vh;
  box-sizing: border-box;
}
.actions-menu { background: var(--card-bg); border: 1px solid var(--border); border-radius:6px; box-shadow:0 6px 18px rgba(0,0,0,0.12); overflow:hidden; }
.actions-item { display:block; padding:8px 12px; color:var(--fg); text-decoration:none; width:100%; text-align:left; background:transparent; border:none; }
.actions-item:hover{ background:rgba(0,0,0,0.05); }
.paper {
  width: 8.5in;
  height: 11in;
  max-width: 100%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  border: 1px solid var(--border);
  background: var(--paper-bg);
  overflow: hidden;
  border-radius: 4px;
  box-sizing: border-box;
}
/* Keep the paper actions control visually subtle (three-dot control)
   to match original print/screen appearance. Overrides any global btn
   gradients that may apply. */
.paper #actionsBtn {
  background: rgba(0,0,0,0.04) !important;
  color: var(--muted) !important;
  border: 1px solid rgba(0,0,0,0.06) !important;
  width: 40px !important;
  height: 40px !important;
  padding: 0 !important;
  border-radius: 50% !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  font-size: 18px !important;
  line-height: 1 !important;
  box-shadow: none !important;
}
.paper #actionsBtn:hover {
  background: rgba(0,0,0,0.08) !important;
  transform: none !important;
}

/* Slightly darker background on schedule table headers */
.paper table.table thead th {
  background: #d5d8dc !important;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
/* Ensure text inside the paper contrasts with the paper background */
.paper, .paper h2, .paper h5, .paper p, .paper li, .paper strong { color: var(--paper-fg); }
.paper .muted { color: var(--muted); }
.header-left h2 { font-size: 1.05rem; font-weight:700; margin:0; }
.schedule-meta { font-size: 0.78rem; line-height: 1.05; }
.paper .paper-body { height: calc(11in - 1rem); overflow: auto; padding: 0.5in; box-sizing: border-box; }
@media (max-width:900px){
  .page-viewport { padding: 1rem; }
  .paper { width: calc(100% - 2rem); height: auto; aspect-ratio: 8.5 / 11; }
}

/* Rotate-to-landscape indicator shown on small portrait devices */
.rotate-indicator {
  position: fixed;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  top: 8px;
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  z-index: 2200;
  box-shadow: 0 6px 18px rgba(0,0,0,0.28);
  opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
  font-size: 13px;
}
.rotate-indicator.show {
  transform: translateX(-50%) translateY(0%);
  opacity: 1;
}
.rotate-indicator .rotate-icon { font-size: 16px; line-height:1; }
.rotate-indicator { left: 50%; right: auto; }
.rotate-indicator .rotate-text { max-width: calc(100vw - 96px); /* leave space for edges and close button */ white-space: normal; overflow: visible; text-overflow: unset; display: block; line-height: 1.15; }
.rotate-indicator .rotate-close { background: transparent; border: none; color: #fff; font-size: 18px; line-height:1; padding: 0 6px; cursor: pointer; }
.rotate-indicator.rotate-pulse { animation: rotatePulse .7s ease; }
@keyframes rotatePulse { 0% { transform: translateX(-50%) translateY(0) scale(1); } 50% { transform: translateX(-50%) translateY(0) scale(1.03); } 100% { transform: translateX(-50%) translateY(0) scale(1); } }

/* Keep indicator subtle on non-mobile widths */
@media (min-width: 431px) {
  .rotate-indicator { display: none !important; }
}

/* ===== Mobile responsive fixes (config & login pages) ===== */
@media (max-width: 576px) {
  /* Reduce body padding to reclaim viewport space */
  body.p-4 { padding: 8px !important; }

  /* Compact panel padding */
  .panel { padding: 8px; }

  /* Shrink header title */
  .d-flex.align-items-center > h1 {
    font-size: 1.55rem !important;
    line-height: 1.2;
  }

  /* Speaker table: fluid name column */
  #speakersTable .speaker-name {
    width: 100% !important;
    max-width: none !important;
  }
  #speakersTable .speaker-num {
    width: 48px !important;
    max-width: 48px !important;
  }

  /* Wards table: let browser auto-size columns, override colgroup inline widths */
  #wardsTable { table-layout: auto !important; width: 100% !important; }
  #wardsTable colgroup col { width: auto !important; }
  #wardsTable col:nth-child(1) { width: 110px !important; } /* Ward column */
  #wardsTable col:nth-child(2) { width: 160px !important; } /* Location */
  #wardsTable col:nth-child(3) { width: 130px !important; } /* Start Time */
  #wardsTable col:last-child { width: 36px !important; } /* keep delete button column narrow */

  /* Speaking months: fluid date input, compact labels */
  #monthsList .month-input { flex: 1 1 auto !important; min-width: 0; }
  #monthsList .month-weekday { flex: 0 0 36px !important; font-size: 0.8em; }
  .months-header-date { flex: 1 1 auto !important; min-width: 0; }
  .months-header-day { flex: 0 0 36px !important; font-size: 0.8em; }
  #monthsList .month-display { flex: 0 0 70px !important; font-size: 0.85em; }

  /* Lodge ALC: fluid date, compact display (!important overrides inline styles from JS) */
  .lodge-date-input { flex: 1 1 auto !important; min-width: 0 !important; }
  .lodge-speaker-input { flex: 0 0 60px !important; }
  .lodge-weekday { flex: 0 0 36px !important; font-size: 0.8em; }
  .lodge-header-date { flex: 1 1 auto !important; min-width: 0; }
  .lodge-header-day { flex: 0 0 36px !important; font-size: 0.8em; }
  .lodge-header-speaker { flex: 0 0 60px !important; font-size: 0.8em; }
  .lodge-display { flex: 0 0 70px !important; font-size: 0.85em; }

  /* Panel header columns: match the fluid input widths */
  .panel > .mb-2 > .row.fw-bold.text-muted.small > .col-4 {
    flex: 1 1 auto !important; max-width: none !important; width: auto !important;
  }
  .panel > .mb-2 > .row.fw-bold.text-muted.small > .col-2,
  .panel > .mb-2 > .row.fw-bold.text-muted.small > .col-3 {
    flex: 0 0 auto !important; max-width: none !important; width: auto !important;
  }

  /* Login page: prevent long title from overflowing */
  .login-card .card-title { font-size: 1.2rem; word-wrap: break-word; }
}

/* Login card: ensure text is visible in dark mode */
.login-card .card-title,
.login-card .form-label {
    color: var(--text-color);
}

/* Hide indicator in print */
@media print { .rotate-indicator { display: none !important; } }

/* Print styling to fit onto 8.5x11 (letter) in portrait */
@page { size: letter portrait; margin: 0.5in; }
@media print {
  /* Keep overall layout margins tight for print */
  body { margin: 0; padding: 0; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Hide viewport wrapper and paper container - print content directly */
  .page-viewport { 
    background: #fff !important; 
    padding: 0 !important;
    display: block !important;
  }
  .paper { 
    width: 100% !important;
    height: auto !important;
    max-width: 100% !important;
    background: #fff !important; 
    color: #000 !important; 
    box-shadow: none !important; 
    border: 0 !important; 
    border-radius: 0 !important;
  }
  .paper-body {
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }

  /* Hide only interactive controls in print (keep header content) */
  #actionsBtn, #actionsMenu, .mb-1 { display: none !important; }

  /* Make muted text readable in print */
  .muted, .text-muted, .small, .muted *, .text-muted * { color: #000 !important; opacity: 1 !important; }
  a, .actions-item { color: #000 !important; text-decoration: none !important; }

  /* Header styling - keep it visible and properly formatted */
  .d-flex.justify-content-between.align-items-start {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    margin-bottom: 0.25in !important;
  }
  .header-left { flex: 1; }
  .header-left h2 { 
    font-size: 16pt !important; 
    font-weight: 700 !important;
    margin: 0 0 0.1in 0 !important;
    color: #000 !important;
  }
  .header-right { 
    flex: 0 0 auto;
    font-size: 11pt !important;
    font-weight: 700 !important;
    color: #000 !important;
  }

  /* Tables: ensure borders are visible and backgrounds print uniformly */
  table { 
    font-size: 9pt; 
    border-collapse: collapse; 
    width: 100% !important; 
    margin-bottom: 0.2in !important;
  }
  th, td { 
    padding: 6px 8px !important; 
    border: 1px solid #333 !important; 
    vertical-align: middle !important; 
    color: #000 !important;
  }
  thead th { 
    background: #e8e8e8 !important; 
    -webkit-print-color-adjust: exact; 
    print-color-adjust: exact;
    font-weight: 600 !important;
  }

  .container-fluid { padding: 0 !important; width: 100% !important; }
  .small { font-size: 8.5pt; }
  .table-responsive { overflow: visible !important; }

  /* THREE COLUMN LAYOUT for Speakers, Legend, and Locations */
  .container-fluid.mt-3 { 
    margin-top: 0.2in !important; 
    display: table !important;
    width: 100% !important;
    page-break-inside: avoid;
    table-layout: fixed;
  }
  .container-fluid.mt-3 .row { 
    display: table-row !important;
  }
  .container-fluid.mt-3 .row > .col-md-4 {
    display: table-cell !important;
    vertical-align: top !important;
    padding: 0 0.15in 0 0 !important;
    width: 33.33% !important;
  }
  .container-fluid.mt-3 .row > .col-md-4:last-child {
    padding-right: 0 !important;
  }
  .container-fluid.mt-3 h5 {
    font-size: 10pt !important;
    font-weight: 700 !important;
    margin: 0 0 0.08in 0 !important;
    color: #000 !important;
  }
  .container-fluid.mt-3 ul {
    padding: 0 !important;
    margin: 0 !important;
    list-style: none !important;
  }
  .container-fluid.mt-3 li {
    font-size: 8.5pt !important;
    line-height: 1.5 !important;
    margin-bottom: 0.05in !important;
    color: #000 !important;
    word-break: normal !important;
    overflow: visible !important;
  }
  .container-fluid.mt-3 li strong {
    font-weight: 700 !important;
  }

  /* Guidance section */
  hr { 
    border: 0;
    border-top: 1px solid #333 !important;
    margin: 0.2in 0 !important;
  }
  .container-fluid.mt-4 { 
    page-break-inside: avoid;
    margin-top: 0.15in !important;
  }
  .container-fluid.mt-4 h5 {
    font-size: 10pt !important;
    margin-bottom: 0.08in !important;
  }
  .container-fluid.mt-4 ul li {
    font-size: 8pt !important;
    line-height: 1.3 !important;
    margin-bottom: 0.06in !important;
  }
  .container-fluid.mt-4 p {
    font-size: 8pt !important;
    line-height: 1.3 !important;
  }
}
