/* =============================================
   i Yard — Design System
   ============================================= */

/* --- CSS Variables --- */
:root {
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 70px;
  --top-nav-height: 64px;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #64748b;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --info: #0891b2;

  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --bg-sidebar-hover: rgba(255,255,255,0.08);
  --bg-sidebar-active: #2563eb;

  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --text-sidebar: rgba(255,255,255,0.82);
  --text-sidebar-active: #ffffff;

  --border-color: #e2e8f0;
  --border-radius-sm: 0.375rem;
  --border-radius: 0.75rem;
  --border-radius-lg: 1rem;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.10), 0 4px 6px -2px rgba(0,0,0,0.05);

  --transition: all 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-app);
  color: var(--text-primary);
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* =============================================
   LAYOUT
   ============================================= */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 1040;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.28s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.28s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.sidebar-brand {
  height: var(--top-nav-height);
  min-height: var(--top-nav-height);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  gap: 0.625rem;
  flex-shrink: 0;
  color: #fff;
  text-decoration: none;
}

.sidebar-brand i {
  font-size: 1.4rem;
  color: var(--primary);
}

.sidebar-brand span {
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-section {
  padding: 1rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
}

.sidebar-nav {
  list-style: none;
  padding: 0.5rem 0;
  margin: 0;
  flex: 1;
}

.sidebar-nav .nav-item {
  margin: 0.125rem 0.625rem;
}

.sidebar-nav .nav-link {
  /*color: var(--text-sidebar);*/
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.688rem 1rem;
  border-radius: var(--border-radius-sm);
  text-decoration: none;
  font-size: 0.9rem;
  /*font-weight: 500;*/
  transition: var(--transition);
  white-space: nowrap;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-nav .nav-link i {
  font-size: 1.05rem;
  width: 1.25rem;
  flex-shrink: 0;
  opacity: 0.8;
  transition: var(--transition);
}

.sidebar-nav .nav-link:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.sidebar-nav .nav-link:hover i { opacity: 1; }

.sidebar-nav .nav-link.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
  /*box-shadow: 0 2px 8px rgba(37,99,235,0.45);*/
  background-color: rgba(37, 99, 235, 0.1);
  /*color: #2563eb;*/
  font-weight: 500;
  border-radius: 6px;
}

.sidebar-nav .nav-link.active i { opacity: 1; }

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.75rem;
  color: rgba(255,255,255,0.3);
  text-align: center;
  flex-shrink: 0;
}

/* Collapsed sidebar (desktop only) */
body.sidebar-collapsed .sidebar {
  width: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .main-content {
  margin-left: var(--sidebar-collapsed-width);
}

body.sidebar-collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
  gap: 0;
}

body.sidebar-collapsed .sidebar-brand i {
  font-size: 1.6rem;
}

body.sidebar-collapsed .sidebar-brand span,
body.sidebar-collapsed .sidebar-section,
body.sidebar-collapsed .sidebar-footer,
body.sidebar-collapsed .sidebar-nav .nav-link span {
  display: none;
}

body.sidebar-collapsed .sidebar-nav .nav-item {
  margin: 0.25rem 0.5rem;
}

body.sidebar-collapsed .sidebar-nav .nav-link {
  justify-content: center;
  padding: 0.75rem;
}

body.sidebar-collapsed .sidebar-nav .nav-link i {
  width: auto;
  font-size: 1.25rem;
  margin: 0;
}

/* Mobile overlay backdrop */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1039;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  opacity: 0;
  transition: opacity 0.28s ease;
}

.sidebar-backdrop.show {
  display: block;
  opacity: 1;
}

/* =============================================
   MAIN CONTENT
   ============================================= */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
}

/* =============================================
   TOP NAV
   ============================================= */
