/* KeepWatch Vigil — Shared Stylesheet
   Warm gold/cream Catholic aesthetic, mobile-first */

:root {
  --gold: #C5963A;
  --gold-light: #E8D5A3;
  --gold-dark: #8B6914;
  --cream: #FDF8F0;
  --cream-dark: #F5EBD8;
  --burgundy: #6B1D2A;
  --burgundy-light: #8B3A4A;
  --text: #2C2416;
  --text-light: #6B5D4F;
  --white: #FFFFFF;
  --green: #2D7A3A;
  --green-light: #E8F5E9;
  --yellow: #F9A825;
  --yellow-light: #FFF8E1;
  --red: #C62828;
  --red-light: #FFEBEE;
  --shadow: 0 2px 8px rgba(44, 36, 22, 0.1);
  --shadow-lg: 0 4px 16px rgba(44, 36, 22, 0.15);
  --radius: 8px;
  --radius-lg: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--cream);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ─── Typography ───────────────────────── */

h1 { font-size: 1.75rem; font-weight: 700; color: var(--burgundy); }
h2 { font-size: 1.35rem; font-weight: 600; color: var(--text); }
h3 { font-size: 1.1rem; font-weight: 600; color: var(--text); }
p { margin-bottom: 0.5rem; }
a { color: var(--burgundy); text-decoration: none; }
a:hover { text-decoration: underline; }
small { color: var(--text-light); font-size: 0.85rem; }

/* ─── Layout ───────────────────────────── */

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
}

.container-narrow {
  max-width: 500px;
  margin: 0 auto;
  padding: 1rem;
}

/* ─── Header / Nav ─────────────────────── */

.header {
  background: var(--burgundy);
  color: var(--white);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.header-brand a { color: var(--gold-light); }
.header-brand a:hover { text-decoration: none; opacity: 0.9; }

.header-nav {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.header-nav a {
  color: var(--gold-light);
  font-size: 0.9rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  transition: background 0.2s;
}

.header-nav a:hover {
  background: rgba(255,255,255,0.1);
  text-decoration: none;
}

.header-nav a.active {
  background: rgba(255,255,255,0.15);
  font-weight: 600;
}

/* ─── Cards ────────────────────────────── */

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--cream-dark);
}

/* ─── Module Tiles (Dashboard) ─────────── */

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.module-tile {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border-left: 4px solid var(--gold);
  text-decoration: none;
  color: var(--text);
  display: block;
}

.module-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  text-decoration: none;
}

.module-tile.disabled {
  opacity: 0.5;
  cursor: default;
  border-left-color: #ccc;
}

.module-tile .tile-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.module-tile .tile-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.module-tile .tile-desc {
  font-size: 0.85rem;
  color: var(--text-light);
}

.module-tile .tile-stat {
  margin-top: 0.75rem;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gold-dark);
}

/* ─── Buttons ──────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--burgundy);
  color: var(--white);
}
.btn-primary:hover { background: var(--burgundy-light); color: var(--white); text-decoration: none; }

.btn-gold {
  background: var(--gold);
  color: var(--white);
}
.btn-gold:hover { background: var(--gold-dark); color: var(--white); text-decoration: none; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--burgundy);
  color: var(--burgundy);
}
.btn-outline:hover { background: var(--burgundy); color: var(--white); text-decoration: none; }

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.btn-danger {
  background: var(--red);
  color: var(--white);
}
.btn-danger:hover { background: #B71C1C; }

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

/* ─── Forms ────────────────────────────── */

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

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.3rem;
  font-size: 0.9rem;
  color: var(--text);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid #D4C9B8;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--white);
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(197, 150, 58, 0.15);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group { flex: 1; }

/* ─── Tables ───────────────────────────── */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

th, td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--cream-dark);
}

