/* ============================================================
   DM Engineering Ltd - Stylesheet
   Plain CSS, no preprocessors, no frameworks.
   ============================================================ */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* Palette: industrial, dark, clean */
  --bg:         #1a1d21;
  --bg-alt:     #22262b;
  --bg-card:    #2a2f35;
  --border:     #3a3f46;
  --text:       #d4d4d4;
  --text-muted: #8a8f96;
  --heading:    #f0f0f0;
  --accent:     #5ba3c9;
  --accent-dim: #3d7a9e;
  --white:      #ffffff;
  --black:      #0d0f11;

  /* Typography */
  --font-body: 'IBM Plex Mono', 'Courier New', monospace;
  --font-heading: 'IBM Plex Mono', 'Courier New', monospace;

  /* Spacing */
  --sp-xs: 0.25rem;
  --sp-sm: 0.5rem;
  --sp-md: 1rem;
  --sp-lg: 2rem;
  --sp-xl: 3rem;
  --sp-2xl: 5rem;

  /* Widths */
  --max-width: 72rem;
  --content-width: 56rem;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* --- Typography --- */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--heading);
  line-height: 1.2;
  font-weight: 700;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; }
h4 { font-size: 1rem; }

p { margin-bottom: var(--sp-md); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s;
}
a:hover { color: var(--white); }

strong { color: var(--heading); }

ul, ol {
  padding-left: var(--sp-lg);
  margin-bottom: var(--sp-md);
}
li { margin-bottom: var(--sp-xs); }

/* --- Layout --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 var(--sp-lg);
}

.container--narrow {
  max-width: var(--content-width);
}

.section {
  padding: var(--sp-xl) 0;
}

.section--alt {
  background-color: var(--bg-alt);
}

.section--dark {
  background-color: var(--black);
}

/* Section with parallax background image */
.section--bg {
  position: relative;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.section--bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to bottom,
    rgba(26, 29, 33, 0.8) 0%,
    rgba(26, 29, 33, 0.5) 160%
  );
  z-index: 0;
}

.section--bg.section--alt::before {
  background: linear-gradient(
    to bottom,
    rgba(26, 29, 33, 0.8) 60%,
    rgba(26, 29, 33, 0.3) 100%
  );
}

.section--bg > .container {
  position: relative;
  z-index: 1;
}

/* --- Grid --- */
.grid {
  display: grid;
  gap: var(--sp-lg);
}

.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }

/* --- Header / Nav --- */
.site-header {
  background-color: var(--black);
  border-bottom: 1px solid var(--border);
  padding: var(--sp-md) 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-md);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
  color: var(--white);
  text-decoration: none;
  font-weight: 700;
  font-size: 1rem;
}

.site-logo img {
  height: 2rem;
  width: auto;
}

.site-logo:hover { color: var(--accent); }

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-lg);
  list-style: none;
  padding: 0;
  margin: 0;
}

