/* KLM / Airbus theme — from FDPFMS design tokens */
:root {
  --klm-blue-dark: #00A1E4;
  --klm-blue: #003d5c;
  --klm-blue-hover: #0080B5;
  --bezel-top: #5b686d;
  --bezel-bottom: #4a5559;
  --bezel-border: #3a4448;
  --fms-bg: #000000;
  --fms-text: #E0E0E0;
  --border-color: #333333;
  --gantt-paper: #ffffff;
  --gantt-work: #b8d4e8;
  --gantt-work-border: #003d5c;
  --gantt-off: #e4e4e4;
  --gantt-pt80: #d4edda;
  --gantt-pt80-text: #2e7d32;
  --gantt-vacation: #81c784;
  --gantt-vacation-border: #388e3c;
  --gantt-vacation-text: #1b5e20;
  --gantt-weekend-gap: 5px;
  --gantt-weekend-edge: #00A1E4;
  --gantt-unsupported: #f0f0f0;
  --font-aviation: 'B612', 'Courier New', monospace;
  --error-color: #ff4444;
}

@media (prefers-color-scheme: light) {
  :root {
    --fms-bg: #ffffff;
    --fms-text: #000000;
    --border-color: #cccccc;
    --klm-blue-dark: #003d5c;
    --gantt-weekend-edge: #0078a8;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  font-family: var(--font-aviation);
  color: var(--fms-text);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html {
  /* Mobile / touch: solid bezel grey — do not load background photo */
  background-color: var(--bezel-top);
  background-image: none;
  min-height: 100vh;
  width: 100%;
}

/* Semi-transparent overlay — only used when the photo background is active (desktop) */
html::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  z-index: 0;
  pointer-events: none;
}

/* Desktop / mouse: load cockpit photo + dim overlay */
@media (hover: hover) and (pointer: fine) {
  html {
    background-color: #000000;
    background-image: url('../background.jpeg');
    background-image: image-set(
      url('../background.webp') type('image/webp'),
      url('../background.jpeg') type('image/jpeg')
    );
    background-size: cover;
    background-position: center center;
    background-attachment: fixed;
    background-repeat: no-repeat;
  }

  html::before {
    background: rgba(0, 0, 0, 0.6);
  }
}

@media (hover: hover) and (pointer: fine) and (prefers-color-scheme: light) {
  html::before {
    background: rgba(91, 104, 109, 0.7);
  }
}

body {
  position: relative;
  z-index: 1;
  padding: 0 30px 15px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.fms-bezel {
  background: linear-gradient(145deg, var(--bezel-top) 0%, var(--bezel-bottom) 100%);
  border: 2px solid var(--bezel-border);
  border-radius: 12px;
  padding: 10px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 15px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4),
    inset 0 2px 4px rgba(255, 255, 255, 0.12),
    inset 0 -2px 4px rgba(0, 0, 0, 0.4);
}

.container {
  background: var(--fms-bg);
  border: 2px solid var(--border-color);
  padding: 12px;
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.35);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.app-title {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--klm-blue-dark);
}

.landscape-chrome {
  display: none;
  gap: 6px;
  flex-wrap: nowrap;
  align-items: center;
}

.header-year {
  flex: 0 0 auto;
}

