/* ---------- Base resilience ---------- */
html {
  -webkit-text-size-adjust: 100%;
}

img,
video {
  max-width: 100%;
  height: auto;
  display: block;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Containers breathe on small screens (won't affect lg+) */
@media (max-width: 1024px) {
  .container {
    padding-left: 18px;
    padding-right: 18px;
  }
}
@media (max-width: 640px) {
  .container {
    padding-left: 14px;
    padding-right: 14px;
  }
}

/* ---------- Header tweaks ---------- */
.main-header .header-upper .header-inner {
  width: 100%;
}
.main-header .main-menu ul {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: center;
} /* ---------- HEADER NAV ALIGN RIGHT ---------- */
.main-header .main-menu {
  display: flex;
  justify-content: flex-end; /* push nav items to the right */
  align-items: center;
  width: 100%;
}

.main-header .main-menu ul {
  justify-content: flex-end;
  width: 100%;
  text-align: right;
}

.main-header .main-menu ul li a {
  text-align: right;
}

@media (max-width: 640px) {
  .main-header .logo img {
    max-height: 40px;
    width: auto;
  }
}

/* ---------- HERO scaling (keeps lg+ sizes) ---------- */
#home h2 {
  /* clamp smooths sizes from phones to tablets; lg+ classes still apply */
  font-size: clamp(42px, 10vw, 160px) !important;
  line-height: 0.95;
  word-break: break-word;
}
@media (max-width: 1024px) {
  .hero-image {
    margin-top: 0 !important;
  }
}
@media (max-width: 768px) {
  .clienti-reviews .reviews {
    font-size: 14px;
  }
  .hero-content p {
    font-size: 15px;
  }
}

/* ---------- Company scroller ---------- */
.company-list .scroller__inner {
  display: flex;
  gap: 28px;
  align-items: center;
}
.company-list img {
  height: 96px;
  width: auto;
}
@media (max-width: 768px) {
  .company-list img {
    height: 64px;
  }
}
@media (max-width: 480px) {
  .company-list img {
    height: 52px;
  }
}

/* ---------- About counters ---------- */
@media (max-width: 768px) {
  .hero-counter-area {
    gap: 12px;
    flex-wrap: wrap;
  }
  .counter-item .counter-title {
    display: block;
    font-size: 13px;
  }
}

/* ---------- Services: flip cards + responsive widths ---------- */
:root {
  --face-pad-x: 22px;
  --face-pad-y: 20px;
  --face-gap: 8px;
}
@media (min-width: 768px) {
  :root {
    --face-pad-x: 26px;
    --face-pad-y: 22px;
    --face-gap: 10px;
  }
}
@media (min-width: 1024px) {
  :root {
    --face-pad-x: 30px;
    --face-pad-y: 24px;
    --face-gap: 12px;
  }
}

#services {
  --svc-card-bg: #f6f4ee;
  --svc-front-bg: #f6f4ee;
  --svc-back-bg: #0e0e0e;
  --svc-text: #0f0f0f;
  --svc-muted: #6b6b6b;
  --svc-ring: rgba(0, 0, 0, 0.07);
  --svc-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
  --svc-shadow-h: 0 14px 40px rgba(0, 0, 0, 0.14);
  --svc-radius: 16px;
}

#services .service-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--svc-radius);
  background: var(--svc-card-bg);
  box-shadow: var(--svc-shadow);
  transition:
    box-shadow 0.25s ease,
    transform 0.25s ease;
  isolation: isolate;
}
@media (hover: hover) {
  #services .service-item:hover {
    box-shadow: var(--svc-shadow-h);
    transform: translateY(-2px);
  }
}

