/* Mobile Optimization Styles - Card-based Layout */
/* Toto je doplňkový soubor k styles.css pro mobilní optimalizace */

/* ====================================== */
/* Hamburger Menu - Mobile Navigation */
/* ====================================== */

/* Hide mobile controls on desktop by default */
.mobile-controls,
.mobile-menu {
  display: none;
}

/* Hamburger button styles */
.hamburger-btn {
  width: 44px;
  height: 44px;
  background: transparent;
  border: 2px solid var(--border-dark);
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  padding: 0;
  transition: all 0.3s ease;
}

.hamburger-btn:hover {
  background: var(--bg);
}

.hamburger-line {
  width: 20px;
  height: 2px;
  background: var(--border-dark);
  transition: all 0.3s ease;
  display: block;
}

/* Hamburger animation when active */
.hamburger-btn.active .hamburger-line:nth-child(1) {
  transform: translateY(6px) rotate(45deg);
}

.hamburger-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.hamburger-btn.active .hamburger-line:nth-child(3) {
  transform: translateY(-6px) rotate(-45deg);
}

/* Mobile language selector */
.mobile-language-selector {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 2px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 14px;
  cursor: pointer;
  font-family: inherit;
  min-height: 44px;
  width: 70px;
}

/* Mobile menu dropdown */
.mobile-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--panel);
  border: 2px solid var(--border-dark);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  margin-top: 8px;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  min-width: 180px;
}

