:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1b2230;
  --muted: #646468;
  --border: #dde3ea;
  --primary: #0a2148;          /* AM Anesthesia navy */
  --primary-hover: #061633;
  --primary-tint: #e9edf5;
  --primary-tint-border: #c9d2e3;
  --brand-gray: #646468;       /* the gray "M" */
  --success: #1e7a4c;
  --success-bg: #e6f4ec;
  --danger: #b3261e;
  --danger-bg: #fbeaea;
  --warning: #8a5a00;
  --warning-bg: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

a { color: var(--primary); }

h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }
h1 + h2, .card > h2:first-child { margin-top: 0; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 24px; padding-bottom: 32px; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Top bar ---------- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: inset 0 3px 0 var(--primary); }
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px 16px; min-height: 60px; padding-top: 8px; padding-bottom: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; padding: 4px 0; }
.brand-mark { height: 36px; width: auto; display: block; }
.brand-word { color: var(--primary); font-size: 0.8rem; font-weight: 500; letter-spacing: 0.34em; text-transform: uppercase; }
.brand-product { color: var(--brand-gray); font-size: 0.85rem; padding-left: 10px; border-left: 1px solid var(--border); }

.auth-brand { text-align: center; margin: 48px 0 8px; }
.auth-brand img { width: 237px; max-width: 70%; height: auto; }
.nav { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.nav a, .nav-button {
  padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none;
  font: inherit; font-size: 0.95rem; background: none; border: 0; cursor: pointer;
}
.nav a:hover, .nav-button:hover { background: var(--bg); color: var(--text); }
.nav a.active { color: var(--primary); background: var(--primary-tint); font-weight: 600; }

/* ---------- Cards, alerts ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.auth-card { max-width: 420px; margin: 16px auto 40px; }
.form-card { max-width: 760px; }
.empty { text-align: center; padding: 40px 20px; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #b9dfc8; }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: #f0c2bf; }
.alert-info { background: var(--primary-tint); color: var(--primary); border-color: var(--primary-tint-border); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border-color: #f1dcaa; }
.alert .inline { margin-left: 8px; }

.phi-warning {
  background: var(--warning-bg); color: var(--warning); border-radius: 8px;
  padding: 10px 12px; font-size: 0.9rem; margin: 0;
}

/* ---------- Forms ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
label .muted { font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="datetime-local"], select, textarea {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff;
  min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(10, 33, 72, 0.25); outline-offset: 1px; border-color: var(--primary);
}

fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0; }
fieldset > * + * { margin-top: 12px; }
legend { font-weight: 700; padding: 0 6px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.inline { display: inline; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.95rem; text-decoration: none; cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: #17613c; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1e18; }
.btn-danger-outline { color: var(--danger); border-color: #f0c2bf; }
.btn-danger-outline:hover { background: var(--danger-bg); }
.btn-small { min-height: 34px; padding: 5px 10px; font-size: 0.85rem; }
.btn-tiny { min-height: 30px; padding: 2px 8px; font-size: 0.78rem; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }


/* ---------- Page header, period navigation, filters ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.breadcrumb { margin: 0 0 8px; font-size: 0.9rem; }
.breadcrumb a { text-decoration: none; }

.period-nav { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.period-nav a {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  text-decoration: none; font-size: 1.2rem; color: var(--text);
}
.period-nav a:hover { background: var(--bg); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none; font-size: 0.88rem; font-weight: 600;
}
.chip span { color: var(--muted); font-weight: 400; margin-left: 2px; }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.active span { color: #c9d2e3; }

.review-meta { margin-top: 0; }
.review-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.review-bar input[type="text"] { flex: 1 1 260px; width: auto; min-height: 40px; padding: 8px 12px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { padding: 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .actions { white-space: nowrap; }
.table .actions > * + * { margin-left: 6px; }
.table .notes { max-width: 260px; white-space: pre-wrap; overflow-wrap: anywhere; }
.table tr.inactive td { color: var(--muted); }
.table tr.weekend td { background: #f8f9fc; }
.table tr.has-warning td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.table tr.total-row td { background: #fafbfc; font-weight: 700; }
/* A day's shifts after the first are joined to it by a dashed line. */
.table tr.more-shifts td { border-bottom-style: dashed; }
.table tr.later-shift td:first-child strong { color: var(--muted); font-weight: 600; }

details.reset, details.inline-edit { display: inline-block; vertical-align: top; text-align: left; }
details.reset summary, details.inline-edit summary { list-style: none; cursor: pointer; }
details.reset summary::-webkit-details-marker, details.inline-edit summary::-webkit-details-marker { display: none; }
.link-summary { color: var(--primary); font-weight: 600; }
.link-summary .small { font-weight: 400; text-decoration: underline; margin-left: 4px; }
.inline-stack { display: flex; gap: 6px; margin-top: 6px; }
.inline-stack input { min-height: 34px; padding: 6px 10px; font-size: 0.85rem; min-width: 200px; }
.edit-panel {
  margin-top: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #fafbfc;
  min-width: 280px; max-width: 420px; white-space: normal; gap: 10px;
}
.edit-panel input[type="text"] { min-height: 36px; padding: 6px 10px; }
.checkbox-list { display: flex; flex-direction: column; gap: 6px; margin: 8px 0 10px; }
label.checkbox { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.checkbox input { width: 18px; height: 18px; flex: none; }
.add-card { margin-top: 24px; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.03em; white-space: nowrap; }
.badge-none { background: #eef0f3; color: var(--muted); }
.badge-draft { background: #eef0f3; color: var(--text); }
.badge-submitted { background: var(--primary-tint); color: var(--primary); }
.badge-approved { background: var(--success-bg); color: var(--success); }
.badge-returned { background: var(--danger-bg); color: var(--danger); }

/* Current / upcoming labels on the doctor's list of pay periods */
.period-tag {
  display: inline-block; margin-left: 8px; padding: 1px 8px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; vertical-align: 1px;
}
.period-tag-current { background: var(--primary); color: #fff; }
.period-tag-upcoming { background: var(--surface); color: var(--brand-gray); border: 1px dashed var(--brand-gray); }
.table tr.upcoming td { background: #fbfbfd; }
.table tr.upcoming td:first-child { box-shadow: inset 3px 0 0 var(--border); }

/* ---------- Timesheet grid ---------- */
.grid-help { display: flex; gap: 12px 24px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 12px; }
.grid-help p { margin: 0; max-width: 720px; }
.grid-tips { margin: 0; padding-left: 1.4em; max-width: 720px; }
.grid-tips li + li { margin-top: 2px; }
.grid-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.ts-grid th, .ts-grid td { padding: 6px 8px; vertical-align: top; }
/* Line plain text up with the fields beside it. */
.ts-grid td.ts-date, .ts-grid td.ts-oncall, .ts-grid td.ts-hours, .ts-grid td.ts-nothing { padding-top: 14px; }
.ts-grid tr.unscheduled td { padding-top: 8px; padding-bottom: 8px; }
.ts-grid .ts-date { white-space: nowrap; }
.ts-grid .ts-date .btn-add { display: flex; margin-top: 8px; }
/* A day's shifts are stacked in one cell; each lines up under the Facility,
   Scheduled, Actual and Notes headings, which use the same columns (in rem, as
   the headings are in a smaller font). */
.shift-list { display: flex; flex-direction: column; gap: 6px; }
.ts-grid .shift {
  display: grid; grid-template-columns: 5.5rem 9.6rem 13.6rem minmax(7.4rem, 1fr);
  gap: 4px 8px; align-items: center;
}
.ts-grid .shift-locked { grid-template-columns: 4.6rem 6.9rem 13.6rem minmax(7.4rem, 1fr); }
.ts-grid .shift-locked .shift-field { min-height: 36px; display: flex; align-items: center; }
.ts-grid .shift-locked .shift-field > .note, .ts-grid .shift-locked .shift-field > .pair { flex: 1; }
.ts-grid .shift-field > input.note { width: 100%; min-width: 0; }
/* A shift can be removed once its day has more than one. */
.ts-grid .shift:not(.shift-locked):not(:only-of-type) { grid-template-columns: 5.5rem 9.6rem 13.6rem minmax(7.4rem, 1fr) 30px; }
.ts-grid .shift:only-of-type .btn-remove { display: none; }
.ts-grid .shift.needs-actual input[data-t^="act_"] { border-color: #e0bf73; }
/* Mid-size screens: each shift's notes go under its times, so the table fits. */
@media (min-width: 721px) and (max-width: 1140px) {
  .ts-grid .shift { grid-template-columns: 5.5rem 9.6rem 13.6rem; }
  .ts-grid .shift-locked { grid-template-columns: 4.6rem 6.9rem 13.6rem; }
  .ts-grid .shift:not(.shift-locked):not(:only-of-type) { grid-template-columns: 5.5rem 9.6rem 13.6rem 30px; }
  .ts-grid .shift-field[data-label="Notes"] { grid-column: 1 / 4; grid-row: 2; }
  .ts-grid .shift-head > span:last-child { grid-column: 1 / 4; }
}
.ts-grid .sched-text { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ts-grid select { width: auto; min-width: 5.5em; min-height: 36px; padding: 6px 8px; }
.ts-grid input.time {
  width: 4.4em; min-height: 36px; padding: 6px 4px; text-align: center; font-variant-numeric: tabular-nums;
}
.ts-grid input.note { min-height: 34px; padding: 6px 8px; font-size: 0.85rem; min-width: 9em; }
/* Low specificity so the size and .invalid rules win. */
.ts-grid :where(input:not([type])) { font: inherit; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 6px; }
.callback-list-edit { display: flex; flex-direction: column; gap: 8px; }
.ts-grid .btn-add { margin-top: 4px; }
.ts-grid .btn-remove { min-width: 30px; padding: 2px 6px; color: var(--muted); font-size: 1rem; line-height: 1; }
.ts-grid .btn-remove:hover { color: var(--danger); border-color: #f0c2bf; background: var(--danger-bg); }
.ts-grid input.call-note { display: block; width: 100%; margin-top: 4px; }
.callback-list div { white-space: nowrap; }
.callback-list .call-note-text { white-space: normal; max-width: 220px; overflow-wrap: anywhere; margin: 0 0 4px; }
.ts-grid input[type="checkbox"] { width: 20px; height: 20px; }
.ts-grid label.on-call-for { flex-direction: row; align-items: center; justify-content: center; gap: 4px; margin-top: 6px; font-weight: 400; }
.ts-grid .on-call-for select { min-width: 0; width: auto; min-height: 32px; padding: 4px 6px; font-size: 0.85rem; }
.ts-grid .ts-hours { min-width: 5.5em; }
.ts-grid .ts-hours span { display: block; }
.ts-grid .needs-actual-tag { color: var(--warning); font-weight: 600; font-size: 0.8rem; }
.pair { display: flex; align-items: center; gap: 4px; }
input.invalid { border-color: var(--danger); background: var(--danger-bg); }
.ts-totals { display: flex; gap: 8px 24px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 4px; }
.timesheet-form .phi-warning { margin-bottom: 8px; }
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5; padding: 12px 0;
  background: var(--bg); border-top: 1px solid var(--border);
}

/* ---------- Schedule import ---------- */
.import-summary ul { margin: 0; padding-left: 1.2em; }
.import-summary li + li { margin-top: 4px; }
.import-attention { color: var(--warning); }
.import-rules { margin: 16px 0 0; padding-left: 1.2em; }
.import-rules li + li { margin-top: 4px; }
.import-conflicts label.checkbox { align-items: flex-start; font-weight: 600; }
.import-conflicts label.checkbox input { margin-top: 2px; }
input[type="file"] { font: inherit; font-weight: 400; }

.footer { color: var(--muted); font-size: 0.8rem; padding-bottom: 24px; }
.footer p { margin: 0 0 4px; }

/* ---------- Confirmation dialog (see app.js) ---------- */
.confirm-dialog {
  width: calc(100% - 32px); max-width: 440px; padding: 20px 20px 16px;
  border: 1px solid var(--border); border-top: 3px solid var(--primary); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: 0 12px 32px rgba(10, 33, 72, 0.22);
}
.confirm-dialog::backdrop { background: rgba(10, 33, 72, 0.35); }
.confirm-dialog p { margin: 0 0 18px; font-size: 1rem; }
.confirm-dialog .confirm-heading:empty { display: none; }
.confirm-dialog .confirm-items { margin: -8px 0 16px; padding-left: 1.4em; font-weight: 600; }
.confirm-dialog.is-warning { border-top-color: var(--warning); }
.confirm-dialog.is-warning .confirm-heading { color: var(--warning); }
.confirm-dialog .form-actions { justify-content: flex-end; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  h1 { font-size: 1.35rem; }
  .brand-product { display: none; }
  .auth-brand { margin-top: 24px; }
  .grid-2 { grid-template-columns: 1fr; }
  .card { padding: 16px; }

  /* Tables become stacked cards */
  .table-wrap { background: none; border: 0; box-shadow: none; overflow: visible; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 12px; padding: 8px 14px;
  }
  .table.responsive tr.weekend td, .table.responsive tr.total-row td { background: none; }
  .table.responsive tr.weekend { background: #f8f9fc; }
  .table.responsive td { border: 0; padding: 6px 0; text-align: left; }
  .table.responsive td[data-label]::before {
    content: attr(data-label); display: block; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--muted); font-weight: 600;
  }
  .table.responsive td.num, .table.responsive td.center { text-align: left; }
  .table.responsive td.actions { padding-top: 10px; white-space: normal; }
  .table .notes { max-width: none; }
  .inline-stack { flex-wrap: wrap; }
  .inline-stack input { min-width: 0; flex: 1; }
  .edit-panel { min-width: 0; max-width: none; }

  .table.responsive td:empty { display: none; }

  /* Each day becomes a compact two-column card: the date and hours, then its
     shifts, then on call and call-backs */
  .table.responsive.ts-grid tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  .table.responsive.ts-grid td { width: auto; padding: 4px 0; }
  .ts-grid td.ts-hours, .ts-grid td.ts-nothing { order: 1; }
  .ts-grid td.ts-shifts { grid-column: 1 / -1; order: 2; }
  .ts-grid td.ts-oncall { grid-column: 1 / -1; order: 3; display: flex; align-items: center; gap: 10px; }
  .ts-grid label.on-call-for { margin-top: 0; }
  .ts-grid td.ts-callbacks { grid-column: 1 / -1; order: 4; }
  .ts-grid td.ts-nothing { align-self: center; }
  /* A shift: facility (and its remove button), scheduled beside actual, then notes.
     Where the schedule is locked: facility beside scheduled, then actual, then notes. */
  .ts-grid .shift, .ts-grid .shift-locked, .ts-grid .shift:not(.shift-locked):not(:only-of-type) {
    grid-template-columns: 1fr 1fr; gap: 6px 12px; align-items: start;
  }
  .ts-grid .shift + .shift { border-top: 1px dashed var(--border); padding-top: 8px; }
  .ts-grid .shift-field::before {
    content: attr(data-label); display: block; font-size: 0.72rem; text-transform: uppercase;
    letter-spacing: 0.04em; color: var(--muted); font-weight: 600;
  }
  .ts-grid .shift-locked .shift-field { display: block; min-height: 0; }
  .ts-grid .shift-field[data-label="Facility"] { grid-column: 1; }
  .ts-grid .shift .btn-remove { grid-column: 2; grid-row: 1; justify-self: end; align-self: end; }
  .ts-grid .shift-field[data-label="Scheduled"] { grid-column: 1; }
  .ts-grid .shift-field[data-label="Actual"] { grid-column: 2; }
  .ts-grid .shift-field[data-label="Notes"] { grid-column: 1 / -1; }
  .ts-grid .shift-locked .shift-field[data-label="Scheduled"] { grid-column: 2; }
  .ts-grid .shift-locked .shift-field[data-label="Actual"] { grid-column: 1 / -1; }
  .ts-grid select { width: 100%; }
  .ts-grid .pair { flex-wrap: wrap; }
  .ts-grid input.time { flex: 1 1 3.8em; width: 3.8em; }
  .ts-grid input.note { width: 100%; min-width: 0; }
  .ts-grid .callback-pair { flex-wrap: nowrap; }
  .ts-totals { justify-content: flex-start; }
}