th {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover { background: var(--cream); }

/* ─── Adoration Schedule Grid ──────────── */

.schedule-grid {
  display: grid;
  grid-template-columns: 60px repeat(7, 1fr);
  gap: 2px;
  background: var(--cream-dark);
  border-radius: var(--radius);
  overflow: hidden;
}

.schedule-grid .hour-label {
  background: var(--white);
  padding: 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
  display: flex;
  align-items: center;
  justify-content: center;
}

.schedule-grid .day-header {
  background: var(--burgundy);
  color: var(--gold-light);
  padding: 0.5rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.schedule-grid .slot {
  background: var(--white);
  padding: 0.3rem;
  min-height: 40px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.schedule-grid .slot:hover { background: var(--cream); }

.schedule-grid .slot.covered {
  background: var(--green-light);
  border-left: 3px solid var(--green);
}

.schedule-grid .slot.partial {
  background: var(--yellow-light);
  border-left: 3px solid var(--yellow);
}

.schedule-grid .slot.empty {
  background: var(--red-light);
  border-left: 3px solid var(--red);
}

.schedule-grid .slot.inactive {
  background: #F5F5F5;
  color: #bbb;
  cursor: default;
}

.slot .adorer-name {
  display: block;
  font-size: 0.65rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot .adorer-count {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-light);
}

/* ─── Stats / Badges ───────────────────── */

.stat-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.stat-box {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  flex: 1;
  min-width: 130px;
  text-align: center;
}

.stat-box .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--burgundy);
}

.stat-box .stat-label {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.2rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-green { background: var(--green-light); color: var(--green); }
.badge-yellow { background: var(--yellow-light); color: #F57F17; }
.badge-red { background: var(--red-light); color: var(--red); }
.badge-info { background: #e3f2fd; color: #1565c0; }
.badge-warning { background: var(--yellow-light); color: #F57F17; }
.badge-success { background: var(--green-light); color: var(--green); }

/* ─── Modals ───────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--burgundy);
}

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

/* ─── Toast / Alert ────────────────────── */

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--text);
  color: var(--white);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 0.9rem;
  z-index: 300;
  animation: slideUp 0.3s ease;
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: #1565c0; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-info { background: #E3F2FD; color: #1565C0; border-left: 4px solid #1565C0; }
.alert-success { background: var(--green-light); color: var(--green); border-left: 4px solid var(--green); }
.alert-warning { background: var(--yellow-light); color: #F57F17; border-left: 4px solid var(--yellow); }
.alert-danger { background: var(--red-light); color: var(--red); border-left: 4px solid var(--red); }

/* ─── Kiosk Mode ───────────────────────── */

body.kiosk-mode {
  background: #1A1210;
  color: var(--cream);
}

.kiosk-time {
  font-size: 4rem;
  font-weight: 200;
  text-align: center;
  color: var(--gold-light);
  margin: 2rem 0 1rem;
}

.kiosk-hour-label {
  font-size: 1.5rem;
  text-align: center;
  color: var(--gold);
  margin-bottom: 2rem;
}

.kiosk-btn {
  display: block;
  width: 100%;
  max-width: 400px;
  margin: 1rem auto;
  padding: 1.5rem;
  font-size: 1.3rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: transform 0.1s;
}

.kiosk-btn:active { transform: scale(0.97); }

.kiosk-btn-primary {
  background: var(--gold);
  color: var(--text);
}

.kiosk-btn-secondary {
  background: rgba(255,255,255,0.1);
  color: var(--gold-light);
  border: 2px solid var(--gold);
}

.kiosk-message {
  text-align: center;
  font-size: 1.2rem;
  color: var(--gold-light);
  margin-top: 2rem;
}

/* ─── Landing Page Hero ────────────────── */

.hero {
  text-align: center;
  padding: 3rem 1rem;
  background: linear-gradient(135deg, var(--burgundy) 0%, #4A1520 100%);
  color: var(--white);
}

.hero h1 {
  font-size: 2.5rem;
  color: var(--gold-light);
  margin-bottom: 0.5rem;
}

.hero .tagline {
  font-size: 1.15rem;
  color: var(--gold-light);
  opacity: 0.9;
  margin-bottom: 2rem;
}

.hero .hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ─── Responsive ───────────────────────── */

/* Safe area insets (iPhone notch, Dynamic Island, rounded Android corners) */
@supports (padding: env(safe-area-inset-top)) {
  .header, .public-header { padding-top: calc(0.75rem + env(safe-area-inset-top)); }
  .toast { bottom: calc(1.5rem + env(safe-area-inset-bottom)); right: calc(1.5rem + env(safe-area-inset-right)); }
  body.kiosk-mode { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
}

/* Touch target sizing — Apple guideline: 44px minimum */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: 44px; min-width: 44px; }
  .header-nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .schedule-grid .slot { min-height: 44px; }
  .form-group input, .form-group select, .form-group textarea { min-height: 44px; font-size: 16px; /* prevents iOS zoom on focus */ }
  select { font-size: 16px; }
  th, td { padding: 0.75rem; }
}

/* High DPI / Retina — thinner borders */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .card { box-shadow: 0 1px 4px rgba(44, 36, 22, 0.08); }
  .schedule-grid { gap: 1px; }
  .form-group input, .form-group select { border-width: 1px; }
}

/* Ultra-wide / TV (2000px+) */
@media (min-width: 2000px) {
  .container { max-width: 1400px; }
  body { font-size: 1.1rem; }
  h1 { font-size: 2.25rem; }
  h2 { font-size: 1.6rem; }
  .btn { padding: 0.8rem 1.5rem; font-size: 1.05rem; }
  .schedule-grid { gap: 3px; }
  .schedule-grid .slot { min-height: 55px; font-size: 0.8rem; }
  .schedule-grid .hour-label { font-size: 0.85rem; }
  .schedule-grid .day-header { font-size: 0.9rem; padding: 0.65rem; }
  .module-grid { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
  .stat-box .stat-value { font-size: 2.25rem; }
  .kiosk-time { font-size: 6rem; }
  .kiosk-btn { font-size: 1.6rem; padding: 2rem; max-width: 500px; }
}

/* Desktop (1440px+) */
@media (min-width: 1440px) {
  .container { max-width: 1200px; }
}

/* iPad Pro landscape (~1366px) */
@media (min-width: 1024px) and (max-width: 1440px) {
  .module-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

/* iPad Air/Pro portrait + iPad mini landscape (~744-1024px) */
@media (min-width: 744px) and (max-width: 1023px) {
  .container { padding: 1rem 1.5rem; }
  .module-grid { grid-template-columns: repeat(2, 1fr); }
  .schedule-grid { grid-template-columns: 65px repeat(7, 1fr); }
}

/* Z Fold open / iPad mini portrait (~720-743px) */
@media (min-width: 600px) and (max-width: 743px) {
  .module-grid { grid-template-columns: repeat(2, 1fr); }
  .schedule-grid { grid-template-columns: 55px repeat(7, 1fr); font-size: 0.7rem; }
  .schedule-grid .slot { min-height: 36px; }
  .hero h1 { font-size: 2rem; }
}

/* Phones — iPhone, Pixel, Galaxy S, Z Fold closed (~360-599px) */
@media (max-width: 599px) {
  .container { padding: 0.75rem; }
  .form-row { flex-direction: column; gap: 0; }
  .stat-row { gap: 0.5rem; }
  .stat-box { min-width: 90px; padding: 0.75rem 0.5rem; }
  .stat-box .stat-value { font-size: 1.4rem; }
  .stat-box .stat-label { font-size: 0.7rem; }
  .hero h1 { font-size: 1.5rem; }
  .hero .tagline { font-size: 0.95rem; }
  .hero { padding: 2rem 0.75rem; }
  h1 { font-size: 1.4rem; }
  h2 { font-size: 1.15rem; }
  .schedule-grid { grid-template-columns: 50px repeat(7, 1fr); font-size: 0.6rem; }
  .schedule-grid .hour-label { font-size: 0.6rem; padding: 0.2rem 0.1rem; }
  .schedule-grid .day-header { font-size: 0.7rem; padding: 0.35rem 0.15rem; }
  .schedule-grid .slot { min-height: 32px; padding: 0.2rem; }
  .slot .adorer-name { font-size: 0.5rem; }
  .slot .adorer-count { font-size: 0.5rem; }
  .header { padding: 0.5rem 0.75rem; }
  .header-brand { font-size: 0.95rem; }
  .header-nav { gap: 0.25rem; }
  .header-nav a { font-size: 0.75rem; padding: 0.3rem 0.4rem; }
  .module-grid { grid-template-columns: 1fr; }
  .card { padding: 1rem; }
  .modal { padding: 1rem; }
  .modal-title { font-size: 1.05rem; }
  .btn { padding: 0.5rem 1rem; font-size: 0.9rem; }
  .toast { left: 1rem; right: 1rem; bottom: 1rem; text-align: center; }
  table { font-size: 0.85rem; }
  th, td { padding: 0.4rem 0.5rem; }
  .kiosk-time { font-size: 3rem; }
  .kiosk-hour-label { font-size: 1.2rem; }
  .kiosk-btn { font-size: 1.1rem; padding: 1.2rem; }
}

/* Small phones — iPhone SE, Galaxy A (~320-374px) */
@media (max-width: 374px) {
  .container { padding: 0.5rem; }
  .hero h1 { font-size: 1.3rem; }
  .hero { padding: 1.5rem 0.5rem; }
  h1 { font-size: 1.25rem; }
  .schedule-grid { grid-template-columns: 42px repeat(7, 1fr); }
  .schedule-grid .hour-label { font-size: 0.55rem; }
  .schedule-grid .day-header { font-size: 0.6rem; padding: 0.25rem 0.1rem; }
  .schedule-grid .slot { min-height: 28px; }
  .slot .adorer-name { display: none; }
  .header-brand { font-size: 0.85rem; }
  .header-nav a { font-size: 0.7rem; padding: 0.25rem 0.3rem; }
  .stat-box { min-width: 70px; }
  .stat-box .stat-value { font-size: 1.2rem; }
  .btn { font-size: 0.85rem; padding: 0.45rem 0.8rem; }
  .card { padding: 0.75rem; }
  .kiosk-time { font-size: 2.5rem; }
  .kiosk-btn { font-size: 1rem; padding: 1rem; }
}

/* Z Flip cover screen (~300px) */
@media (max-width: 319px) {
  .hero, .hero-actions { display: none; }
  .header-nav { display: none; }
  .header-brand { font-size: 0.8rem; }
  .container { padding: 0.25rem; }
  h1 { font-size: 1.1rem; }
  .schedule-grid { grid-template-columns: 35px repeat(7, 1fr); }
  .schedule-grid .day-header { font-size: 0.5rem; }
  .stat-row { display: none; }
  .module-grid { gap: 0.5rem; }
  .module-tile { padding: 0.75rem; }
  .module-tile .tile-icon { font-size: 1.3rem; margin-bottom: 0.25rem; }
  .module-tile .tile-title { font-size: 0.9rem; }
  .module-tile .tile-desc { display: none; }
}

/* Landscape phone — compact layout */
@media (max-height: 500px) and (orientation: landscape) {
  .header { padding: 0.35rem 0.75rem; }
  .header-brand { font-size: 0.9rem; }
  .hero { padding: 1rem 0.75rem; }
  .hero h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
  .hero .tagline { font-size: 0.9rem; margin-bottom: 0.75rem; }
  .container { padding: 0.5rem 1rem; }
  .card { padding: 0.75rem; margin-bottom: 0.5rem; }
  .stat-box { padding: 0.5rem; }
  .stat-box .stat-value { font-size: 1.3rem; }
  .schedule-grid .slot { min-height: 30px; }
  .kiosk-time { font-size: 2.5rem; margin: 0.5rem 0; }
  .kiosk-hour-label { font-size: 1rem; margin-bottom: 0.75rem; }
  .kiosk-btn { padding: 1rem; font-size: 1.1rem; margin: 0.5rem auto; }
}

/* Orientation change — auto-adjust */
@media (orientation: landscape) and (min-width: 600px) and (max-width: 1023px) {
  .module-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-row { flex-wrap: nowrap; }
}

/* Print */
@media print {
  .header, .public-header, .toast, .btn, .hero-actions, .modal-overlay { display: none !important; }
  .container { max-width: 100%; padding: 0; }
  .schedule-grid .slot { border: 1px solid #ccc; }
  body { background: white; }
}

/* ─── Utility ──────────────────────────── */

.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 0.5rem; }
.hidden { display: none !important; }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--cream-dark);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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