.site-nav a {
  color: var(--text-muted);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.site-nav a:hover,
.site-nav a[aria-current="page"] {
  color: var(--white);
}

/* Contact info in header */
.header-contact {
  display: flex;
  align-items: center;
  gap: var(--sp-lg);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.header-contact a { color: var(--text-muted); }
.header-contact a:hover { color: var(--accent); }

/* --- Hero --- */
.hero {
  padding: var(--sp-2xl) 0 var(--sp-xl);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

/* Hero with background image */
.hero--bg {
  min-height: 80vh;
  display: flex;
  align-items: flex-end;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

.hero--bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(26, 29, 33, 0.45);
  z-index: 1;
}

.hero--bg .container {
  position: relative;
  z-index: 2;
}

.hero--bg h1 {
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: var(--sp-sm);
}

.hero .tagline {
  font-size: 1.125rem;
  color: var(--text-muted);
  margin-bottom: var(--sp-lg);
  max-width: 40rem;
}

.hero--bg .tagline {
  color: var(--text);
}

.hero .hero-contact {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-lg);
  font-size: 0.875rem;
  color: var(--text-muted);
  padding-top: var(--sp-md);
  border-top: 1px solid var(--border);
}

.hero--bg .hero-contact {
  border-top-color: rgba(255, 255, 255, 0.15);
}

.hero .hero-contact a { color: var(--accent); }

/* --- Contact Bar (persistent on homepage) --- */
.contact-bar {
  background-color: var(--accent-dim);
  color: var(--white);
  padding: var(--sp-sm) 0;
  font-size: 0.8125rem;
}

.contact-bar .container {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: var(--sp-md) var(--sp-xl);
}

.contact-bar a {
  color: var(--white);
}
.contact-bar a:hover {
  color: var(--heading);
}

/* --- Service Cards --- */
.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  padding: var(--sp-lg);
  transition: border-color 0.2s;
}

.card:hover {
  border-color: var(--accent-dim);
}

.card h3 {
  margin-bottom: var(--sp-sm);
}

.card p {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.card--highlight {
  border-color: var(--accent-dim);
  background: linear-gradient(135deg, var(--bg-card) 0%, rgba(91,163,201,0.08) 100%);
}

/* Cards as clickable links */
a.card {
  display: block;
  position: relative;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
}
a.card::after {
  content: '+';
  position: absolute;
  bottom: var(--sp-sm);
  right: var(--sp-sm);
  font-size: 1.25rem;
  color: var(--accent);
  line-height: 1;
}
a.card:hover { color: var(--text); }
a.card h3 { color: var(--heading); }

/* --- Project Cards --- */
.project-card {
  display: block;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, transform 0.2s;
  overflow: hidden;
}

.project-card:hover {
  border-color: var(--accent-dim);
  transform: translateY(-2px);
  color: var(--text);
}

.project-card img {
  width: 100%;
  height: 12rem;
  object-fit: cover;
  display: block;
}

.project-card .project-card__body {
  padding: var(--sp-md);
}

.project-card h3 {
  font-size: 0.9375rem;
  margin-bottom: var(--sp-xs);
}

.project-card p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0;
}

.project-card .project-card__meta {
  font-size: 0.6875rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--sp-sm);
}

/* --- Image Gallery (project pages) --- */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: var(--sp-sm);
}

.gallery a,
.gallery .gallery__item {
  display: block;
  overflow: hidden;
  aspect-ratio: 4 / 3;
}

.gallery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.3s;
}

.gallery a:hover img {
  transform: scale(1.05);
}

/* --- Lightbox (CSS :target fallback, enhanced with <dialog>) --- */
/* CSS-only lightbox using :target */
.lightbox {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.92);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: var(--sp-lg);
}

.lightbox:target {
  display: flex;
}

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
}

.lightbox__close {
  position: absolute;
  top: var(--sp-md);
  right: var(--sp-lg);
  color: var(--white);
  font-size: 2rem;
  text-decoration: none;
  line-height: 1;
}
.lightbox__close:hover { color: var(--accent); }

/* --- Detail Panel (CSS :target expand-on-click) --- */
.detail-panel {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 500;
  visibility: hidden;
  pointer-events: none;
  transition: visibility 0s linear 0.4s;
}

.detail-panel:target {
  visibility: visible;
  pointer-events: auto;
  transition: visibility 0s linear 0s;
}

.detail-panel__overlay {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.65);
  opacity: 0;
  transition: opacity 0.35s ease;
}

.detail-panel:target .detail-panel__overlay {
  opacity: 1;
}

.detail-panel__body {
  position: relative;
  z-index: 1;
  width: 94%;
  max-width: var(--max-width);
  max-height: 85vh;
  margin: 0 auto;
  background: var(--bg-alt);
  border-bottom: 3px solid var(--accent);
  padding: var(--sp-xl) var(--sp-lg);
  overflow-y: auto;
  transform-origin: center bottom;
  transform: translateY(45vh) scale(0.25);
  opacity: 0;
  transition: transform 0.45s cubic-bezier(0.16, 1, 0.3, 1),
              opacity 0.3s ease;
}

