/* ============================================================================
   Custom Courses ("My Courses") — picker tab additions + Create Course wizard
   ============================================================================ */

/* ── My Courses picker actions row (Create + Refresh) ──────────────────── */
.my-course-picker-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.my-course-picker-actions > button { flex: 0 0 auto; }
.my-course-picker-actions #myCourseCreateBtn { flex: 1 1 auto; }

/* Distinguish two-line course option for My Courses (name + meta) */
.course-option .course-option-name {
  font-weight: 600;
}
.course-option .course-option-meta {
  opacity: 0.7;
  margin-top: 2px;
}

/* ── Create Course Wizard modal ───────────────────────────────────────── */
.create-course-modal[hidden],
.create-course-modal-backdrop[hidden] { display: none; }

.create-course-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 10090;
}

.create-course-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* Wider on desktop so the 18-hole table doesn't horizontal-scroll. */
  width: min(940px, calc(100vw - 24px));
  /* Subtract the Android nav-bar inset (top + bottom) so the modal can't
     extend under the system bars. env() is 0 in Android WebView — the
     --safe-top/bottom-inset variables carry the measured native inset. */
  max-height: calc(100dvh - 32px - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)) - var(--safe-top-inset, env(safe-area-inset-top, 0px)));
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  z-index: 10091;
  overflow: hidden;
}

.create-course-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  flex-shrink: 0;
}
.create-course-titles h3 {
  margin: 0;
  font-size: var(--text-lg);
}
.create-course-subtitle {
  font-size: calc(11px + var(--font-size-step));
  color: var(--muted);
  margin-top: 2px;
}

.create-course-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
}

.create-course-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  flex-shrink: 0;
}
.create-course-footer-spacer { flex: 1 1 auto; }
.create-course-footer .btn { min-width: 100px; }
.create-course-next {
  background: linear-gradient(180deg, #2384dc, #176dc6);
  border-color: #4a9eff;
  color: #ffffff;
}
.create-course-next:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

body.create-course-modal-open { overflow: hidden; }

/* Step 1: Meta form */
.create-course-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.create-course-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.create-course-field-label {
  font-size: calc(12px + var(--font-size-step));
  font-weight: 600;
}
.create-course-required { color: #d9534f; }
.create-course-optional { color: var(--muted); font-weight: 400; }
.create-course-field input[type="text"] {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-alt, transparent);
  color: var(--ink);
  font-size: calc(14px + var(--font-size-step));
}
.create-course-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.create-course-hint {
  font-size: calc(11px + var(--font-size-step));
  color: var(--muted);
  margin: 4px 0 0;
}
.create-course-warning {
  font-size: calc(12px + var(--font-size-step));
  background: rgba(220, 53, 69, 0.1);
  border-left: 3px solid #d9534f;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
}

/* Step 2: Source picker */
.create-course-source-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.create-course-source-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 22px 14px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel-alt, transparent);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.create-course-source-tile:not(:disabled):hover {
  transform: translateY(-1px);
  border-color: rgba(74, 158, 255, 0.55);
}
.create-course-source-tile:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.create-course-source-tile-icon { color: #4a9eff; }
.create-course-source-tile-title {
  font-weight: 700;
  font-size: calc(14px + var(--font-size-step));
}
.create-course-source-tile-sub { color: var(--muted); line-height: 1.35; }
.create-course-source-tile-warning {
  color: #d9534f;
  font-size: calc(11px + var(--font-size-step));
}
@media (max-width: 540px) {
  .create-course-source-grid { grid-template-columns: 1fr; }
}

/* Step 3: Edit table — modeled on the scorecard header */
.create-course-edit-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.create-course-edit-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.create-course-table {
  width: 100%;
  border-collapse: collapse;
  font-size: calc(12px + var(--font-size-step));
  min-width: 760px; /* ensures all 20 columns are visible without crowding */
}
.create-course-table th,
.create-course-table td {
  border: 1px solid color-mix(in srgb, var(--line) 60%, transparent);
  text-align: center;
  padding: 4px;
  white-space: nowrap;
}
.create-course-table thead th {
  background: rgba(74, 158, 255, 0.1);
  font-weight: 700;
}
.create-course-row-label {
  background: rgba(74, 158, 255, 0.06);
  font-weight: 700;
  text-align: left;
  padding-left: 8px;
  padding-right: 8px;
  position: sticky;
  left: 0;
  z-index: 1;
}
.create-course-table .create-course-out,
.create-course-table .create-course-in,
.create-course-table .create-course-tot {
  font-weight: 700;
  background: rgba(74, 158, 255, 0.06);
}
.create-course-table input[type="number"] {
  width: 100%;
  min-width: 42px;
  max-width: 64px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: center;
  font-size: inherit;
  font-weight: 600;
  font-family: inherit;
  /* Hide spinner buttons for a clean look — users use the keyboard. */
  -moz-appearance: textfield;
}
.create-course-table input[type="number"]::-webkit-inner-spin-button,
.create-course-table input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.create-course-table input[type="number"]:focus {
  outline: 2px solid #4a9eff;
  outline-offset: -2px;
  background: rgba(74, 158, 255, 0.08);
}
.create-course-validation {
  font-size: calc(12px + var(--font-size-step));
  color: var(--muted);
  min-height: 1.3em;
}
.create-course-validation.is-error {
  color: #d9534f;
  background: rgba(220, 53, 69, 0.08);
  border-left: 3px solid #d9534f;
  padding: 6px 10px;
  border-radius: 4px;
}

/* Saving spinner step */
.create-course-saving {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 32px 16px;
}
.create-course-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(74, 158, 255, 0.25);
  border-top-color: #4a9eff;
  border-radius: 50%;
  animation: ccSpinnerRotate 0.9s linear infinite;
}
@keyframes ccSpinnerRotate {
  to { transform: rotate(360deg); }
}

