/* Appointments (public/js/appointments.js: admin page and teacher portal;
   public/js/parent-appointments.js: parent portal). */
.appt { display: grid; gap: 14px; color: var(--text); min-width: 0; }
.appt button, .appt input, .appt select, .appt textarea,
.appt-dialog button, .appt-dialog input, .appt-dialog select, .appt-dialog textarea { font: inherit; }
.appt h2 { margin: 0; font-size: 1.25rem; }
.appt h3, .appt-dialog h3 { margin: 0 0 10px; font-size: 1.05rem; }
.appt-h { margin: 18px 0 8px; font-size: 1rem; }
.appt-sub { color: var(--text-muted); font-size: 0.85em; }
p.appt-sub { margin: 2px 0 8px; }
.appt-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px; }
.appt-head > div:first-child { min-width: 0; flex: 1 1 320px; }
.appt-head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.appt-head-actions select { min-height: 38px; max-width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); color: var(--text); }
.appt-tabs { display: flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; width: fit-content; max-width: 100%; }
.appt-tabs button { border: 0; background: var(--card); color: var(--text); padding: 8px 14px; cursor: pointer; min-height: 40px; }
.appt-tabs button + button { border-left: 1px solid var(--border); }
.appt-tabs button.active { background: var(--primary); color: #fff; }
.appt-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow-sm); min-width: 0; }
.appt-body { display: grid; gap: 14px; min-width: 0; }

.appt-msg { margin: 6px 0; color: var(--text-muted); }
.appt-msg.error { color: var(--danger); background: var(--danger-bg); padding: 8px 10px; border-radius: var(--radius-md); }
.appt-msg.ok { color: var(--success); background: var(--success-bg); padding: 8px 10px; border-radius: var(--radius-md); }
.appt-msg.warn { color: var(--text); background: var(--warning-bg); padding: 8px 10px; border-radius: var(--radius-md); border-left: 4px solid var(--warning); }

.appt-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 38px; padding: 7px 14px; width: auto;
  border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); color: var(--text); cursor: pointer; font-weight: 600;
}
.appt-btn:hover { background: var(--card-hover); }
.appt-btn:focus-visible, .appt-slot:focus-visible, .appt-tabs button:focus-visible, .appt-result:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.appt-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.appt-btn.primary:hover { background: var(--primary-hover); }
.appt-btn.danger { color: var(--danger); border-color: var(--danger); }
.appt-btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.appt-btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.85em; font-weight: 500; }
.appt-btn:disabled { opacity: 0.6; cursor: progress; }

.appt-pill { display: inline-block; padding: 1px 8px; border-radius: var(--radius-pill); font-size: 0.8em; font-weight: 600; white-space: nowrap; background: var(--bg-alt); color: var(--text-muted); }
.appt-pill.ok { background: var(--success-bg); color: var(--success); }
.appt-pill.warn { background: var(--warning-bg); color: var(--warning); }
.appt-pill.bad { background: var(--danger-bg); color: var(--danger); }

/* Appointment cards */
.appt-list { display: grid; gap: 8px; }
.appt-date-head { font-weight: 700; margin: 8px 0 0; color: var(--text-secondary); }
.appt-item {
  display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 10px 14px; align-items: start;
  padding: 12px; border: 1px solid var(--border-light); border-radius: var(--radius-md); background: var(--card);
}
.appt-item.status-requested { border-left: 4px solid var(--warning); }
.appt-item.status-confirmed { border-left: 4px solid var(--success); }
.appt-time { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.appt-main { min-width: 0; display: grid; gap: 3px; }
.appt-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.appt-who { min-width: 0; overflow-wrap: anywhere; }
.appt-reason { white-space: pre-wrap; overflow-wrap: anywhere; }
.appt-line { font-size: 0.9em; overflow-wrap: anywhere; }
.appt-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

/* Forms */
.appt-form { display: grid; gap: 14px; max-width: 760px; }
.appt-field { display: grid; gap: 4px; font-weight: 600; font-size: 0.9em; min-width: 0; }
/* The portals style bare labels as small capitals; these are sentences. */
.appt .appt-field, .appt-dialog .appt-field, .appt .appt-check, .appt-dialog .appt-check, .appt-form .appt-field {
  text-transform: none; letter-spacing: normal; color: var(--text);
}
.appt-field small { font-weight: 400; color: var(--text-muted); }
.appt-field input, .appt-field select, .appt-field textarea {
  width: 100%; min-height: 38px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--card); color: var(--text); font-weight: 400;
}
.appt-field textarea { resize: vertical; }
.appt-inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; align-items: end; margin-top: 12px; }
.appt-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; min-height: 32px; }
.appt-check input { width: 18px; height: 18px; }
.appt-custom { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.appt-search { display: grid; gap: 6px; }
.appt-result-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; max-height: 260px; overflow-y: auto; }
.appt-result { width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--border-light); border-radius: var(--radius-md); background: var(--card); color: var(--text); cursor: pointer; font-weight: 400; }
.appt-result:hover { background: var(--card-hover); }
.appt-chosen { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-weight: 400; }

/* Slot picker */
.appt-picker { display: grid; gap: 10px; font-weight: 400; }
.appt-slot-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.appt-slots { display: grid; gap: 10px; }
.appt-slot-day { display: grid; gap: 6px; }
.appt-slot-date { font-weight: 600; font-size: 0.9em; }
.appt-slot-times { display: flex; flex-wrap: wrap; gap: 6px; }
.appt-slot {
  min-width: 64px; min-height: 38px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--card); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums;
}
.appt-slot:hover { border-color: var(--primary); }
.appt-slot[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.appt-slot.current { border-style: dashed; color: var(--text-muted, #6b7280); cursor: not-allowed; text-decoration: line-through; }
.appt-slot.current:hover { border-color: inherit; }

/* Hours table */
.appt-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.appt-table { width: 100%; border-collapse: collapse; font-size: 0.92em; }
.appt-table th, .appt-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.appt-table th { color: var(--text-muted); font-weight: 600; font-size: 0.85em; white-space: nowrap; }
.appt-blocked, .appt-conflicts { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
.appt-history { margin: 0; padding-left: 20px; display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; font-size: 0.9em; }

/* Dialog */
.appt-backdrop { position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, 0.45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.appt-dialog {
  width: min(560px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; display: grid; gap: 12px;
  background: var(--card); color: var(--text); border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-lg);
}
.appt-dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* Parent portal */
.parent-portal .appt-item { grid-template-columns: 76px minmax(0, 1fr) auto; }
.appt-past { margin-top: 16px; }
.parent-portal .appt-cancel { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.appt-past summary { cursor: pointer; font-weight: 600; padding: 6px 0; }

@media (max-width: 640px) {
  .appt-item, .parent-portal .appt-item { grid-template-columns: 1fr; }
  .appt-when { display: flex; gap: 8px; align-items: baseline; }
  .appt-actions { justify-content: flex-start; }
  .appt-tabs { width: 100%; }
  .appt-tabs button { flex: 1 1 auto; }
  .appt-dialog { padding: 14px; }
}

/* Selects look the same in Safari/WebKit, which otherwise draws a 23 px
   native menulist that ignores min-height. */
.appt select:not([multiple]):not([size]), .appt-dialog select:not([multiple]):not([size]) {
  -webkit-appearance: none; appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}