.detail-panel:target .detail-panel__body {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.detail-panel__close {
  position: absolute;
  top: var(--sp-md);
  right: var(--sp-lg);
  font-size: 2rem;
  color: var(--text-muted);
  text-decoration: none;
  line-height: 1;
  z-index: 3;
}
.detail-panel__close:hover { color: var(--accent); }

/* Cascade background images (30-degree diagonal, scrolling) */
.detail-panel__cascade {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}

.detail-panel__cascade::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    rgba(34, 38, 43, 0.93) 0%,
    rgba(34, 38, 43, 0.84) 40%,
    rgba(34, 38, 43, 0.90) 100%
  );
  z-index: 1;
}

.cascade-strip {
  display: flex;
  gap: 0.75rem;
  position: absolute;
  left: -20%;
  will-change: transform;
}

.cascade-strip:first-child {
  top: 8%;
  animation: cascade-scroll 45s linear infinite;
}

.cascade-strip:nth-child(2) {
  top: 52%;
  animation: cascade-scroll-rev 55s linear infinite;
}

.cascade-strip img {
  width: 28rem;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  opacity: 0.22;
  filter: grayscale(30%) contrast(1.1);
  flex-shrink: 0;
}

@keyframes cascade-scroll {
  from { transform: rotate(-30deg) translateX(0); }
  to   { transform: rotate(-30deg) translateX(-50%); }
}

@keyframes cascade-scroll-rev {
  from { transform: rotate(-30deg) translateX(-50%); }
  to   { transform: rotate(-30deg) translateX(0); }
}

/* Clickable panel background → full page */
.detail-panel__link {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
}

/* Pointer cursor on the whole panel body */
.detail-panel__body {
  cursor: pointer;
}

/* Ensure panel content sits above cascade and link */
.detail-panel__grid,
.detail-panel__body > h2,
.detail-panel__body > p,
.detail-panel__body > .mt-md,
.detail-panel__body > .mt-lg {
  position: relative;
  z-index: 2;
  pointer-events: none;
}

details {
  position: relative;
  z-index: 2;
  pointer-events: auto;
}

/* Panel navigation (prev / next) */
.detail-panel__nav {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--sp-xl);
  padding-top: var(--sp-lg);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.detail-panel__nav .btn {
  pointer-events: auto;
  order: 0;
}

.detail-panel__nav-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-muted);
  opacity: 0.45;
  text-decoration: none;
  transition: opacity 0.25s, color 0.25s;
  pointer-events: auto;
}

.detail-panel__nav-btn:hover {
  opacity: 1;
  color: var(--accent);
}

.detail-panel__nav-btn .nav-chevron {
  font-size: 3rem;
  line-height: 1;
  font-weight: 300;
}

.detail-panel__nav-btn .nav-label {
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-weight: 700;
}

/* Mobile: button full-width on top, prev/next below */
@media (max-width: 48rem) {
  .detail-panel__nav .btn {
    width: 100%;
    text-align: center;
    margin-bottom: var(--sp-md);
  }
}

/* Project panel thumbnail strip */
.detail-panel__thumbs {
  position: relative;
  z-index: 2;
  display: flex;
  gap: var(--sp-sm);
  margin-top: var(--sp-lg);
  overflow: hidden;
  pointer-events: none;
}

.detail-panel__thumbs img {
  width: 7rem;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  opacity: 0.55;
  filter: grayscale(20%);
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.detail-panel__grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--sp-xl);
  align-items: start;
}

.detail-panel__grid .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

/* Dialog-based lightbox (progressive enhancement) */
dialog.lightbox-dialog {
  background: transparent;
  border: none;
  padding: 0;
  max-width: 90vw;
  max-height: 90vh;
}

dialog.lightbox-dialog::backdrop {
  background: rgba(0, 0, 0, 0.92);
}

dialog.lightbox-dialog img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  display: block;
}

dialog.lightbox-dialog .lightbox-dialog__close {
  position: absolute;
  top: -2rem;
  right: 0;
  background: none;
  border: none;
  color: var(--white);
  font-size: 1.5rem;
  cursor: pointer;
  font-family: var(--font-body);
}
dialog.lightbox-dialog .lightbox-dialog__close:hover { color: var(--accent); }

/* --- Details / Summary --- */
details {
  border: 1px solid var(--border);
  padding: var(--sp-md) var(--sp-lg);
  margin-bottom: var(--sp-sm);
  background-color: var(--bg-card);
}

summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--heading);
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

