/* =====================================================
   SANDY LAKE LIGHTHOUSE — Email Planner v6
   Warm paper aesthetic, clean hierarchy
   ===================================================== */

:root {
  --blue:      #1d4ed8;
  --blue-soft: #e8eefb;
  --blue-ink:  #1e2a52;
  --blue-mid:  #3b5fbd;

  --paper:     #fbfaf6;
  --card:      #ffffff;
  --card-alt:  #f7f5ef;
  --line:      #ebe7dc;
  --line-soft: #f1ede2;

  --ink:       #1d2230;
  --ink-70:    #4a4f5e;
  --ink-50:    #7a7d88;
  --ink-30:    #b0b3bb;

  --pending-fg:  #7a5c1e;
  --pending-bg:  #f6eed6;
  --past-fg:     #7a7d88;
  --past-bg:     #ececea;
  --ok-fg:       #3a6e45;
  --ok-bg:       #deeade;
  --draft-fg:    #1d4ed8;
  --draft-bg:    #e8eefb;

  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --sans:  'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --header-h:  58px;
  --subnav-h:  44px;
}

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

html {
  scroll-behavior: smooth;
  /* Prevent any child from ever making the page wider than the viewport */
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* =====================================================
   LOGIN SCREEN
   ===================================================== */
.screen-overlay {
  position: fixed; inset: 0; z-index: 9000;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(150deg, #0f1f52 0%, #1d3a8a 60%, #0d1530 100%);
}

/* ── Loading overlay — shown during sign-in / auth check ── */
.login-loading {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 1.25rem;
  background: linear-gradient(150deg, #0f1f52 0%, #1d3a8a 60%, #0d1530 100%);
  border-radius: 0;
}

.login-loading-logo img {
  width: 72px; height: 72px;
  object-fit: contain;
  animation: pulse-logo 2s ease-in-out infinite;
}

@keyframes pulse-logo {
  0%, 100% { opacity: .7; transform: scale(1); }
  50%       { opacity: 1;  transform: scale(1.06); }
}

.login-loading-spinner {
  position: relative; width: 40px; height: 40px;
}

.spinner-ring {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: #facc15;
  animation: spin .85s linear infinite;
}

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

.login-loading-text {
  font-family: var(--sans); font-size: .85rem; font-weight: 500;
  color: rgba(255,255,255,.65); letter-spacing: .03em;
}

/* ── Login card ── */
.login-card {
  background: var(--card);
  border-radius: 18px;
  padding: 2.25rem 2.25rem 1.75rem;
  max-width: 400px; width: 100%;
  text-align: center;
  box-shadow: 0 32px 80px rgba(0,0,0,.45), 0 0 0 1px rgba(255,255,255,.05);
  position: relative;
}

.login-logo-wrap { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.login-logo { width: 80px; height: 80px; display: block; object-fit: contain; }

.login-eyebrow {
  font-size: .63rem; font-weight: 700;
  letter-spacing: .15em; text-transform: uppercase;
  color: #b08d3a; margin-bottom: .35rem;
}

.login-title {
  font-family: var(--serif);
  font-size: 1.85rem; font-weight: 500;
  color: var(--ink); letter-spacing: -.02em;
  line-height: 1.1; margin-bottom: .25rem;
}
.login-title-accent { color: var(--blue); }

.login-church-tag {
  font-size: .63rem; font-weight: 600;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-30); margin-bottom: 0;
}

.login-divider {
  height: 1px; background: var(--line);
  margin: 1.5rem 0 1.25rem;
}

/* Google button */
.btn-google {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; width: 100%; padding: .82rem 1.5rem;
  border: 1.5px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink);
  font-family: var(--sans); font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: border-color .18s, box-shadow .18s;
}
.btn-google:hover { border-color: #9ab0e8; box-shadow: 0 2px 12px rgba(29,78,216,.12); }
.btn-google:disabled { opacity: .55; cursor: not-allowed; }

/* Email toggle link */
.login-toggle-link {
  display: block; width: 100%; margin-top: .85rem;
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: .78rem; font-weight: 500;
  color: var(--blue); text-decoration: underline;
  text-underline-offset: 2px; transition: color .14s;
  padding: .25rem 0;
}
.login-toggle-link:hover { color: var(--blue-ink); }

/* Email/password form */
.email-signin-form { text-align: left; margin-top: .5rem; }

.login-or-divider {
  display: flex; align-items: center; gap: .75rem;
  margin: .75rem 0 1rem;
}
.login-or-divider::before,
.login-or-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}
.login-or-divider span {
  font-size: .65rem; font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-30); white-space: nowrap;
}

.login-field { margin-bottom: .75rem; }
.login-field-label {
  display: block; font-size: .67rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-50); margin-bottom: .35rem;
}
.login-field-input {
  width: 100%; border: 1.5px solid var(--line);
  border-radius: 8px; padding: .62rem .85rem;
  font-family: var(--sans); font-size: .9rem; color: var(--ink);
  background: var(--paper); transition: border-color .15s, background .15s;
}
.login-field-input:focus {
  outline: none; border-color: #9ab0e8; background: var(--card);
}
.login-field-input::placeholder { color: var(--ink-30); }