.header-year select {
  font-family: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  padding: 6px 8px;
  min-height: 34px;
  border: 2px solid var(--klm-blue-dark);
  border-radius: 4px;
  background: var(--fms-bg);
  color: var(--fms-text);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

@media (prefers-color-scheme: light) {
  .header-year select {
    background: #fff;
    border-color: var(--klm-blue);
    color: #000;
  }
}

.btn-ls {
  padding: 4px 8px;
  min-height: 28px;
  font-size: 0.58rem;
  letter-spacing: 0.5px;
}

.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.rotate-landscape-hint {
  display: none;
  flex: 1 1 8rem;
  align-self: center;
  margin: 0;
  font-size: 0.65rem;
  line-height: 1.4;
  letter-spacing: 0;
  text-transform: none;
  color: var(--fms-text);
  max-width: 11rem;
}

.sw-update-banner {
  position: sticky;
  top: 0;
  z-index: 10010;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  padding: 8px 12px;
  background: rgba(0, 61, 92, 0.95);
  border-bottom: 2px solid var(--klm-blue);
  color: #fff;
}

.sw-update-banner.hidden { display: none !important; }

/* First-run: Add to Home Screen (Apple Safari tab) */
.install-overlay {
  position: fixed;
  inset: 0;
  z-index: 10005;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px max(20px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.72);
}

.install-overlay.hidden {
  display: none !important;
}

.install-overlay-box {
  width: min(100%, 22rem);
  padding: 16px 16px 14px;
  border: 2px solid var(--klm-blue-dark);
  border-radius: 8px;
  background: var(--fms-bg);
  color: var(--fms-text);
  box-sizing: border-box;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

.install-overlay.is-pulsing .install-overlay-box {
  animation: install-overlay-pulse 1.45s ease-in-out infinite;
}

.install-overlay-pulse {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  line-height: 1.25;
  color: var(--klm-blue-dark);
  text-transform: uppercase;
}

.install-overlay-step {
  margin: 0 0 8px;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--fms-text);
}

.install-overlay-step:last-of-type {
  margin-bottom: 12px;
}

.install-overlay-box .btn {
  width: 100%;
  min-height: 40px;
}

@keyframes install-overlay-pulse {
  0%, 100% {
    border-color: var(--klm-blue-dark);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45), 0 0 0 0 rgba(0, 161, 228, 0);
  }
  50% {
    border-color: #5ecfff;
    box-shadow:
      0 8px 32px rgba(0, 0, 0, 0.45),
      0 0 0 3px rgba(0, 161, 228, 0.55),
      0 0 22px rgba(0, 161, 228, 0.45);
  }
}

@media (prefers-color-scheme: light) {
  @keyframes install-overlay-pulse {
    0%, 100% {
      border-color: var(--klm-blue-dark);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2), 0 0 0 0 rgba(0, 61, 92, 0);
    }
    50% {
      border-color: #003d7a;
      box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.2),
        0 0 0 3px rgba(0, 61, 122, 0.35),
        0 0 0 7px rgba(0, 61, 122, 0.12);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .install-overlay.is-pulsing .install-overlay-box {
    animation: none;
  }
}

.sw-update-text {
  margin: 0;
  flex: 1 1 200px;
  font-size: 0.72rem;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
}

.sw-update-banner .btn {
  flex: 0 0 auto;
  background: #fff;
  color: var(--klm-blue-dark);
  border-color: #fff;
}

