* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.4 system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #111;
  background: #f3f3f0;
}
[hidden], .hidden { display: none !important; }

a { color: #0033aa; }
h1, h2, h3 { margin: 0 0 8px; font-size: 1.15rem; font-weight: 700; }
h1 { font-size: 1.25rem; }
p { margin: 0 0 8px; }
p:last-child { margin-bottom: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
label { font-weight: 650; display: block; margin-bottom: 3px; }

.skip {
  position: absolute;
  left: -999px;
}
.skip:focus { left: 8px; top: 8px; z-index: 40; background: #fff; padding: 6px 10px; border: 2px solid #111; }

/* Login */
#view-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
  background: #eee;
}
.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid #111;
  padding: 20px 20px 16px;
}
.login-card h1 { margin-bottom: 2px; }
.sub { color: #333; margin-bottom: 16px; }
.note {
  background: #fff8d6;
  border: 1px solid #111;
  padding: 8px 10px;
  font-size: 13px;
  margin: 10px 0 14px;
}
.err { color: #8b1210; font-weight: 700; min-height: 1.2em; margin: 6px 0; font-size: 13px; }
.switch { margin-top: 12px; font-size: 13px; }
.switch button {
  background: none;
  border: 0;
  color: #0033aa;
  text-decoration: underline;
  padding: 0;
  font-weight: 700;
}

.field { margin-bottom: 10px; }
.field input, .field select, .field textarea, .inline input, .inline select {
  width: 100%;
  border: 1px solid #111;
  background: #fff;
  padding: 7px 8px;
  border-radius: 0;
}
.field input:focus, .field select:focus, .field textarea:focus,
.inline input:focus, .inline select:focus {
  outline: 2px solid #0033aa;
  outline-offset: 0;
}
.field textarea { min-height: 90px; resize: vertical; }
.hint { font-size: 12px; color: #333; margin-top: 4px; font-weight: 400; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid #111;
  background: #111;
  color: #fff;
  padding: 7px 12px;
  font-weight: 700;
}
.btn:hover { background: #333; }
.btn:focus-visible { outline: 2px solid #0033aa; outline-offset: 2px; }
.btn-block { width: 100%; }
.btn-light { background: #fff; color: #111; }
.btn-light:hover { background: #eee; }
.btn-danger { background: #8b1210; border-color: #8b1210; color: #fff; }
.btn-danger:hover { background: #6a0e0c; }
.btn-small { padding: 4px 8px; font-size: 13px; }

/* Shell */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: #111;
  color: #fff;
}
.brand { font-weight: 800; text-decoration: none; color: #fff; }
.brand small {
  display: inline-block;
  margin-left: 8px;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.85;
}
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a, .nav button.link {
  color: #fff;
  background: none;
  border: 0;
  text-decoration: none;
  padding: 5px 8px;
  font-weight: 650;
  font-size: 14px;
}
.nav a[aria-current="page"] { text-decoration: underline; text-underline-offset: 3px; }
.nav a:hover, .nav button.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.badge-admin {
  border: 1px solid #fff;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-right: 4px;
}

main {
  flex: 1;
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 40px;
}
.page { display: none; }
.page.is-on { display: block; }

/* Dashboard */
.dash {
  display: grid;
  grid-template-columns: 1fr 340px;
  grid-template-areas:
    "bookings tony"
    "bookings messages"
    "jobs jobs";
  gap: 12px;
  align-items: start;
}
#section-bookings { grid-area: bookings; }
#section-jobs { grid-area: jobs; }
#section-tony { grid-area: tony; }
#section-messages { grid-area: messages; min-width: 0; }

.panel {
  background: #fff;
  border: 1px solid #111;
  padding: 12px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.panel-head h2 { margin: 0; }
.muted { color: #333; font-size: 13px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}
table.data th, table.data td {
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid #ccc;
  padding: 6px 6px 6px 0;
}
table.data th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid #111;
  padding-bottom: 4px;
  white-space: nowrap;
}
table.data .col-nights { width: 4.4rem; }
table.data .col-status { width: 7.4rem; }
table.data .col-time { width: 3.6rem; white-space: nowrap; }
table.data .col-actions { width: 7.8rem; }
table.data .col-notes { overflow-wrap: anywhere; }
table.data tr:last-child td { border-bottom: 0; }
table.data .actions { white-space: nowrap; }
table.data .actions .btn { margin-left: 4px; }

.status {
  display: inline-block;
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border: 1px solid #111;
  padding: 1px 5px;
}
.status-confirmed { background: #d9efe3; }
.status-pending { background: #fff3bf; }
.status-cancelled { background: #eee; color: #333; }
.status-blocked { background: #f3e0c3; }
.status-no_handover { background: #e4e4e4; }
.ex { font-size: 10px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; margin-left: 4px; }

.job-list { list-style: none; margin: 0; padding: 0; }
.job-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: start;
  border-bottom: 1px solid #ccc;
  padding: 7px 0;
}
.job-list li:last-child { border-bottom: 0; }
.job-list li.overdue {
  background: #fde8e6;
  border: 1px solid #8b1210;
  padding: 7px 8px;
  margin: 0 0 6px;
}
.job-list li.overdue .overdue-flag {
  color: #8b1210;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  margin-left: 6px;
}
.job-list li.done .job-title { text-decoration: line-through; color: #333; }
.job-meta { font-size: 12px; color: #333; margin-top: 2px; }
.job-list input[type="checkbox"] { width: 16px; height: 16px; margin-top: 3px; }

.add-job {
  display: grid;
  grid-template-columns: 1fr 130px 1fr auto;
  gap: 6px;
  align-items: end;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #ccc;
}
.add-job .btn { height: 34px; }

.tony-dl { margin: 0 0 10px; }
.tony-dl div {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px solid #eee;
  font-size: 13px;
}
.tony-dl dt { font-weight: 700; color: #333; }
.tony-dl dd { margin: 0; }
.tony-notes { min-height: 64px; }
.tony-notes[readonly] {
  background: #fafafa;
  min-height: 64px;
}

details.past, details.done-jobs {
  margin-top: 10px;
  border-top: 1px solid #111;
  padding-top: 8px;
}
details summary { cursor: pointer; font-weight: 700; }

/* Van info */
.ref {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.kv { margin: 0; }
.kv div {
  display: grid;
  grid-template-columns: 42% 1fr;
  gap: 8px;
  border-bottom: 1px solid #ddd;
  padding: 5px 0;
  font-size: 13px;
}
.kv dt { font-weight: 700; }
.kv dd { margin: 0; }
.ph {
  display: inline-block;
  background: #fff8d6;
  border: 1px solid #111;
  padding: 0 5px;
  font-size: 12px;
  font-weight: 700;
}
.checklist { margin: 0; padding-left: 1.15em; }
.checklist li { margin: 0 0 6px; }
.source { font-size: 12px; color: #333; margin-bottom: 12px; }

/* Modal */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: start center;
  padding: 24px 12px;
  overflow: auto;
  z-index: 30;
}
.modal {
  width: min(560px, 100%);
  background: #fff;
  border: 2px solid #111;
  padding: 16px;
}
.modal h2 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.toast {
  position: fixed;
  right: 12px;
  bottom: 12px;
  background: #111;
  color: #fff;
  padding: 8px 12px;
  z-index: 40;
  display: none;
  font-size: 13px;
  font-weight: 700;
}
.toast.is-on { display: block; }

footer.app-foot {
  border-top: 1px solid #111;
  font-size: 12px;
  color: #333;
  padding: 8px 14px;
  background: #e8e8e4;
}

@media (max-width: 860px) {
  .dash, .ref, .add-job, .row-2, .tony-dl div, .kv div {
    grid-template-columns: 1fr;
  }
  .dash {
    grid-template-areas:
      "bookings"
      "jobs"
      "tony"
      "messages";
  }
  table.data thead { display: none; }
  table.data tr {
    display: block;
    border: 1px solid #111;
    padding: 8px;
    margin-bottom: 8px;
  }
  table.data td, table.data th {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border: 0;
    padding: 2px 0;
  }
  table.data td::before {
    content: attr(data-label);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
    color: #333;
    flex: 0 0 7rem;
  }
  table.data .actions { display: flex; justify-content: flex-end; }
  table.data .actions::before { content: none; }
}

.message-form {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid #111;
}
.message-form textarea { min-height: 52px; }
.msg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow: auto;
}
.msg-list li {
  border-bottom: 1px solid #ddd;
  padding: 8px 0;
}
.msg-list li:last-child { border-bottom: 0; }
.msg-list .from {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.msg-list .from b { font-weight: 800; }
.msg-list .when { color: #333; white-space: nowrap; }
.msg-list .body { margin-top: 3px; white-space: pre-wrap; }
.msg-list li.role-van { background: #f4f7f4; margin: 0 0 6px; padding: 8px; border: 1px solid #ccc; }
