:root {
  --green-dark: #2d5016;
  --green-mid: #4a7c26;
  --green-light: #7ab648;
  --gold: #c8952b;
  --gold-light: #f0c060;
  --cream: #faf8f2;
  --brown: #6b4c2a;
  --text: #2c2c2c;
  --text-light: #666;
  --border: #d4c9b0;
  --white: #ffffff;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --success: #27ae60;
  --success-light: #eafaf1;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 8px;
}

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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background-color: var(--cream);
  background-image: url('/images/Background.png');
  background-size: cover;
  background-position: center top;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

a { color: var(--green-mid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- NAVBAR ---- */
.navbar {
  background: var(--green-dark);
  color: white;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 58px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--gold-light);
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.navbar-brand img {
  height: 34px;
  background: rgba(255,255,255,0.18);
  border-radius: 50%;
  padding: 4px;
}

.navbar-nav {
  display: flex;
  gap: 4px;
  list-style: none;
  flex: 1;
}

.navbar-nav a {
  color: rgba(255,255,255,0.85);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background 0.15s;
}

.navbar-nav a:hover, .navbar-nav a.active {
  background: rgba(255,255,255,0.15);
  color: white;
  text-decoration: none;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #e53935;
  color: white;
  border-radius: 10px;
  font-size: 0.62rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  vertical-align: middle;
  margin-left: 5px;
  line-height: 1;
}
.btn-link-inline {
  background: none;
  border: none;
  padding: 0;
  color: #4a7c59;
  font-size: 0.78rem;
  cursor: pointer;
  text-decoration: underline;
  margin-top: 2px;
}

.navbar-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255,255,255,0.85);
  font-size: 0.88rem;
}

.navbar-user .yard-tag {
  background: var(--gold);
  color: white;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Hamburger toggle — hidden on desktop, shown on mobile via the responsive block */
.nav-toggle {
  display: none;
  background: none;
  border: 0;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 10px;
  margin-left: auto;
}

/* ---- LAYOUT ---- */
.page-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px;
  position: relative;
  z-index: 1;
}

/* Subtle overlay so background image doesn't overpower content */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: rgba(250, 248, 242, 0.25);
  z-index: 0;
  pointer-events: none;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-title {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--green-dark);
}

.page-subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-top: 2px;
}

/* ---- CARDS ---- */
.card {
  background: rgba(255, 255, 255, 0.93);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  background: var(--green-dark);
  color: white;
  padding: 14px 20px;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body { padding: 20px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--green-dark);
}