.btn {
  font-family: inherit;
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 7px 12px;
  border-radius: 4px;
  border: 2px solid var(--klm-blue-dark);
  background: var(--klm-blue-hover);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover { background: var(--klm-blue); }

.btn-secondary {
  background: transparent;
  color: var(--klm-blue-dark);
}

/* Touch devices keep :hover after tap — don't paint secondary like a solid primary */
@media (hover: hover) and (pointer: fine) {
  .btn-secondary:hover {
    background: rgba(0, 161, 228, 0.12);
    color: var(--klm-blue-dark);
  }
}

@media (hover: none), (pointer: coarse) {
  .btn-secondary:hover,
  .btn-secondary:focus {
    background: transparent;
    color: var(--klm-blue-dark);
  }
}

@keyframes vacation-breathe {
  0%, 100% {
    box-shadow: 0 0 4px 1px rgba(255, 152, 0, 0.35);
    border-color: #ff9800;
  }
  50% {
    box-shadow: 0 0 14px 4px rgba(255, 152, 0, 0.65);
    border-color: #ff9800;
  }
}

.btn-vacation-hot {
  animation: vacation-breathe 2.2s ease-in-out infinite;
  border-color: #ff9800 !important;
  color: #ff9800 !important;
  touch-action: manipulation;
}

.vacation-status {
  margin: 0 0 8px;
  padding: 8px 10px;
  font-size: 0.72rem;
  line-height: 1.4;
  text-transform: none;
  letter-spacing: 0;
  border: 2px solid #ff9800;
  border-radius: 4px;
  background: rgba(255, 152, 0, 0.12);
  color: var(--fms-text);
  max-width: 100%;
  overflow-wrap: break-word;
}

@media (prefers-color-scheme: light) {
  .btn-vacation-hot {
    background: #fff !important;
    color: #e67e00 !important;
    border-color: #ff9800 !important;
  }
}

@media (prefers-color-scheme: light) {
  .btn { background: var(--klm-blue); border-color: var(--klm-blue); }
  .btn-secondary { background: #fff; color: var(--klm-blue); }

  @media (hover: none), (pointer: coarse) {
    .btn-secondary:hover,
    .btn-secondary:focus {
      background: #fff;
      color: var(--klm-blue);
    }
  }

  @media (hover: hover) and (pointer: fine) {
    .btn-secondary:hover {
      background: #f0f7fb;
      color: var(--klm-blue);
    }
  }
}

.settings-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px 16px;
  margin-bottom: 10px;
}

.field { flex: 1 1 140px; min-width: 120px; }
.field-parttime { flex: 0 1 210px; min-width: 190px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field label {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 4px;
  color: var(--klm-blue-dark);
}

.field label.field-label-anchor {
  color: var(--klm-blue-dark);
}

/* Settings row controls — height matches date-picker-btn (A-cycle anchor reference) */
.settings-form .field select,
.settings-form .date-picker-btn {
  width: 100%;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.2;
  padding: 8px 10px;
  border: 2px solid var(--border-color);
  background: var(--fms-bg);
  color: var(--fms-text);
  border-radius: 4px;
  box-sizing: border-box;
  min-height: 38px;
  height: 38px;
}

.settings-form .date-picker-btn {
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.settings-form .date-picker-btn:hover {
  border-color: var(--klm-blue-dark);
}

@media (prefers-color-scheme: light) {
  .settings-form .field select,
  .settings-form .date-picker-btn {
    background: #f9f9f9;
    border-color: #999;
    color: #000;
  }
}

.hidden { display: none !important; }

.form-error {
  color: var(--error-color);
  font-size: 0.78rem;
  text-transform: none;
  margin: 0 0 8px;
}

.form-debug {
  margin: 0 0 8px;
  padding: 8px 10px;
  font-size: 0.62rem;
  line-height: 1.45;
  text-transform: none;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #8bc34a;
  background: rgba(139, 195, 74, 0.08);
  border: 1px solid rgba(139, 195, 74, 0.35);
  border-radius: 4px;
  max-height: 140px;
  overflow: auto;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.help-legend {
  margin: 0 0 8px;
  padding: 8px 0 4px;
  border-top: 1px solid var(--border-color);
}

.help-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 14px;
}

.help-actions .btn {
  width: 100%;
  min-height: 36px;
  padding: 6px 8px;
  font-size: 0.62rem;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.year-summary {
  margin: 0;
  font-size: 0.65rem;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
  text-align: right;
  color: var(--fms-text);
  /* Portrait / default: own row under header controls */
  flex: 1 1 100%;
  order: 20;
}

.year-summary:empty {
  display: none;
}

.legend-item { display: flex; align-items: center; gap: 5px; }

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.swatch-work {
  background: var(--gantt-work);
  border-color: var(--gantt-work-border);
}
.swatch-off { background: var(--gantt-off); }
.swatch-pt80 {
  background: var(--gantt-pt80);
  border-color: #81c784;
}
.swatch-vacation {
  background: var(--gantt-vacation);
  border-color: var(--gantt-vacation-border);
}
.swatch-today {
  background: #fff;
  position: relative;
  overflow: hidden;
}
.swatch-today::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 12px 12px 0;
  border-color: transparent transparent #222 transparent;
  pointer-events: none;
}

.gantt-panel {
  background: var(--gantt-paper);
  color: #111;
  border: 1px solid #bbb;
  border-radius: 4px;
  padding: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 280px;
  display: flex;
  flex-direction: column;
}

.gantt-table {
  border-collapse: collapse;
  width: 100%;
  height: 100%;
  table-layout: fixed;
  font-size: 0.56rem;
}

.gantt-table thead tr {
  height: 22px;
}

.gantt-table tbody tr {
  height: calc((100% - 22px) / 12);
}

.gantt-table th,
.gantt-table td {
  border: 1px solid #bbb;
  text-align: center;
  padding: 0;
  position: relative;
  vertical-align: middle;
}

.gantt-month-label {
  width: 36px;
  font-weight: 700;
  background: #f5f5f5;
  color: var(--klm-blue);
  font-size: 0.6rem;
}

.gantt-dow-head {
  background: #eee;
  color: #111;
  font-size: 0.58rem;
  font-weight: 800;
}

.gantt-dow-head.gantt-sat-col,
.gantt-dow-head.gantt-sun-col {
  background: #eee;
  color: #111;
  font-weight: 800;
}

/* Weekend boundaries: dedicated gutter columns Fri→Sat and Sun→Mon */
.gantt-weekend-gap {
  width: var(--gantt-weekend-gap);
  min-width: var(--gantt-weekend-gap);
  max-width: var(--gantt-weekend-gap);
  padding: 0 !important;
  border-top: 1px solid #bbb;
  border-bottom: 1px solid #bbb;
  border-left: 0;
  border-right: 0;
  background: var(--gantt-paper);
  position: relative;
  vertical-align: middle;
}

thead .gantt-weekend-gap {
  background: #eee;
}

.gantt-weekend-gap::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 1px;
  bottom: 1px;
  width: 2px;
  margin-left: -1px;
  background: var(--gantt-weekend-edge);
  border-radius: 1px;
  pointer-events: none;
  z-index: 2;
}

.gantt-cell.gantt-sat-col.gantt-empty,
.gantt-cell.gantt-sun-col.gantt-empty {
  background: #fafafa;
}

.gantt-empty {
  background: #fafafa;
}

.gantt-work {
  background: var(--gantt-work);
  box-shadow: inset 0 0 0 1px var(--gantt-work-border);
}

.gantt-off { background: var(--gantt-off); }

.gantt-pt80 {
  background: var(--gantt-pt80);
  box-shadow: inset 0 0 0 1px #81c784;
}

.gantt-unsupported { background: var(--gantt-unsupported); }

.gantt-vacation,
.gantt-vacation.gantt-work,
.gantt-vacation.gantt-off,
.gantt-vacation.gantt-pt80,
.gantt-vacation.gantt-work.gantt-sat-col,
.gantt-vacation.gantt-work.gantt-sun-col,
.gantt-vacation.gantt-off.gantt-sat-col,
.gantt-vacation.gantt-off.gantt-sun-col,
.gantt-vacation.gantt-pt80.gantt-sat-col,
.gantt-vacation.gantt-pt80.gantt-sun-col {
  background: var(--gantt-vacation) !important;
  background-image: none !important;
  box-shadow: inset 0 0 0 1px var(--gantt-vacation-border) !important;
}

.gantt-vacation-pending {
  outline: 3px dashed #ff9800 !important;
  outline-offset: -3px;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px #ff9800 !important;
}

.gantt-table.vacation-armed .gantt-cell:not(.gantt-empty) {
  cursor: pointer;
  touch-action: none;
}

.gantt-panel.vacation-armed {
  touch-action: none;
  overflow-x: hidden;
}

.day-num {
  font-size: 0.6rem;
  color: #222;
  font-weight: 600;
  line-height: 1;
}

/* Today — screen only: bottom-left ink triangle (legs flush with cell edges) */
.gantt-cell.gantt-today::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 11px 11px 0;
  border-color: transparent transparent #222 transparent;
  pointer-events: none;
  z-index: 2;
}

@media (prefers-color-scheme: dark) {
  .gantt-cell.gantt-today::after {
    border-color: transparent transparent #1a1a1a transparent;
  }
}

/* Gantt chart stays on light paper in both app themes — keep label contrast explicit */
@media (prefers-color-scheme: dark) {
  .gantt-dow-head,
  .gantt-dow-head.gantt-sat-col,
  .gantt-dow-head.gantt-sun-col {
    color: #111;
  }

  .day-num {
    color: #1a1a1a;
  }
}

@media (prefers-color-scheme: light) {
  .gantt-dow-head,
  .gantt-dow-head.gantt-sat-col,
  .gantt-dow-head.gantt-sun-col {
    color: #111;
  }

  .day-num {
    color: #222;
  }
}

.cycle-mark {
  position: absolute;
  bottom: 0;
  right: 1px;
  font-size: 0.77rem;
  font-weight: 700;
  color: var(--klm-blue);
  opacity: 0.38; /* dimmed on screen; print/PDF restore full strength */
  line-height: 1;
}

.pt-mark {
  position: absolute;
  top: 3px;
  left: 3px;
  font-size: 0.42rem;
  font-weight: 700;
  color: var(--gantt-pt80-text);
  line-height: 1;
}

.vac-mark {
  position: absolute;
  top: 2px;
  left: 0;
  right: 0;
  font-size: 0.44rem;
  font-weight: 700;
  color: var(--gantt-vacation-text);
  line-height: 1;
  text-align: center;
}

.holiday-mark {
  position: absolute;
  /* Above the day number (td vertical-align often centers the date) */
  top: 50%;
  left: 50%;
  right: auto;
  transform: translate(-50%, calc(-50% - 0.65rem));
  font-size: 0.6rem;
  font-weight: 600;
  color: #b71c1c;
  line-height: 1;
  pointer-events: none;
}

.print-only { display: none; }

.print-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.help-version {
  margin: 16px 0 0;
  text-align: right;
  font-size: 0.62rem;
  opacity: 0.55;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.modal-overlay:not(.hidden) {
  display: flex !important;
}

.vacation-tip-toast {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100002;
  max-width: 420px;
  width: calc(100% - 32px);
  padding: 14px 16px;
  background: var(--fms-bg);
  border: 2px solid var(--klm-blue-dark);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  text-transform: none;
  letter-spacing: 0;
  pointer-events: none;
}

.vacation-tip-toast:not(.hidden) {
  display: block !important;
}

.vacation-tip-toast.hidden {
  display: none !important;
  pointer-events: none !important;
}

.vacation-tip-toast p {
  margin: 0 0 6px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--fms-text);
}

.vacation-tip-toast p:last-child {
  margin-bottom: 0;
}

.day-info-toast {
  position: fixed;
  left: 50%;
  top: max(12px, env(safe-area-inset-top));
  bottom: auto;
  transform: translateX(-50%);
  z-index: 100001;
  width: max-content;
  max-width: min(280px, calc(100% - 24px));
  padding: 5px 8px;
  background: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(0, 161, 228, 0.85);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  pointer-events: none;
}

/* JS sets left/top from visualViewport + tapped cell (zoom-safe, never covers the day) */
.day-info-toast.day-info-toast--placed {
  bottom: auto;
  transform: none;
}

.day-info-toast:not(.hidden) {
  display: block !important;
}

.day-info-toast.hidden {
  display: none !important;
}

.day-info-date {
  margin: 0 0 1px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: #9ad8f0;
}

.day-info-detail {
  margin: 0;
  font-size: 0.65rem;
  line-height: 1.25;
  color: #ffffff;
}

@media (prefers-color-scheme: light) {
  .day-info-toast {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(0, 61, 92, 0.65);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  }

  .day-info-date {
    color: var(--klm-blue);
  }

  .day-info-detail {
    color: #111;
  }
}

@media (prefers-color-scheme: light) {
  .vacation-tip-toast {
    background: #fff;
  }
  .vacation-tip-toast p {
    color: #111;
  }
}

.modal-card {
  background: var(--fms-bg);
  border: 2px solid var(--border-color);
  border-radius: 8px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.modal-header h2 {
  margin: 0;
  font-size: 0.85rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--klm-blue-dark);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--fms-text);
  padding: 0 4px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.help-body {
  padding: 14px;
  font-size: 0.82rem;
  line-height: 1.55;
  text-transform: none;
  letter-spacing: 0;
}

.help-body p { margin: 0 0 12px; }

.help-topic {
  margin: 0 0 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

/* Phone vs tablet/desktop help copy */
.help-phone {
  display: none;
}

body.phone-ui .help-phone {
  display: block;
}

body.phone-ui .help-wide {
  display: none;
}

.help-topic-label {
  color: var(--klm-blue-dark);
}

.help-topic a {
  color: var(--klm-blue-dark);
  word-break: break-all;
}

.help-holiday-h {
  color: #b71c1c;
}

/* iOS Share symbol (SF Symbol square.and.arrow.up) — same as FDPFMS */
.help-ios-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: -0.2em;
  margin: 0 0.15em;
  color: var(--klm-blue-dark);
}

.help-ios-share svg {
  display: block;
}

.help-actions + .help-topic {
  border-top: none;
  padding-top: 0;
}

.help-pro-tip {
  font-size: 0.82rem;
  color: var(--fms-text);
  opacity: 0.92;
}

.help-disclaimer {
  font-size: 0.78rem;
  color: var(--fms-text);
  opacity: 0.85;
}

.cycle-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  font-size: 0.68rem;
  text-transform: uppercase;
  flex: 1 1 auto;
  min-width: 0;
}

