/* JNPA Port Visibility System — Stylesheet */

:root {
  --navy: #0a2550;
  --navy-dark: #071a3a;
  --teal: #0e6e8c;
  --teal-light: #3ca2be;
  --amber: #d97706;
  --green: #059669;
  --red: #dc2626;
  --grey-50: #f8fafc;
  --grey-100: #f1f5f9;
  --grey-200: #e2e8f0;
  --grey-300: #cbd5e1;
  --grey-400: #94a3b8;
  --grey-600: #475569;
  --grey-700: #334155;
  --grey-900: #0f172a;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
  --safe-bottom: env(safe-area-inset-bottom, 0);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--grey-900);
  background: var(--grey-100);
  line-height: 1.5;
  padding-bottom: var(--safe-bottom);
}

a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Top nav ───────────────────────────────────────── */
.topnav {
  background: var(--navy);
  color: var(--white);
  box-shadow: var(--shadow-md);
  position: sticky; top: 0; z-index: 100;
}
.nav-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 60px;
  gap: 2rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--white); }
.brand:hover { text-decoration: none; }
.brand-mark {
  background: var(--teal);
  color: var(--white);
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  font-size: 0.9rem;
  letter-spacing: 1px;
}
.brand-text { font-weight: 600; font-size: 1.05rem; }

.nav-links { display: flex; gap: 1.5rem; flex: 1; }
.nav-links a {
  color: #bfdbfe;
  font-size: 0.95rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  transition: all 0.15s;
}
.nav-links a:hover { color: var(--white); background: rgba(255,255,255,0.1); text-decoration: none; }

.nav-user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.88rem; }
.nav-user-name { color: var(--white); font-weight: 600; }
.nav-user-role {
  color: #bfdbfe;
  padding: 2px 8px;
  border: 1px solid rgba(191,219,254,0.3);
  border-radius: 12px;
  font-size: 0.78rem;
}
.logout-link { color: #bfdbfe; padding-left: 0.75rem; border-left: 1px solid rgba(255,255,255,0.2); }
.logout-link:hover { color: var(--white); }

/* Mobile-only nav panel — hidden on desktop */
.nav-panel { display: none; }

/* Hamburger — hidden on desktop */
.nav-toggle {
  display: none;
  background: transparent;
  border: 0;
  color: var(--white);
  font-size: 1.5rem;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  margin-left: auto;
  border-radius: 4px;
}
.nav-toggle:hover { background: rgba(255,255,255,0.1); }

/* ─── Main content ──────────────────────────────────── */
.main-content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }
.main-content-auth { max-width: 420px; margin: 4rem auto; padding: 1rem; }

/* ─── Flash messages ────────────────────────────────── */
.flash-container { margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin-bottom: 0.5rem;
  font-size: 0.92rem;
  border-left: 4px solid;
}
.flash-success { background: #d1fae5; color: #065f46; border-color: var(--green); }
.flash-error { background: #fee2e2; color: #991b1b; border-color: var(--red); }
.flash-info { background: #dbeafe; color: #1e40af; border-color: var(--teal); }
.flash-warning { background: #fef3c7; color: #92400e; border-color: var(--amber); }

/* ─── Offline banner (PWA) ──────────────────────────── */
.offline-banner {
  background: var(--amber);
  color: var(--white);
  padding: 0.5rem 1rem;
  text-align: center;
  font-size: 0.88rem;
  font-weight: 600;
}

/* ─── Cards & containers ────────────────────────────── */
.card {
  background: var(--white);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--grey-200);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--grey-200);
  gap: 0.75rem;
  flex-wrap: wrap;
}
.card-title { font-size: 1.15rem; font-weight: 600; color: var(--navy); }

/* ─── Page headers ──────────────────────────────────── */
.page-header {
  margin-bottom: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.6rem; font-weight: 700; color: var(--navy); }
.page-subtitle { color: var(--grey-600); font-size: 0.95rem; margin-top: 0.25rem; }
.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ─── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.55rem 1.1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: inherit;
  min-height: 40px;
}
.btn-primary { background: var(--teal); color: var(--white); }
.btn-primary:hover { background: #0a5870; text-decoration: none; color: var(--white); }
.btn-secondary { background: var(--white); color: var(--grey-700); border-color: var(--grey-300); }
.btn-secondary:hover { background: var(--grey-100); text-decoration: none; }
.btn-danger { background: var(--red); color: var(--white); }
.btn-danger:hover { background: #b91c1c; color: var(--white); text-decoration: none; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; min-height: 32px; }
.btn-block { width: 100%; }

/* Bump button touch size on coarse-pointer (touch) devices */
@media (pointer: coarse) {
  .btn { min-height: 44px; padding: 0.65rem 1.1rem; }
  .btn-sm { min-height: 40px; padding: 0.45rem 0.9rem; font-size: 0.88rem; }
}

/* ─── Forms ─────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--grey-700);
  margin-bottom: 0.35rem;
}
.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--grey-300);
  border-radius: 6px;
  font-size: 16px; /* 16px prevents iOS from auto-zooming on focus */
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
  background: var(--white);
}
.form-control:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14,110,140,0.15);
}
.form-hint { font-size: 0.82rem; color: var(--grey-600); margin-top: 0.3rem; }