/* Scan-progress view (wizard step shown during Vertex AI round-trip) */
.create-course-scan {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 12px 4px 4px;
}
.create-course-scan-progress {
  height: 8px;
  background: rgba(74, 158, 255, 0.16);
  border-radius: 999px;
  overflow: hidden;
}
.create-course-scan-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2384dc, #4a9eff);
  border-radius: 999px;
  transition: width 0.28s ease-out;
  /* Subtle moving shimmer so the user reads "alive" even when the bar
     is paused mid-step. Pure CSS, no JS keyframe scheduling. */
  background-image: linear-gradient(90deg, #2384dc, #4a9eff),
                    linear-gradient(90deg, rgba(255,255,255,0.0) 0%, rgba(255,255,255,0.35) 50%, rgba(255,255,255,0.0) 100%);
  background-size: 100% 100%, 30% 100%;
  background-position: 0 0, 0 0;
  background-repeat: no-repeat, repeat-x;
  animation: ccScanShimmer 1.4s linear infinite;
}
@keyframes ccScanShimmer {
  from { background-position: 0 0, -30% 0; }
  to   { background-position: 0 0, 100% 0; }
}
.create-course-scan-status {
  text-align: center;
}
.create-course-scan-status-label {
  font-weight: 700;
  font-size: calc(14px + var(--font-size-step));
}
.create-course-scan-status-detail {
  margin-top: 2px;
  color: var(--muted);
}
.create-course-scan-steps {
  list-style: none;
  margin: 0;
  padding: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.create-course-scan-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: calc(13px + var(--font-size-step));
  color: var(--muted);
}
.create-course-scan-step-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(74, 158, 255, 0.14);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.create-course-scan-step.is-done .create-course-scan-step-dot {
  background: #2384dc;
  color: #fff;
}
.create-course-scan-step.is-current .create-course-scan-step-dot {
  background: #4a9eff;
  color: #fff;
  /* Pulse to draw the eye to the live step. */
  animation: ccScanStepPulse 1.2s ease-in-out infinite;
}
.create-course-scan-step.is-current .create-course-scan-step-label {
  color: var(--ink);
  font-weight: 600;
}
.create-course-scan-step.is-done .create-course-scan-step-label {
  color: var(--ink);
  opacity: 0.85;
}
@keyframes ccScanStepPulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}
.create-course-scan-footnote {
  margin: 4px 0 0;
  color: var(--muted);
  line-height: 1.4;
  text-align: center;
}

/* Light theme: white panel + darker borders */
:root[data-theme="light"] .create-course-modal {
  background: #ffffff;
}
:root[data-theme="light"] .create-course-table thead th {
  background: #eef4fb;
}
:root[data-theme="light"] .create-course-row-label,
:root[data-theme="light"] .create-course-table .create-course-out,
:root[data-theme="light"] .create-course-table .create-course-in,
:root[data-theme="light"] .create-course-table .create-course-tot {
  background: #f2f7fc;
}

