/* ================================================================
   TT Saisonplanung – Custom Styles
   ================================================================ */

:root {
  --tt-green: #1a6b3c;
  --tt-green-light: #2d9c5b;
  --tt-dark: #17202C;
  --tt-dark-border: #243041;
  --calc-bg: #f0f4f8;
}

body {
  background: #f0f2f5;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.9rem;
  color: #212529;
}

/* ---- Navbar & Footer – match ttheader.png background ---- */
.navbar.bg-dark,
footer.bg-dark {
  background-color: var(--tt-dark) !important;
}
footer.bg-dark {
  border-top-color: var(--tt-dark-border) !important;
}

/* ---- Navbar ---- */
.navbar-brand i { color: #4caf50; }
.navbar-brand { font-weight: 700; letter-spacing: 0.02em; }

/* ---- Index page – planning cards ---- */
.planning-card {
  border: 1px solid #dee2e6;
  border-radius: 10px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.planning-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12) !important;
}
.planning-card .card-title { font-weight: 700; font-size: 1.05rem; }
.planning-card .card-footer { border-radius: 0 0 10px 10px; }

/* ---- Section cards ---- */
.card { border-radius: 10px; border: 1px solid #dee2e6; }
.card-header {
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  border-radius: 10px 10px 0 0 !important;
  padding: 0.6rem 1rem;
}
.card-header h6 { font-size: 0.88rem; font-weight: 700; color: #495057; }

/* ---- Settings form ---- */
.form-label { font-size: 0.8rem; font-weight: 600; color: #6c757d; margin-bottom: 2px; text-transform: uppercase; letter-spacing: 0.05em; }

/* ---- Players table ---- */
#players-container .table th { font-size: 0.75rem; }
#players-container .table td { vertical-align: middle; }

/* ---- Matches table wrapper ---- */
#matches-container { overflow-x: visible; }

/* Outer div clips the rounded corners; inner div enables horizontal scroll */
.matches-clip {
  border-radius: 8px;
  overflow: hidden;
  /* Force GPU compositing layer – fixes overflow:hidden + border-radius not
     correctly clipping sticky children (col-nr) in Safari / iOS WebKit.     */
  -webkit-transform: translateZ(0);
  transform: translateZ(0);
}
/* Dark mode: the rounded-corner "frame" normally comes from the contrast
   between the clipped table content and the card-body behind it.
   In dark mode both are similarly dark → the curve looks broken.
   box-shadow follows border-radius and provides an explicit visible ring
   without affecting layout (unlike border).                                  */
[data-bs-theme="dark"] .matches-clip {
  box-shadow: 0 0 0 1px #4a6080;
}
.matches-scroll {
  overflow-x: auto;
}

/* ---- Matches table – remove inner vertical borders (keep outer frame) ---- */
/* Right borders of all non-last, non-col-nr cells → transparent.            */
/* col-nr is excluded: its right border is the sticky-column separator        */
/* and should remain visible throughout the full table height.                */
.matches-table th:not(:last-child):not(.col-nr),
.matches-table td:not(:last-child):not(.col-nr) {
  border-right-color: transparent !important;
}
/* Left borders of all non-first cells → transparent                         */
.matches-table th:not(:first-child),
.matches-table td:not(:first-child) {
  border-left-color: transparent !important;
}

/* ---- Matches table – remove horizontal line between the two header rows -- */
.matches-table thead tr:first-child th,
.matches-table thead tr:first-child td {
  border-bottom-color: transparent !important;
}
.matches-table thead .ttr-row th,
.matches-table thead .ttr-row td {
  border-top-color: transparent !important;
}

/* ---- ttr-row fix: its border-color rule has specificity 0,2,2 which beats  */
/* the generic transparent rules above (0,2,1). These rules reach 0,3,2.      */
/* col-nr excluded here too so the separator remains visible in the ttr-row.  */
.matches-table thead .ttr-row td:not(:last-child):not(.col-nr) {
  border-right-color: transparent !important;
}
.matches-table thead .ttr-row td:not(:first-child) {
  border-left-color: transparent !important;
}

.matches-table {
  font-size: 0.8rem;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 600px;
}

.matches-table thead th {
  background: #1a2535 !important;
  color: #fff !important;
  font-size: 0.72rem;
  white-space: nowrap;
  padding: 5px 7px;
  vertical-align: middle;
  position: sticky;
  top: 0;
  z-index: 3;
  border: 1px solid #4a6080;
}
.matches-table thead .ttr-row th {
  background: #1a2535 !important;
  color: #adb5bd !important;
  font-size: 0.7rem;
  font-weight: 400;
  padding: 2px 5px;
  text-align: center;
}
.matches-table thead .ttr-row td {
  background: #1a2535 !important;
  border-color: #4a6080 !important;
}
.matches-table thead th.player-col-public {
  background: #1a4a7a !important;
  color: #7ec8e3 !important;
}

.matches-table tbody td {
  padding: 3px 5px;
  vertical-align: middle;
  border: 1px solid #dee2e6;
}

.matches-table tbody tr:hover > td { background-color: rgba(0,0,0,0.02); }

/* Sticky first column (Nr. for editors, Datum for viewers) */
.col-nr {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #e9ecef !important;
  border-right: 2px solid #adb5bd !important;
  text-align: center;
  font-weight: 700;
  min-width: 36px;
  color: #495057;
}
/* Viewer-mode: sticky date column needs more width */
.col-date { min-width: 80px !important; }
.matches-table thead .col-nr {
  background: #1a2535 !important;
  border-right-color: #4a6080 !important;
  z-index: 4;
}

/* Player header cells */
.player-col-header {
  background: #2c3e50 !important;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Inline form controls in table */
.matches-table input.form-control,
.matches-table select.form-select {
  font-size: 0.78rem;
  padding: 2px 5px;
  height: 26px;
  min-height: unset;
  border-radius: 4px;
}

/* Assignment dropdown */
.assign-select {
  font-size: 0.78rem !important;
  padding: 1px 4px !important;
  height: 24px !important;
  min-height: unset !important;
  border: 1px solid rgba(0,0,0,0.12) !important;
  border-radius: 4px !important;
  font-weight: 600 !important;
  cursor: pointer;
  min-width: 58px;
}

/* Read-only assignment label (replaces disabled select for pure viewers) */
.assign-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  min-width: 32px;
  min-height: 24px;
}

/* Assignment cell background colors */
.assign-tbd { background: #b3d9ff !important; }
.assign-ed  { background: #c8e6c9 !important; }
.assign-e   { background: #dcedc8 !important; }
.assign-d   { background: #b2dfdb !important; }
.assign-v   { background: #fff9c4 !important; }
.assign-na  { background: #ffcdd2 !important; }

/* Calculated result cells */
.calc-cell {
  text-align: center;
  white-space: nowrap;
  font-size: 0.74rem;
  padding: 4px 6px !important;
  background: var(--calc-bg);
}

.cell-gut     { background: #c8e6c9 !important; color: #1b5e20 !important; }
.cell-gleich  { background: #fff9c4 !important; color: #7c6100 !important; }
.cell-schlecht { background: #ffcdd2 !important; color: #b71c1c !important; font-weight: 700; }
.cell-ok      { background: #c8e6c9 !important; color: #1b5e20 !important; }
.cell-nok     { background: #ffcdd2 !important; color: #b71c1c !important; font-weight: 700; }
.cell-ttr     { background: #e8f5e9 !important; font-weight: 600; color: #2e7d32; }

/* Win probability gradient cell */
.cell-winprob { font-weight: 600; }

/* ---- Legend ---- */
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
}
.legend-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.15);
  flex-shrink: 0;
}

/* ---- Save status indicator ---- */
#save-status { font-size: 0.78rem; }

/* ---- Assignment count badges ---- */
.badge-single { background: #28a745 !important; }
.badge-double { background: #17a2b8 !important; }

/* ---- Buttons ---- */
.btn-sm { font-size: 0.78rem; }

/* Equal width for "Spieler hinzufügen" / "Spieltag hinzufügen" */
#btn-add-player,
#btn-add-match { min-width: 170px; }

/* ICS calendar buttons – custom purple #732BF5 */
.btn-ics {
  color: #732BF5;
  border-color: #732BF5;
  background: transparent;
}
.btn-ics:hover, .btn-ics:active {
  color: #fff;
  background: #732BF5;
  border-color: #732BF5;
}
[data-bs-theme="dark"] .btn-ics {
  color: #a878f8;
  border-color: #a878f8;
}
[data-bs-theme="dark"] .btn-ics:hover,
[data-bs-theme="dark"] .btn-ics:active {
  color: #fff;
  background: #732BF5;
  border-color: #732BF5;
}

/* ---- Empty state ---- */
.empty-state { text-align: center; padding: 3rem 1rem; color: #6c757d; }
.empty-state i { font-size: 3rem; opacity: 0.3; }

/* ---- Dirty indicator dot ---- */
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---- Toast / alert area ---- */
.toast-container { z-index: 1100; }

/* ---- Print ---- */
@media print {
  .no-print { display: none !important; }
  .navbar   { display: none !important; }
  body      { background: white; font-size: 0.75rem; }
  .card     { box-shadow: none !important; border: 1px solid #ccc; }
  .col-nr   { position: static; }
  .matches-table thead th { position: static; }
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .matches-table { font-size: 0.72rem; }
}

/* ================================================================
   Mobile – logo, matches table, footer
   ================================================================ */
@media (max-width: 575px) {
  /* Shrink navbar logo on small screens */
  .nav-logo-img { max-height: 70px !important; width: auto !important; }

  /* Tighter matches table */
  .matches-table { font-size: 0.68rem; }
  .matches-table tbody td { padding: 2px 3px; }
  .matches-table thead th { padding: 3px 4px; font-size: 0.66rem; }
  .assign-select { min-width: 42px !important; font-size: 0.68rem !important; padding: 0 2px !important; height: 22px !important; }
  .matches-table input.form-control,
  .matches-table select.form-select { font-size: 0.7rem; padding: 1px 3px; height: 22px; min-height: unset; }
  .col-date { min-width: 60px !important; }

  /* Players table – give name column more room */
  #players-container .table td:nth-child(3),
  #players-container .table th:nth-child(3) { width: 58px !important; }
  #players-container .table td:nth-child(4),
  #players-container .table th:nth-child(4),
  #players-container .table td:nth-child(5),
  #players-container .table th:nth-child(5) { width: 34px !important; }

  /* Footer links wrap to separate lines */
  footer small { display: flex; flex-direction: column; align-items: center; gap: 2px; }
  .footer-sep  { display: none; }
}

/* ================================================================
   Navbar dark-mode toggle button
   ================================================================ */
.nav-dm-btn {
    color: rgba(255,255,255,.75);
    border: 1px solid rgba(255,255,255,.25);
    background: transparent;
    border-radius: 4px;
    line-height: 1;
}
.nav-dm-btn:hover {
    color: #fff;
    border-color: rgba(255,255,255,.5);
    background: rgba(255,255,255,.08);
}

/* ================================================================
   Planning page – centred navbar title (visible on all screen sizes)
   ================================================================ */
.nav-planning-title {
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 38%;
}
@media (max-width: 575.98px) {
    .nav-planning-title { font-size: .7rem; max-width: 36%; }
}
@keyframes nav-ticker {
    0%,  20% { transform: translateX(0); }
    80%, 100% { transform: translateX(var(--ticker-offset, 0px)); }
}
.nav-planning-title.is-scrolling {
    text-overflow: clip;
    text-align: left;
}
.nav-planning-title.is-scrolling > span {
    display: inline-block;
    animation: nav-ticker 9s ease-in-out infinite alternate;
}

/* ================================================================
   Dark mode – custom overrides
   (Bootstrap's data-bs-theme="dark" handles cards, forms, modals, tables)
   ================================================================ */

/* body background is hardcoded in our CSS – let Bootstrap's variable take over */
[data-bs-theme="dark"] body { background: var(--bs-body-bg); }

/* Card header has a hardcoded light bg in our CSS – override for dark */
[data-bs-theme="dark"] .card-header {
  background: rgba(255,255,255,.04) !important;
  border-bottom-color: var(--bs-border-color) !important;
}
[data-bs-theme="dark"] .card-header h6 { color: #adb5bd; }

/* Matches table – tbody cell borders are hardcoded */
[data-bs-theme="dark"] .matches-table tbody td {
  border-color: var(--bs-border-color);
}

/* Sticky col-nr */
[data-bs-theme="dark"] .col-nr {
  background: #1e2530 !important;
  color: #adb5bd;
  border-right-color: #4a6080 !important;
}

/* Assignment cell colours – muted dark variants */
[data-bs-theme="dark"] .assign-tbd { background: #1b3a56 !important; }
[data-bs-theme="dark"] .assign-ed  { background: #163a25 !important; }
[data-bs-theme="dark"] .assign-e   { background: #223d10 !important; }
[data-bs-theme="dark"] .assign-d   { background: #103d38 !important; }
[data-bs-theme="dark"] .assign-v   { background: #3a3a10 !important; }
[data-bs-theme="dark"] .assign-na  { background: #3d1212 !important; }

/* Assign select text – readable on dark cell background */
[data-bs-theme="dark"] .assign-select { color: #dde2ea !important; }

/* Quality / planning result cells */
[data-bs-theme="dark"] .cell-gut      { background: #163a25 !important; color: #88d088 !important; }
[data-bs-theme="dark"] .cell-gleich   { background: #3a3a10 !important; color: #d0c870 !important; }
[data-bs-theme="dark"] .cell-schlecht { background: #3d1212 !important; color: #d07878 !important; }
[data-bs-theme="dark"] .cell-ok       { background: #163a25 !important; color: #88d088 !important; }
[data-bs-theme="dark"] .cell-nok      { background: #3d1212 !important; color: #d07878 !important; }
[data-bs-theme="dark"] .cell-ttr      { background: #163a25 !important; color: #88d088 !important; }

/* General calc cell background */
[data-bs-theme="dark"] .calc-cell { background: var(--bs-card-bg) !important; }

/* Outline-secondary buttons inside the matches table (location, type toggles) */
[data-bs-theme="dark"] .matches-table .btn-outline-secondary {
    color: rgba(255,255,255,.80) !important;
    border-color: rgba(255,255,255,.35) !important;
}
[data-bs-theme="dark"] .matches-table .btn-outline-secondary:hover {
    color: #fff !important;
    background-color: rgba(255,255,255,.12) !important;
    border-color: rgba(255,255,255,.55) !important;
}

/* Form labels (uppercase custom style) */
[data-bs-theme="dark"] .form-label { color: #8d9aaa; }

/* Empty state text */
[data-bs-theme="dark"] .empty-state { color: #8d9aaa; }
[data-bs-theme="dark"] .empty-state i { color: #8d9aaa; }

/* ================================================================
   Offcanvas navigation menu
   ================================================================ */
.nav-offcanvas-link {
    color: rgba(255,255,255,.7) !important;
    border-bottom: 1px solid rgba(255,255,255,.08);
    font-size: .92rem;
    transition: background-color .15s, color .15s;
}
.nav-offcanvas-link:last-child { border-bottom: none; }
.nav-offcanvas-link:hover {
    background: rgba(255,255,255,.07);
    color: #fff !important;
}