.help-cycle-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  margin: 0 0 10px;
}

.btn-share-url {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 0.62rem;
  letter-spacing: 0.6px;
  white-space: nowrap;
  align-self: center;
}

.settings-modal {
  max-width: 480px;
  width: 100%;
}

.settings-body {
  padding: 12px 14px 16px;
  max-height: min(70vh, 520px);
  overflow: auto;
}

.settings-modal .settings-form {
  margin-bottom: 14px;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.settings-actions .btn {
  flex: 1 1 140px;
  min-height: 44px;
  font-size: 0.68rem;
  text-align: center;
}

/* Phone SET — vacation range calendar (hidden on tablet/desktop) */
.phone-vacation-panel {
  margin: 0 0 14px;
  padding: 10px 0 4px;
  border-top: 1px solid var(--border-color);
}

.phone-vacation-panel.hidden {
  display: none !important;
}

.phone-vac-heading {
  margin: 0 0 6px;
  font-size: 0.72rem;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--klm-blue-dark);
}

.phone-vac-hint {
  margin: 0 0 8px;
  font-size: 0.62rem;
  line-height: 1.35;
  text-transform: none;
  letter-spacing: 0;
  color: var(--fms-text);
  opacity: 0.9;
}

.phone-vac-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.phone-vac-title {
  flex: 1 1 auto;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.5px;
}

