:root {
  --border: #ccc;
  --accent: #54595f;
  --ink: #1a1a1a;
  --ruled: #fff3cd;
  --overridden: #e2e4e7;
  --paper: #ffffff;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
}
body { margin: 0; padding: 0; background: #e9ebee; color: var(--ink); }
h1, h2, h3 { font-family: inherit; }

.app-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 1.25rem; background: var(--accent); color: white; }
.app-header h1 { font-size: 1.1rem; margin: 0; }
.backup-controls button, .backup-controls .file-label {
  background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px; padding: 0.35rem 0.7rem; margin-left: 0.5rem; cursor: pointer; font-size: 0.85rem;
}

#nav { display: flex; gap: 0.25rem; padding: 0.5rem 1.25rem; background: white; border-bottom: 1px solid var(--border); }
.nav-btn { background: none; border: none; padding: 0.5rem 0.9rem; cursor: pointer; border-radius: 4px; font-size: 0.95rem; }
.nav-btn.active { background: var(--accent); color: white; }
.nav-btn:not(.active):hover { background: #eee; }

main { padding: 1.25rem; max-width: 1100px; margin: 0 auto; }

.hint { color: #666; font-size: 0.85rem; }
.error { color: #b00020; font-weight: bold; }

.form-grid { display: flex; flex-direction: column; gap: 0.75rem; }
.form-grid fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem 1rem; }
.form-grid label { display: block; margin-bottom: 0.5rem; font-size: 0.9rem; }
.form-grid input[type=text], .form-grid input[type=number], .form-grid select, .form-grid textarea, .form-grid input:not([type]) {
  display: block; width: 100%; max-width: 420px; margin-top: 0.2rem; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; box-sizing: border-box;
}
.actions { margin-top: 0.5rem; }
.form-grid button, .sheet-toolbar button { background: var(--accent); color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; }
.form-grid button:hover, .sheet-toolbar button:hover { opacity: 0.9; }

.week-list { columns: 2; column-gap: 2rem; font-size: 0.9rem; }

.col-group { margin-bottom: 0.6rem; }
.col-group-title { font-weight: 600; font-size: 0.85rem; margin-bottom: 0.3rem; color: var(--accent); }
.col-check { display: inline-flex; align-items: center; gap: 0.3rem; width: 48%; font-size: 0.85rem; margin-bottom: 0.3rem; }

.rule-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.5rem 0; border-bottom: 1px solid #eee; }
.rule-summary { flex: 1; }
.rule-delete { background: #eee; border: 1px solid var(--border); border-radius: 4px; padding: 0.25rem 0.6rem; cursor: pointer; }

.saved-list { width: 100%; border-collapse: collapse; }
.saved-list th, .saved-list td { text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid #eee; }
.saved-list button { margin-right: 0.3rem; }

.sheet-toolbar { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.sheet-toolbar button:disabled { opacity: 0.4; cursor: not-allowed; }
.style-toolbar {
  display: flex; align-items: center; gap: 1.25rem; margin-bottom: 1rem;
  background: white; border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.9rem; font-size: 0.85rem;
}
.style-toolbar label { display: flex; align-items: center; gap: 0.4rem; }
.style-toolbar select { padding: 0.2rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; }
.style-toolbar input[type=color] { width: 32px; height: 26px; padding: 1px; border: 1px solid var(--border); border-radius: 4px; cursor: pointer; }
.style-toolbar button { margin-left: auto; background: #eee; border: 1px solid var(--border); border-radius: 4px; padding: 0.3rem 0.7rem; cursor: pointer; }

#pages {
  --sheet-font-family: "Times New Roman", "David", "David Libre", serif;
  --sheet-font-size: 10pt;
  --sheet-header-scale: 1;
}

/* --- Printable page, styled to look like a real Letter (11x8.5in landscape) sheet
   even on screen --- */
.page {
  background: var(--paper);
  width: 11in;
  min-height: 8.5in;
  margin: 0 auto 2rem;
  padding: 0.35in 0.5in;
  box-sizing: border-box;
  box-shadow: 0 2px 10px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  font-family: var(--sheet-font-family);
}

/* Everything on a printed page is bold by default (matches the shul's house style). */
.page { font-weight: 700; }

.page-header { display: flex; flex-direction: column; align-items: center; margin-bottom: 0.1in; }
.header-row { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 0.15in; }
.header-icon { height: calc(0.85in * var(--sheet-header-scale)); width: auto; flex-shrink: 0; }
.header-center { display: flex; flex-direction: column; align-items: center; flex: 1; }
.header-logo { height: calc(0.62in * var(--sheet-header-scale)); width: auto; }
.header-subtitle { font-size: calc(var(--sheet-font-size) + 1.5pt); margin-top: 1pt; }
.header-rabbi { font-size: var(--sheet-font-size); text-align: right; white-space: pre-line; flex-shrink: 0; line-height: 1.3; }

table { width: 100%; border-collapse: collapse; font-size: var(--sheet-font-size); flex: 1; table-layout: auto; }
th, td { border: 1px solid #9aa7b3; padding: 0.035in 0.05in; vertical-align: middle; text-align: center; }
th {
  background: var(--sheet-accent, var(--accent));
  color: white;
  font-weight: 700;
  font-size: calc(var(--sheet-font-size) + 2pt);
  white-space: pre-line;
  line-height: 1.2;
}
.parsha-cell { background: color-mix(in srgb, var(--sheet-accent, var(--accent)) 12%, white); text-align: center; font-size: calc(var(--sheet-font-size) + 2pt); }
tbody tr:nth-child(even) td:not(.parsha-cell) { background: color-mix(in srgb, var(--sheet-accent, var(--accent)) 5%, white); }
/* Cell content is direction:ltr even inside the RTL table — without this, the Unicode
   bidi algorithm can visually reverse "/"-separated time lists (e.g. "9:03 / 9:15"
   rendering as "9:15 / 9:03") since bare numbers are directionally weak. Hebrew words
   inside a cell (e.g. "פלג 6:45") still render correctly as embedded RTL runs. */
/* overflow-wrap/word-break reset to "normal": Chrome applies break-word to
   [contenteditable] elements by default, which breaks lines anywhere (even at a
   non-breaking space) once content doesn't fit — defeating the NBSP protection above
   that keeps a time pair like "7:30 / 8:15" on one line. */
.cell { min-height: 1.1em; outline: none; white-space: pre-line; text-align: center; line-height: 1.2; direction: ltr; overflow-wrap: normal; word-break: normal; }
.cell:focus { background: #fffbe6; }
td.ruled .cell { background: var(--ruled); }
/* Manually-edited cells no longer get a persistent background tint — only the brief
   yellow flash while actively focused (above) shows anything changed. */
.ul, .cell u { text-decoration: underline; text-underline-offset: 2px; }

.col-width-panel { margin-bottom: 1rem; background: white; border: 1px solid var(--border); border-radius: 6px; padding: 0.25rem 0.9rem; font-size: 0.85rem; }
.col-width-panel summary { cursor: pointer; padding: 0.4rem 0; color: var(--accent); font-weight: 600; }
.col-width-grid { display: flex; flex-wrap: wrap; gap: 0.6rem; padding: 0.5rem 0 0.75rem; align-items: flex-end; }
.col-width-input { display: flex; flex-direction: column; font-size: 0.75rem; color: #555; gap: 0.15rem; }
.col-width-input input { width: 70px; padding: 0.2rem 0.35rem; border: 1px solid var(--border); border-radius: 4px; }
#col-width-reset { background: #eee; border: 1px solid var(--border); border-radius: 4px; padding: 0.3rem 0.7rem; cursor: pointer; height: 28px; }

.page-footer {
  margin-top: 0.08in;
  display: flex;
  align-items: center;
  gap: 0.12in;
}
.footer-line { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, #9aa7b3, transparent); }
.footer-text { font-size: calc(var(--sheet-font-size) - 2.5pt); color: #444; text-align: center; white-space: pre-line; line-height: 1.3; }
.footer-address { display: block; font-size: calc(var(--sheet-font-size) + 3pt); color: var(--ink); margin-top: 2pt; }
