/* GB350 라이딩 노트 — 다크 라이더 톤 */
:root {
  --bg: #0e1116;
  --surface: #1a1f29;
  --surface-2: #232a37;
  --line: #2c3340;
  --text: #e7ebf0;
  --muted: #8a93a3;
  --accent: #f4c430;      /* 도로 황색 */
  --accent-2: #3aa0ff;
  --ok: #5bd97a;
  --warn: #ffa94d;
  --danger: #ff6b6b;
  --radius: 10px;
  --shadow: 0 2px 14px rgba(0,0,0,.4);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Pretendard",
               "Apple SD Gothic Neo", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
code, .mono, .data-table td:nth-child(3),
#t-waypoints td:nth-child(3), #t-waypoints td:nth-child(4) {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .92em;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(180deg, #11151c 0%, rgba(17,21,28,.92) 100%);
  border-bottom: 1px solid var(--line);
  padding: 14px 22px;
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand h1 {
  margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .2px;
}
.brand-mark {
  width: 36px; height: 8px; border-radius: 2px;
  background:
    repeating-linear-gradient(90deg,
      var(--accent) 0 10px, transparent 10px 16px);
  box-shadow: 0 0 0 1px rgba(244,196,48,.15);
}

.tabnav {
  margin-top: 12px;
  display: flex; gap: 4px; flex-wrap: wrap;
}
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab.active {
  color: var(--bg);
  background: var(--accent);
  font-weight: 600;
}

/* ---------- Main ---------- */
main { padding: 22px; max-width: 1280px; margin: 0 auto; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel h2 { margin: 4px 0 18px; font-weight: 600; }

/* ---------- Grid / Card ---------- */
.grid { display: grid; gap: 16px; }
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 22px; }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; color: var(--text); }
.card-label { color: var(--muted); font-size: 12px; letter-spacing: .5px; text-transform: uppercase; margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 700; }
.card-value small { font-size: 13px; color: var(--muted); font-weight: 400; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card.alert { border-left: 3px solid var(--accent); }

/* ---------- Table ---------- */
.data-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
.data-table th, .data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.data-table th {
  color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: .3px; text-transform: uppercase;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table .empty {
  text-align: center; color: var(--muted); padding: 26px 0; font-style: italic;
}
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge.ok { background: rgba(91,217,122,.15); color: var(--ok); }
.badge.warn { background: rgba(255,169,77,.15); color: var(--warn); }
.badge.danger { background: rgba(255,107,107,.15); color: var(--danger); }
.badge.muted { background: rgba(138,147,163,.15); color: var(--muted); }

/* ---------- Map ---------- */
#map {
  height: 320px; width: 100%; border-radius: var(--radius);
  margin-bottom: 14px; border: 1px solid var(--line);
}
.leaflet-container { background: #0a0d12; }

/* ---------- Chart wrapper (Chart.js 부모 높이 고정으로 무한 확장 차단) ---------- */
.chart-wrap {
  position: relative;
  height: 280px;
  max-height: 320px;
  width: 100%;
}
.chart-wrap > canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ---------- Dashboard gear summary ---------- */
.gear-summary {
  margin-top: 22px;
}
.gear-summary h3 {
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 600;
}
.gear-summary .hint {
  margin-top: 8px;
  font-size: 12px;
}

/* ---------- Goals ---------- */
.goal {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.goal-head {
  width: 100%;
  background: transparent; border: none; color: var(--text);
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  margin: 0 0 10px; padding: 0;
  cursor: pointer; text-align: left;
  font: inherit;
}
.goal-head:hover .goal-title { color: var(--accent); }
.goal-head-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.goal-title { font-size: 16px; font-weight: 600; margin: 0; }
.goal-meta { color: var(--muted); font-size: 13px; }
.goal-caret {
  color: var(--muted); font-size: 14px;
  transition: transform .15s ease;
  flex-shrink: 0;
}
.goal.expanded .goal-caret { transform: rotate(180deg); }
.progress {
  height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin: 8px 0 14px;
}
.progress-bar {
  height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent));
  width: 0%; transition: width .4s ease;
}
.goal-detail { display: none; padding-top: 4px; }
.goal.expanded .goal-detail { display: block; }
.goal-section { margin-top: 14px; }
.goal-section:first-child { margin-top: 0; }
.goal-section-title {
  margin: 0 0 8px;
  font-size: 12px; font-weight: 600;
  color: var(--muted); letter-spacing: .5px; text-transform: uppercase;
}
.goal-section p { margin: 0 0 8px; line-height: 1.6; }
.goal-section p:last-child { margin-bottom: 0; }
.goal-list { list-style: none; margin: 0; padding: 0; }
.goal-list li {
  padding: 6px 0; border-bottom: 1px dashed var(--line);
  line-height: 1.55;
}
.goal-list li:last-child { border-bottom: none; }
.goal-table { margin-top: 2px; }
.goal-table tr.goal-top td { border-left: 3px solid var(--accent); }
.goal-table tr.goal-top td:first-child { padding-left: 8px; }
.phases { list-style: none; margin: 0; padding: 0; }
.phases li {
  padding: 7px 0; border-bottom: 1px dashed var(--line);
  display: flex; align-items: flex-start; gap: 10px;
}
.phases li:last-child { border-bottom: none; }
.phases .chk {
  display: inline-block; width: 16px; height: 16px; border-radius: 4px;
  border: 1.5px solid var(--muted); margin-top: 3px; flex-shrink: 0;
}
.phases li.done .chk { background: var(--ok); border-color: var(--ok); }
.phases li.done { color: var(--muted); text-decoration: line-through; }

/* ---------- Research notes ---------- */
.research-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 18px;
  align-items: start;
}
.research-sidebar {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px;
  position: sticky; top: 110px;
  max-height: calc(100vh - 130px); overflow-y: auto;
}
.research-item {
  display: flex; flex-direction: column; gap: 2px;
  text-align: left;
  background: transparent; border: 1px solid transparent;
  color: var(--text);
  padding: 8px 10px; border-radius: 6px;
  cursor: pointer;
  font: inherit; font-size: 13px;
  transition: background .12s ease, border-color .12s ease;
}
.research-item:hover { background: var(--surface-2); }
.research-item.active {
  background: var(--surface-2);
  border-color: var(--accent);
}
.research-item-title { font-weight: 500; line-height: 1.35; }
.research-item-cat { color: var(--muted); font-size: 11px; letter-spacing: .3px; text-transform: uppercase; }