.phone-vac-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  margin-bottom: 8px;
}

.phone-vac-weekday {
  text-align: center;
  font-size: 0.55rem;
  letter-spacing: 0.3px;
  opacity: 0.7;
  padding: 2px 0;
}

.phone-vac-day {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: transparent;
  color: var(--fms-text);
  font-family: inherit;
  font-size: 0.68rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.phone-vac-day--pad {
  border: none;
  pointer-events: none;
  min-height: 36px;
}

.phone-vac-day--saved {
  background: var(--gantt-vacation);
  color: var(--gantt-vacation-text);
  border-color: var(--gantt-vacation-border);
  font-weight: 700;
}

.phone-vac-day--start {
  outline: 2px solid var(--klm-blue-dark);
  outline-offset: 1px;
}

body.phone-ui #btn-mark-vacation,
body.phone-ui #vacation-status {
  display: none !important;
}

body.phone-ui .settings-body {
  max-height: min(78vh, 640px);
}

.cycle-block {
  display: flex;
  flex-direction: column;
  min-width: 72px;
}

.cycle-block-label {
  font-weight: 700;
  color: var(--klm-blue-dark);
  margin-bottom: 2px;
}

.cycle-block-bar {
  display: flex;
  height: 14px;
  border-radius: 2px;
  overflow: hidden;
  border: 1px solid var(--bezel-border);
}

