/* ═══════════════════════════════════════════
   NORDIC INDUSTRIAL — Custom layer
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=Instrument+Sans:wght@400;500;600;700&display=swap');

:root {
  --slate-950: #0a0e17;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  /* --blue-* variables are injected per-tenant from views/partials/header.ejs */
}

/* Grain texture overlay */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 200px 200px;
}

/* Entrance animations */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes revealLine {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}
@keyframes subtlePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.animate-fade-up {
  animation: fadeUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.animate-fade-in {
  animation: fadeIn 0.6s ease both;
}
.animate-slide-in {
  animation: slideIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-4 { animation-delay: 0.4s; }
.delay-5 { animation-delay: 0.5s; }
.delay-6 { animation-delay: 0.6s; }
.delay-7 { animation-delay: 0.7s; }

/* Accent line decoration */
.accent-line::after {
  content: '';
  display: block;
  width: 48px;
  height: 3px;
  background: var(--blue-600);
  margin-top: 12px;
  transform-origin: left;
  animation: revealLine 0.8s cubic-bezier(0.22, 1, 0.36, 1) 0.4s both;
}

/* Typography overrides */
.font-display {
  font-family: 'DM Serif Display', Georgia, serif;
}
.font-body {
  font-family: 'Instrument Sans', system-ui, sans-serif;
}

/* Nav link hover effect */
.nav-link {
  position: relative;
}
.nav-link::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--blue-600);
  transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.nav-link:hover::after {
  width: 100%;
}

/* Protocol card hover */
.protocol-card {
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1),
              box-shadow 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.protocol-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.15);
}

/* Form inputs */
.form-input {
  font-family: 'Instrument Sans', system-ui, sans-serif;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.form-input:focus {
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px rgba(var(--brand-rgb), 0.15);
  outline: none;
}
.form-input::placeholder {
  color: var(--slate-400);
  font-weight: 400;
}

/* File upload zone */
.upload-zone {
  position: relative;
  border: 2px dashed var(--slate-300);
  border-radius: 12px;
  transition: border-color 0.3s ease, background 0.3s ease;
  background-size: cover;
  background-position: center;
  cursor: pointer;
}
.upload-zone.ratio-16-9 {
  aspect-ratio: 16 / 9;
  height: auto !important;
}
.upload-zone:hover {
  border-color: var(--blue-600);
  background-color: rgba(var(--brand-rgb), 0.04);
}
.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* Section block (inspection) */
.section-block {
  border-left: 3px solid var(--blue-600);
  transition: background 0.3s ease;
}
.section-block:hover {
  background: rgba(245, 245, 244, 0.7);
}

/* Sortable ghost styling */
.sortable-ghost {
  opacity: 0.4;
  background: rgba(var(--brand-rgb), 0.08) !important;
  border-left-color: var(--blue-400) !important;
}
.sortable-chosen {
  box-shadow: 0 8px 24px -4px rgba(0, 0, 0, 0.12);
}

/* Row-level sortable */
.row-sortable-ghost {
  opacity: 0.3;
  border: 2px dashed var(--blue-400) !important;
  border-radius: 12px;
}
.row-sortable-chosen {
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* Always show row actions on touch devices (no hover) */
@media (hover: none) {
  .touch-visible {
    opacity: 1 !important;
  }
}

/* Button base */
.btn-amber {
  background: var(--blue-600);
  color: white;
  transition: background 0.25s ease, transform 0.15s ease, box-shadow 0.25s ease;
}
.btn-amber:hover {
  background: var(--blue-700);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--brand-rgb), 0.3);
}
.btn-amber:active {
  transform: translateY(0);
}

.btn-outline {
  border: 1.5px solid var(--slate-300);
  color: var(--slate-700);
  transition: all 0.25s ease;
}
.btn-outline:hover {
  border-color: var(--blue-600);
  color: var(--blue-600);
  background: rgba(var(--brand-rgb), 0.04);
}

/* Hero diagonal slice */
.hero-slice {
  clip-path: polygon(0 0, 100% 0, 100% 92%, 0 100%);
}
@media (min-width: 640px) {
  .hero-slice {
    clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
  }
}