.mobile-menu.open {
  display: block;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.mobile-menu-item {
  display: block;
  width: 100%;
  padding: 12px 20px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.mobile-menu-item:last-child {
  border-bottom: none;
}

.mobile-menu-item:hover {
  background: var(--bg);
}

/* ====================================== */
/* Mobile Breakpoints - Progressive Enhancement */
/* ====================================== */

/* Small phones (320px - 479px) */
@media (max-width: 479px) {
  /* Show mobile navigation, hide desktop */
  .desktop-controls {
    display: none !important;
  }

  .mobile-controls {
    display: flex !important;
    gap: 12px;
    align-items: center;
  }

  /* Make header position relative for dropdown */
  header {
    position: relative;
  }

  /* Hide desktop-only columns */
  .s-labor:not(.service-detail-value),
  .s-overhead:not(.service-detail-value),
  .s-subtotal:not(.service-detail-value),
  .s-tax:not(.service-detail-value),
  .s-price:not(.service-detail-value) {
    display: none;
  }
  .container {
    max-width: 100%;
    margin: 16px auto;
    padding: 0 12px;
  }

  h1 {
    font-size: 20px;
  }

  h2 {
    font-size: 18px;
  }

  /* Touch-friendly buttons - minimum 44px height */
  .btn,
  button {
    min-height: 44px;
    padding: 12px 16px;
    font-size: 14px;
  }

  /* Touch-friendly inputs */
  input[type="text"],
  input[type="number"],
  select,
  textarea {
    min-height: 44px;
    padding: 12px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Header optimization */
  header {
    flex-direction: column;
    text-align: center;
    gap: 16px;
  }

  /* Stack control buttons */
  .header-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }

  /* Services Table - Card Layout */
  .table {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .row.header {
    display: none !important;
  }

  /* Show mobile-only labels */
  .mobile-only {
    display: block !important;
  }

  /* Service Row as Card */
  .row.service {
    display: flex !important;
    flex-direction: column !important;
    gap: 12px;
    padding: 16px;
    background: var(--panel);
    border: 2px solid var(--border);
    border-radius: 4px;
    position: relative;
    grid-template-columns: unset !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }

  /* Service name and note group */
  .row.service .s-name {
    font-size: 16px;
    font-weight: 600;
    width: calc(100% - 50px); /* Space for note icon */
    margin-bottom: 8px;
  }

  /* Service wrappers become visible */
  .service-inputs,
  .service-totals {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    width: 100%;
  }

  .service-inputs {
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
  }

  .service-totals {
    padding-top: 12px;
  }

  /* Three column layout for specific fields */
  .service-inputs {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .service-inputs .service-detail:nth-child(1),
  .service-inputs .service-detail:nth-child(2) {
    grid-column: span 1;
  }

  .service-inputs .service-detail:nth-child(3) {
    grid-column: span 1;
  }

  .service-inputs .service-detail:nth-child(4),
  .service-inputs .service-detail:nth-child(5) {
    grid-column: span 1.5;
  }

  /* Service detail styling */
  .service-detail {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .service-detail-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
  }

  .service-detail-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
  }

  /* Make inputs full width in mobile */
  .service-detail input,
  .service-detail select {
    width: 100%;
    font-size: 14px;
  }

  /* Special styling for total */
  .service-detail:has(.total) .service-detail-value {
    color: var(--accent);
    font-size: 16px;
  }

  /* Delete button - positioned absolutely */
  .delete-icon {
    position: absolute;
    top: 16px;
    right: 16px;
    min-width: 44px;
    min-height: 44px;
  }

  /* Note icon */
  .note-icon {
    min-width: 44px;
    min-height: 44px;
  }

  /* Monthly plan as cards */
  .monthly-plan-row {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 4px;
  }

  /* 3-column grid responsive */
  .grid.cols-3 {
    display: block !important;
  }

  .grid.cols-3 > div {
    width: 100% !important;
    margin-bottom: 16px;
  }

  /* Make all inputs and selects full width on mobile */
  .grid.cols-3 input,
  .grid.cols-3 select {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    font-size: 16px !important; /* Prevent iOS zoom */
  }

  /* Variant rows stack vertically */
  .variant-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Footer buttons stack */
  .footer {
    flex-direction: column;
    gap: 12px;
  }

  .footer .btn {
    width: 100%;
  }

  /* Modal optimization */
  .modal-content {
    width: 95%;
    max-width: none;
    margin: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Donation buttons - 2x2 grid */
  .donation-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .donation-buttons a {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 12px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    font-weight: 600;
    font-size: 12px;
  }
}

/* Medium phones (480px - 767px) */
@media (min-width: 480px) and (max-width: 767px) {
  /* Show mobile navigation, hide desktop */
  .desktop-controls {
    display: none !important;
  }

  .mobile-controls {
    display: flex !important;
    gap: 12px;
    align-items: center;
  }

  /* Make header position relative for dropdown */
  header {
    position: relative;
  }

  .container {
    max-width: 100%;
    margin: 24px auto;
    padding: 0 16px;
  }

  /* Touch-friendly elements */
  .btn,
  button,
  input[type="text"],
  input[type="number"],
  select,
  textarea {
    min-height: 44px;
    font-size: 16px;
  }

  /* Services - Enhanced Card Layout */
  .row.service {
    display: grid;
    grid-template-areas:
      "name name delete"
      "details details details"
      "totals totals totals";
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    padding: 16px;
    background: var(--panel);
    border: 2px solid var(--border);
    border-radius: 4px;
  }

  .row.service .s-name {
    grid-area: name;
    font-size: 16px;
    font-weight: 600;
  }

  .row.service .delete-icon {
    grid-area: delete;
  }

  /* Service inputs in grid */
  .service-inputs {
    grid-area: details;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* Service totals */
  .service-totals {
    grid-area: totals;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }

  /* Variant grid responsive */
  .grid.cols-3 {
    grid-template-columns: 1fr;
  }

  /* Donation buttons - horizontal */
  .donation-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
  }

  .donation-buttons a {
    min-height: 44px;
    padding: 12px 20px;
  }
}

/* Tablets and medium displays (768px - 1600px) */
@media (min-width: 768px) and (max-width: 1600px) {
  /* Keep most desktop layout but optimize touch */
  .btn,
  button {
    min-height: 40px;
  }

  input[type="text"],
  input[type="number"],
  select,
  textarea {
    min-height: 40px;
    font-size: 14px;
  }

  /* Services table - horizontal scroll wrapper */
  .table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding-bottom: 20px; /* Space for scrollbar */
    margin-bottom: -20px; /* Compensate padding to avoid extra space */
  }

  /* Keep desktop grid columns - table will be wider than viewport */
  .row {
    min-width: 1200px; /* Force table to be wider than tablet viewport */
  }

  /* Sticky first column (Name) during horizontal scroll */
  .row > .s-name {
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 1;
  }

  .row.header > .h-name {
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 2;
  }

  /* 3-column grid to 2 columns */
  .grid.cols-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Monthly Plan table - horizontal scroll */
  section:has(.row.plan) .table {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px; /* Space for scrollbar */
    margin-bottom: -20px; /* Compensate padding to avoid extra space */
  }

  .row.plan {
    min-width: 1000px; /* Force table to be wider than tablet viewport */
  }

  /* Sticky first column (Service name) in Monthly Plan during horizontal scroll */
  .row.plan > .p-name {
    position: sticky;
    left: 0;
    background: var(--bg);
    z-index: 1;
  }

  /* Sticky first column in Monthly Plan header */
  section:has(.row.plan) .row.header > div:first-child {
    position: sticky;
    left: 0;
    background: var(--panel);
    z-index: 2;
  }
}

/* ====================================== */
/* Collapsible Sections for Mobile */
/* ====================================== */
@media (max-width: 767px) {
  /* Section headers clickable */
  .card h2 {
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  /* Collapse indicator */
  .card h2::after {
    content: '▼';
    font-size: 14px;
    color: var(--muted);
    transition: transform 0.3s ease;
  }

  .card.collapsed h2::after {
    transform: rotate(-90deg);
  }

  /* Collapsed state */
  .card.collapsed > *:not(h2) {
    display: none;
  }

  /* Help icon positioning in header */
  .help-icon {
    margin-left: auto;
    margin-right: 8px;
  }
}

/* ====================================== */
/* Sticky Headers & Navigation */
/* ====================================== */
@media (max-width: 767px) {
  /* Sticky section headers */
  .card h2 {
    position: sticky;
    top: 0;
    background: var(--panel);
    z-index: 10;
    padding: 16px 0;
    margin: -24px -24px 16px;
    padding: 16px 24px;
    border-bottom: 2px solid var(--border);
  }

  /* Scroll to top button */
  .scroll-to-top {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    background: var(--border-dark);
    color: var(--panel);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    z-index: 100;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    border: 2px solid var(--panel);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  }

  .scroll-to-top.visible {
    opacity: 1;
    visibility: visible;
  }
}

/* ====================================== */
/* Print Styles Override for Mobile */
/* ====================================== */
@media print {
  /* Ensure mobile styles don't affect print */
  .card {
    display: block !important;
  }

  .card h2::after {
    display: none;
  }

  .row {
    display: grid !important;
    grid-template-columns: auto !important;
  }

  .scroll-to-top {
    display: none !important;
  }
}

/* ====================================== */
/* Accessibility & Performance */
/* ====================================== */

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card {
    border-width: 3px;
  }

  .btn {
    border-width: 3px;
  }

  input, select, textarea {
    border-width: 2px;
  }
}

/* ====================================== */
/* Mobile Warning Modal */
/* ====================================== */

/* Make modal content more mobile-friendly on small screens */
@media (max-width: 767px) {
  .mobile-warning-modal .modal-content {
    margin: 16px;
    padding: 20px;
  }

  .mobile-warning-modal h3 {
    font-size: 18px !important;
  }

  .mobile-warning-modal p,
  .mobile-warning-modal ul {
    font-size: 13px !important;
  }

  .mobile-warning-modal .btn {
    width: 100%;
    padding: 14px 20px;
  }
}