.stat-card .stat-label {
  font-size: 0.82rem;
  color: var(--text-light);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card.warning .stat-value { color: var(--danger); }
.stat-card.gold .stat-value { color: var(--gold); }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn-warning { background: #d97706; color: white; }
.btn-warning:hover { background: #b45309; color: white; text-decoration: none; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #a52318; color: white; text-decoration: none; }

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

.btn-sm { padding: 5px 12px; font-size: 0.82rem; }
.btn-icon { padding: 6px 10px; }

/* ---- FORMS ---- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 5px;
  font-size: 0.88rem;
  color: var(--text);
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.93rem;
  color: var(--text);
  background: white;
  transition: border-color 0.15s;
}
.form-control:focus { outline: none; border-color: var(--green-mid); }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead th {
  background: var(--green-dark);
  color: white;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f5f2ea; }
tbody td { padding: 10px 14px; vertical-align: middle; }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-green { background: var(--success-light); color: var(--success); }
.badge-red { background: var(--danger-light); color: var(--danger); }
.badge-gold { background: #fff3cd; color: #856404; }
.badge-grey { background: #eee; color: #666; }
.badge-blue   { background: #e3f0ff; color: #1a5fb4; }
.badge-purple { background: #f3e8ff; color: #6b21a8; }
.badge-teal   { background: #ccfbf1; color: #0f766e; }

/* ---- MODAL ---- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.modal-header {
  background: var(--green-dark);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.modal-header .close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---- ALERTS ---- */
.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-success { background: var(--success-light); color: #145a32; border: 1px solid #a9dfbf; }
.alert-error { background: var(--danger-light); color: #7b241c; border: 1px solid #f5b7b1; }

/* ---- LOGIN PAGE ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
  overflow: hidden;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo h1 {
  font-size: 1.5rem;
  color: var(--green-dark);
  font-weight: 700;
}

.login-logo p {
  color: var(--text-light);
  font-size: 0.88rem;
  margin-top: 4px;
}

.login-logo .horseshoe {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.login-logo-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
  margin: 0 auto 12px;
}

.reg-logo-img {
  height: 30px;
  vertical-align: middle;
  filter: brightness(0) invert(1);
  margin-right: 4px;
}

.reg-hero {
  position: relative;
  overflow: hidden;
}

.reg-hero-horse {
  position: absolute;
  right: 48px;
  top: 50%;
  transform: translateY(-50%);
  height: 130px;
  opacity: 0.12;
  filter: brightness(0) invert(1);
  pointer-events: none;
}

.feature-icon-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

/* ---- NOTICES SCROLLER ---- */
.notices-scroller {
  background: rgba(45, 80, 22, 0.82);
  color: white;
  padding: 16px 24px;
  overflow: hidden;
  position: relative;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.notices-scroller h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold-light);
  margin-bottom: 8px;
}

.notice-items { display: flex; flex-direction: column; gap: 10px; }

.notice-item {
  background: rgba(255,255,255,0.1);
  border-left: 3px solid var(--gold);
  padding: 10px 14px;
  border-radius: 0 6px 6px 0;
}

.notice-item .notice-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--gold-light);
}

.notice-item .notice-body {
  font-size: 0.88rem;
  color: rgba(255,255,255,0.85);
  margin-top: 2px;
}

/* ---- YARD HOME HERO ---- */
.yard-hero {
  background: rgba(45, 80, 22, 0.72);
  color: white;
  padding: 28px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.yard-hero h2 { font-size: 1.6rem; font-weight: 700; }
.yard-hero p { color: rgba(255,255,255,0.8); margin-top: 4px; }

/* ---- BOOKING GRID ---- */
.booking-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 6px;
}

.slot-btn {
  padding: 7px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  cursor: pointer;
  font-size: 0.82rem;
  text-align: center;
  background: white;
  transition: all 0.15s;
}
.slot-btn.available:hover { background: var(--green-light); color: white; border-color: var(--green-light); }
.slot-btn.booked { background: #fee; border-color: #fcc; color: var(--danger); cursor: not-allowed; }
.slot-btn.mine { background: var(--success-light); border-color: var(--success); color: var(--success); }

/* ---- TABS ---- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 9px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-light);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  border-radius: 6px 6px 0 0;
}

.tab-btn:hover { color: var(--green-mid); background: rgba(0,0,0,0.03); }
.tab-btn.active { color: var(--green-dark); border-bottom-color: var(--green-mid); font-weight: 600; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- MISC ---- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-light); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-gold { color: var(--gold); }
.fw-bold { font-weight: 700; }

.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }

.actions-col { white-space: nowrap; }

.pound::before { content: '£'; }

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 820px) {
  /* Navigation: collapse the links + user block behind a hamburger */
  .navbar { flex-wrap: wrap; height: auto; min-height: 58px; padding: 0 14px; gap: 8px; }
  .navbar-brand { order: 1; }
  .nav-toggle { display: block; order: 2; }
  .navbar-nav, .navbar-user {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    display: none;
  }
  .navbar.nav-open .navbar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 6px 0 8px;
  }
  .navbar.nav-open .navbar-user {
    display: flex;
    flex-wrap: wrap;
    margin-left: 0;
    padding: 10px 0 12px;
    border-top: 1px solid rgba(255,255,255,0.15);
  }
  .navbar-nav a { display: block; padding: 11px 12px; border-radius: 6px; }

  /* Layout */
  .page-container { padding: 18px 14px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .yard-hero { padding: 20px; }
  .card-body { padding: 16px; }

  /* Wide data tables scroll horizontally instead of cramming */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { font-size: 0.85rem; }
  .table-wrap th, .table-wrap td { white-space: nowrap; }

  /* Modals fill the screen with a small margin */
  .modal-overlay { padding: 12px; align-items: flex-start; }
  .modal { max-width: 100%; max-height: calc(100vh - 24px); }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1 1 auto; }

  /* Tabs scroll sideways rather than stacking tall */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; }

  /* Booking slot grid: smaller slots so more fit per row */
  .booking-grid { grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); }

  /* Comfortable tap targets */
  .login-card { padding: 28px 22px; }

  /* Wide data tables marked .cards-sm become stacked cards on mobile, with
     each cell labelled by its column header (set by pwa.js). */
  table.cards-sm, table.cards-sm tbody, table.cards-sm tr, table.cards-sm td { display: block; width: auto; }
  table.cards-sm thead { display: none; }
  table.cards-sm tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 4px 12px;
    background: #fff;
  }
  table.cards-sm td {
    white-space: normal;
    border: none;
    padding: 8px 0;
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: baseline;
    text-align: right;
  }
  table.cards-sm td + td { border-top: 1px dashed var(--border); }
  table.cards-sm td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-light);
    text-align: left;
    flex: 0 0 40%;
    font-size: 0.82rem;
  }
  /* Action/button cells: full width, no label, left aligned */
  table.cards-sm td.actions-col,
  table.cards-sm td[data-label="Actions"] { justify-content: flex-start; text-align: left; flex-wrap: wrap; gap: 6px; }
  table.cards-sm td.actions-col::before,
  table.cards-sm td[data-label="Actions"]::before { display: none; }
}

/* ---- PWA INSTALL BANNER ---- */
.pwa-install-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--green-dark);
  color: #fff;
  padding: 12px 14px;
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
  font-size: 0.9rem;
  max-width: 520px;
  margin: 0 auto;
}
.pwa-install-banner .pwa-install-text { flex: 1; line-height: 1.35; }
.pwa-install-banner button {
  border: 0;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.pwa-install-banner .pwa-install-go { background: var(--gold); color: #fff; }
.pwa-install-banner .pwa-install-dismiss { background: rgba(255,255,255,0.18); color: #fff; }
