:root {
  color-scheme: light dark;
  --border: #3a3a3a55;
  --ok: #2e7d32;
  --err: #c62828;
  --warn: #b8860b;
  --accent: #3b82f6;
  --track: #3a3a3a33;
}

body {
  font-family: system-ui, sans-serif;
  margin: 0;
  padding: 1.5rem 2rem 3rem;
}

.map-panel {
  position: relative;
  width: 100%;
  height: 40vh;
  min-width: 280px;
  min-height: 140px;
  max-width: 100%;
  margin-bottom: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.map-panel iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.map-resize-handle {
  position: absolute;
  z-index: 2;
  /* Without this, mobile browsers treat the drag as a page-scroll gesture
     and can swallow it before our touchmove handler's preventDefault() gets
     a chance to stop that. */
  touch-action: none;
}

.map-resize-handle.bottom {
  left: 0;
  right: 10px;
  bottom: 0;
  height: 6px;
  cursor: ns-resize;
}

.map-resize-handle.right {
  top: 0;
  bottom: 10px;
  right: 0;
  width: 6px;
  cursor: ew-resize;
}

.map-resize-handle.corner {
  right: 0;
  bottom: 0;
  width: 10px;
  height: 10px;
  cursor: nwse-resize;
}

/* Touch targets below are too thin to reliably grab with a finger --
   widen them on touch/coarse-pointer devices without changing the mouse
   experience on desktop. */
@media (pointer: coarse) {
  .map-resize-handle.bottom {
    height: 18px;
  }

  .map-resize-handle.right {
    width: 18px;
  }

  .map-resize-handle.corner {
    width: 24px;
    height: 24px;
  }
}

.map-resize-handle:hover,
.map-resize-handle.resizing {
  background: color-mix(in srgb, var(--accent) 50%, transparent);
}

#map-reset-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 1;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: light-dark(#f5f5f5ee, #1a1a1aee);
  color: inherit;
  cursor: pointer;
}

#map-reset-btn:hover {
  background: light-dark(#e6e6e6ee, #2a2a2aee);
}

.plane-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.title-block {
  /* Buttons row (board-nav-row) then h1 stack in plain DOM order -- both
     are block-level, so no flex/grid needed here. This whole block is a
     single flex item within <header>, so header's own space-between still
     puts it flush left as one unit instead of pulling h1 and the buttons
     apart from each other. */
  margin-bottom: 0.25rem;
}

.board-nav-row {
  margin-bottom: 0.4rem;
}

/* On the board, "+ New Ticket" sits next to Tickets/Options and should
   match their (smaller) size, unlike the tickets page's own copy of this
   same button/id, which is deliberately bigger for easier mobile tapping.
   Background/color still come from the shared #new-ticket-btn rule below. */
.board-nav-row #new-ticket-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
}

.options-menu {
  position: relative;
}

#options-btn,
.nav-link-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

#options-btn:hover,
.nav-link-btn:hover {
  background: light-dark(#00000011, #ffffff11);
}

.current-user {
  font-size: 0.85rem;
  opacity: 0.7;
}

header form,
.controls form {
  display: inline-flex;
  margin: 0;
}

.options-panel {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 10;
  min-width: 260px;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: light-dark(#ffffff, #1e1e1e);
  box-shadow: 0 4px 16px light-dark(#00000022, #00000066);
}

.options-panel.hidden {
  display: none;
}

.options-section + .options-section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.options-section-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.4rem;
}

.options-panel label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0;
  font-size: 0.85rem;
  white-space: nowrap;
}

.options-hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  opacity: 0.7;
  line-height: 1.3;
  white-space: normal;
}

.controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.status-bar {
  margin: 0.75rem 0;
  font-size: 0.85rem;
  opacity: 0.85;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.status-bar .source.ok { color: var(--ok); }
.status-bar .source.error { color: var(--err); }
.status-bar .source.not-configured { color: var(--warn); }

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  padding: 0.4rem 1rem;
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 6px 6px 0 0;
  cursor: pointer;
}