/* Step counter */
.step-number {
  font-family: 'DM Serif Display', serif;
  font-size: 3rem;
  line-height: 1;
  color: rgba(var(--brand-rgb), 0.15);
  position: absolute;
  top: -8px;
  left: -4px;
}

/* Mobile menu */
.mobile-menu {
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.mobile-menu.open {
  transform: translateX(0);
}

/* Recommendation priority chips */
.priority-urgent { border-left: 4px solid var(--blue-700); }
.priority-medium { border-left: 4px solid var(--blue-500); }
.priority-low    { border-left: 4px solid var(--slate-400); }

/* Toast notification */
.toast {
  transform: translateY(-100%);
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.show {
  transform: translateY(0);
}

/* Geometric decorative elements */
.geo-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue-600);
  display: inline-block;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--stone-100); }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* Print */
@media print {
  body::before { display: none; }
  nav, .no-print { display: none !important; }
  header { position: fixed; top: 0; left: 0; right: 0; background: #eee; }
  main { margin-top: 4em; }
  .section-block { break-inside: avoid; }
}

/* Smooth page transitions */
html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}
body {
  overflow-x: hidden;
}

/* Prevent long words from overflowing containers */
h1, h2, h3, p, span, a {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* ═══════════════════════════════════════════
   iPad & iPhone optimizations
   ═══════════════════════════════════════════ */

/* Prevent iOS auto-zoom on input focus (requires >= 16px) */
@media screen and (max-width: 768px) {
  .form-input,
  input[type="text"],
  input[type="month"],
  input[type="date"],
  input[type="email"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* Minimum 44px touch targets (Apple HIG) */
@media (pointer: coarse) {
  .collapse-toggle {
    min-width: 44px;
    min-height: 44px;
    width: 44px;
    height: 44px;
  }
  .addRow,
  .btn-outline,
  .btn-amber {
    min-height: 44px;
    padding-top: 0.625rem;
    padding-bottom: 0.625rem;
  }
  .cursor-grab {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  /* Larger upload zones on touch */
  .upload-zone {
    min-height: 160px;
  }
  /* Bigger tap targets for nav links in mobile menu */
  .mobile-menu nav a {
    min-height: 44px;
    display: flex;
    align-items: center;
  }
}

/* iOS momentum scrolling */
.mobile-menu nav {
  -webkit-overflow-scrolling: touch;
}

/* Prevent rubber-band effect on body when menu open */
body.menu-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Disable hover effects on touch (prevents sticky :hover on iOS) */
@media (hover: none) {
  .protocol-card:hover {
    transform: none;
    box-shadow: none;
  }
  .nav-link::after {
    display: none;
  }
  .btn-amber:hover {
    transform: none;
  }
  /* Active states instead */
  .protocol-card:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
  }
  .btn-amber:active {
    opacity: 0.85;
  }
  .btn-outline:active {
    border-color: var(--blue-600);
    color: var(--blue-600);
    background: rgba(var(--brand-rgb), 0.06);
  }
}

/* Stack submit buttons on mobile for full-width thumb reach */
@media (max-width: 480px) {
  .flex.justify-end.gap-3 {
    flex-direction: column-reverse;
  }
  .flex.justify-end.gap-3 > * {
    width: 100%;
    justify-content: center;
  }
}

/* iPad landscape — wider protocol grid */
@media (min-width: 1024px) {
  .protocol-card {
    /* allow 3-col on very wide screens handled by grid */
  }
}

/* Reduce hero padding on small phones */
@media (max-width: 380px) {
  .hero-slice .max-w-6xl {
    padding-top: 3rem;
    padding-bottom: 5rem;
  }
}

/* Reduce grain texture GPU impact on mobile */
@media (max-width: 768px) {
  body::before {
    background-size: 150px 150px;
    opacity: 0.02;
  }
}

/* Safe area horizontal padding */
@supports (padding: env(safe-area-inset-left)) {
  header > div,
  footer > div,
  main section {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
}
