:root {
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-primary-light: #eef2ff;
  --color-primary-ring: rgba(79, 70, 229, 0.18);
  --color-accent: #818cf8;

  --color-bg: #f6f7fb;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #0f172a;
  --color-text-muted: #64748b;

  --color-secondary: #64748b;
  --color-secondary-dark: #475569;
  --color-danger: #e11d48;
  --color-danger-dark: #be123c;
  --color-success: #059669;

  --header-bg: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);

  --radius-sm: 8px;
  --radius-md: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-primary: 0 4px 12px rgba(79, 70, 229, 0.25);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 480px at 50% -120px, var(--color-primary-light), transparent),
    var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

header.topbar {
  background: var(--header-bg);
  color: #fff;
  padding: 0.85rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow-md);
}
header.topbar a { color: #fff; text-decoration: none; font-weight: 600; }
header.topbar > a:first-child { display: flex; align-items: center; gap: 0.6rem; letter-spacing: -0.01em; }
header.topbar > a:first-child::before {
  content: '';
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--color-accent), var(--color-primary));
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  flex: 0 0 auto;
}
header.topbar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
header.topbar nav a { color: #c7d2fe; font-weight: 400; font-size: 0.9rem; transition: color 0.15s ease; }
header.topbar nav a:hover { color: #fff; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
h1 { color: var(--color-text); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { color: var(--color-text); font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
@media (min-width: 641px) {
  main { padding: 1.75rem 1.5rem; }
  h1 { font-size: 1.85rem; }
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem;
  margin-bottom: 1rem;
}
@media (min-width: 641px) {
  .card { padding: 1.35rem; }
}

.home-grid .card { transition: transform 0.15s ease, box-shadow 0.15s ease; }
.home-grid .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.agenda-item { transition: transform 0.1s ease, box-shadow 0.15s ease; }

form label { display: block; margin-bottom: 0.75rem; font-size: 0.9rem; font-weight: 600; color: #334155; }
form input, form select {
  display: block;
  width: 100%;
  padding: 0.65rem 0.75rem;
  margin-top: 0.3rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 16px; /* keep >=16px: prevents iOS Safari auto-zoom-on-focus */
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
form input:focus, form select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-ring);
}

button {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-primary);
  transition: background 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
button:hover { background: var(--color-primary-dark); box-shadow: 0 6px 16px rgba(79, 70, 229, 0.32); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
button.secondary { background: var(--color-secondary); box-shadow: none; }
button.secondary:hover { background: var(--color-secondary-dark); box-shadow: none; }
button.danger { background: var(--color-danger); box-shadow: 0 4px 12px rgba(225, 29, 72, 0.25); }
button.danger:hover { background: var(--color-danger-dark); box-shadow: 0 6px 16px rgba(225, 29, 72, 0.32); }

.error { color: var(--color-danger-dark); margin: 0.5rem 0; }
.success { color: var(--color-success); margin: 0.5rem 0; }
.muted { color: var(--color-text-muted); font-size: 0.9rem; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  padding: 0.5rem;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
}
td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--color-border); font-size: 0.9rem; }

/* Responsive tables: restack rows as labeled cards below 641px.
   Requires the row-rendering JS to set a data-label attribute per <td>. */
@media (max-width: 640px) {
  table.responsive-table,
  table.responsive-table thead,
  table.responsive-table tbody,
  table.responsive-table th,
  table.responsive-table td,
  table.responsive-table tr { display: block; }
  table.responsive-table thead { display: none; }
  table.responsive-table tr {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  table.responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border: none;
    text-align: right;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    text-align: left;
    margin-right: auto;
  }
  table.responsive-table td:empty { display: none; }
}

.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.slot-btn {
  background: #fff;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  font-size: 0.85rem;
  box-shadow: none;
}
.slot-btn:hover { background: var(--color-primary-light); }
.slot-btn[disabled] { border-color: var(--color-border); color: #9ca3af; background: #f3f4f6; cursor: not-allowed; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.status-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.status-booked { background: #eef2ff; color: #4338ca; }
.status-checked_in { background: #fef3c7; color: #92400e; }
.status-completed { background: #d1fae5; color: #047857; }
.status-cancelled { background: #f1f5f9; color: #64748b; }
.status-no_show { background: #ffe4e6; color: #be123c; }

.board-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.board-col h3 { margin-top: 0; }
.board-row { padding: 0.4rem 0; border-bottom: 1px solid #eee; font-size: 0.9rem; }

/* Home page */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-top: 1.25rem; }
.home-grid .card { display: flex; flex-direction: column; margin-bottom: 0; }
.home-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-top: 0.75rem; }
.home-actions a { flex: 1 1 140px; text-decoration: none; }
.home-actions button { width: 100%; }

/* Week nav (desktop) + day strip (mobile) for the grower weekly calendar */
.week-nav { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.week-nav button { padding: 0.45rem 0.75rem; font-size: 0.85rem; box-shadow: none; }
.week-label { margin-left: 0.25rem; font-weight: 600; color: #334155; }

.day-strip {
  display: none;
  gap: 0.4rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.15rem 0.1rem 0.6rem;
  margin-bottom: 0.25rem;
}
.day-strip button {
  flex: 0 0 auto;
  background: #fff;
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.5rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: none;
}
.day-strip button.active { background: var(--color-primary); color: #fff; border-color: var(--color-primary); box-shadow: var(--shadow-primary); }

@media (max-width: 640px) {
  .week-nav #this-week, .week-nav .week-label { display: none; }
  .week-nav button { flex: 1 1 auto; }
  .day-strip { display: flex; }
}

.calendar-wrap { overflow-x: auto; }
.calendar-grid {
  display: grid;
  border-top: 1px solid var(--color-border);
  border-left: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.calendar-time-label {
  grid-column: 1;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  padding: 0.15rem 0.4rem;
  text-align: right;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
}
.calendar-time-label.hour-mark { border-bottom-color: var(--color-border); color: #334155; font-weight: 600; }
.calendar-day-header, .calendar-dock-header {
  padding: 0.4rem 0.3rem;
  text-align: center;
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  background: #f8fafc;
  font-size: 0.85rem;
}
.calendar-day-header { font-weight: 700; color: var(--color-text); }
.calendar-dock-header { font-weight: 600; color: var(--color-primary-dark); font-size: 0.75rem; background: var(--color-primary-light); }
.calendar-row-line {
  border-right: 1px solid var(--color-border);
  border-bottom: 1px solid #f1f5f9;
}
.calendar-row-line.hour-mark { border-bottom-color: var(--color-border); }
.calendar-slot {
  margin: 1px;
  border: 1px solid var(--color-primary);
  background: #fff;
  color: var(--color-primary);
  border-radius: 4px;
  font-size: 0.7rem;
  padding: 0.15rem;
  cursor: pointer;
  overflow: hidden;
  box-shadow: none;
  font-weight: 600;
}
.calendar-slot:hover { background: var(--color-primary-light); }
.calendar-slot[disabled] {
  border-color: var(--color-border);
  color: #9ca3af;
  background: #f8fafc;
  cursor: not-allowed;
}
.calendar-empty { padding: 1rem; color: var(--color-text-muted); font-size: 0.9rem; }

@media (max-width: 640px) {
  /* Single-day mobile mode has far fewer columns, so slots get room to be proper tap targets. */
  .calendar-slot { min-height: 2.75rem; font-size: 0.85rem; padding: 0.4rem; }
  .calendar-time-label { font-size: 0.7rem; }
}

.board-layout { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; margin-top: 0.75rem; }
.board-layout .calendar-wrap { flex: 3 1 480px; }
.board-agenda { flex: 1 1 280px; max-width: 340px; max-height: 75vh; overflow-y: auto; position: sticky; top: 1rem; }
.board-agenda h2 { margin-top: 0; font-size: 1rem; }
.agenda-item {
  border: 1px solid var(--color-border);
  border-left: 4px solid #94a3b8;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  font-size: 0.85rem;
}
.agenda-item:hover { background: #f8fafc; box-shadow: var(--shadow-sm); }
.agenda-item.selected { border-left-color: var(--color-primary); background: var(--color-primary-light); }
.agenda-item .agenda-time { font-weight: 700; color: var(--color-text); }
.agenda-item .agenda-dock { color: var(--color-text-muted); font-size: 0.8rem; }

.board-block {
  margin: 1px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 0.7rem;
  padding: 0.15rem 0.3rem;
  overflow: hidden;
  text-align: left;
  cursor: pointer;
  position: relative;
  z-index: 1;
  box-shadow: none;
  font-weight: 600;
}
.board-block.status-booked { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.board-block.status-checked_in { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
.board-block.status-completed { background: #d1fae5; color: #047857; border-color: #6ee7b7; }
.board-block.status-no_show { background: #ffe4e6; color: #be123c; border-color: #fda4af; }
.board-block.selected { outline: 2px solid var(--color-primary); outline-offset: 1px; }

.board-open-band {
  margin: 1px;
  border-radius: 4px;
  background: #f8fafc;
  border: 1px dashed #e2e8f0;
  position: relative;
  z-index: 0;
  pointer-events: none;
}