summary::after {
  content: '+';
  font-size: 1.25rem;
  color: var(--accent);
  transition: transform 0.2s;
}

details[open] summary::after {
  content: '\2212'; /* minus sign */
}

details > *:not(summary) {
  margin-top: var(--sp-md);
}

/* Slide-close animation for details (abrupt open, smooth close) */
details::details-content {
  interpolate-size: allow-keywords;
  overflow: clip;
  block-size: 0;
  transition: block-size 0.35s ease, content-visibility 0.35s allow-discrete;
}

details[open]::details-content {
  block-size: auto;
  transition-duration: 0s;
}

/* --- About / Text Sections --- */
.about-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: var(--sp-xl);
  align-items: start;
}

.about-grid .label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

/* --- Buttons / Links --- */
.btn {
  display: inline-block;
  padding: var(--sp-sm) var(--sp-lg);
  font-family: var(--font-body);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-decoration: none;
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.btn:hover {
  background-color: var(--accent);
  color: var(--black);
}

.btn--filled {
  background-color: var(--accent);
  color: var(--black);
}
.btn--filled:hover {
  background-color: var(--white);
  color: var(--black);
}

/* --- Footer --- */
.site-footer {
  background-color: var(--black);
  border-top: 1px solid var(--border);
  padding: var(--sp-xl) 0 var(--sp-lg);
  font-size: 0.8125rem;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: var(--sp-xl);
  margin-bottom: var(--sp-xl);
}

.footer-grid h4 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: var(--sp-md);
}

.footer-grid ul {
  list-style: none;
  padding: 0;
}

.footer-grid li { margin-bottom: var(--sp-xs); }

.footer-grid a {
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.footer-grid a:hover { color: var(--white); }

.footer-bottom {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-md);
  color: var(--text-muted);
  font-size: 0.75rem;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-md);
}

/* --- Video Embeds --- */
.video-wrap {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
}

.video-wrap iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* --- Contact Table --- */
.contact-table {
  border-collapse: collapse;
  width: 100%;
}

.contact-table td {
  padding: var(--sp-sm) var(--sp-md) var(--sp-sm) 0;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.contact-table tr:last-child td {
  border-bottom: none;
}

.contact-table td:first-child {
  white-space: nowrap;
  width: 7rem;
  color: var(--text-muted);
}

/* --- Utilities --- */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.mt-sm { margin-top: var(--sp-sm); }
.mt-md { margin-top: var(--sp-md); }
.mt-lg { margin-top: var(--sp-lg); }
.mt-xl { margin-top: var(--sp-xl); }
.mb-md { margin-bottom: var(--sp-md); }
.mb-lg { margin-bottom: var(--sp-lg); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* --- Responsive --- */
@media (max-width: 64rem) {
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
  .footer-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 48rem) {
  :root {
    --sp-lg: 1.5rem;
    --sp-xl: 2rem;
    --sp-2xl: 3rem;
  }

  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.25rem; }
  .hero h1 { font-size: 1.75rem; }

  body { font-size: 0.8125rem; }

  /* Fixed backgrounds break on mobile — fall back to scroll */
  .hero--bg,
  .section--bg {
    background-attachment: scroll;
  }

  .hero--bg {
    min-height: 50vh;
  }

  /* Hide the contact bar on mobile */
  .contact-bar {
    display: none;
  }

  .grid--2,
  .grid--3,
  .grid--4 {
    grid-template-columns: 1fr;
  }

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

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

  .site-header .container {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-contact {
    flex-direction: column;
    gap: var(--sp-xs);
  }

  .gallery {
    grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
  }

  .detail-panel__body {
    width: 100%;
    max-height: 90vh;
  }

  .detail-panel__grid {
    grid-template-columns: 1fr;
    gap: var(--sp-md);
  }
}

@media (max-width: 30rem) {
  .hero h1 { font-size: 1.35rem; }
  h2 { font-size: 1.1rem; }

  .hero .hero-contact {
    flex-direction: column;
    gap: var(--sp-sm);
  }

  .hero .tagline {
    font-size: 0.875rem;
  }

  .card p,
  .project-card p {
    font-size: 0.75rem;
  }
}