.research-body {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px 26px;
  min-height: 400px;
}
.prose { max-width: 780px; line-height: 1.65; font-size: 14.5px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  color: var(--text);
  font-weight: 600;
  line-height: 1.3;
  margin: 1.4em 0 .55em;
}
.prose h1 { font-size: 22px; border-bottom: 1px solid var(--line); padding-bottom: .3em; }
.prose h2 { font-size: 18px; }
.prose h3 { font-size: 16px; }
.prose h4 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.prose h1:first-child, .prose h2:first-child { margin-top: 0; }
.prose p { margin: 0 0 .9em; }
.prose ul, .prose ol { margin: 0 0 .9em; padding-left: 1.4em; }
.prose li { margin: .25em 0; }
.prose strong { color: var(--text); font-weight: 600; }
.prose em { color: var(--text); }
.prose a { color: var(--accent-2); text-decoration: none; }
.prose a:hover { text-decoration: underline; }
.prose hr { border: none; border-top: 1px dashed var(--line); margin: 1.6em 0; }
.prose blockquote {
  margin: .9em 0; padding: .6em 14px;
  border-left: 3px solid var(--accent);
  background: var(--surface-2); color: var(--text);
  border-radius: 0 6px 6px 0;
}
.prose code {
  background: var(--surface-2);
  padding: 1px 6px; border-radius: 4px;
  font-size: .92em;
}
.prose pre {
  background: #0a0d12; border: 1px solid var(--line);
  padding: 12px 14px; border-radius: var(--radius);
  overflow-x: auto;
  margin: 0 0 .9em;
}
.prose pre code { background: transparent; padding: 0; }
.prose table {
  width: 100%; border-collapse: collapse; font-size: 13.5px;
  margin: .6em 0 1em;
}
.prose table th, .prose table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top;
}
.prose table th {
  color: var(--muted); font-weight: 500;
  font-size: 12px; letter-spacing: .3px; text-transform: uppercase;
  background: var(--surface-2);
}
.prose table tr:hover td { background: rgba(255,255,255,.02); }