/* Mobile compact: smaller padding + tighter table cells */
@media (max-width: 600px) {
  /* Mobile: don't let the modal fully fill dvh on Android — leave room for
     the nav bar so the footer's "Save" button stays tappable. */
  .create-course-modal {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)) - var(--safe-top-inset, env(safe-area-inset-top, 0px)));
    border-radius: 14px;
  }
  .create-course-body { padding: 12px; }
  .create-course-row-2 { grid-template-columns: 1fr; }
  .create-course-table input[type="number"] { padding: 4px 2px; min-width: 36px; }
  .create-course-table th, .create-course-table td { padding: 3px; }
}

/* ============================================================================
   My Courses management modal (opened from hamburger menu).
   Separate from the inline picker in Score Options — this one is a
   standalone listing surface with search + create + per-row delete.
   ============================================================================ */

.my-courses-modal-backdrop[hidden],
.my-courses-modal[hidden] { display: none; }

.my-courses-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10080;
}

.my-courses-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(540px, calc(100vw - 24px));
  /* Subtract Android nav-bar inset so the delete button on the last row
     never lands under the system bar. */
  max-height: min(78dvh, 720px, calc(100dvh - 32px - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)) - var(--safe-top-inset, env(safe-area-inset-top, 0px))));
  background: var(--panel);
  border: 2px solid var(--line-soft, rgba(136, 165, 191, 0.3));
  border-radius: 18px;
  box-shadow: 0 22px 48px -16px rgba(8, 24, 48, 0.55);
  z-index: 10081;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.my-courses-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line-soft, rgba(136, 165, 191, 0.2));
}

.my-courses-modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.my-courses-modal-close {
  min-width: 36px;
  min-height: 36px;
  padding: 0 10px;
  font-size: 18px;
  line-height: 1;
}

.my-courses-modal-toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  align-items: stretch;
  border-bottom: 1px solid var(--line-soft, rgba(136, 165, 191, 0.18));
}

.my-courses-modal-search {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-alt);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}

.my-courses-modal-create {
  flex: 0 0 auto;
  height: 40px;
  padding: 0 14px;
  font-weight: 700;
  white-space: nowrap;
}

.my-courses-modal-hint,
.my-courses-modal-status,
.my-courses-modal-empty {
  padding: 8px 16px;
  color: var(--muted);
}

.my-courses-modal-status:empty,
.my-courses-modal-hint[hidden],
.my-courses-modal-empty[hidden] { display: none; }

.my-courses-modal-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.my-courses-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft, rgba(136, 165, 191, 0.22));
  border-radius: 12px;
  background: var(--panel-alt);
}

.my-courses-row-body {
  flex: 1 1 auto;
  min-width: 0;
}