.bar-work { background: var(--klm-blue); flex: 1; }
.bar-off { background: var(--gantt-off); flex: 1; }
.bar-work-a { flex: 9; }
.bar-off-a { flex: 7; }
.bar-work-b { flex: 8; }
.bar-off-b { flex: 6; }
.bar-work-c,
.bar-work-d { flex: 9; }
.bar-off-c,
.bar-off-d { flex: 6; }

.cycle-block-sub {
  font-size: 0.62rem;
  opacity: 0.85;
  margin-top: 2px;
}

.calendar-modal { max-width: 340px; }

.cal-nav {
  background: none;
  border: 2px solid var(--klm-blue-dark);
  color: var(--klm-blue-dark);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  line-height: 1;
}

#cal-title {
  flex: 1;
  text-align: center;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--klm-blue-dark);
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 12px;
}

.cal-dow {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--klm-blue-dark);
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  border: 1px solid var(--border-color);
  background: var(--fms-bg);
  color: var(--fms-text);
  font-family: inherit;
  font-size: 0.85rem;
  border-radius: 4px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cal-day:hover { border-color: var(--klm-blue-dark); }

.cal-selected {
  background: var(--klm-blue);
  color: #fff;
  border-color: var(--klm-blue);
}

.cal-weekend { opacity: 0.75; }
.cal-pad { visibility: hidden; pointer-events: none; }