/* ---------- Ride form ---------- */
.ride-form-card { margin-bottom: 18px; }
.ride-form-card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.ride-form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px 14px;
}
.rf-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rf-field > span {
  color: var(--muted);
  font-size: 12px; letter-spacing: .3px; text-transform: uppercase;
}
.rf-field-wide { grid-column: span 2; }
.rf-field-full { grid-column: 1 / -1; }
.rf-field input,
.rf-field select,
.rf-field textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .12s ease;
}
.rf-field input:focus,
.rf-field select:focus,
.rf-field textarea:focus {
  border-color: var(--accent);
}
.rf-field textarea { resize: vertical; min-height: 52px; font-family: inherit; }
.ride-form-actions {
  margin-top: 14px;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.btn-primary {
  background: var(--accent); color: var(--bg);
  border: none; border-radius: 999px;
  padding: 8px 18px; font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: filter .12s ease;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; cursor: pointer;
}
.btn-secondary:hover { color: var(--text); border-color: var(--muted); }
.ride-form-msg { color: var(--muted); font-size: 13px; }
.ride-form-msg.ok { color: var(--ok); }
.ride-form-msg.err { color: var(--danger); }

/* 표 액션 버튼 */
.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.row-btn {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 3px 9px; font-size: 12px; cursor: pointer;
  transition: all .12s ease;
}
.row-btn:hover { color: var(--text); border-color: var(--accent); }
.row-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

/* 코스 라벨 — 클릭 가능 */
.course-link {
  color: var(--accent-2);
  cursor: pointer;
  text-decoration: none;
  border-bottom: 1px dashed transparent;
}
.course-link:hover { border-bottom-color: var(--accent-2); }

/* 코스 탭의 라이딩 이력 섹션 */
.course-rides-title {
  margin: 18px 0 10px;
  font-size: 13px; font-weight: 600;
  color: var(--muted); letter-spacing: .3px; text-transform: uppercase;
}
#t-course-rides { font-size: 13px; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 36px; padding: 18px 22px;
  border-top: 1px solid var(--line);
  display: flex; justify-content: space-between;
  color: var(--muted); font-size: 12px;
}

.hint { color: var(--muted); font-size: 13px; margin-top: 12px; }
code {
  background: var(--surface-2);
  padding: 1px 6px; border-radius: 4px;
}