.my-courses-row-name {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-courses-row-meta {
  margin-top: 2px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.my-courses-row-delete {
  flex: 0 0 auto;
  min-width: 38px;
  height: 38px;
  padding: 0 10px;
  border-radius: 10px;
  background: transparent;
  color: var(--danger, #d44a4a);
  border: 1px solid color-mix(in srgb, var(--danger, #d44a4a) 45%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.my-courses-row-delete:hover {
  background: color-mix(in srgb, var(--danger, #d44a4a) 14%, transparent);
}

@media (max-width: 480px) {
  .my-courses-modal {
    width: calc(100vw - 12px);
    max-height: calc(90dvh - var(--safe-bottom-inset, env(safe-area-inset-bottom, 0px)));
    border-radius: 14px;
  }
  .my-courses-modal-toolbar {
    flex-wrap: wrap;
  }
  .my-courses-modal-create {
    flex: 1 1 100%;
  }
}

/* ============================================================================
   New-round course picker dialog (js/cloudsync/bridges/course-picker.js).
   Migrated off style.cssText — every value below is verbatim from the
   original inline styles so the dialog renders pixel-identical. Builds on
   the shared .ui-dialog-* scaffold (stylesheet/ui-dialogs.css); the compound
   selectors override the scaffold's confirm-dialog defaults back to this
   dialog's original values (and out-specificity it regardless of stylesheet
   order).
   ============================================================================ */

/* Scaffold scrim, kept above the welcome overlay + side-menu layers. The
   scaffold's fadeIn animation is disabled — the original dialog had none. */
.ui-dialog-scrim.course-picker-scrim {
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: var(--z-overlay-top);
  animation: none;
}

.ui-dialog-card.course-picker-card {
  width: min(520px, 96vw);
  max-width: none;
  max-height: 88vh;
  overflow: auto;
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: none;
  animation: none;
}

.course-picker-title {
  margin: 0;
  font-size: var(--text-xl);
}

/* Bordered sub-panels (Round Name / Course) — read as paired sections. */
.course-picker-section {
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--panel-solid, var(--panel));
}
.course-picker-section--stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Section heading ("Course") — compound with .small so the weight/opacity
   win over any .small rule regardless of order. */
.small.course-picker-heading {
  font-weight: 700;
  opacity: 0.9;
}

/* "Round name" label above its input. */
.small.course-picker-field-label {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  opacity: 0.9;
}

/* Search + round-name text inputs. Scoped under the card so the rule
   ((0,2,0)) beats forms.css's input[type="text"] sizing ((0,1,1)) the way
   the old inline styles did. */
.course-picker-card .course-picker-input {
  width: 100%;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.course-picker-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
}

/* Course result rows (selection state stays inline — it's per-item dynamic). */
.btn.course-picker-result {
  justify-content: space-between;
  text-align: left;
}

/* "+ Create New Course" (My Courses tab only). */
.btn.course-picker-create-btn {
  align-self: stretch;
  text-align: center;
  font-weight: 700;
}

/* "Current selection" highlight card. */
.small.course-picker-selected {
  padding: 12px 14px;
  border: 2px solid rgba(74, 158, 255, 0.6);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(74, 158, 255, 0.18), rgba(74, 158, 255, 0.08));
  font-weight: 800;
  font-size: var(--text-base);
  line-height: 1.35;
}

.small.course-picker-hint {
  margin-top: 6px;
  opacity: 0.75;
  line-height: 1.3;
}

/* Cancel/Start row — scaffold supplies display:flex + gap:8px; restore the
   original no-wrap, right-aligned layout. */
.ui-dialog-actions.course-picker-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ============================================================================
   Cloud-sync join-progress overlay (js/cloudsync/session/join-progress.js).
   Migrated off style.cssText — values verbatim from the original inline
   styles. Builds on the shared .ui-dialog-* scaffold; JS still drives the
   dynamic bits inline (overlay opacity fade, percent-bar width, and the
   success/error spinner + text recolors in complete()/fail()).
   ============================================================================ */

.ui-dialog-scrim.cloud-join-progress-overlay {
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: var(--z-progress);
  padding: 0;
  animation: none;
  opacity: 0;
  /* 0.15s matches the JS clear() delay in complete()/finish() so the CSS
     fade lands a hair before DOM removal — no visible cut. Tuned tighter
     than the original 0.2s after Android-side profiling showed the fade
     was the dominant lingering frame. */
  transition: opacity 0.15s ease;
}

.ui-dialog-card.cloud-join-progress-card {
  color: var(--ink);
  padding: 18px 20px;
  width: min(92vw, 420px);
  max-width: none;
  text-align: center;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.38);
  animation: none;
}

.cloud-join-progress-spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 12px auto;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: #1f9d55;
  border-radius: 50%;
  animation: cloudJoinSpin 0.9s linear infinite;
}
@keyframes cloudJoinSpin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.cloud-join-progress-title {
  font-size: var(--text-xl);
  font-weight: 700;
  margin-bottom: 6px;
}

.cloud-join-progress-phase {
  font-size: var(--text-md);
  color: var(--ink);
  font-weight: 650;
  line-height: 1.3;
  margin-bottom: 6px;
}

.cloud-join-progress-shell {
  margin: 10px 0 8px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 8px;
}

.cloud-join-progress-track {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 50%, transparent);
  overflow: hidden;
}

/* Bar width is the live percent — JS sets style.width inline. */
.cloud-join-progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, #1f9d55 80%, #ffffff 20%), #1f9d55);
  transition: width 0.2s ease;
}

.cloud-join-progress-percent {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  min-width: 34px;
  text-align: right;
}

.cloud-join-progress-text {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
  min-height: 1.2em;
}
