:root {
  color-scheme: light;
  --bg: #f7f4ee;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #14213d;
  --muted: #596579;
  --line: #ded8cb;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --coral: #e76f51;
  --gold: #f4c95d;
  --green: #2f855a;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(20, 33, 61, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.10), transparent 260px),
    var(--bg);
  color: var(--ink);
}

body.dialog-open {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--teal-dark);
}

button.secondary {
  background: #ebe5d8;
  color: var(--ink);
}

button.danger {
  background: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

a {
  color: inherit;
}

.app-shell {
  width: min(1120px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 44px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 10px 0 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  min-width: 0;
}

.brand img {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
}

.brand span {
  display: grid;
  min-width: 0;
}

.brand strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.05rem;
}

.brand small {
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.72);
}

.nav-tabs a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  padding: 0 12px;
  text-decoration: none;
  color: var(--muted);
  font-weight: 800;
}

.nav-tabs a.active {
  background: var(--ink);
  color: #fff;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 6px 0 24px;
}

.status-strip > div {
  min-height: 88px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stat-value {
  display: block;
  font-size: clamp(1.25rem, 2vw, 1.65rem);
  font-weight: 900;
}

.stat-label {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.view {
  animation: fade-in 180ms ease-out;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.section-heading h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3.8vw, 2.8rem);
  line-height: 1.05;
}

.section-heading p {
  max-width: 360px;
  margin: 0;
  color: var(--muted);
  font-weight: 650;
}

.appointment-list,
.admin-list {
  display: grid;
  gap: 12px;
}

.appointment-card,
.admin-row,
.form-panel,
.info-panel,
.admin-login,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(20, 33, 61, 0.06);
}

.appointment-card {
  display: grid;
  grid-template-columns: minmax(124px, 0.34fr) minmax(0, 1fr);
  overflow: hidden;
}

.calendar-panel {
  display: grid;
  gap: 14px;
}

.monthly-calendar {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 22px rgba(20, 33, 61, 0.06);
  overflow: hidden;
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fff9ed;
}

.calendar-header h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.5rem);
}

.calendar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.calendar-controls button {
  min-height: 36px;
  padding: 0 12px;
}

.calendar-controls .icon-button {
  width: 38px;
  padding: 0;
  font-size: 1.05rem;
}

.calendar-legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-weight: 850;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.legend-dot.covered,
.calendar-marker.covered {
  background: #dff4e8;
  color: #11633d;
}

.legend-dot.needs,
.calendar-marker.needs {
  background: #ffe1de;
  color: #9d241b;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.calendar-weekdays {
  border-bottom: 1px solid var(--line);
  background: #f6f0e4;
}