/* ---------- 정비 이력 카드 ---------- */
.recent-maint-card { padding: 16px; }
.recent-maint-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}
.recent-maint-row {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s ease;
}
.recent-maint-row:hover, .recent-maint-row:focus { background: var(--surface-3, #2a2a2a); outline: none; }
.recent-maint-row .rm-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.recent-maint-row .rm-item { color: var(--text); font-weight: 500; }
.recent-maint-row .rm-odo { color: var(--muted); font-variant-numeric: tabular-nums; }
.recent-maint-empty { color: var(--muted); font-size: 13px; padding: 8px 0; }

/* 점프 후 하이라이트 */
tr.flash { animation: flash-anim 1.6s ease-out; }
@keyframes flash-anim {
  0% { background: rgba(244, 196, 48, 0.45); }
  100% { background: transparent; }
}

/* ---------- 사진/동영상 업로드 ---------- */
.rf-media-row { grid-column: 1 / -1; }
.rf-media-input {
  display: block;
  width: 100%;
  padding: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--surface-3, #444);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.rf-media-input:hover { border-color: var(--accent, #f4c430); }
.rf-media-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  margin-top: 8px;
}
.rf-media-thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}
.rf-media-thumb img, .rf-media-thumb video {
  width: 100%; height: 100%; object-fit: cover;
}
.rf-media-thumb .badge-video {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.6); color: #fff;
  font-size: 10px; padding: 1px 4px; border-radius: 3px;
}
.rf-media-thumb .remove-btn {
  position: absolute; top: 2px; left: 2px;
  background: rgba(0,0,0,0.7); color: #fff;
  border: 0; width: 18px; height: 18px;
  border-radius: 50%; font-size: 12px;
  cursor: pointer; line-height: 1;
}
.rf-media-status { font-size: 12px; color: var(--muted); margin-top: 4px; }
.rf-media-status.err { color: var(--danger, #e57373); }

/* 라이딩 행의 미디어 썸네일 */
.ride-media-cell { display: flex; gap: 4px; flex-wrap: wrap; max-width: 200px; }
.ride-media-cell img, .ride-media-cell video {
  width: 40px; height: 40px; object-fit: cover; border-radius: 3px; cursor: pointer;
}

/* 리서치 표 정렬 헤더 */
.prose th.sortable {
  position: relative;
  user-select: none;
  padding-right: 18px;
}
.prose th.sortable:hover { background: var(--surface-3, #2a2a2a); }
.prose th.sortable::after {
  content: "↕";
  position: absolute;
  right: 6px;
  opacity: 0.35;
  font-size: 11px;
}
.prose th.sortable.sorted-asc::after { content: "▲"; opacity: 1; color: var(--accent, #f4c430); }
.prose th.sortable.sorted-desc::after { content: "▼"; opacity: 1; color: var(--accent, #f4c430); }

/* 정비 세부 모달 (lightbox 패턴 재활용) */
.maint-modal-content {
  background: var(--surface, #1a1a1a);
  border: 1px solid var(--surface-2, #2a2a2a);
  border-radius: 8px;
  padding: 24px 28px;
  max-width: 460px;
  width: 100%;
  color: var(--text, #eee);
}
.maint-modal-title { margin: 0 0 16px; font-size: 18px; color: var(--accent, #f4c430); }
.maint-modal-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.maint-modal-table th {
  text-align: left;
  padding: 8px 12px 8px 0;
  color: var(--muted);
  font-weight: 500;
  width: 80px;
  vertical-align: top;
}
.maint-modal-table td { padding: 8px 0; }
.maint-modal-table tr + tr th, .maint-modal-table tr + tr td { border-top: 1px solid var(--surface-2); }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: none; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.lightbox.open { display: flex; }
.lightbox img, .lightbox video {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
.lightbox .close {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.15); color: #fff;
  border: 0; width: 40px; height: 40px;
  border-radius: 50%; font-size: 20px; cursor: pointer;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  main { padding: 12px; }
  .brand h1 { font-size: 16px; }
  .card { padding: 12px; }
  .card-value { font-size: 20px; }
  .data-table { font-size: 13px; }
  .data-table th, .data-table td { padding: 6px 5px; }
  #map { height: 240px; }

  /* 폰트 16px 이상 (iOS 자동 줌 방지) */
  input, select, textarea { font-size: 16px !important; }

  /* 탭바 가로 스크롤 */
  .tabs, .tabnav { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap !important; }
  .tab { flex: 0 0 auto; min-height: 44px; }

  /* 표 가로 스크롤 wrapper */
  .table-wrap, .data-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* 버튼 터치 타깃 */
  button, .row-btn { min-height: 36px; }

  /* 카드 그리드 1열 */
  .grid.cards { grid-template-columns: 1fr 1fr; }
  .grid.two { grid-template-columns: 1fr; }

  .research-layout { grid-template-columns: 1fr; }
  .research-sidebar {
    position: static; max-height: none;
    flex-direction: row; flex-wrap: wrap;
  }
  .research-item { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .research-body { padding: 16px; }
  .prose { font-size: 14px; }
  .prose table { font-size: 12.5px; }
  .prose pre { font-size: 11.5px; }

  .ride-form-grid { grid-template-columns: 1fr; }
  .rf-field-wide { grid-column: 1; }

  .recent-maint-row { grid-template-columns: 84px 1fr auto; font-size: 12.5px; padding: 7px 8px; }
}