@media (prefers-color-scheme: light) {
  .modal-card { background: #fff; }
  .cal-day { background: #f9f9f9; color: #000; }
}

@media (min-width: 900px) {
  .gantt-table { font-size: 0.52rem; }
  .gantt-table th, .gantt-table td { height: 22px; }
}

@supports (-webkit-touch-callout: none) {
  html {
    background-attachment: scroll;
  }
}

/* Touch phones/tablets — edge-to-edge, no FMS bezel (portrait + landscape) */
@media (hover: none) and (pointer: coarse) {
  html {
    background-color: var(--fms-bg);
  }

  body {
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }

  .fms-bezel {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--fms-bg);
    min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .container {
    border: none;
    box-shadow: none;
    padding: 6px 8px;
    background: var(--fms-bg);
  }
}

@media (max-width: 768px) {
  .settings-form {
    gap: 10px 12px;
  }

  .vacation-status {
    font-size: 0.58rem;
    line-height: 1.35;
    padding: 6px 8px;
  }

  .header-year select {
    min-height: 40px;
    font-size: 0.85rem;
    padding: 6px 8px;
  }

  .field-parttime {
    flex: 1 1 100%;
    min-width: 0;
  }

  .settings-form .field select,
  .settings-form .date-picker-btn {
    min-height: 44px;
    height: 44px;
  }

  .btn,
  .cal-nav {
    min-height: 40px;
  }

  .gantt-table {
    min-width: 680px;
  }

  .cal-day {
    min-height: 44px;
  }

  .vacation-tip-toast {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    transform: none;
    width: auto;
    max-width: none;
  }
}

/* Phone portrait — compact controls + rotate nudge */
@media (max-width: 768px) and (orientation: portrait) {
  .app-header {
    gap: 6px;
    margin-bottom: 6px;
    padding-bottom: 6px;
    align-items: center;
  }

  .app-title {
    font-size: 0.85rem;
    letter-spacing: 1px;
    flex: 1 1 auto;
    min-width: 0;
  }

  .header-year {
    flex: 0 0 auto;
    margin-left: auto;
  }

  .header-year select {
    min-height: 36px;
    font-size: 0.78rem;
    padding: 4px 8px;
  }

  .header-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    align-items: stretch;
  }

  .header-actions .btn {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    padding: 6px 8px;
    font-size: 0.65rem;
    letter-spacing: 0.4px;
    white-space: nowrap;
  }

  #btn-settings {
    grid-column: 1;
    grid-row: 1;
  }

  #btn-help {
    grid-column: 2;
    grid-row: 1;
    letter-spacing: 0.25px;
  }

  #btn-mark-vacation {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 0.58rem;
    letter-spacing: 0.2px;
    padding: 5px 6px;
    white-space: normal;
    line-height: 1.15;
  }

  .rotate-landscape-hint {
    grid-column: 1 / -1;
    grid-row: 3;
    align-self: center;
    max-width: none;
    margin: 0;
    padding: 2px 0 0;
    font-size: 0.58rem;
    line-height: 1.3;
    text-align: center;
    white-space: normal;
  }

  /* Phones: no Mark Vacation — hint directly under SET / HELP | ACT */
  body.phone-ui .rotate-landscape-hint {
    grid-row: 2;
  }

  .container {
    padding: 4px 6px;
  }

  .year-summary {
    font-size: 0.58rem;
    margin: 0;
    text-align: center;
  }
}

@media (max-width: 768px) and (orientation: portrait) and (hover: none) and (pointer: coarse) {
  .rotate-landscape-hint {
    display: inline;
  }
}

@media (orientation: landscape) {
  .rotate-landscape-hint {
    display: none !important;
  }
}

/* Tablet + computer landscape — year summary sits in the header centre (saves chart height) */
@media (orientation: landscape) {
  body:not(.phone-ui) .app-header {
    flex-wrap: nowrap;
    align-items: center;
  }

  body:not(.phone-ui) .year-summary {
    flex: 1 1 auto;
    order: 0;
    margin: 0 10px;
    padding: 0;
    text-align: center;
    font-size: 0.72rem;
    line-height: 1.25;
    min-width: 0;
  }

  body:not(.phone-ui) .header-actions {
    flex: 0 1 auto;
  }

  body:not(.phone-ui) .app-title,
  body:not(.phone-ui) .header-year {
    flex: 0 0 auto;
  }
}