.top-nav {
  height: var(--top-nav-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 1020;
  box-shadow: var(--shadow-sm);
  gap: 1rem;
}

.top-nav .breadcrumb {
  margin: 0;
  font-size: 0.875rem;
}

.top-nav .breadcrumb-item a {
  color: var(--primary);
  text-decoration: none;
}

.top-nav .breadcrumb-item a:hover { text-decoration: underline; }

.search-form { position: relative; }

.search-form .input-group { border-radius: var(--border-radius); overflow: hidden; }

.search-form .input-group-text {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-right: none;
  color: var(--text-secondary);
}

.search-form .form-control {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-left: none;
  min-width: 180px;
  font-size: 0.875rem;
}

.search-form .form-control:focus {
  box-shadow: none;
  border-color: var(--primary);
  background: #fff;
}

#globalSearchResults {
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  overflow: hidden;
  max-height: 320px;
  overflow-y: auto;
}

#globalSearchResults .list-group-item {
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  border: none;
  border-bottom: 1px solid var(--border-color);
}

/* =============================================
   CONTENT
   ============================================= */
.content-body {
  flex: 1;
  padding: 1.5rem;
}

.content-footer {
  padding: 0.875rem 1.5rem;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Page title */
.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0;
  letter-spacing: -0.02em;
}

/* =============================================
   AUTH PAGES
   ============================================= */
.auth-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 50%, #2563eb 100%);
  padding: 1rem;
  position: relative;
  overflow: hidden;
}

.auth-wrapper::before {
  content: '';
  position: absolute;
  top: -30%;
  right: -10%;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background: rgba(255,255,255,0.05);
}

.auth-wrapper::after {
  content: '';
  position: absolute;
  bottom: -20%;
  left: -10%;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}

.auth-card {
  background: #fff;
  border-radius: var(--border-radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 420px;
  padding: 2.5rem;
  position: relative;
  z-index: 1;
}

.auth-logo {
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  color: #fff;
  margin: 0 auto 1.25rem;
  box-shadow: 0 4px 14px rgba(37,99,235,0.4);
}

.auth-title {
  font-size: 1.5rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

/* =============================================
   CARDS
   ============================================= */
.card {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-sm);
  background: var(--bg-card);
}

.card-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--border-radius) var(--border-radius) 0 0 !important;
}

/* Stat Cards */
.stat-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  padding: 1.375rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: transparent;
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--border-radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-value {
  font-size: 1.625rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  margin-top: 0.125rem;
}

.stat-trend {
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 0.25rem;
}

/* Table Card */
.table-card {
  background: var(--bg-card);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.table-card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.table-card-header .title {
  font-weight: 600;
  font-size: 0.9375rem;
  margin: 0;
}

/* =============================================
   TABLES
   ============================================= */
.table {
  font-size: 0.875rem;
  margin: 0;
}

.table th {
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: #f8fafc;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
  padding: 0.875rem 1rem;
}

.table td {
  padding: 0.875rem 1rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.table tbody tr {
  transition: background 0.12s ease;
}

.table tbody tr:hover { background: #f8fafc; }
.table tbody tr:last-child td { border-bottom: none; }

/* =============================================
   FORMS
   ============================================= */
.form-label {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-primary);
  margin-bottom: 0.375rem;
}

.form-control, .form-select {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
  padding: 0.5rem 0.875rem;
  color: var(--text-primary);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
  outline: none;
}

.form-control::placeholder { color: var(--text-muted); }

.input-group-text {
  border: 1px solid var(--border-color);
  background: #f8fafc;
  color: var(--text-secondary);
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--border-radius-sm);
  padding: 0.5rem 1rem;
  transition: var(--transition);
  border-width: 1px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.35);
}

.btn-primary:active { transform: translateY(0); }

.btn-outline-primary {
  color: var(--primary);
  border-color: var(--primary);
}

.btn-outline-primary:hover {
  background: var(--primary);
  color: #fff;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.875rem;
    border-radius: 0.25rem;
}

.btn-lg {
    padding: 0.75rem 1.5rem;
    font-size: 1.25rem;
    border-radius: 0.5rem;
}

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-sm);
}

/* =============================================
   BADGES
   ============================================= */
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.3em 0.65em;
  border-radius: 99px;
  letter-spacing: 0.02em;
}

