/* =========================================================
   PilotMetrics - Visual Training Timeline Styles
   ========================================================= */

.read-only-banner {
  background: var(--line);
  border: 1px solid var(--line-light);
  color: var(--text-soft);
  padding: 8px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
}

.controls-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 220px;
}

.filter-options {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.filter-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

/* Timeline Visual Tree Structure */
.timeline-tree-wrapper {
  padding: 20px 10px;
  position: relative;
}

.month-block {
  margin-bottom: 28px;
  position: relative;
}

.month-header {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 1px solid var(--cyan);
  color: var(--cyan);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.month-header .month-count {
  font-size: 12px;
  background: var(--cyan-light);
  padding: 2px 6px;
  border-radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.tree-group {
  position: relative;
  padding-left: 18px;
}

/* Vertical Trunk Line (│) */
.tree-group::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 7px;
  width: 2px;
  background: var(--line-light);
}

/* Individual Branch Node */
.timeline-node {
  position: relative;
  display: flex;
  align-items: flex-start;
  margin-bottom: 12px;
  padding-left: 24px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Branch Connector Line (├──) */
.timeline-node::before {
  content: "";
  position: absolute;
  top: 14px;
  left: -11px;
  width: 20px;
  height: 2px;
  background: var(--line-light);
}

/* Marker Point */
.node-marker {
  position: absolute;
  left: 5px;
  top: 9px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--muted);
  z-index: 2;
  transition: all 0.2s ease;
}

.timeline-node:hover .node-marker {
  transform: scale(1.25);
}

/* Node Content Box */
.node-card {
  background: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  width: 100%;
  max-width: 720px;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.node-card:hover {
  border-color: var(--line-light);
  transform: translateX(3px);
}

.node-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.node-title {
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.node-date {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.node-details {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.node-remarks {
  font-size: 12px;
  color: var(--text-soft);
  font-style: italic;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}

/* Milestone Tag Badges */
.badge-ms {
  font-size: 12px;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.ms-first-flight {
  background: var(--blue-light);
  color: var(--blue-text);
  border: 1px solid rgba(59, 130, 246, 0.4);
}
.ms-solo {
  background: var(--amber-light);
  color: var(--alert-soon);
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.ms-landaway {
  background: var(--cyan-light);
  color: var(--next);
  border: 1px solid rgba(6, 182, 212, 0.4);
}
.ms-qxc {
  background: var(--line);
  color: var(--text-soft);
  border: 1px solid rgba(148, 163, 184, 0.4);
}
.ms-night {
  background: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  border: 1px solid #475569;
}
.ms-instrument {
  background: rgba(14, 116, 144, 0.2);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
}
.ms-skilltest {
  background: var(--gold-light);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.5);
}
.ms-stage {
  background: var(--green-light);
  color: var(--green-text);
  border: 1px solid rgba(16, 185, 129, 0.4);
}
.ms-relocation {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger-text);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.ms-training-start {
  background: rgba(20, 184, 166, 0.15);
  color: #2dd4bf;
  border: 1px solid rgba(20, 184, 166, 0.4);
}

/* Special Highlighting for Nodes */
.timeline-node.highlight-milestone .node-card {
  border-color: var(--blue);
  background: #131d33;
}
.timeline-node.highlight-milestone .node-marker {
  border-color: var(--blue);
  background: var(--blue);
}

/* Gap Node Specifics */
.timeline-node.gap-node::before {
  border-top: 2px dashed var(--amber);
  background: transparent;
}
.timeline-node.gap-node .node-marker {
  border-color: var(--amber);
  background: var(--amber);
}
.timeline-node.gap-node .node-card {
  background: rgba(245, 158, 11, 0.05);
  border: 1px dashed rgba(245, 158, 11, 0.3);
}
.gap-title {
  color: var(--amber);
  font-weight: 700;
  font-size: 12px;
}

/* Modal and Overlay Helpers */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}
.modal-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.auth-error {
  color: var(--danger-text);
  font-size: 12px;
  margin-top: 6px;
}
.toast-notification {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 12px;
  border: 1px solid;
  z-index: 2000;
}

.ms-cancellation {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger-text);
  border: 1px solid rgba(239, 68, 68, 0.4);
}
.ms-standby {
  background: rgba(245, 158, 11, 0.2);
  color: var(--alert-soon);
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.timeline-node.cancellation-node .node-card {
  border-color: rgba(239, 68, 68, 0.3);
  background: #1a1520;
}
.timeline-node.cancellation-node .node-marker {
  border-color: var(--danger-text);
  background: var(--danger-text);
}

/* Events added by hand (Pro) */
.timeline-node.editable .node-card { cursor: pointer; }
.node-edit-hint {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.timeline-node.editable:hover .node-edit-hint { opacity: 1; }

.ms-flight-ms { background: var(--blue-light); color: var(--blue-text); border: 1px solid rgba(59, 130, 246, 0.4); }
.ms-training { background: var(--green-light); color: var(--green-text); border: 1px solid rgba(16, 185, 129, 0.4); }
.ms-school { background: var(--cyan-light); color: var(--next); border: 1px solid rgba(6, 182, 212, 0.4); }
.ms-personal { background: rgba(148, 163, 184, 0.12); color: var(--text-soft); border: 1px solid rgba(148, 163, 184, 0.35); }
.ms-exam { background: var(--line); color: var(--text-soft); border: 1px solid rgba(148, 163, 184, 0.45); }

.timeline-node.custom-node .node-card { border-left: 3px solid var(--node-accent, var(--line-light)); }
.timeline-node.custom-node .node-marker { border-color: var(--node-accent); background: var(--node-accent); }
.timeline-node.custom-flight { --node-accent: var(--blue); }
.timeline-node.custom-training { --node-accent: var(--green); }
.timeline-node.custom-school { --node-accent: var(--cyan); }
.timeline-node.custom-personal { --node-accent: var(--muted); }

/* Ground exams: purple card with a diamond marker, so they stand apart from flying */
.timeline-node.exam-node .node-card {
  background: #171431;
  border-color: rgba(148, 163, 184, 0.45);
  border-left: 3px solid var(--line-light);
}
.timeline-node.exam-node .node-marker {
  border-radius: 2px;
  transform: rotate(45deg);
  border-color: var(--line-light);
  background: var(--line-light);
}
.timeline-node.exam-node:hover .node-marker { transform: rotate(45deg) scale(1.25); }
.timeline-node.exam-node.exam-failed .node-card { border-left-color: var(--danger); }
.exam-result { font-weight: 800; }
.exam-result.passed { color: var(--green-text); }
.exam-result.failed { color: var(--danger-text); }

/* Add / edit event modal */
.event-modal { max-width: 560px; }
.event-type-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
  margin-bottom: 14px;
}
.event-type-picker button {
  background: var(--inset);
  color: var(--muted);
  border: 1px solid var(--line-light);
  text-align: left;
  font-size: 12px;
  padding: 8px 10px;
}
.event-type-picker button:hover { color: #fff; border-color: var(--blue); }
.event-type-picker button.active { color: #fff; border-color: var(--blue); background: var(--blue-light); }
.event-type-picker button:disabled { opacity: 0.45; cursor: not-allowed; }
.event-fields { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.event-field-row { display: flex; gap: 10px; }
.event-privacy-note { margin: 0; font-size: 12px; color: var(--muted); }
.event-modal textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--line-light);
  border-radius: 6px;
  background: var(--inset);
  color: #fff;
  font: inherit;
  font-size: 12px;
  resize: vertical;
}
.event-modal textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); outline: none; }

@media (max-width: 600px) {
  /* Date goes under the title so it isn't squeezed onto three lines beside it */
  .node-header { flex-direction: column; align-items: flex-start; gap: 4px; }
  .node-date { white-space: nowrap; }
  .node-details { flex-wrap: wrap; }
  .search-box, .search-box input { width: 100%; }
  .event-field-row { flex-direction: column; }
  .controls-wrapper {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-options {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Months fold: the latest are open */
summary.month-header { cursor: pointer; list-style: none; }
summary.month-header::-webkit-details-marker { display: none; }
summary.month-header::after { content: "\25B8"; font-size: 12px; }
details[open] > summary.month-header::after { content: "\25BE"; }
.month-block:not([open]) { margin-bottom: 8px; }
.month-block:not([open]) > summary.month-header { margin-bottom: 0; }