.tab-btn.active {
  font-weight: 600;
  border-bottom: 2px solid currentColor;
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.3em;
  height: 1.3em;
  margin-left: 0.45rem;
  padding: 0 0.35em;
  border-radius: 999px;
  background: var(--err);
  /* Black text on var(--err) is only ~3.7:1 contrast, under WCAG AA's
     4.5:1 for normal text -- white gets ~5.7:1 and is also just the
     conventional choice for a red notification badge. */
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.tab-badge.hidden {
  display: none;
}

.board-scroll {
  overflow-x: auto;
}

/* The board used to be an HTML <table> with table-layout:fixed, but Chrome
   (and other browsers) will not shrink a table column below the width
   needed to render its longest unbreakable text, no matter what CSS is
   applied -- verified directly with an isolated, never-before-rendered
   table with an explicit <col style="width:10px"> that still rendered at
   169px. CSS Grid tracks with an explicit length don't have that behavior,
   so each "table" is a column of .board-row grid containers instead, all
   sharing the same --board-cols track list (see updateGridColumns in
   app.js) so header and body rows always line up. */
.board {
  min-width: fit-content;
}

.board.hidden {
  display: none;
}

.board-row {
  display: grid;
  /* Falls back to natural content-sized columns before JS has measured and
     applied real widths (see initColumnResize) -- avoids a flash of evenly
     split columns on first paint. */
  grid-template-columns: var(--board-cols, repeat(14, max-content));
}

.board-header {
  border-bottom: 1px solid var(--border);
}

.board-body .board-row:nth-child(even) {
  background: light-dark(#00000009, #ffffff0d);
}

.board-cell {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-right: 1px solid var(--border);
  font-size: 0.9rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  /* Grid (and flex) items default to a content-based automatic minimum
     size, same idea as table cells but -- unlike table cells -- this one
     genuinely is overridable, which is what actually lets a column shrink
     narrower than its own text. */
  min-width: 0;
}

.board-cell:last-child {
  border-right: none;
}

.col-hidden {
  display: none;
}

.empty-row .board-cell {
  grid-column: 1 / -1;
  opacity: 0.6;
  font-style: italic;
}

.board-header .board-cell {
  position: relative;
  cursor: pointer;
  user-select: none;
}

.board-header .board-cell:hover {
  opacity: 0.75;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 1;
  /* Without this, mobile browsers treat the drag as a page-scroll gesture
     and can swallow it before our touchmove handler's preventDefault() gets
     a chance to stop that. */
  touch-action: none;
}

/* Invisible wider hit-area than the 8px visible divider -- the @media
   (pointer: coarse) widening below assumes the browser correctly reports
   touch capability, which some WebViews (including the Android app's,
   embedded directly as a plain WebView with no viewport/pointer hints) do
   not reliably do. This works unconditionally regardless of that. */
.col-resizer::before {
  content: "";
  position: absolute;
  inset: 0 -8px;
}

.col-resizer:hover,
.col-resizer.resizing {
  background: var(--accent);
  opacity: 0.5;
}

/* 8px is too thin to reliably grab with a finger -- widen the touch target
   on touch/coarse-pointer devices without changing the mouse experience on
   desktop. */
@media (pointer: coarse) {
  .col-resizer {
    width: 20px;
  }
}

.board-header .board-cell[data-key]::after {
  content: "";
  display: inline-block;
  width: 0.7em;
  opacity: 0.5;
}

.board-header .board-cell.sorted-asc::after {
  content: "▲";
  opacity: 1;
}

.board-header .board-cell.sorted-desc::after {
  content: "▼";
  opacity: 1;
}

.progress {
  position: relative;
  width: 90px;
  height: 1.1rem;
  background: var(--track);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--accent);
  height: 100%;
}

.progress-label {
  position: relative;
  z-index: 1;
  font-size: 0.72rem;
  line-height: 1.1rem;
  padding: 0 0.35rem;
  mix-blend-mode: difference;
  color: white;
}

/* --- Tickets page --- */

#new-ticket-btn {
  padding: 0.52rem 1.17rem;
  font-size: 1.17rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

#new-ticket-btn:hover {
  opacity: 0.9;
}

.tickets-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-top: 1.5rem;
}

@media (max-width: 800px) {
  .tickets-main {
    grid-template-columns: 1fr;
  }

  /* Single-column layout stacks sections in DOM order (Open, In Progress,
     Completed, ...) -- a long Open list would otherwise bury In Progress
     many scrolls down. Moving it first here is purely visual (CSS order),
     the DOM/tab order and the two-column desktop layout are unaffected. */
  .tickets-section-in-progress {
    order: -1;
  }
}

.tickets-section h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.tickets-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.tickets-section-header h2 {
  margin: 0;
}

.clear-completed-btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--err);
  border-radius: 6px;
  background: transparent;
  color: var(--err);
  cursor: pointer;
}

.clear-completed-btn:hover {
  background: color-mix(in srgb, var(--err) 15%, transparent);
}

.clear-completed-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.ticket-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ticket-empty {
  opacity: 0.6;
  font-style: italic;
  font-size: 0.9rem;
}

.ticket-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  background: light-dark(#fafafa, #1a1a1a);
}

.ticket-card.ticket-priority-urgent {
  border: 2px solid var(--err);
}

.ticket-card.ticket-priority-overnight {
  border: 2px solid var(--accent);
}

.ticket-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.ticket-tail {
  font-weight: 600;
  font-size: 1rem;
}