/* Status badges */
.badge-active   { background: #dcfce7; color: #15803d; }
.badge-inactive { background: #fee2e2; color: #b91c1c; }
.badge-pending  { background: #fef9c3; color: #a16207; }
.badge-approved { background: #dbeafe; color: #1d4ed8; }

/* =============================================
   ALERTS
   ============================================= */
.alert {
  border: none;
  border-radius: var(--border-radius-sm);
  font-size: 0.875rem;
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.alert-success { background: #f0fdf4; color: #15803d; }
.alert-danger   { background: #fef2f2; color: #b91c1c; }
.alert-warning  { background: #fffbeb; color: #92400e; }
.alert-info     { background: #eff6ff; color: #1e40af; }

/* =============================================
   DROPDOWNS
   ============================================= */
.dropdown-menu {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  padding: 0.375rem;
  min-width: 180px;
}

.dropdown-item {
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  color: var(--text-primary);
  transition: background 0.12s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.dropdown-item:hover { background: var(--primary-light); color: var(--primary); }
.dropdown-item i { font-size: 0.9rem; opacity: 0.7; }
.dropdown-divider { border-color: var(--border-color); margin: 0.25rem 0; }

/* =============================================
   PAGINATION
   ============================================= */
.pagination {
  gap: 0.25rem;
  margin: 0;
}

.page-link {
  border-radius: var(--border-radius-sm) !important;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
  transition: var(--transition);
}

.page-link:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.page-item.active .page-link { background: var(--primary); border-color: var(--primary); }

/* =============================================
   MODAL
   ============================================= */
.modal-content {
  border: none;
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
  padding: 1.125rem 1.25rem;
}

.modal-footer {
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.25rem;
}

/* =============================================
   UTILITY
   ============================================= */
.text-primary-custom { color: var(--primary) !important; }
.bg-primary-light { background: var(--primary-light) !important; }

/* Action buttons group */
.btn-action-group { display: flex; gap: 0.375rem; flex-wrap: wrap; }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
}
.empty-state i { font-size: 3rem; margin-bottom: 0.75rem; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; margin: 0; }

/* Filter bar */
.filter-bar {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Chart wrapper */
.chart-wrapper {
  position: relative;
  width: 100%;
}

/* PWA install banner */
#pwa-install-bar {
  display: none;
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--bg-sidebar);
  color: #fff;
  padding: 0.875rem 1.25rem;
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.875rem;
  max-width: calc(100vw - 2rem);
  animation: slideUp 0.3s ease;
}

#pwa-install-bar.hidden { display: none !important; }

@keyframes slideUp {
  from { transform: translateX(-50%) translateY(1rem); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* =============================================
   RESPONSIVE
   ============================================= */

/* Tablet */
@media (max-width: 1024px) {
  .search-form .form-control { min-width: 140px; }
}

/* Mobile */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: none;
  }

  .sidebar.show {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    margin-left: 0 !important;
  }

  .content-body {
    padding: 1rem;
  }

  .top-nav {
    padding: 0 1rem;
  }

  .table-card-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-value { font-size: 1.375rem; }

  .search-form {
    display: none;
  }

  .search-form.mobile-visible {
    display: block;
    position: fixed;
    top: var(--top-nav-height);
    left: 0;
    right: 0;
    z-index: 1030;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
  }

  .search-form.mobile-visible .form-control {
    min-width: unset;
    width: 100%;
  }

  .page-title { font-size: 1.125rem; }

  /* Stack action buttons on mobile */
  .btn-action-group { gap: 0.25rem; }
  .btn-action-group .btn { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
}

/* Small mobile */
@media (max-width: 575.98px) {
  .auth-card { padding: 1.75rem 1.25rem; }
  .content-body { padding: 0.875rem; }

  .table-responsive-stack thead { display: none; }
  .table-responsive-stack tbody tr {
    display: block;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    margin-bottom: 0.75rem;
    padding: 0.5rem;
  }
  .table-responsive-stack tbody td {
    display: flex;
    justify-content: space-between;
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
  }
  .table-responsive-stack tbody td:last-child { border-bottom: none; }
  .table-responsive-stack tbody td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
  }
}

/* Print */
@media print {
  .sidebar, .top-nav, .content-footer, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0 !important; }
  .content-body { padding: 0; }
}

/* ═══════════════════════════════════════════════
   Container Diagram — Survey Damage Selection
   ═══════════════════════════════════════════════ */
.container-diagram-wrapper {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
}

.container-diagram-flex {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.container-svg-wrap {
  flex: 0 0 auto;
  width: 100%;
  max-width: 840px;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem;
  box-shadow: var(--shadow-sm);
}

.container-svg-wrap svg .zone {
  transition: fill 0.15s ease, opacity 0.15s ease;
}

/* Legend sidebar */
.container-legend-list {
  flex: 1 1 200px;
  min-width: 180px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}

.legend-item:hover {
  background: #e8f0fe;
  border-color: #3b5bdb;
}

.legend-item.legend-active {
  background: #fff0f0;
  border-color: #f03e3e;
  animation: legendPulse 0.4s ease;
}

@keyframes legendPulse {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.legend-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: #3b5bdb;
  color: #fff;
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  flex-shrink: 0;
}

.legend-text {
  font-size: 0.75rem;
  color: var(--text-primary);
  line-height: 1.2;
}

/* Zone badge in damage table rows */
.zone-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px dashed var(--border-color);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 600;
}

.zone-badge.zone-badge-filled {
  background: #3b5bdb;
  color: #fff;
  border: none;
}

/* Damage code chips */
.damage-code-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 0.5rem 0.75rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius-md);
}

.damage-code-chip {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

@media (max-width: 768px) {
  .container-diagram-flex { flex-direction: column; }
  .container-svg-wrap     { max-width: 100%; }
  .legend-grid            { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
  .legend-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════
   Damage Table — Comfortable desktop & mobile card stack
   ═══════════════════════════════════════════════ */
#damageTable {
  min-width: 1100px; /* force horizontal scroll on small desktops instead of crushing columns */
}
#damageTable tbody .damage-row td {
  padding: 0.5rem 0.5rem;
  vertical-align: middle;
}
#damageTable tbody .damage-row td .form-control,
#damageTable tbody .damage-row td .form-select {
  font-size: 0.95rem;
  min-height: 40px;
  padding: 0.5rem 0.75rem;
}
#damageTable tbody .damage-row td .form-select-lg,
#damageTable tbody .damage-row td .form-control-lg {
  font-size: 1rem;
  min-height: 44px;
  padding: 0.55rem 0.85rem;
}
#damageTable tbody .damage-row td textarea.form-control {
  resize: vertical;
  min-height: 52px;
  padding: 0.5rem 0.75rem;
}
#damageTable tbody .damage-row td .form-check-input {
  width: 1.3rem;
  height: 1.3rem;
}
#damageTable tbody .damage-row td .form-check-label {
  font-size: 0.95rem;
}
#damageTable tbody .damage-row td .btn.remove-damage-row {
  padding: 0.45rem 0.7rem;
}