.btn-email-submit {
  display: block; width: 100%;
  padding: .82rem 1.5rem; margin-top: .25rem;
  background: var(--blue); color: #fff;
  border: none; border-radius: 9px;
  font-family: var(--sans); font-size: .9rem; font-weight: 600;
  cursor: pointer; transition: background .18s;
}
.btn-email-submit:hover { background: var(--blue-ink); }
.btn-email-submit:disabled { opacity: .6; cursor: not-allowed; }

.login-forgot {
  text-align: center; margin-top: .75rem;
}
.login-forgot a {
  font-size: .75rem; color: var(--ink-30);
  text-decoration: underline; text-underline-offset: 2px;
  transition: color .14s;
}
.login-forgot a:hover { color: var(--ink-70); }

.login-reset-success {
  text-align: center; margin-top: .65rem;
  font-size: .78rem; color: #3a6e45;
  background: var(--ok-bg); border: 1px solid #8ec49a;
  border-radius: 7px; padding: .5rem .75rem;
}

/* Error message with shake */
.login-error {
  margin-top: .9rem; padding: .6rem .9rem;
  background: #fef2f2; border: 1px solid #fecaca;
  border-radius: 8px; color: #b91c1c; font-size: .8rem;
  text-align: center; line-height: 1.5;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%       { transform: translateX(-6px); }
  40%       { transform: translateX(6px); }
  60%       { transform: translateX(-4px); }
  80%       { transform: translateX(4px); }
}
.login-error.shake { animation: shake .35s ease; }

/* Footer note */
.login-footer-note {
  font-size: .68rem; color: var(--ink-30);
  margin-top: 1.25rem; line-height: 1.5;
}

.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .75rem 1.5rem;
  border: 1.5px solid var(--line); border-radius: 9px;
  background: var(--card); color: var(--ink-70);
  font-family: var(--sans); font-size: .875rem; font-weight: 500;
  cursor: pointer; transition: background .18s;
}
.btn-secondary:hover { background: var(--card-alt); }

/* =====================================================
   APP SHELL
   ===================================================== */
.app {
  display: flex; flex-direction: column;
  height: 100vh; width: 100%; max-width: 100vw;
  overflow: hidden; position: relative;
}

/* --- Top Header --- */
.app-header {
  height: var(--header-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  z-index: 200;
  overflow: hidden; /* prevent header children from blowing out width */
  min-width: 0;
}

.header-brand {
  display: flex; align-items: center; gap: 14px;
  min-width: 0; flex-shrink: 1; overflow: hidden;
}

.header-logo-img {
  width: 34px; height: 34px;
  display: block; flex-shrink: 0;
  object-fit: contain;
}

.header-name-block { display: flex; flex-direction: column; line-height: 1.25; }
.header-church-name {
  font-family: var(--serif);
  font-size: .98rem; font-weight: 500;
  color: var(--ink); letter-spacing: -.01em;
}
.header-app-label {
  font-size: .6rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-30);
}

.header-nav {
  display: flex; gap: 0; align-items: flex-end;
  height: 100%; margin-left: 8px;
  border-bottom: none;
}

.header-nav-link {
  display: flex; align-items: center; height: 100%;
  padding: 0 14px;
  font-size: .82rem; font-weight: 500;
  color: var(--ink-50); text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color .14s;
  white-space: nowrap;
}
.header-nav-link:hover { color: var(--ink-70); }
.header-nav-link.active {
  color: var(--blue-ink);
  border-bottom-color: var(--blue);
  font-weight: 600;
}

.header-right { display: flex; align-items: center; gap: 14px; }

.autosave-dot {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .72rem; color: var(--ink-50);
}
.autosave-dot-pip {
  width: 6px; height: 6px; border-radius: 50%;
  background: #5a9e6a; flex-shrink: 0;
}

.user-chip { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--blue); color: #fff;
  font-weight: 700; font-size: .72rem;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-display-name {
  font-size: .8rem; color: var(--ink-70);
  max-width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.btn-signout {
  font-size: .75rem; color: var(--ink-30); background: none; border: none;
  cursor: pointer; font-family: var(--sans); font-weight: 500;
  padding: 0; text-decoration: none;
  transition: color .14s;
}
.btn-signout:hover { color: var(--ink-70); }

/* =====================================================
   MONTH STRIP (shared)
   ===================================================== */
.month-strip {
  height: var(--subnav-h);
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center;
  padding: 0 1.5rem;
  gap: 4px;
  flex-shrink: 0;
  overflow-x: auto; scrollbar-width: none;
  z-index: 190;
  /* Never wider than viewport */
  max-width: 100%;
  min-width: 0;
  /* Smooth touch scroll */
  -webkit-overflow-scrolling: touch;
}
.month-strip::-webkit-scrollbar { display: none; }

.year-btn {
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: .85rem;
  color: var(--ink-30); padding: 4px 6px; border-radius: 5px;
  transition: color .14s;
}
.year-btn:hover { color: var(--ink-70); }

.year-label {
  font-size: .85rem; font-weight: 600; color: var(--ink);
  padding: 4px 6px; min-width: 40px; text-align: center;
}

.strip-divider {
  width: 1px; height: 16px; background: var(--line);
  margin: 0 10px; flex-shrink: 0;
}

.month-tab {
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: .8rem; font-weight: 500;
  color: var(--ink-30); padding: 10px 10px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap; transition: color .14s;
}
.month-tab:hover { color: var(--ink-70); }
.month-tab.active {
  color: var(--blue-ink); font-weight: 600;
  border-bottom-color: var(--blue);
}

/* =====================================================
   PAGE HEADER (toolbar-style)
   ===================================================== */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  padding: 1.5rem 1.5rem 1rem;
  flex-shrink: 0;
  background: var(--paper);
  width: 100%; min-width: 0;
}