.ticket-priority-badge {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.ticket-priority-badge.ticket-priority-urgent {
  background: color-mix(in srgb, var(--err) 20%, transparent);
  color: var(--err);
}

.ticket-priority-badge.ticket-priority-overnight {
  background: color-mix(in srgb, var(--accent) 20%, transparent);
  color: var(--accent);
}

.ticket-priority-options {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.ticket-time {
  font-size: 0.78rem;
  opacity: 0.65;
  white-space: nowrap;
}

.created-by,
.confirmed-by {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.6;
}

.ticket-services {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.ticket-actions {
  display: flex;
  gap: 0.5rem;
}

.ticket-actions button {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.ticket-actions button:hover {
  background: light-dark(#00000011, #ffffff11);
}

.ticket-actions .ticket-delete-btn {
  border-color: var(--err);
  color: var(--err);
}

.ticket-actions .ticket-delete-btn:hover {
  background: color-mix(in srgb, var(--err) 15%, transparent);
}

.ticket-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}

.ticket-comments {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px solid var(--border);
}

.ticket-comment-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.ticket-comment-author {
  font-weight: 600;
  font-size: 0.8rem;
}

.ticket-comment-time {
  margin-left: 0.4rem;
  font-size: 0.72rem;
  opacity: 0.6;
}

.ticket-comment-text {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
}

.ticket-comment-form {
  display: flex;
  gap: 0.4rem;
  align-items: flex-end;
}

.ticket-comment-input {
  flex: 1;
  resize: vertical;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  box-sizing: border-box;
}

.ticket-comment-submit-btn {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.ticket-comment-submit-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.service-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: light-dark(#e6e6e6, #2a2a2a);
  font-size: 0.78rem;
}

.service-badge.service-started {
  background: color-mix(in srgb, var(--warn) 30%, transparent);
}

.service-badge.service-done {
  background: color-mix(in srgb, var(--ok) 25%, transparent);
}

.service-confirm {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  user-select: none;
}

.service-confirm input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
}

/* Open/in-progress tickets: each service shows its note plus two
   independent stage checkboxes (Started / Completed), since a different
   person often handles each half across a shift change. */
.service-progress {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.service-stage-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  user-select: none;
  font-size: 0.75rem;
  opacity: 0.85;
}

.service-stage-toggle input[type="checkbox"] {
  cursor: pointer;
  margin: 0;
}

.service-stage-toggle input[type="checkbox"]:disabled {
  cursor: default;
}

.service-stage-toggle:has(input:disabled) {
  opacity: 0.4;
}

/* --- New ticket modal --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #00000066;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  width: min(420px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: light-dark(#ffffff, #1e1e1e);
  box-shadow: 0 8px 32px #00000044;
}

.modal h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

.modal-field {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.modal-field input[type="text"],
.modal-field input[type="password"],
.modal-field textarea {
  display: block;
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.4rem 0.5rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  box-sizing: border-box;
}

.modal-field textarea {
  font-family: inherit;
  resize: vertical;
}

.service-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.service-row .service-notes {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  box-sizing: border-box;
}

.service-row .service-notes.hidden {
  display: none;
}

.fuel-type-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.85rem;
  margin: 0.35rem 0 0 1.5rem;
  font-size: 0.85rem;
}

.fuel-type-options.hidden {
  display: none;
}

.ticket-error {
  color: var(--err);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.ticket-error.hidden {
  display: none;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-actions button {
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: transparent;
  color: inherit;
}

#ticket-submit-btn,
#suggestion-submit-btn {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.suggestion-message {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.9rem;
}

/* --- Login / setup page --- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
  box-sizing: border-box;
}

.auth-card {
  width: min(360px, 100%);
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: light-dark(#ffffff, #1e1e1e);
  box-shadow: 0 8px 32px #00000044;
}

.auth-card h1 {
  font-size: 1.3rem;
}

.auth-card h2 {
  margin: 0.25rem 0 1.25rem;
  font-size: 0.95rem;
  font-weight: 400;
  opacity: 0.75;
}

.auth-form .modal-field {
  margin-bottom: 0.9rem;
}

.auth-remember-me {
  margin-bottom: 1.1rem;
  font-size: 0.9rem;
}

.auth-submit-btn {
  width: 100%;
  padding: 0.55rem;
  font-size: 0.95rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

.auth-submit-btn:hover {
  filter: brightness(1.08);
}

/* --- Admin: users --- */

.admin-badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  font-size: 0.7rem;
  font-weight: 600;
  vertical-align: middle;
}

.admin-new-user-form {
  display: flex;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.admin-new-user-form .modal-field {
  margin-bottom: 0;
  min-width: 180px;
}

.admin-new-user-form .checkbox-label {
  margin-bottom: 0.55rem;
}

.admin-user-actions {
  display: flex;
  gap: 0.5rem;
}

.admin-user-toggles {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.admin-user-actions button {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.admin-user-actions .delete-user-btn {
  border-color: var(--err);
  color: var(--err);
}

.admin-user-actions .delete-user-btn:hover {
  background: color-mix(in srgb, var(--err) 15%, transparent);
}

.admin-user-actions button:disabled {
  opacity: 0.5;
  cursor: default;
}