@media (max-width: 991px) {
  #damageTable { width: 100%; min-width: auto; }
  .damage-table-wrap { overflow-x: visible !important; }

  #damageTable thead { display: none; }

  #damageTable tbody .damage-row {
    display: block;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    background: #fff;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }

  #damageTable tbody .damage-row td {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border: none;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.95rem;
  }

  #damageTable tbody .damage-row td:last-child {
    border-bottom: none;
  }

  #damageTable tbody .damage-row td::before {
    content: attr(data-label);
    flex: 0 0 120px;
    padding-top: 0.45rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
  }

  #damageTable tbody .damage-row td.row-num-cell {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    justify-content: center;
    padding: 0.5rem 0.85rem;
  }
  #damageTable tbody .damage-row td.row-num-cell::before { display: none; }

  #damageTable tbody .damage-row td select,
  #damageTable tbody .damage-row td input[type="text"],
  #damageTable tbody .damage-row td input[type="number"],
  #damageTable tbody .damage-row td textarea {
    flex: 1;
    width: 100%;
    font-size: 1rem;
    min-height: 44px;
    padding: 0.55rem 0.85rem;
  }
  #damageTable tbody .damage-row td textarea {
    min-height: 72px;
  }
  #damageTable tbody .damage-row td .form-select-lg,
  #damageTable tbody .damage-row td .form-control-lg {
    min-height: 48px;
  }

  #damageTable tbody .damage-row td.repair-cell {
    justify-content: flex-start;
    align-items: center;
  }
  #damageTable tbody .damage-row td.repair-cell::before {
    padding-top: 0;
  }

  #damageTable tbody .damage-row td.remove-cell {
    justify-content: flex-end;
    border-bottom: none;
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
  }
  #damageTable tbody .damage-row td.remove-cell::before { display: none; }

  #damageTable tbody .damage-row td.zone-cell { display: none; }

  #damageTable tfoot tr {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-top: 0.25rem;
  }
  #damageTable tfoot td { display: inline; border: none; padding: 0; }
  #damageTable tfoot td:first-child { display: none; }
  #damageTable tfoot #totalCostDisplay { font-size: 1.1rem; }
}

