:root {
  --canvas: #111214;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-raised: rgba(255, 255, 255, 0.082);
  --surface-strong: rgba(255, 255, 255, 0.115);
  --control: rgba(0, 0, 0, 0.24);
  --control-border: rgba(255, 255, 255, 0.16);
  --text: rgba(255, 255, 255, 0.94);
  --text-soft: rgba(255, 255, 255, 0.78);
  --muted: rgba(255, 255, 255, 0.60);
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.20);
  --accent: #ff7a18;
  --accent2: #f2b544;
  --danger: #ef4444;
  --success: #2bb673;
  --warning: #f2b544;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --radius: 14px;
  --radius-sm: 10px;
  --tap: 48px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255, 122, 24, 0.10), transparent 220px),
    var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 18px 30px;
}

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

.header-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 640px;
}

.header-actions .btn {
  min-height: 44px;
}

.brand {
  display: inline-block;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: rgba(255, 255, 255, 0.86);
  margin-bottom: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.055);
}

.brand-logo {
  display: inline-flex;
  vertical-align: middle;
  align-items: center;
}

.brand-logo img {
  height: 22px;
  width: auto;
  display: block;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.35));
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.04;
  letter-spacing: 0;
}

.home-title {
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0;
  margin-top: 6px;
}

.home-shell {
  min-height: 100vh;
  padding: 22px 18px 34px;
}

.home-hero {
  max-width: 1120px;
  margin: 0 auto 16px;
  padding: 12px 4px 4px;
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.home-brand-text {
  display: grid;
  gap: 6px;
}

.home-kicker {
  font-size: 12px;
  letter-spacing: 0.18em;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.78);
}

.home-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 16px;
}

.home-main {
  max-width: 1120px;
  margin: 0 auto;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.home-tile {
  position: relative;
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  aspect-ratio: 4 / 3;
  text-decoration: none;
  color: var(--text);
  transform: translateZ(0);
  min-height: 210px;
}

.home-tile-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  filter: saturate(1.05) contrast(1.02);
  transform: scale(1.02);
  transition: transform 220ms ease, filter 220ms ease;
}

.home-tile-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.40) 58%, rgba(0, 0, 0, 0.78));
}

.home-tile-content {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 18px;
  text-align: left;
}

.home-tile-title {
  width: 100%;
  font-size: 20px;
  font-weight: 800;
}

.home-tile-desc {
  width: 100%;
  font-size: 14px;
  line-height: 1.28;
  color: rgba(255, 255, 255, 0.78);
}

.home-tile:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(255, 122, 24, 0.28);
}

.home-tile:hover {
  border-color: rgba(255, 122, 24, 0.42);
  box-shadow: var(--shadow);
}

.home-tile:hover .home-tile-img {
  transform: scale(1.06);
  filter: saturate(1.12) contrast(1.05);
}

.home-footnote {
  margin-top: 14px;
  padding: 10px 4px;
}

.home-install {
  margin-top: 14px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 980px) {
  .home-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .home-title {
    font-size: 34px;
  }
}

@media (max-width: 680px) {
  .home-grid {
    grid-template-columns: 1fr;
  }
}

.subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  margin: 12px 0;
}

.setup-grid {
  display: grid;
  grid-template-columns: minmax(300px, 0.82fr) minmax(420px, 1.18fr);
  gap: 12px;
  align-items: stretch;
}

.setup-grid .card {
  margin: 0;
}

.setup-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-card {
  margin-top: 12px;
}

.table-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.day-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 12px;
}

.tab {
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: rgba(255, 255, 255, 0.86);
  cursor: pointer;
  font-weight: 700;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.10);
}

.tab-active {
  border-color: rgba(255, 122, 24, 0.65);
  background: rgba(255, 122, 24, 0.28);
}

h2 {
  margin: 0;
  font-size: 18px;
}

.training-summary {
  margin-top: auto;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255, 122, 24, 0.10);
  color: rgba(255, 255, 255, 0.86);
  line-height: 1.35;
}

.form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.form .btn {
  min-width: 0;
}

#trainingForm {
  grid-template-columns: 1fr 1fr 0.72fr 1fr;
}

#trainingForm .field:nth-child(1),
#trainingForm .field:nth-child(2) {
  grid-column: span 2;
}

.row-actions {
  margin: 10px 0;
}

.client-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 820px) {
  .client-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .form {
    grid-template-columns: 1fr;
  }
}

.field span,
.search span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

input {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--control-border);
  background: var(--control);
  color: var(--text);
  outline: none;
  font-size: 16px;
}

input:focus {
  border-color: rgba(255, 122, 24, 0.75);
  box-shadow: 0 0 0 4px rgba(255, 122, 24, 0.18);
}

.btn {
  min-height: var(--tap);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  touch-action: manipulation;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.10);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  border-color: rgba(255, 122, 24, 0.8);
  color: #fff;
}

.btn-danger {
  color: #ffffff;
  border-color: rgba(239, 68, 68, 0.62);
  background: rgba(239, 68, 68, 0.18);
}

.home-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 900px) {
  .home-actions {
    grid-template-columns: 1fr;
  }
}