.card-rotator {
  position: relative;
  width: 100%;
  transform-style: preserve-3d;
  transition: transform 600ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
.card-face {
  position: absolute;
  inset: 0;
  border-radius: var(--svc-radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-face.front {
  background: var(--svc-front-bg);
  color: var(--svc-text);
}
.card-face.back {
  background: var(--svc-back-bg);
  color: #f7f7f7;
  transform: rotateY(180deg);
}

.card-face .face-inner {
  height: 100%;
  padding: var(--face-pad-y) var(--face-pad-x);
  display: grid;
  grid-auto-rows: min-content;
  align-content: start;
  row-gap: var(--face-gap);
}

/* Desktop hover flip; touch/keyboard toggles via JS */
@media (hover: hover) and (pointer: fine) {
  #services .service-item:hover .card-rotator,
  #services .service-item:focus-within .card-rotator {
    transform: rotateY(180deg);
  }
}
.service-item.is-flipped .card-rotator {
  transform: rotateY(180deg);
}

/* Card micro-UI */
#services .svc-chip {
  position: absolute;
  right: 14px;
  top: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--svc-ring);
  color: var(--svc-muted);
  font-size: 18px;
  transition:
    transform 0.2s ease,
    background 0.2s ease;
}
@media (hover: hover) {
  #services .service-item:hover .svc-chip {
    transform: translateY(-2px);
    background: rgba(0, 0, 0, 0.08);
  }
}
#services .svc-num {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font:
    600 11px/1.1 ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial;
  color: var(--svc-muted);
  background: var(--svc-ring);
  padding: 6px 8px;
  border-radius: 8px;
  width: fit-content;
}
#services h4 {
  font:
    800 22px/1.15 "Archivo Black",
    "Oswald",
    ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial;
  letter-spacing: 0.2px;
  margin-top: 2px;
}
#services p {
  font:
    400 15px/1.55 ui-sans-serif,
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    "Helvetica Neue",
    Arial;
  color: var(--svc-muted);
}
#services .svc-divider {
  height: 1px;
  background: rgba(0, 0, 0, 0.06);
  margin-top: 6px;
}
#services .card-face.back h4 {
  color: #fff;
}
#services .card-face.back p {
  color: #d7d7d7;
}

/* Services widths: 1 per row on phones, 2 per row on tablets, preserve custom 55/45 on lg+ */
.svc-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.svc-col {
  flex: 1 1 100%;
}
@media (min-width: 768px) {
  .svc-col {
    flex: 1 1 calc(50% - 12px);
  }
}
/* lg and up: lock to your current layout proportions */
@media (min-width: 1024px) {
  .svc-50 {
    flex: 0 0 calc(50% - 12px);
  }
  .svc-55 {
    flex: 0 0 calc(55% - 12px);
  }
  .svc-45 {
    flex: 0 0 calc(45% - 12px);
  }
  .svc-100 {
    flex: 0 0 calc(100% - 12px);
  }
}
/* tighter content on phones */
@media (max-width: 640px) {
  #services .card-face .face-inner {
    padding: 18px;
    row-gap: 8px;
  }
  #services h4 {
    font-size: 18px;
  }
  #services p {
    font-size: 14px;
  }
  #services .svc-chip {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}

/* ---------- Portfolio: robust fallback grid (keeps lg/xl spans) ---------- */
/* Use flex fallback below xl to avoid awkward gaps when utility grid classes are strict */
.portfolio-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}
.portfolio-item {
  flex: 1 1 100%;
}
@media (min-width: 768px) {
  .portfolio-item {
    flex: 1 1 calc(50% - 12px);
  }
}
@media (min-width: 1280px) {
  /* On xl+, let your existing utility classes rule; stop flex from overriding */
  .portfolio-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 24px;
  }
  .portfolio-item {
    flex: unset;
  }
}
.portfolio-box img {
  width: 100%;
  height: auto;
  display: block;
}
/* Optional: reduce CLS on small by enforcing aspect ratio */
@media (max-width: 768px) {
  .portfolio-box img {
    aspect-ratio: 16/10;
    object-fit: cover;
  }
}

/* ---------- Testimonials / Stories compact padding on small ---------- */
@media (max-width: 768px) {
  .testimonial-item {
    padding: 14px !important;
  }
}
@media (max-width: 1024px) {
  .blog-area .max-w-5xl {
    padding: 20px !important;
  }
}

/* ---------- Contact form comfortable tap targets ---------- */
@media (max-width: 640px) {
  .contact-form .form-group label {
    font-size: 14px;
  }
  .contact-form .form-control {
    font-size: 15px;
    padding: 10px 12px;
  }
  .theme-btn,
  .theme-btn-two {
    padding: 10px 16px;
    font-size: 14px;
  }
}

/* ---------- Footer headline scaling (lg+ untouched) ---------- */
@media (max-width: 640px) {
  .main-footer h2 {
    padding: 12px !important;
    line-height: 0.95;
  }
}