.calendar-weekdays span {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.calendar-day {
  min-width: 0;
  min-height: 126px;
  display: grid;
  align-content: start;
  gap: 8px;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 10px;
  text-align: left;
}

.calendar-day:hover {
  background: #f7fbf9;
}

.calendar-day:disabled {
  cursor: default;
  opacity: 1;
}

.calendar-day:disabled:hover {
  background: var(--surface-strong);
}

.calendar-day.outside-month:disabled:hover {
  background: #faf6ec;
}

.calendar-day.has-rides {
  cursor: pointer;
}

.calendar-day.has-rides:hover {
  outline: 3px solid rgba(15, 118, 110, 0.26);
  outline-offset: -3px;
}

.calendar-day.needs-ride:hover {
  outline-color: rgba(180, 35, 24, 0.28);
}

.calendar-day:nth-child(7n) {
  border-right: 0;
}

.calendar-day:nth-last-child(-n + 7) {
  border-bottom: 0;
}

.calendar-day.outside-month {
  background: #faf6ec;
  color: #99a0ad;
}

.calendar-day.today .calendar-date {
  background: var(--ink);
  color: #fff;
}

.calendar-date {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 950;
}

.calendar-markers {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.calendar-marker,
.calendar-more {
  min-height: 24px;
  display: flex;
  align-items: center;
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.76rem;
  font-weight: 900;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.marker-label-short {
  display: none;
}

.calendar-more {
  background: #eee8dd;
  color: var(--muted);
}

.date-block {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 18px;
  background: #f0e7d7;
  border-right: 1px solid var(--line);
}

.date-block strong {
  font-size: 1.35rem;
}

.date-block span,
.detail-row span {
  color: var(--muted);
  font-weight: 750;
}

.card-body {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.card-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.card-title h2 {
  margin: 0;
  font-size: 1.1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.pill.open {
  background: #dbf4ea;
  color: #0d5f3c;
}

.pill.claimed {
  background: #fff1c2;
  color: #765405;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-row {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.detail-row strong,
.detail-row span,
.notes,
.assigned {
  overflow-wrap: anywhere;
}

.notes {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.assigned {
  margin: 0;
  color: var(--ink);
  font-weight: 750;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding-top: 2px;
}

.release-form {
  grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.87rem;
  font-weight: 850;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--ink);
  padding: 11px 12px;
  min-width: 0;
}

textarea {
  resize: vertical;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.info-grid .section-heading {
  grid-column: 1 / -1;
}

.info-panel {
  padding: 18px;
}

.info-panel h2,
.form-panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.info-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.span-two {
  grid-column: 1 / -1;
}

.text-link {
  display: inline-flex;
  margin-top: 12px;
  color: var(--teal-dark);
  font-weight: 900;
}

.admin-login,
.form-panel {
  padding: 18px;
  margin-bottom: 14px;
}

.admin-login {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-panel button {
  margin-top: 14px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
}

.admin-row h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.admin-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state strong {
  color: var(--ink);
  margin-bottom: 4px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 28px));
  padding: 13px 16px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
  z-index: 20;
}

.ride-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}

.ride-dialog-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  border-radius: 0;
  background: rgba(20, 33, 61, 0.36);
  padding: 0;
}

.ride-dialog-backdrop:hover {
  background: rgba(20, 33, 61, 0.42);
}

.ride-dialog-panel {
  position: relative;
  width: min(860px, 100%);
  max-height: min(82vh, 760px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.ride-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #fff9ed;
}

.ride-dialog-header span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.ride-dialog-header h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2vw, 1.5rem);
}

.ride-dialog-header button {
  margin: 0;
  flex: 0 0 auto;
}

.ride-dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px;
  overflow: auto;
}

.ride-dialog-body .appointment-card {
  box-shadow: none;
}

@media (max-width: 820px) {
  .topbar,
  .section-heading,
  .admin-login,
  .admin-row {
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: grid;
  }

  .nav-tabs {
    overflow-x: auto;
    justify-content: start;
  }

  .detail-grid,
  .info-grid,
  .form-grid,
  .inline-form,
  .calendar-header {
    grid-template-columns: 1fr;
  }

  .calendar-header {
    display: grid;
  }

  .calendar-controls {
    justify-content: space-between;
  }

  .appointment-card {
    grid-template-columns: 1fr;
  }

  .date-block {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .admin-actions {
    justify-content: start;
  }

  .ride-dialog {
    align-items: end;
    padding: 10px;
  }

  .ride-dialog-panel {
    max-height: 88vh;
  }

  .ride-dialog-header {
    align-items: start;
  }
}

@media (max-width: 520px) {
  body {
    padding-bottom: calc(72px + env(safe-area-inset-bottom));
  }

  .app-shell {
    width: min(100% - 16px, 1120px);
    padding-top: calc(8px + env(safe-area-inset-top));
    padding-bottom: 22px;
  }

  .topbar {
    gap: 10px;
    padding: 4px 0 10px;
  }

  .brand img {
    width: 38px;
    height: 38px;
  }

  .brand {
    gap: 9px;
  }

  .brand strong {
    font-size: 0.98rem;
  }

  .brand small {
    font-size: 0.78rem;
  }

  .nav-tabs {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    padding: 5px;
    overflow: visible;
    background: rgba(255, 253, 248, 0.96);
    box-shadow: 0 12px 34px rgba(20, 33, 61, 0.18);
  }

  .nav-tabs a {
    min-height: 42px;
    padding: 0 4px;
    font-size: 0.83rem;
  }

  .status-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin: 2px 0 14px;
  }

  .status-strip > div {
    min-height: 62px;
    padding: 9px 8px;
  }

  .stat-value {
    font-size: 1.1rem;
  }

  .stat-label {
    font-size: 0.76rem;
    line-height: 1.1;
  }

  .section-heading {
    gap: 6px;
    margin-bottom: 10px;
  }

  .section-heading h1 {
    font-size: 1.55rem;
  }

  .section-heading p {
    font-size: 0.9rem;
    line-height: 1.25;
  }

  .calendar-header {
    gap: 10px;
    padding: 12px;
  }

  .calendar-header h2 {
    font-size: 1.12rem;
  }

  .calendar-controls {
    display: grid;
    grid-template-columns: 42px 1fr 42px;
    gap: 8px;
  }

  .calendar-controls button {
    min-height: 38px;
  }

  .calendar-legend {
    gap: 12px;
    padding: 9px 12px;
  }

  .legend-item {
    font-size: 0.82rem;
  }

  .legend-dot {
    width: 10px;
    height: 10px;
  }

  .calendar-weekdays span {
    font-size: 0.72rem;
    min-height: 30px;
  }

  .calendar-day {
    min-height: 70px;
    padding: 5px;
    gap: 4px;
  }

  .calendar-date {
    width: 22px;
    height: 22px;
    font-size: 0.82rem;
  }

  .calendar-marker,
  .calendar-more {
    min-height: 18px;
    padding: 2px 3px;
    font-size: 0.58rem;
    border-radius: 5px;
  }

  .marker-label-full {
    display: none;
  }

  .marker-label-short {
    display: inline;
  }

  .ride-dialog {
    align-items: end;
    padding: 0;
  }

  .ride-dialog-panel {
    width: 100%;
    max-height: min(90dvh, 760px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 14px 14px 0 0;
  }

  .ride-dialog-header {
    padding: 12px 14px;
  }

  .ride-dialog-header h2 {
    font-size: 1.12rem;
  }

  .ride-dialog-header button {
    min-height: 38px;
    padding: 0 13px;
  }

  .ride-dialog-body {
    gap: 10px;
    padding: 10px 10px calc(12px + env(safe-area-inset-bottom));
  }

  .ride-dialog-body .date-block {
    display: none;
  }

  .ride-dialog-body .card-body {
    gap: 11px;
    padding: 14px;
  }

  .ride-dialog-body .card-title h2 {
    font-size: 1rem;
  }

  .ride-dialog-body .detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .ride-dialog-body .notes {
    font-size: 0.92rem;
    line-height: 1.38;
  }

  .ride-dialog-body .inline-form {
    gap: 8px;
  }

  .ride-dialog-body input {
    padding: 10px;
  }

  .ride-dialog-body .inline-form button {
    width: 100%;
    margin-top: 2px;
  }
}