/*
 * iPad Air 11" (A2903) / tablet landscape ≈ 1180×820 —
 * Fixed shell like phone landscape + navlog-note; touch only, not desktop Chrome.
 * body.viewport-a2903 is set by js/viewport-a2903.js for exact 820×1180 screens.
 */
@media (orientation: landscape) and (min-width: 769px) and (max-width: 1366px) and (min-height: 501px) and (hover: none) and (pointer: coarse) {
  html, body {
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    width: 100%;
    max-width: 100%;
    margin: 0;
  }

  body {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
  }

  .fms-bezel {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    max-width: min(100%, 1180px);
    width: 100%;
    height: auto;
    margin: 0 auto;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--fms-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .container {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    padding: 6px 8px;
    border: none;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app-header {
    flex: 0 0 auto;
    flex-wrap: nowrap;
    gap: 10px;
    margin-bottom: 6px;
  }

  .app-title {
    flex: 0 1 auto;
    font-size: 1rem;
    letter-spacing: 1.5px;
    white-space: nowrap;
  }

  .header-actions {
    flex: 1 1 auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    width: auto;
    min-width: 0;
    gap: 6px;
  }

  .header-actions .btn {
    font-size: 0.65rem;
    padding: 6px 9px;
    letter-spacing: 0.8px;
    white-space: nowrap;
    min-height: 44px;
  }

  /* Match default .btn size (0.72rem) — header chips stay at 0.65rem to fit the row */
  body:not(.phone-ui) .year-summary {
    font-size: 0.72rem;
    line-height: 1.25;
  }

  .vacation-status {
    flex: 0 0 auto;
    font-size: 0.58rem;
    line-height: 1.35;
    padding: 6px 8px;
  }

  .print-area {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: auto;
    overflow: hidden;
  }

  .gantt-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
    border-radius: 0;
  }

  /* Home Screen PWA — slightly tighter chrome */
  html.is-standalone-app .app-header,
  body.is-standalone-app .app-header {
    margin-bottom: 4px;
    padding-bottom: 4px;
  }

  html.is-standalone-app .container,
  body.is-standalone-app .container {
    padding: 4px 6px;
  }
}

/* Exact A2903 screen class — same shell if media query edge cases miss (e.g. zoomed layout) */
@media (orientation: landscape) {
  body.viewport-a2903 {
    position: fixed;
    inset: 0;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    box-sizing: border-box;
  }

  body.viewport-a2903 .fms-bezel {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    max-width: min(100%, 1180px);
    width: 100%;
    margin: 0 auto;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--fms-bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.viewport-a2903 .container {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.viewport-a2903 .print-area {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  body.viewport-a2903 .gantt-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
  }
}

/* iPhone / phone landscape — chart-only, edge-to-edge within the browser viewport */
@media (orientation: landscape) and (max-height: 500px) and (hover: none) and (pointer: coarse) {
  html, body {
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
    padding: 0;
    margin: 0;
  }

  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .fms-bezel {
    position: fixed;
    top: env(safe-area-inset-top);
    right: env(safe-area-inset-right);
    bottom: env(safe-area-inset-bottom);
    left: env(safe-area-inset-left);
    max-width: none;
    width: auto;
    min-height: 0;
    height: auto;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--fms-bg);
  }

  .container {
    padding: 2px 4px;
    min-height: 0;
    height: 100%;
    border: none;
    box-shadow: none;
  }

  .app-header {
    flex-wrap: nowrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 2px;
    padding-bottom: 1px;
    border-bottom: 1px solid var(--border-color);
  }

  .app-title {
    font-size: 0.62rem;
    letter-spacing: 1px;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
  }

  .landscape-chrome {
    display: flex;
    flex: 0 0 auto;
    gap: 6px;
  }

  .header-actions {
    display: none !important;
  }

  .year-summary {
    display: none !important;
  }

  .header-year {
    flex: 0 0 auto;
  }

  .header-year select {
    min-height: 28px;
    font-size: 0.62rem;
    padding: 2px 6px;
  }

  .vacation-status {
    display: none !important;
  }

  .print-area {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .gantt-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
    border-radius: 0;
  }

  .gantt-table {
    min-width: 640px;
  }
}

/* True browser fullscreen (Android / some tablets) — hide system chrome when API works */
html:fullscreen .fms-bezel,
html:-webkit-full-screen .fms-bezel {
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  border: none;
}