.page-title {
  font-family: var(--serif);
  font-size: 1.75rem; font-weight: 500;
  color: var(--ink); letter-spacing: -.015em; line-height: 1.05;
}

.page-subtitle {
  font-size: .78rem; color: var(--ink-50); margin-top: 5px;
}

.page-actions { display: flex; align-items: center; gap: 10px; }

.btn-primary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: .5rem 1rem;
  background: var(--blue); color: #fff;
  border: none; border-radius: 8px;
  font-family: var(--sans); font-size: .8rem; font-weight: 600;
  cursor: pointer; transition: background .18s;
}
.btn-primary:hover { background: var(--blue-ink); }

.btn-outline {
  display: inline-flex; align-items: center; gap: 7px;
  padding: .48rem .95rem;
  background: var(--card); color: var(--ink);
  border: 1.5px solid var(--line); border-radius: 8px;
  font-family: var(--sans); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: border-color .18s, background .18s;
}
.btn-outline:hover { border-color: #bbbcbf; background: #f9f7f1; }

/* =====================================================
   PLANNER TABLE
   ===================================================== */
.sheet-wrap {
  flex: 1;
  overflow: auto;      /* scrolls both axes within the flex child */
  background: var(--paper);
  /* Ensure it never makes the app wider */
  min-width: 0;
  width: 100%;
  /* On touch devices, use momentum scrolling */
  -webkit-overflow-scrolling: touch;
}

.email-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.email-table thead { position: sticky; top: 0; z-index: 100; }

.col-header-row th {
  background: var(--card-alt);
  color: var(--ink-50);
  font-size: .62rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  padding: .65rem 1rem;
  text-align: left;
  border-right: 1px solid var(--line);
  border-bottom: 2px solid var(--line);
}
.col-header-row th:last-child { border-right: none; }

.th-note {
  display: block; font-size: .55rem; font-weight: 400;
  text-transform: none; letter-spacing: 0;
  color: var(--ink-30); margin-top: 2px;
}

.th-expand  { width: 88px; }
.th-week    { width: 0; display: none; }
.th-send    { width: 148px; }
.th-event   { width: 148px; }
.th-status  { width: 120px; }
.th-actions { width: 148px; }

/* Week section header */
tr.week-divider td { padding: 0; border: none; }

.week-divider-inner {
  display: flex; align-items: center;
  padding: .55rem 1rem;
  background: var(--card-alt);
  border-top: 2px solid var(--line);
  border-bottom: 1px solid var(--line);
  gap: 10px;
  cursor: pointer;
  transition: background .12s;
}
.week-divider-inner:hover { background: #f0ede4; }

.week-divider-inner.is-current {
  background: var(--blue-soft);
  border-top-color: var(--blue);
}
.week-divider-inner.is-current:hover { background: #dde6f8; }

.week-divider-inner.is-past { opacity: .7; }

.week-divider-label {
  font-family: var(--serif);
  font-size: .95rem; font-weight: 500;
  color: var(--ink); letter-spacing: -.005em; flex: 1;
}
.week-divider-inner.is-current .week-divider-label { color: var(--blue-ink); }

.week-divider-date {
  font-size: .75rem; color: var(--ink-50);
}

.week-badge {
  font-size: .62rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--blue); padding: 2px 8px;
  border-radius: 999px; background: var(--blue-soft);
}

.week-badge-past {
  font-size: .62rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-30); padding: 2px 8px;
  border-radius: 999px; background: var(--past-bg);
}

.week-chevron {
  color: var(--ink-30); transition: transform .18s;
  display: flex; align-items: center;
}
.week-chevron.open { transform: rotate(180deg); }

/* Data rows */
tr.data-row td {
  border-bottom: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  padding: 0; vertical-align: middle;
  background: var(--card);
  transition: background .1s;
}
tr.data-row td:last-child { border-right: none; }
tr.data-row:nth-child(even) td { background: #fdfcf8; }
tr.data-row:hover td { background: #f5f2e8 !important; }
tr.data-row.row-editing td { background: #f0f4fd !important; }
tr.data-row.row-past { opacity: .55; }

/* Hidden rows when week is collapsed */
tr.data-row.week-hidden,
tr.detail-row.week-hidden,
tr.add-row-tr.week-hidden { display: none; }

/* Details column header link style */
.th-details-link {
  display: block;
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
  font-size: .62rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase;
  cursor: default;
}

.expand-cell { text-align: center; padding: 0 !important; cursor: pointer; }
.expand-btn {
  display: flex; align-items: center; justify-content: center;
  gap: 5px;
  width: 100%; height: 100%; min-height: 40px;
  background: none; border: none; cursor: pointer;
  color: var(--blue);
  font-family: var(--sans); font-size: .72rem; font-weight: 600;
  letter-spacing: .02em;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color .15s, background .15s;
  padding: 0 8px;
}
.expand-btn:hover {
  color: var(--blue-ink);
  background: var(--blue-soft);
  text-decoration: underline;
}
.expand-btn svg { transition: transform .2s; flex-shrink: 0; }
.expand-btn.is-open svg { transform: rotate(90deg); }
.expand-btn.is-open {
  color: #b08d3a;
  text-decoration: underline;
}
.expand-btn.is-open:hover {
  color: #8a6d2d;
  background: #fdf4d8;
}

.cell-week-num {
  display: none; /* redundant — week divider header already shows the week number */
}

.editable-wrap { display: flex; align-items: stretch; min-height: 40px; width: 100%; }

.cell-input {
  flex: 1; background: transparent; border: none; outline: none;
  font-family: var(--sans);
  font-size: .845rem; color: var(--ink);
  padding: .5rem 1rem; width: 100%;
  resize: none; overflow: hidden;
  line-height: 1.55; min-height: 40px;
  cursor: default; transition: background .12s, box-shadow .12s;
}
.cell-input::placeholder { color: var(--ink-30); }
.cell-input:focus {
  background: var(--card);
  box-shadow: inset 0 0 0 2px #9ab0e8;
  border-radius: 4px; cursor: text;
}

input.cell-input[type="date"] { cursor: pointer; min-height: 40px; color-scheme: light; }
textarea.cell-input { min-height: 54px; padding-top: .55rem; padding-bottom: .55rem; }

/* Status */
.status-wrap { padding: .4rem 1rem; }

.status-sel {
  appearance: none; -webkit-appearance: none;
  border: 1.5px solid transparent; border-radius: 999px;
  padding: .28rem .9rem;
  font-family: var(--sans); font-size: .7rem; font-weight: 600;
  cursor: pointer; text-align: center; width: 100%;
  transition: filter .15s;
}
.status-sel:focus { outline: none; box-shadow: 0 0 0 2px #9ab0e8; }
.status-sel.s-pending { background: var(--pending-bg); border-color: #d4b270; color: var(--pending-fg); }
.status-sel.s-draft   { background: var(--draft-bg);   border-color: #9ab0e8; color: var(--draft-fg); }
.status-sel.s-sent    { background: var(--ok-bg);      border-color: #8ec49a; color: var(--ok-fg); }

/* Actions */
.actions-wrap { display: flex; align-items: center; gap: 4px; padding: .3rem .6rem; }

.btn-action {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 3px; background: transparent;
  border: 1px solid var(--line); border-radius: 6px;
  padding: .26rem .52rem;
  font-family: var(--sans); font-size: .68rem; font-weight: 500;
  cursor: pointer; transition: all .14s; white-space: nowrap;
  color: var(--ink-50);
}
.btn-action:hover { background: var(--card-alt); border-color: #c8c2b2; }

.btn-copy-week { color: var(--blue); border-color: #c2d0f0; background: var(--blue-soft); }
.btn-copy-week:hover { background: #d8e4f8; border-color: #9ab0e8; }

.btn-delete { color: #b91c1c; border-color: #f5c6c6; background: #fff5f5; }
.btn-delete:hover { background: #fee2e2; border-color: #f09090; }

/* Expanded detail drawer */
tr.detail-row td {
  padding: 0 !important;
  border-bottom: 1px solid var(--line) !important;
  background: #f9f7f1 !important;
}

.detail-drawer {
  display: none;
  padding: 1rem 1.25rem 1.1rem 3.5rem;
  gap: 1.5rem; flex-wrap: wrap; align-items: flex-start;
  border-top: 1px solid var(--line-soft);
}
.detail-drawer.is-open { display: flex; }

.drawer-section { display: flex; flex-direction: column; gap: .45rem; }

.drawer-section-label {
  font-size: .62rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-30); margin-bottom: .1rem;
}

.dest-checks { display: flex; flex-direction: column; gap: .4rem; }

.dest-check-label {
  display: flex; align-items: center; gap: 8px;
  font-size: .8rem; color: var(--ink-70);
  cursor: pointer; user-select: none;
}
.dest-check-label input[type="checkbox"] {
  width: 15px; height: 15px; accent-color: var(--blue);
  cursor: pointer; flex-shrink: 0;
}
.dest-check-label:hover { color: var(--blue); }

.dest-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dest-dot-email  { background: var(--blue); }
.dest-dot-web    { background: #7c3aed; }
.dest-dot-annc   { background: #c2660c; }
.dest-dot-social { background: #be185d; }

/* Poster section */
.drawer-poster { display: flex; flex-direction: column; gap: .6rem; }

.poster-upload-area {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .85rem;
  border: 1.5px dashed var(--line);
  border-radius: 8px; background: var(--card);
  cursor: pointer; transition: all .18s; min-width: 230px;
}
.poster-upload-area:hover { border-color: #9ab0e8; background: var(--blue-soft); }

.poster-upload-icon {
  width: 30px; height: 30px; border-radius: 6px;
  background: var(--blue-soft); display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; color: var(--blue);
}
.poster-upload-title { font-size: .77rem; font-weight: 600; color: var(--ink-70); }
.poster-upload-sub   { font-size: .67rem; color: var(--ink-30); }
.poster-file-input   { display: none; }

.poster-thumb-wrap {
  display: none; position: relative;
  width: 76px; height: 76px; border-radius: 8px;
  overflow: hidden; border: 1.5px solid var(--line); flex-shrink: 0;
}
.poster-thumb-wrap.has-poster { display: block; }
.poster-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }

.poster-thumb-del {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(0,0,0,.5); border: none;
  color: #fff; font-size: .75rem; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.poster-thumb-del:hover { background: #b91c1c; }

.poster-thumb-link {
  font-size: .72rem; color: var(--blue);
  text-decoration: none; margin-top: .3rem; display: block;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.poster-thumb-link:hover { text-decoration: underline; }

.drawer-notes { flex: 1; min-width: 220px; }
.drawer-notes textarea {
  width: 100%; border: 1.5px solid var(--line);
  border-radius: 8px; padding: .55rem .75rem;
  font-family: var(--sans); font-size: .82rem; color: var(--ink-70);
  resize: vertical; min-height: 70px; background: var(--card);
  transition: border-color .15s;
}
.drawer-notes textarea:focus { outline: none; border-color: #9ab0e8; }
.drawer-notes textarea::placeholder { color: var(--ink-30); }

/* Add row */
tr.add-row-tr td {
  border-bottom: 1px dashed var(--line);
  background: var(--paper) !important; padding: .28rem 1rem;
}

.btn-add-row {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: none;
  color: var(--blue); font-family: var(--sans);
  font-size: .76rem; font-weight: 500;
  padding: .22rem .5rem; cursor: pointer; transition: opacity .14s;
}
.btn-add-row:hover { opacity: .7; }

/* =====================================================
   CALENDAR PAGE
   ===================================================== */
.calendar-body {
  display: flex; flex: 1;
  overflow: hidden;
  min-width: 0; width: 100%;
}

.calendar-grid-wrap {
  flex: 1; overflow: auto;
  padding: 0 1.5rem 2rem;
  min-width: 0; /* critical — prevents flex child from overflowing */
  -webkit-overflow-scrolling: touch;
}

.calendar-sidebar {
  width: 260px; flex-shrink: 0;
  border-left: 1px solid var(--line);
  background: var(--card);
  overflow-y: auto;
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 1rem;
}

/* Calendar grid */
.cal-grid {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  min-width: 560px; /* allows horizontal scroll on small screens rather than bleed */
}

.cal-dow-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  background: var(--card-alt);
  border-bottom: 1px solid var(--line);
}

.cal-dow-cell {
  padding: .65rem 1rem;
  font-size: .6rem; font-weight: 700;
  letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-50);
}
.cal-dow-cell.is-wed { color: var(--blue-ink); }

.cal-cells {
  display: grid; grid-template-columns: repeat(7, 1fr);
}

.cal-cell {
  min-height: 110px; padding: .65rem .75rem;
  border-right: 1px solid var(--line-soft);
  border-top: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 4px;
  position: relative;
  background: var(--card);
  transition: background .12s;
}
.cal-cell:hover { background: #faf8f2; }
.cal-cell.out-of-month { background: #faf8f1; opacity: .55; }
.cal-cell.is-wed-col { background: #f6f8fd; }
.cal-cell.is-wed-col:hover { background: #eef2fb; }
.cal-cell.is-today { background: #f0f4fd; }
.cal-cell:nth-child(7n) { border-right: none; }

.cal-day-num {
  font-size: .8rem; font-weight: 600; color: var(--ink-70);
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.cal-cell.is-wed-col .cal-day-num { color: var(--blue-ink); }
.cal-cell.is-today .cal-day-num {
  background: var(--blue); color: #fff;
}

.cal-week-num {
  position: absolute; top: .45rem; right: .55rem;
  font-size: .58rem; font-weight: 700;
  color: var(--ink-30); letter-spacing: .05em;
}

/* Calendar chips */
.cal-chip {
  display: flex; align-items: center; gap: 5px;
  font-size: .7rem; padding: 2px 7px;
  border-radius: 5px; border: 1px solid transparent;
  white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; cursor: pointer;
  transition: filter .12s;
  line-height: 1.4;
}
.cal-chip:hover { filter: brightness(.95); }
.cal-chip-dot {
  width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0;
}

.cal-chip.chip-email {
  background: var(--blue-soft); border-color: #c2d0f0;
  color: var(--blue-ink);
}
.cal-chip.chip-email.chip-sent {
  background: var(--past-bg); border-color: #d0d0cc;
  color: var(--past-fg); text-decoration: line-through;
}
.cal-chip.chip-email.chip-pending .cal-chip-dot { background: #c2a140; }
.cal-chip.chip-email.chip-sent .cal-chip-dot    { background: var(--ink-30); }

/* Event dates pulled from email planner rows — warm amber */
.cal-chip.chip-email-event {
  background: #fdf4d8; border-color: #e8d990; color: #7a5b1a;
}
.cal-chip.chip-email-event .cal-chip-dot { background: #c2a140; }

.cal-chip.chip-event-service {
  background: #efeaf6; border-color: #d5c8e8; color: #5a3e7d;
}
.cal-chip.chip-event-service .cal-chip-dot { background: #9577b8; }

.cal-chip.chip-event-social {
  background: #fdf4d8; border-color: #e8d990; color: #7a5b1a;
}
.cal-chip.chip-event-social .cal-chip-dot { background: #d4a93a; }

.cal-chip.chip-event-general {
  background: #f0f9f1; border-color: #b8dfc0; color: #3a6e45;
}
.cal-chip.chip-event-general .cal-chip-dot { background: #5a9e6a; }

/* Add event chip */
.cal-add-chip {
  display: none; align-items: center; gap: 4px;
  font-size: .68rem; color: var(--ink-30);
  background: none; border: 1px dashed var(--line);
  border-radius: 5px; padding: 2px 7px;
  cursor: pointer; font-family: var(--sans);
  transition: all .14s;
}
.cal-cell:hover .cal-add-chip { display: flex; }
.cal-add-chip:hover { color: var(--blue); border-color: #9ab0e8; }

/* Calendar sidebar panels */
.sidebar-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
}

.sidebar-panel-title {
  font-size: .6rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--ink-30); margin-bottom: .75rem;
}

.sidebar-item {
  display: flex; align-items: flex-start; gap: 9px;
  padding: .4rem 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: .78rem;
}
.sidebar-item:last-child { border-bottom: none; }

.sidebar-item-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0; margin-top: 5px;
}

.sidebar-item-main { color: var(--ink-70); line-height: 1.4; }
.sidebar-item-sub  { font-size: .7rem; color: var(--ink-30); margin-top: 2px; }

.sidebar-stat {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: .8rem; color: var(--ink-70); padding: .25rem 0;
}
.sidebar-stat-val {
  font-family: var(--serif);
  font-size: 1.05rem; font-weight: 500; color: var(--ink);
}

.cal-legend {
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; color: var(--ink-50);
}
.cal-legend-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0;
}

/* Calendar event modal / edit overlay */
.cal-event-modal {
  position: fixed; inset: 0; z-index: 8000;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background: rgba(0,0,0,.25);
}
.cal-event-modal.hidden { display: none; }

.cal-modal-card {
  background: var(--card); border-radius: 14px;
  padding: 1.75rem; width: 100%; max-width: 440px;
  box-shadow: 0 16px 48px rgba(0,0,0,.22);
}

.cal-modal-title {
  font-family: var(--serif);
  font-size: 1.1rem; font-weight: 500;
  color: var(--ink); margin-bottom: 1.25rem;
}

.cal-modal-field { margin-bottom: .9rem; }
.cal-modal-field label {
  display: block;
  font-size: .65rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-30); margin-bottom: .35rem;
}
.cal-modal-field input,
.cal-modal-field textarea,
.cal-modal-field select {
  width: 100%; border: 1.5px solid var(--line);
  border-radius: 8px; padding: .55rem .75rem;
  font-family: var(--sans); font-size: .875rem; color: var(--ink);
  background: var(--paper); transition: border-color .15s;
}
.cal-modal-field input:focus,
.cal-modal-field textarea:focus,
.cal-modal-field select:focus {
  outline: none; border-color: #9ab0e8;
  background: var(--card);
}

.cal-modal-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 1.25rem;
}

/* =====================================================
   LOADING / EMPTY / TOAST
   ===================================================== */
.empty-cell {
  text-align: center; padding: 4rem 1rem !important;
  color: var(--ink-30); font-size: .9rem;
  background: var(--card) !important;
}
.loading-inner { display: flex; flex-direction: column; align-items: center; gap: .3rem; }

.toast {
  position: fixed; bottom: 1.75rem; right: 1.75rem;
  background: var(--ink); color: #fff;
  padding: .72rem 1.2rem; border-radius: 9px;
  font-size: .85rem; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,.25);
  z-index: 9999; border-left: 3px solid var(--blue);
  transition: opacity .3s, transform .3s;
  opacity: 1; transform: translateY(0);
}
.toast.toast-success { border-left-color: #5a9e6a; }
.toast.toast-error   { border-left-color: #b91c1c; }
.toast.toast-info    { border-left-color: #b08d3a; }
.toast.hiding        { opacity: 0; transform: translateY(8px); }

.hidden { display: none !important; }

/* =====================================================
   MOBILE CARDS — shown instead of table on < 768px
   ===================================================== */

/* Desktop default: table visible, cards hidden */
.mobile-cards { display: none; }

.mobile-week-header {
  display: flex; align-items: center;
  padding: .65rem 1rem;
  background: var(--card-alt);
  border-top: 2px solid var(--line);
  border-bottom: 1px solid var(--line);
  cursor: pointer; gap: 10px;
  transition: background .12s;
  position: sticky; top: 0; z-index: 10;
}
.mobile-week-header:hover { background: #f0ede4; }
.mobile-week-header.is-current { background: var(--blue-soft); border-top-color: var(--blue); }
.mobile-week-header.is-past { opacity: .7; }

.mobile-week-label {
  font-family: var(--serif);
  font-size: .95rem; font-weight: 500; color: var(--ink); flex: 1;
}
.mobile-week-header.is-current .mobile-week-label { color: var(--blue-ink); }

.mobile-week-meta { font-size: .72rem; color: var(--ink-50); white-space: nowrap; }

.mobile-week-chevron {
  color: var(--ink-30); display: flex; align-items: center;
  transition: transform .18s; flex-shrink: 0;
}
.mobile-week-chevron.open { transform: rotate(180deg); }

.mobile-week-body { display: flex; flex-direction: column; }
.mobile-week-body.hidden { display: none; }

/* Individual card */
.mobile-card {
  background: var(--card);
  border-bottom: 1px solid var(--line-soft);
  padding: .875rem 1rem;
}
.mobile-card.is-past { opacity: .55; }

/* Card top row: dates left, status right */
.mobile-card-top {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: .75rem;
  margin-bottom: .55rem;
}

.mobile-card-dates { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }

.mobile-card-date-row { display: flex; align-items: center; gap: 5px; }
.mobile-card-date-label {
  font-size: .58rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-30); min-width: 36px;
}
.mobile-card-date-input {
  border: none; background: transparent; outline: none;
  font-family: var(--sans); font-size: .72rem; color: var(--ink-50);
  padding: 2px 4px; cursor: pointer; width: 112px;
  border-radius: 4px; transition: background .12s;
}
.mobile-card-date-input:focus {
  color: var(--ink); background: var(--blue-soft);
}

/* Status badge */
.mobile-card-status select {
  appearance: none; -webkit-appearance: none;
  border: 1.5px solid transparent; border-radius: 999px;
  padding: .24rem .8rem;
  font-family: var(--sans); font-size: .68rem; font-weight: 600;
  cursor: pointer;
}
.mobile-card-status select:focus { outline: none; }
.mobile-card-status select.s-pending { background: var(--pending-bg); border-color: #d4b270; color: var(--pending-fg); }
.mobile-card-status select.s-draft   { background: var(--draft-bg);   border-color: #9ab0e8; color: var(--draft-fg); }
.mobile-card-status select.s-sent    { background: var(--ok-bg);      border-color: #8ec49a; color: var(--ok-fg); }

/* Item textarea */
.mobile-card-item {
  width: 100%; border: 1.5px solid transparent; border-radius: 7px;
  padding: .5rem .6rem; font-family: var(--sans);
  font-size: .9rem; color: var(--ink);
  background: var(--paper); resize: none; overflow: hidden;
  line-height: 1.6; min-height: 44px;
  transition: border-color .15s, background .15s;
}
.mobile-card-item:focus { outline: none; border-color: #9ab0e8; background: var(--card); }
.mobile-card-item::placeholder { color: var(--ink-30); }

/* Footer: Details btn + action btns */
.mobile-card-footer {
  display: flex; align-items: center;
  justify-content: space-between; gap: .5rem;
  margin-top: .6rem; padding-top: .55rem;
  border-top: 1px solid var(--line-soft);
}

.mobile-details-btn {
  background: none; border: none; cursor: pointer;
  font-family: var(--sans); font-size: .75rem; font-weight: 600;
  color: var(--blue); text-decoration: underline;
  text-underline-offset: 2px; padding: 0;
  display: inline-flex; align-items: center; gap: 4px;
  transition: color .14s;
}
.mobile-details-btn:hover { color: var(--blue-ink); }
.mobile-details-btn.is-open { color: #b08d3a; }
.mobile-details-btn svg { transition: transform .2s; }
.mobile-details-btn.is-open svg { transform: rotate(90deg); }

.mobile-card-actions { display: flex; align-items: center; gap: 5px; }

/* Drawer inside card — same content as desktop */
.mobile-card-drawer {
  display: none; flex-direction: column; gap: 1rem;
  padding: .75rem 0 .1rem; margin-top: .6rem;
  border-top: 1px solid var(--line-soft);
}
.mobile-card-drawer.is-open { display: flex; }

/* Destinations inside mobile drawer */
.mobile-card-drawer .dest-checks { flex-direction: row; flex-wrap: wrap; gap: .5rem .75rem; }

/* Add row button */
.mobile-add-btn {
  display: flex; align-items: center; gap: 6px;
  padding: .7rem 1rem; width: 100%;
  background: var(--paper); border: none;
  border-bottom: 1px dashed var(--line);
  cursor: pointer; font-family: var(--sans);
  font-size: .78rem; font-weight: 500;
  color: var(--blue); transition: background .14s; text-align: left;
}
.mobile-add-btn:hover { background: var(--blue-soft); }

/* =====================================================
   RESPONSIVE — TABLET (≤ 900px)
   ===================================================== */
@media (max-width: 900px) {
  /* Hide lower-priority header items */
  .autosave-dot { display: none; }
  .header-app-label { display: none; }
  .cal-legend { display: none; }

  /* Tighten header padding */
  .app-header { padding: 0 1rem; gap: 8px; }

  /* Page header stacks */
  .page-header {
    flex-direction: column; align-items: flex-start;
    padding: 1rem 1rem .75rem; gap: .6rem;
  }
  .page-title { font-size: 1.4rem; }

  /* Calendar sidebar drops below on tablet */
  .calendar-body { flex-direction: column; }
  .calendar-sidebar {
    width: 100%; border-left: none;
    border-top: 1px solid var(--line);
    max-height: 260px; overflow-y: auto;
    display: grid; grid-template-columns: 1fr 1fr; gap: .75rem;
    padding: 1rem;
  }
  .calendar-grid-wrap { padding: 0 1rem 1rem; }
}

/* =====================================================
   RESPONSIVE — MOBILE (≤ 768px) — CARD LAYOUT
   ===================================================== */
@media (max-width: 768px) {
  /* Hide table, show cards */
  .email-table { display: none; }
  .mobile-cards { display: block; }

  /* Hide table column header */
  .col-header-row { display: none; }

  /* Sheet wrap becomes a normal scroll container */
  .sheet-wrap { overflow-y: auto; overflow-x: hidden; }
}

/* =====================================================
   RESPONSIVE — MOBILE (≤ 640px)
   ===================================================== */
@media (max-width: 640px) {
  :root {
    --header-h: 52px;
    --subnav-h: 40px;
  }

  /* Header: logo + name only, nav moves below */
  .app-header {
    padding: 0 .875rem;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .header-nav { display: none; } /* nav tabs move to month strip area */
  .user-display-name { display: none; }
  .header-right { gap: 8px; }

  /* Show mobile nav as a second row below header */
  .month-strip {
    height: auto; min-height: var(--subnav-h);
    padding: 0 .875rem;
    flex-wrap: nowrap;
    gap: 2px;
  }

  /* Page header compact */
  .page-header {
    padding: .75rem .875rem .6rem;
    flex-direction: column; gap: .5rem;
  }
  .page-title { font-size: 1.25rem; }
  .page-subtitle { font-size: .72rem; }
  .page-actions .btn-outline { font-size: .72rem; padding: .38rem .7rem; }

  /* Table: tighter column widths on mobile, horizontal scroll if needed */
  .th-send    { width: 110px; }
  .th-event   { width: 110px; }
  .th-status  { width: 90px; }
  .th-actions { width: 105px; }
  .th-expand  { width: 64px; }

  /* Tighter cell padding */
  .col-header-row th { padding: .5rem .6rem; }
  .cell-input { padding: .4rem .6rem; font-size: .8rem; }
  .status-wrap { padding: .35rem .6rem; }
  .actions-wrap { padding: .25rem .35rem; gap: 3px; }
  .btn-action { font-size: .62rem; padding: .22rem .38rem; }

  /* Drawer tweaks */
  .detail-drawer { padding: .75rem .875rem .875rem 2.5rem; gap: 1rem; }

  /* Calendar: single column sidebar */
  .calendar-sidebar {
    grid-template-columns: 1fr;
    max-height: 200px;
  }
  .calendar-grid-wrap { padding: 0 .5rem .75rem; }
  .cal-cell { min-height: 72px; padding: .4rem .4rem; }
  .cal-chip  { font-size: .62rem; padding: 2px 5px; }
  .cal-dow-cell { padding: .5rem .4rem; font-size: .58rem; }
  .cal-day-num  { font-size: .72rem; width: 20px; height: 20px; }

  /* Modal full-screen on mobile */
  .cal-event-modal { padding: 0; align-items: flex-end; }
  .cal-modal-card {
    border-radius: 16px 16px 0 0;
    max-width: 100%; padding: 1.5rem 1.25rem;
  }

  /* Toast anchored to bottom center */
  .toast {
    bottom: 1rem; right: 1rem; left: 1rem;
    text-align: center;
  }
}

/* =====================================================
   RESPONSIVE — VERY SMALL (≤ 380px)
   ===================================================== */
@media (max-width: 380px) {
  .header-church-name { font-size: .82rem; }
  .btn-signout { font-size: .68rem; }
  .page-title  { font-size: 1.1rem; }

  /* On very small screens, hide the send date column — it's redundant
     with the week header which already shows the send date */
  .th-send, td:nth-child(3) { display: none; }
  .email-table { min-width: 520px; }
}