/* ---------- Success & Error messages ---------- */
.input-success {
  display: none;
  color: #047857;
  font-weight: 600;
  background: #d1fae5;
  border: 1px solid #10b981;
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 12px;
  text-align: center;
}
.input-error {
  display: none;
  color: #ff3b3b;
  font-weight: 500;
  background: rgba(255, 50, 50, 0.08);
  border: 1px solid rgba(255, 80, 80, 0.3);
  padding: 10px 14px;
  border-radius: 8px;
  margin-top: 12px;
}

/* ===== STORIES: Responsive layout (scoped) ===== */
#stories .stories-feature {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
@media (min-width: 1024px) {
  #stories .stories-feature {
    grid-template-columns: 1fr 1fr; /* lg+: two columns */
  }
}

#stories .stories-teasers {
  display: grid;
  grid-template-columns: 1fr; /* phones */
  gap: 24px;
}
@media (min-width: 640px) {
  #stories .stories-teasers {
    grid-template-columns: repeat(2, 1fr); /* tablets */
  }
}
@media (min-width: 1024px) {
  #stories .stories-teasers {
    grid-template-columns: repeat(3, 1fr); /* lg+ */
  }
}

/* Media placeholders / thumbnails keep shape */
#stories .thumb {
  aspect-ratio: 16 / 10;
  width: 100%;
  border-radius: 12px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
}
#stories .thumb > div {
  width: 100%;
  height: 100%;
}

/* Feature card container spacing on small/medium */
@media (max-width: 1024px) {
  #stories .feature-card {
    padding: 20px !important;
  }
}

/* Tighter text on phones */
@media (max-width: 640px) {
  #stories .section-title p {
    padding-left: 6px;
    padding-right: 6px;
  }
}

/* ===== CONTACT: responsive fixes (scoped to #contact) ===== */
#contact .contact-content-part {
  display: grid;
  gap: 20px;
}
#contact .about-social ul {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
}
#contact .about-social a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #000000;
  color: inherit;
}
@media (max-width: 640px) {
  #contact .about-social a {
    width: 38px;
    height: 38px;
  }
}

/* Form grid breathing on small/medium */
#contact .contact-form .grid {
  gap: 16px !important;
}
@media (min-width: 768px) {
  #contact .contact-form .grid {
    gap: 20px !important;
  }
}

/* Make controls reliably full-width and non-overflowing */
#contact .form-group {
  position: relative;
  min-width: 0;
}
#contact .form-control,
#contact input[type="text"],
#contact input[type="email"],
#contact textarea {
  width: 100%;
  max-width: 100%;
  padding: 12px 14px 12px 12px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 10px;
  background: #fff;
  font-size: 16px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
#contact textarea {
  resize: vertical;
  min-height: 140px;
}

/* Icon-inside-field alignment */
#contact .for-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  opacity: 0.6;
}
#contact .for-icon i {
  font-size: 16px;
}

/* Labels and spacing */
#contact .form-group > label:not(.for-icon) {
  display: inline-block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
}

/* Button/tap targets */
#contact .theme-btn,
#contact .theme-btn-two {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 10px;
  white-space: nowrap;
}
@media (max-width: 640px) {
  #contact .theme-btn,
  #contact .theme-btn-two {
    width: 100%;
  }
}

/* Success/Error messages */
#contact .input-success,
#contact .input-error {
  display: none;
  margin-top: 12px;
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
}
#contact .input-success {
  color: #047857;
  background: #d1fae5;
  border: 1px solid #10b981;
}
#contact .input-error {
  color: #ff3b3b;
  background: rgba(255, 50, 50, 0.08);
  border: 1px solid rgba(255, 80, 80, 0.3);
}

/* Column comfort on tablets/phones (lg+ layout unchanged) */
@media (max-width: 1024px) {
  #contact .single-contact h2 {
    font-size: 16px;
    margin-top: 6px;
  }
  #contact .single-contact p {
    font-size: 15px;
  }
}
@media (max-width: 640px) {
  #contact .contact-content-part {
    gap: 16px;
  }
  #contact .contact-form .form-group label {
    font-size: 13px;
  }
  #contact .form-control {
    font-size: 15px;
    padding: 11px 12px;
  }
}
/* Preloader dismiss */
.preloader {
  opacity: 1;
  pointer-events: auto;
  transition: opacity 0.35s ease;
}
.preloader.is-done {
  opacity: 0;
  pointer-events: none;
}
