/* Responsive Styles for Cykloman */

@media screen and (max-width: 980px) {
  /* Přizpůsobení šířce obrazovky – žádný horizontální scroll */
  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }

  /* Zvětšení základního písma na mobilech */
  body,
  td,
  th {
    font-size: 16px;
  }

  /* Hlavní kontejner na celou šířku */
  #container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  /* Zrušení fixních šířek a plovoucích prvků u obsahu */
  .mainpage #main,
  .mainpage #side,
  .page #main,
  .page #side,
  .panel-left,
  .panel-right,
  .panel-middle {
    width: 100% !important;
    float: none !important;
    padding: 10px !important;
    box-sizing: border-box;
    height: auto !important;
  }

  #content {
    height: auto !important;
    padding-bottom: 0;
  }

  /* Hlavička – flex: logo vlevo, sponzoři vpravo, nav na vlastním řádku */
  #header {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    padding: 5px 8px !important;
    height: auto !important;
  }

  /* h1 je v DOM za .overhead – order:1 ho přesune vizuálně na první místo */
  #header h1 {
    order: 1;
    position: relative !important;
    width: 110px !important;
    min-width: 110px !important;
    height: 58px !important;
    overflow: hidden !important;
    flex-shrink: 0;
    margin: 0 !important;
    padding: 0 !important;
  }

  #header h1 a {
    position: absolute !important;
    width: 110px !important;
    height: 58px !important;
    background-size: contain !important;
    background-position: left center !important;
    display: block !important;
  }

  /* Loga sponzorů – order:2, vedle h1 na prvním řádku */
  .overhead {
    order: 2;
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: auto !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    flex-wrap: nowrap !important;
    gap: 8px;
    padding-left: 10px;
    margin: 0 !important;
  }

  .overhead img {
    max-height: 50px !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    display: block !important;
    margin: 0 !important;
  }

  /* user-tools – přihlašovací formulář: celý řádek, přebíjí absolutní pozici z main CSS */
  #header #user-tools {
    order: 3;
    flex: 0 0 100%;
    position: static !important;
    top: auto !important;
    right: auto !important;
  }

  /* Na mobilu formulář není absolutní, legend není potřeba (máme toolbar tlačítko) */
  #header #user-tools .form-login {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    border: none !important;
    background: transparent !important;
    top: auto !important;
    right: auto !important;
  }

  #header #user-tools .form-login legend {
    position: static !important;
    display: none !important;
  }

  /* Když je aktivní login tlačítko v toolbaru, formulář je skrytý dokud se neotevře */
  html.has-login-btn #header #user-tools {
    display: none;
    order: 4;
  }

  html.has-login-btn #header #user-tools.login-open {
    display: block;
    background: #f5f5f5;
    padding: 6px 10px;
    border-top: 1px solid #ddd;
  }

  /* Nav se při login-btn posune za formulář */
  html.has-login-btn #header #nav {
    order: 5;
  }

  #login-toolbar-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 15px;
    padding: 12px 6px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* logged – vždy position:static, výchozí stav (bez JS) */
  #logged {
    order: 3;
    flex: 0 0 100%;
    position: static !important;
    top: auto !important;
    right: auto !important;
    background: #6b6d6f url(../images/bg-nav.png) repeat-x top;
    background: -moz-linear-gradient(center top, #717375, #5c5e60);
    background: -webkit-gradient(linear, 0 0, 0 100%, from(#717375), to(#5c5e60));
    padding: 0;
  }

  #logged li {
    display: inline !important;
  }

  #logged li a {
    font-size: 14px !important;
    padding: 12px 14px !important;
    color: #fff !important;
  }

  #header #nav {
    order: 4;
    flex: 0 0 100%;
  }

  /* Toolbar: ročník vlevo, hamburger vpravo (vždy viditelný na mobilu) */
  #mobile-toolbar {
    order: 3;
    flex: 0 0 100%;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #5c5e60;
    padding: 0 8px 0 8px;
    position: relative;
    overflow: visible;
    border-radius: 4px;
    margin-bottom: 4px;
  }

  #mobile-year {
    position: relative;
  }

  #mobile-year-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 15px;
    padding: 12px 6px;
    cursor: pointer;
    white-space: nowrap;
  }

  #mobile-year-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 200;
    background: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.2);
    min-width: 130px;
    max-height: 60vh;
    overflow-y: auto;
  }

  #mobile-year-menu.year-menu-open {
    display: block;
  }

  #mobile-year-menu a {
    display: block;
    padding: 9px 14px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    border-bottom: 1px solid #eee;
  }

  #mobile-year-menu a:last-child {
    border-bottom: none;
  }

  #mobile-year-menu a.current {
    background: #5c5e60;
    color: #fff;
    font-weight: bold;
  }

  #mobile-year-menu a:hover {
    background: #f0f0f0;
  }

  #mobile-year-menu a.current:hover {
    background: #4a4c4e;
  }

  /* Původní select z nav – na mobilu skrytý (JS ho schovává přes style) */
  #nav > ul > li:last-child {
    display: none !important;
  }

  #hamburger-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 12px 0;
    flex-shrink: 0;
  }

  /* #logged skrytý, dokud hamburger není otevřen */
  html.has-hamburger #logged {
    order: 4;
    display: none;
    border-top: 1px solid #ddd;
  }

  html.has-hamburger #logged.logged-open {
    display: block;
  }

  /* Nav se posouvá na order:5, aby byl vždy pod toolbarem */
  html.has-hamburger #header #nav {
    order: 5;
  }

  /* Navigace - horizontální swipe menu */
  #nav {
    height: auto !important;
    background-size: cover;
    overflow: hidden;
    position: relative;
  }

  /* Swipe šipky – vizuální hint */
  #nav::before,
  #nav::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 30px;
    pointer-events: none;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    color: rgba(255, 255, 255, 0.9);
    transition: opacity 0.2s;
  }

  #nav::after {
    content: '\203A';
    right: 0;
    background: linear-gradient(to right, transparent, rgba(92, 94, 96, 0.9) 55%);
    opacity: 1;
  }

  #nav::before {
    content: '\2039';
    left: 0;
    background: linear-gradient(to left, transparent, rgba(92, 94, 96, 0.9) 55%);
    opacity: 0;
  }

  #nav.nav-scrolled::before {
    opacity: 1;
  }
  #nav.nav-at-end::after {
    opacity: 0;
  }

  #nav > ul {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important; /* Firefox */
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    align-items: stretch;
  }

  /* Schovat scrollbar - WebKit (Chrome, Safari) */
  #nav > ul::-webkit-scrollbar {
    display: none;
  }

  #nav li {
    display: block !important;
    width: auto !important;
    flex: 0 0 auto;
    text-align: center;
    float: none !important;
    margin: 0 !important;
  }

  #nav li a {
    float: none !important;
    display: block;
    white-space: nowrap;
    padding: 12px 14px;
    width: auto !important;
    border-bottom: none;
  }

  /* Obrázky a formuláře */
  img {
    max-width: 100%;
    height: auto;
  }

  input,
  textarea,
  select {
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Skrytí složitých dekorací pro zjednodušení */
  .intro-tree {
    display: none !important;
  }

  /* Intro banner – úvodní stránka: odebrat obrázek cyklisty, 440px levý padding by text schoval */
  .mainpage #intro {
    padding: 15px 20px !important;
    height: auto !important;
    background-image: none !important;
    background-color: #a5c016 !important;
  }

  /* Intro banner – podstránky: po skrytí .intro-tree je div prázdný, skrýt ho */
  .page #intro {
    display: none !important;
  }

  /* Login formulář */
  .form-login {
    position: relative !important;
    top: auto !important;
    right: auto !important;
    width: 100% !important;
    border: 1px solid #ccc !important;
    margin-top: 10px !important;
  }

  /* Tabulka výsledků – horizontální scroll, sticky první 2 sloupce */
  .tab_v_c,
  .tab_v_xx {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
    width: 100%;
  }

  .tab_v_c table,
  .tab_v_xx table {
    min-width: 600px;
  }

  /* Sticky: pořadí (1. sloupec) */
  .tab_v_c th:first-child,
  .tab_v_c td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    min-width: 28px;
    width: 28px;
    background: #e8ecf0;
    border-right: 1px solid #999;
  }

  .tab_v_c thead th:first-child {
    background: #ffad33;
    color: #006;
  }

  /* Sticky: jméno (2. sloupec) */
  .tab_v_c th:nth-child(2),
  .tab_v_c td:nth-child(2) {
    position: sticky;
    left: 30px; /* šíře 1. sloupce (28px) + border (1px) + 1px */
    z-index: 2;
    background: #e8ecf0;
    min-width: 110px;
    max-width: 140px;
    white-space: normal;
    word-break: break-word;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.12);
    border-right: 1px solid #999;
  }

  .tab_v_c thead th:nth-child(2) {
    background: #ffad33;
    color: #006;
  }

  /* Bílé odkazy v hlavičce – na sticky sloupcích s oranžovým pozadím použít tmavou barvu */
  .tab_v_c thead th:first-child a,
  .tab_v_c thead th:nth-child(2) a {
    color: #006;
  }

  /* Tabulka .general – propozice závodu */
  .general {
    width: 100% !important;
    display: block;
    border-collapse: collapse;
  }

  .general tbody {
    display: block;
  }

  .general tr {
    display: block;
    border-bottom: 1px solid #dfe5eb;
    padding: 4px 0;
  }

  .general th[scope='row'] {
    display: block;
    white-space: normal !important;
    font-size: 0.82em;
    color: #666;
    padding: 6px 8px 2px;
    background: #f5f7f9;
  }

  .general td {
    display: block;
    padding: 4px 8px 8px;
  }

  /* iframe uvnitř tabulky – přepis inline width/height atributů */
  .general td iframe {
    width: 100% !important;
    height: 68vw !important;
    max-height: 320px;
    display: block;
  }

  /* Obrázek hned za tabulkou .general */
  .general + img {
    display: block;
    max-width: 100%;
    height: auto;
    margin-top: 12px;
  }

  /* Propozice – dl.etapa2 */
  dl.etapa2 {
    margin: 0;
    padding: 0;
  }

  dl.etapa2 dt {
    font-weight: bold;
    margin-top: 12px;
    padding: 4px 0 2px;
    border-top: 1px solid #dfe5eb;
    color: #444;
  }

  dl.etapa2 dd {
    margin: 2px 0;
    padding: 1px 0;
  }

  /* Tabulka bodování .tab – horizontální scroll */
  .tab {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    display: block;
    width: 100%;
  }

  .tab table {
    min-width: 480px;
  }

  .tab.doprava,
  .tab.doprava table {
    text-align: left;
  }
}