/* ─── Tables ────────────────────────────────────────── */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--white);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.data-table th {
  background: var(--navy);
  color: var(--white);
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--grey-200);
  font-size: 0.93rem;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--grey-50); }
.data-table .row-total td { font-weight: 700; background: var(--grey-100); }
.data-table .row-total:hover td { background: var(--grey-200); }
.data-table .row-highlight td { background: #ecfdf5; box-shadow: inset 3px 0 0 var(--green); }
.data-table .row-highlight:hover td { background: #d1fae5; }

/* ─── Info tables (key/value pairs, e.g. facility info) ─ */
.info-table { width: 100%; font-size: 0.93rem; border-collapse: collapse; }
.info-table td { padding: 0.35rem 0; vertical-align: top; }
.info-table td:first-child { color: var(--grey-600); width: 200px; }
@media (max-width: 540px) {
  .info-table, .info-table tbody, .info-table tr, .info-table td { display: block; width: 100%; }
  .info-table tr { padding: 0.5rem 0; border-bottom: 1px dashed var(--grey-200); }
  .info-table tr:last-child { border-bottom: none; }
  .info-table td:first-child {
    width: 100%;
    padding: 0;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
  }
  .info-table td + td { padding: 0.15rem 0 0; font-weight: 500; }
}

/* ─── Status badges & colours ──────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-green { background: #d1fae5; color: #065f46; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-red   { background: #fee2e2; color: #991b1b; }
.badge-grey  { background: var(--grey-200); color: var(--grey-700); }

/* ─── Progress bar ──────────────────────────────────── */
.progress {
  height: 10px;
  background: var(--grey-200);
  border-radius: 5px;
  overflow: hidden;
  position: relative;
}
.progress-bar { height: 100%; transition: width 0.3s; }
.progress-green { background: var(--green); }
.progress-amber { background: var(--amber); }
.progress-red { background: var(--red); }
.progress-grey { background: var(--grey-400); }

/* ─── Stat cards ────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--white);
  border-radius: 8px;
  padding: 1.25rem;
  border: 1px solid var(--grey-200);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  font-size: 0.82rem;
  color: var(--grey-600);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}
.stat-sub { font-size: 0.85rem; color: var(--grey-600); margin-top: 0.3rem; }

/* ─── Login page ────────────────────────────────────── */
.login-card {
  background: var(--white);
  border-radius: 10px;
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--teal);
}
.login-header {
  text-align: center;
  margin-bottom: 2rem;
}
.login-header h1 { color: var(--navy); font-size: 1.5rem; margin-bottom: 0.3rem; }
.login-header p { color: var(--grey-600); font-size: 0.92rem; }
.login-brand-mark {
  display: inline-block;
  background: var(--teal);
  color: var(--white);
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  letter-spacing: 2px;
  margin-bottom: 1rem;
}

/* ─── Map ───────────────────────────────────────────── */
#map {
  height: calc(100vh - 60px - 3rem);
  min-height: 500px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--grey-200);
  position: relative;
  z-index: 0;
  isolation: isolate;
}
.map-legend {
  background: var(--white);
  padding: 0.75rem;
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  font-size: 0.85rem;
  line-height: 1.8;
}
.legend-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.legend-dot-green { background: var(--green); }
.legend-dot-amber { background: var(--amber); }
.legend-dot-red { background: var(--red); }
.legend-dot-grey { background: var(--grey-400); }

/* Leaflet's default `.leaflet-container a` rule overrides .btn colors inside popups. */
.leaflet-container a.btn-primary,
.leaflet-container a.btn-primary:hover { color: var(--white); }
.leaflet-container a.btn-secondary,
.leaflet-container a.btn-secondary:hover { color: var(--grey-700); }
.leaflet-container a.btn-danger,
.leaflet-container a.btn-danger:hover { color: var(--white); }