/* ═══════════════════════════════════════════════
   Damage Entry Modal (desktop only)
   ═══════════════════════════════════════════════ */
#damageModal .modal-body {
  padding: 1.5rem;
}
#damageModal .form-label {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}
#damageModal .form-select,
#damageModal .form-control {
  font-size: 1rem;
  min-height: 42px;
}
#damageModal textarea.form-control {
  min-height: 80px;
  resize: vertical;
}
#damageModal .form-check-input {
  width: 1.3rem;
  height: 1.3rem;
}
#damageModal .form-check-label {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Detail view label/value pairs */
.detail-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.detail-value {
  font-size: 0.92rem;
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════════
   Gate Entry — Photo Capture Slots
   ═══════════════════════════════════════════════ */
.photo-slot {
  position: relative;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transition: border-color 0.2s;
}
.photo-slot:hover { border-color: var(--primary); }

.photo-slot-label {
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem;
  width: 100%;
  text-align: center;
  margin: 0;
}
.photo-slot-label:hover { background: rgba(99,102,241,0.05); }

.photo-file-input {
  display: block;
  width: 100%;
  font-size: 0.75rem;
  margin-top: 0.25rem;
  cursor: pointer;
  opacity: 0.01;
  position: absolute;
  inset: 0;
  height: calc(100% - 32px); /* stop before clear btn area */
  z-index: 1;
}

.photo-preview {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  border-radius: var(--radius-md);
}

.photo-clear-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(255,255,255,0.9);
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  box-shadow: var(--shadow-sm);
  z-index: 3;
}

/* Gate Entry index mobile cards */
.gate-card { overflow: hidden; }
.gate-card-header { background: var(--primary); }

/* ═══════════════════════════════════════════════
   Damaged legend items in read-only view */
.legend-item-damaged {
  background: #fff5f5;
  border-color: #f03e3e !important;
}

.legend-badge-damaged {
  background: #f03e3e !important;
}

.submenu-list {
    list-style: none;
    padding-left: 1.25rem;
    margin: 0;
}

.submenu-toggle {
    cursor: pointer;
}

.submenu-toggle .submenu-caret {
    transition: transform 0.25s ease;
    font-size: 0.75rem;
}

.submenu-toggle[aria-expanded="true"] .submenu-caret {
    transform: rotate(180deg);
}

.has-submenu.submenu-open > .submenu-toggle {
    /*color: #2563eb;*/
}

/* Smooth collapse animation (Bootstrap already animates height, this just polishes it) */
.submenu-list.collapsing {
    transition: height 0.25s ease;
}

.section-header > .submenu-toggle {
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: #94a3b8;
    padding-top: 0.75rem;
    padding-bottom: 0.5rem;
}

.section-header > .submenu-toggle:hover {
    color: #64748b;
}

.section-header > .submenu-toggle .submenu-caret {
    font-size: 0.65rem;
}