.home-btn {
  display: grid;
  place-items: center;
  text-decoration: none;
  padding: 18px 14px;
  font-size: 16px;
  border-radius: 16px;
}

.home-hint {
  margin-top: 12px;
}

.btn-ghost {
  background: transparent;
}

.gdrive-connected {
  color: #ffffff;
  border-color: rgba(43, 182, 115, 0.72);
  background: rgba(43, 182, 115, 0.20);
}

.gdrive-loading {
  color: var(--text-soft);
  border-color: rgba(242, 181, 68, 0.55);
  background: rgba(242, 181, 68, 0.12);
}

.gdrive-unavailable {
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.10);
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  max-height: calc(100vh - 390px);
  min-height: 220px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
  background: rgba(0, 0, 0, 0.16);
}

.table input {
  min-width: 96px;
}

.table td:first-child,
.table th:first-child {
  position: sticky;
  left: 0;
  z-index: 3;
  background: rgba(20, 20, 22, 0.98);
}

.table td:first-child {
  background: rgba(17, 18, 20, 0.98);
}

th,
td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.10);
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  background: rgba(20, 20, 22, 0.96);
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
  z-index: 2;
}

.day-group {
  text-align: center;
}

th.day-group {
  text-align: center;
  color: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(255, 122, 24, 0.18), rgba(0, 0, 0, 0.18));
}

tr:hover td {
  background: rgba(255, 255, 255, 0.04);
}

.sig-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  min-width: 128px;
}