.map-filters {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}
.filter-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--grey-700);
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  font-size: 0.92rem;
}
.checkbox-inline input { width: 18px; height: 18px; }

/* ─── Utility classes ───────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--grey-600); }
.text-sm { font-size: 0.85rem; }
.text-bold { font-weight: 600; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-2 { margin-top: 1rem; }
.flex { display: flex; gap: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* ─── Responsive: tablet/narrow-laptop ─────────────── */
@media (max-width: 900px) {
  .main-content { padding: 1rem; }
  .nav-inner { padding: 0 1rem; gap: 1rem; }
}

/* ─── Responsive: mobile nav ────────────────────────── */
@media (max-width: 768px) {
  .nav-inner { gap: 0.5rem; position: relative; }
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; }
  .brand-text { display: none; }

  /* Slide-down panel containing links + user info */
  .nav-panel {
    display: flex;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--navy);
    box-shadow: var(--shadow-md);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
    flex-direction: column;
  }
  .nav-panel.open { max-height: 80vh; overflow-y: auto; }
  .nav-panel .nav-links {
    flex-direction: column;
    gap: 0;
    padding: 0.5rem 0;
  }
  .nav-panel .nav-links a {
    padding: 0.9rem 1.25rem;
    border-radius: 0;
    font-size: 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }
  .nav-panel .nav-user {
    padding: 1rem 1.25rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  .nav-panel .logout-link {
    padding-left: 0;
    border-left: none;
    margin-top: 0.35rem;
  }

  /* On desktop nav-links/nav-user live directly in nav-inner; hide those copies on mobile */
  .nav-inner > .nav-links,
  .nav-inner > .nav-user { display: none; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-title { font-size: 1.3rem; }
  .header-actions { flex-wrap: wrap; }
  .header-actions .btn { flex: 1 1 auto; }

  .card { padding: 1rem; }
  .stat-value { font-size: 1.6rem; }

  /* Map on mobile: fill more of the screen, compact filters */
  #map {
    height: calc(100vh - 60px - 11rem);
    min-height: 340px;
  }
  .map-filters {
    gap: 0.5rem;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
    -webkit-overflow-scrolling: touch;
  }
  .map-filters > * { flex-shrink: 0; }
  .map-filters input[type="search"] { width: 180px !important; }

  .data-table th, .data-table td {
    padding: 0.6rem 0.7rem;
    font-size: 0.88rem;
  }

  .login-card { padding: 1.75rem 1.25rem; }
}

/* ─── Responsive: stacked-card tables on small screens ─ */
@media (max-width: 640px) {
  /* Any table inside .table-scroll.stack-on-mobile transforms to cards */
  .table-scroll.stack-on-mobile { overflow-x: visible; }
  .table-scroll.stack-on-mobile .data-table,
  .table-scroll.stack-on-mobile .data-table thead,
  .table-scroll.stack-on-mobile .data-table tbody,
  .table-scroll.stack-on-mobile .data-table tr,
  .table-scroll.stack-on-mobile .data-table td {
    display: block;
    width: 100%;
    box-shadow: none;
  }
  .table-scroll.stack-on-mobile .data-table thead { display: none; }
  .table-scroll.stack-on-mobile .data-table tr {
    background: var(--white);
    border: 1px solid var(--grey-200);
    border-radius: 8px;
    margin-bottom: 0.75rem;
    padding: 0.5rem 0.75rem;
    box-shadow: var(--shadow-sm);
  }
  .table-scroll.stack-on-mobile .data-table td {
    border-bottom: 1px dashed var(--grey-200);
    padding: 0.5rem 0;
    text-align: left !important;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    word-break: break-word;
    overflow-wrap: anywhere;
    min-width: 0;
  }
  .table-scroll.stack-on-mobile .data-table td > * { min-width: 0; max-width: 100%; }
  .table-scroll.stack-on-mobile .data-table td:last-child { border-bottom: none; }
  .table-scroll.stack-on-mobile .data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--grey-600);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    max-width: 45%;
  }
  .table-scroll.stack-on-mobile .data-table td:not([data-label])::before { content: ""; }
  .table-scroll.stack-on-mobile .data-table tr:hover td { background: transparent; }
  /* Number/total rows in stacked view: full-width emphasis */
  .table-scroll.stack-on-mobile .data-table .row-total td { background: transparent; }
  .table-scroll.stack-on-mobile .data-table .row-total {
    background: var(--grey-100);
    border-color: var(--grey-300);
  }
}