.sig-preview {
  width: 100%;
  height: 52px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(0, 0, 0, 0.18);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.sig-preview-button {
  color: inherit;
  cursor: pointer;
  font: inherit;
  padding: 0;
  touch-action: manipulation;
}

.sig-preview-button:focus-visible {
  outline: none;
  border-color: rgba(255, 122, 24, 0.82);
  box-shadow: 0 0 0 4px rgba(255, 122, 24, 0.18);
}

.sig-cell .btn {
  min-height: 42px;
  width: 100%;
  padding: 9px 10px;
  font-size: 14px;
}

.sig-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.muted {
  color: var(--muted);
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.consent {
  display: grid;
  gap: 14px;
}

.consent .row {
  display: grid;
  gap: 10px;
}

.consent .row.two {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 720px) {
  .consent .row.two {
    grid-template-columns: 1fr;
  }
}

.consent .text p {
  margin: 0 0 10px;
  color: rgba(255, 255, 255, 0.86);
  line-height: 1.45;
}

.sig-block {
  display: grid;
  gap: 10px;
}

.sig-label {
  font-size: 12px;
  color: var(--muted);
}

.sig-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.print-pages {
  display: none;
}

body.print-mode {
  background: #ffffff;
  color: #111827;
}

body.print-mode .app {
  display: none !important;
}

body.print-mode .print-pages {
  display: block !important;
}

body.print-mode .legal-footer {
  display: block !important;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 4mm 10mm;
  font-size: 8px;
  line-height: 1.15;
  color: #111827;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
}

.legal-footer {
  display: none;
}

.dialog {
  border: none;
  padding: 0;
  background: transparent;
}

.system-dialog {
  width: min(430px, calc(100vw - 32px));
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: rgba(22, 22, 24, 0.98);
  color: var(--text);
  padding: 22px;
  box-shadow: var(--shadow);
  text-align: left;
  line-height: 1.5;
}

.system-dialog::backdrop {
  background: rgba(0, 0, 0, 0.70);
}

.system-dialog h3 {
  margin: 0 0 12px;
  font-size: 20px;
}

.system-dialog p {
  margin: 10px 0;
  color: var(--text-soft);
}

.system-dialog-btn {
  width: 100%;
  margin-top: 16px;
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-card {
  width: min(960px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  background: rgba(22, 22, 24, 0.98);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.icon-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
}

.select-col {
  width: 44px;
  min-width: 44px;
  text-align: center;
}

.select-cell {
  text-align: center;
  vertical-align: middle;
}

.select-col input,
.select-cell input.person-select {
  width: 24px;
  height: 24px;
  accent-color: var(--orange);
}

.bulk-actions {
  justify-content: flex-end;
  margin: 4px 0 10px;
}

.canvas-wrap {
  width: min(900px, calc(100vw - 52px));
  margin: 0 auto;
  flex: 0 0 auto;
  height: clamp(300px, 46vh, 430px);
  max-height: calc(100vh - 210px);
  border-radius: 14px;
  border: 2px solid rgba(255, 122, 24, 0.76);
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 0 0 6px rgba(255, 122, 24, 0.10);
}

#signCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
  background: #ffffff;
}

.canvas-wrap {
  cursor: crosshair;
}

.dialog-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

@media (min-width: 900px) and (max-width: 1180px) {
  .app {
    padding-top: 14px;
  }

  .header {
    align-items: flex-start;
  }

  .header-actions {
    max-width: 700px;
  }

  .header-actions .btn {
    flex: 0 1 auto;
    white-space: normal;
  }

  .table-wrap {
    max-height: calc(100vh - 360px);
  }
}

@media (max-width: 900px) {
  .app {
    padding: 14px 12px 24px;
  }

  .header {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
  }

  .header-actions {
    max-width: none;
    justify-content: stretch;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .setup-grid {
    grid-template-columns: 1fr;
  }

  #trainingForm {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #trainingForm .field:nth-child(1),
  #trainingForm .field:nth-child(2) {
    grid-column: span 1;
  }

  .table-head {
    display: grid;
    align-items: start;
  }

  .table-actions,
  .search {
    width: 100%;
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 680px) {
  h1 {
    font-size: 25px;
  }

  .header-actions {
    grid-template-columns: 1fr;
  }

  .home-brand {
    align-items: flex-start;
  }

  .home-tile {
    aspect-ratio: 16 / 9;
    min-height: 176px;
  }

  .day-tabs {
    grid-template-columns: 1fr;
  }

  #trainingForm {
    grid-template-columns: 1fr;
  }

  .dialog-card {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
  }

  .canvas-wrap {
    width: calc(100vw - 44px);
    height: clamp(260px, 42vh, 380px);
  }
}

.spacer {
  flex: 1;
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    background: #ffffff;
    color: #111827;
  }

  .app {
    max-width: none;
    padding: 0;
  }

  .legal-footer {
    display: block !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6mm 14mm;
    font-size: 10px;
    line-height: 1.25;
    color: #111827;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
  }

  .card {
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 0;
    background: transparent;
    padding: 0;
  }

  .subtitle,
  .muted {
    color: #374151;
  }

  .header-actions,
  #addForm,
  #trainingForm,
  .day-tabs,
  .table-actions,
  .sig-cell button,
  #resetBtn,
  #pdfBtn,
  .footer {
    display: none !important;
  }

  #printBtn,
  #clearBtn,
  .sig-actions {
    display: none !important;
  }

  body.print-mode .app {
    display: none !important;
  }

  body.print-mode .print-pages {
    display: block !important;
  }

  body.print-mode .legal-footer {
    padding: 4mm 10mm;
    font-size: 8px;
    line-height: 1.15;
  }

  body.print-mode .print-page {
    padding: 10mm 10mm;
    padding-bottom: 18mm;
  }

  .print-page {
    padding: 18mm 14mm;
    page-break-after: always;
    padding-bottom: 28mm;
  }

  .print-page:last-child {
    page-break-after: auto;
  }

  .print-title {
    margin: 10px 0 0;
    font-size: 18px;
  }

  .print-meta {
    margin-top: 12px;
    display: grid;
    gap: 6px;
    font-size: 12px;
  }

  .print-text {
    margin-top: 14px;
    font-size: 12px;
    line-height: 1.45;
  }

  .print-text p {
    margin: 0 0 10px;
  }

  .print-signature {
    margin-top: 16px;
  }

  body.print-mode .print-title {
    font-size: 12px;
    margin: 4px 0 0;
  }

  body.print-mode .print-meta {
    margin-top: 6px;
    gap: 3px;
    font-size: 10px;
  }

  body.print-mode .print-text {
    margin-top: 8px;
    font-size: 9.5px;
    line-height: 1.15;
  }

  body.print-mode .print-text p {
    margin: 0 0 4px;
  }

  body.print-mode .print-signatures-row {
    margin-top: 8px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10mm;
    align-items: start;
  }

  body.print-mode .print-signature {
    margin-top: 0;
  }

  .print-sig-box {
    margin-top: 8px;
    width: 100%;
    height: 55mm;
    border: 1px solid #111827;
  }

  body.print-mode .print-sig-box {
    height: 28mm;
  }

  body.print-mode .droit-image-page .print-text {
    margin-top: 6px;
    font-size: 8.2px;
    line-height: 1.08;
    word-spacing: 0.12em;
  }

  body.print-mode .droit-image-page .print-text p {
    margin: 0 0 3px;
    break-inside: avoid;
  }

  body.print-mode .droit-image-page .print-meta {
    margin-top: 5px;
    gap: 2px;
    font-size: 9px;
  }

  body.print-mode .droit-image-page .print-signatures-row,
  body.print-mode .droit-image-page .print-signature {
    break-inside: avoid;
  }

  .print-sig {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }

  .print-sig.empty {
    width: 100%;
    height: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    max-height: none;
    min-height: 0;
  }

  .table {
    background: transparent;
    min-width: 0;
  }

  th {
    position: static;
    background: transparent;
    color: #111827;
    border-bottom: 1px solid #e5e7eb;
  }

  td {
    border-bottom: 1px solid #e5e7eb;
  }

  .table td:first-child,
  .table th:first-child {
    position: static;
    background: transparent;
  }

  .sig-preview {
    width: 180px;
    height: 52px;
    border: 1px solid #d1d5db;
    background: transparent;
  }

  .new-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    border: 1px solid rgba(255, 122, 24, 0.55);
    background: rgba(255, 122, 24, 0.16);
    color: rgba(255, 255, 255, 0.92);
  }

  @media print {
    .new-badge {
      color: #111827;
      background: rgba(255, 122, 24, 0.14);
      border-color: rgba(255, 122, 24, 0.55);
    }
  }
}
