/* =============================================================================
 * FILE:     public/css/styles.css
 * PURPOSE:  All styling for the main app: colours (CSS variables in :root),
 *           layout, sidebar, cards, forms, buttons, tables, modals, toasts.
 * RUNS ON:  Browser (linked by public/index.html).
 * USED BY:  public/index.html and every page in public/js/pages/.
 * NOTES:    sign.html and survey.html have their own inline styles instead.
 *           Bump CACHE_VERSION in public/sw.js after changes.
 * ========================================================================== */
:root {
  --c-navy: #0F2B52;
  --c-bg: #F4F7FB;
  --c-card: #FFFFFF;
  --c-border: #CBD8EA;
  --c-primary: #1B5FA8;
  --c-text: #1C2B3A;
  --c-autofill: #F0F3F7;
  --c-amber: #F59E0B;
  --c-teal: #0F9D72;
  --c-red: #DC2626;
  --c-divider: #E2EAF4;
  --c-sidebar-active: rgba(27,95,168,0.18);
  
  --c-srv-r: #1B5FA8;
  --c-srv-i: #3B82F6;
  --c-mnt: #0F9D72;
  --c-cal: #7C3AED;
  --c-com: #16A34A;
  --c-wrn: #EA580C;
  --c-ctr-ev: #DC2626;
  --c-ctr-pm: #64748B;

  --c-res-fully: #0F9D72;
  --c-res-partial: #1B5FA8;
  --c-res-pending: #F59E0B;
  --c-res-follow: #F59E0B;
  --c-res-escalated: #E05A2B;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background-color: var(--c-bg);
  line-height: 1.5;
}

/* Typography */
h1, h2, h3, h4, h5, h6 { font-weight: 700; color: var(--c-navy); }
.page-title { font-size: 22px; margin-bottom: 20px; }
.section-label {
  color: var(--c-navy);
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
  display: block;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.sidebar {
  width: 220px;
  background-color: var(--c-navy);
  color: #FFF;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-y: auto;
}
.main-content {
  padding: 24px 28px;
  flex: 1;
  overflow-x: hidden;
  max-width: 100%;
  box-sizing: border-box;
}
.main-content::-webkit-scrollbar { width: 6px; }
.main-content::-webkit-scrollbar-thumb { background: var(--c-navy); border-radius: 4px; }

/* Sidebar items */
.sidebar .logo { padding: 20px; text-align: center; font-size: 20px; font-weight: 700; border-bottom: 1px solid rgba(255,255,255,0.1); }
.nav-menu { flex: 1; padding: 10px 0; overflow-y: auto; }
.nav-item {
  padding: 12px 20px;
  display: flex;
  align-items: center;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  cursor: pointer;
  transition: 150ms;
}
.nav-item:hover, .nav-item.active {
  background-color: var(--c-sidebar-active);
  color: #FFF;
}
.nav-badge {
  background: var(--c-amber);
  color: #FFF;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}
.user-info {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 13px;
}
.user-info .logout { color: var(--c-amber); cursor: pointer; display: block; margin-top: 8px; }

/* Header */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.global-filters { display: flex; gap: 12px; }

/* Cards */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  box-shadow: 0 1px 4px rgba(15,43,82,0.07);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 20px;
}
.card--accent-blue { border-left: 4px solid var(--c-primary); }
.card--accent-amber { border-left: 4px solid var(--c-amber); }
.card--accent-red { border-left: 4px solid var(--c-red); }
.card--accent-teal { border-left: 4px solid var(--c-teal); }

.stats-row { display: flex; gap: 20px; margin-bottom: 24px; }
.stat-card { flex: 1; background: #FFF; border: 1px solid var(--c-border); border-radius: 6px; padding: 20px; text-align: center; }
.stat-card .kpi { font-size: 28px; font-weight: 700; color: var(--c-primary); }

/* Grid */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 20px; }
.grid-5 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--c-text); margin-bottom: 6px; }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 14px;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--c-primary);
}
.form-textarea { min-height: 100px; resize: vertical; }
.input--autofill { background-color: var(--c-autofill); cursor: default; pointer-events: none; }
.radio-group { display: flex; gap: 16px; }
.radio-option { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: 150ms;
}
.btn--primary { background: var(--c-primary); color: #FFF; }
.btn--primary:hover { background: #154c8a; }
.btn--secondary { background: #FFF; border-color: var(--c-border); color: var(--c-text); }
.btn--secondary:hover { background: var(--c-bg); }
.btn--danger { background: var(--c-red); color: #FFF; }
.btn--sm { padding: 4px 8px; font-size: 12px; }
.btn--lg { padding: 12px 24px; font-size: 16px; }
/* Uniform toolbar button — same height, same font, same padding everywhere */
.btn--header {
  height: 36px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 500;
  line-height: 36px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* Tables */
.data-table { width: 100%; border-collapse: collapse; background: #FFF; border-radius: 6px; overflow: hidden; }
.data-table th, .data-table td { padding: 12px; text-align: left; border-bottom: 1px solid var(--c-divider); }
.data-table th { background: var(--c-navy); color: #FFF; font-weight: 600; font-size: 13px; }
.data-table tr:hover { background-color: rgba(244, 247, 251, 0.5); }

/* Badges */
.badge { padding: 4px 8px; border-radius: 12px; font-size: 12px; font-weight: 600; color: #FFF; }
.badge--teal { background: var(--c-teal); }
.badge--blue { background: var(--c-primary); }
.badge--amber { background: var(--c-amber); }
.badge--red { background: var(--c-red); }
.badge--orange { background: #EA580C; }
.badge--grey { background: #64748B; }

/* Clickable report number in table */
.report-num-link {
  color: inherit;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1.5px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  cursor: pointer;
}
.report-num-link:hover {
  color: var(--c-primary);
  border-bottom-color: var(--c-primary);
}


/* Specifics */
.sticky-footer {
  position: sticky;
  bottom: 0;
  background: #FFF;
  border-top: 1px solid var(--c-border);
  padding: 12px 28px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  z-index: 100;
}
.sync-badge { position: absolute; top: 10px; right: 28px; background: var(--c-amber); color: #FFF; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 600; }

.sig-pad-container { border: 1px solid var(--c-border); background: #FFF; border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.sig-pad-container canvas { width: 100%; height: 150px; cursor: crosshair; }

.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--c-navy); color: #FFF; padding: 12px 20px; border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s forwards; }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,43,82,0.6); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.modal-box { background: #FFF; border-radius: 6px; width: 90%; max-width: 500px; padding: 24px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); }

.spinner { border: 4px solid var(--c-border); border-top: 4px solid var(--c-primary); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 0 auto; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.fullscreen-loading { position: fixed; inset: 0; background: var(--c-bg); display: flex; justify-content: center; align-items: center; z-index: 9999; }

@media print {
  .sidebar { display: none !important; }
  .sticky-footer { display: none !important; }
  .main-wrapper { flex: 1 1 100%; }
  .card { border: 1px solid #999; box-shadow: none; break-inside: avoid; }
}

/* ── Collapsible nav sections ────────────────────────────────────────────── */
.nav-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.4);
  background: none;
  border: none;
  cursor: pointer;
  transition: color 150ms;
}
.nav-section-header:hover { color: rgba(255,255,255,0.7); }
.nav-chevron {
  font-size: 10px;
  display: inline-block;
  transition: transform 0.2s ease;
  transform: rotate(-90deg);
}
.nav-section.open .nav-chevron { transform: rotate(0deg); }
.nav-section-body {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.25s ease;
}
.nav-section.open .nav-section-body { max-height: 500px; }

/* + New Report — primary action styling */
.nav-item--primary {
  color: var(--c-blue) !important;
  font-weight: 600;
}
.nav-item--primary:hover, .nav-item--primary.active {
  background-color: rgba(27,95,168,0.25) !important;
}

/* Offline banner inside sidebar */
.sidebar-offline-banner {
  margin: 8px 12px;
  font-size: 11px;
  background: rgba(245,158,11,0.15);
  color: #F59E0B;
  border-radius: 6px;
  padding: 6px 10px;
  text-align: center;
  border: 1px solid rgba(245,158,11,0.3);
}

/* ── Phase 2: Stat cards grid ───────────────────────────────────────────── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: #FFF;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 18px 16px;
  border-left: 4px solid var(--c-primary);
}
.stat-card--alert { border-left-color: var(--c-amber); }
.stat-card__value {
  font-size: 26px;
  font-weight: 700;
  color: var(--c-primary);
  line-height: 1.1;
}
.stat-card__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text);
  opacity: 0.65;
  margin-top: 4px;
}
.stat-card__sub {
  font-size: 11px;
  opacity: 0.5;
  margin-top: 2px;
}

/* ── Phase 2: Section label ─────────────────────────────────────────────── */
.section-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-navy);
  margin-bottom: 12px;
}

/* ── Phase 2: Filter panel ──────────────────────────────────────────────── */
.filter-panel {
  background: #FFF;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  padding: 16px 20px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(15,43,82,0.07);
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.filter-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--c-navy); opacity: 0.75; }
.filter-select {
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  font-family: inherit;
  font-size: 13px;
  color: var(--c-text);
  background: #FFF;
}
.filter-select:focus { outline: none; border-color: var(--c-primary); }

/* ── Phase 2: Active filter pills ───────────────────────────────────────── */
.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(27,95,168,0.1);
  color: var(--c-primary);
  border: 1px solid rgba(27,95,168,0.25);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 500;
}

/* ── Phase 2: Global filter bar (in page header) ────────────────────────── */
.global-filter-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Phase 2: Table last column no-wrap ─────────────────────────────────── */
.data-table td:last-child { white-space: nowrap; }
.data-table tr:last-child td { border-bottom: none; }

/* ── Entity card grid (By Customer / By Equipment level-1 & level-2) ─────── */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.entity-card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 10px;
  padding: 20px 22px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}
.entity-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(15,43,82,0.13);
  border-color: var(--c-primary);
}

.entity-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.entity-card__name {
  font-size: 15px;
  font-weight: 700;
  color: var(--c-navy);
  line-height: 1.3;
}
.entity-card__arrow {
  color: var(--c-primary);
  font-size: 16px;
  opacity: 0.5;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}
.entity-card:hover .entity-card__arrow {
  opacity: 1;
  transform: translateX(3px);
}

.entity-card__stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.entity-card__stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--c-navy);
  line-height: 1;
}
.entity-card__stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--c-text);
  opacity: 0.5;
  margin-top: 2px;
}

.entity-card__footer {
  border-top: 1px solid var(--c-divider);
  padding-top: 10px;
  font-size: 12px;
  opacity: 0.6;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.entity-card--alert { border-left: 3px solid var(--c-amber); }

/* detail page back header */
.detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}
.detail-header__back {
  flex-shrink: 0;
}

/* ═══ AI Chat Drawer ══════════════════════════════════════════════════ */
.ai-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 9998;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #1B5FA8, #0F2B52);
  border: none; cursor: pointer; font-size: 26px; line-height: 56px;
  box-shadow: 0 4px 16px rgba(15,43,82,0.35);
  transition: transform 0.2s, box-shadow 0.2s;
  animation: ai-pulse 3s ease-in-out infinite;
}
.ai-fab:hover { transform: scale(1.1); box-shadow: 0 6px 24px rgba(15,43,82,0.5); }
@keyframes ai-pulse {
  0%, 100% { box-shadow: 0 4px 16px rgba(15,43,82,0.35); }
  50%      { box-shadow: 0 4px 24px rgba(27,95,168,0.55); }
}

.ai-drawer {
  position: fixed; top: 0; right: -100%; height: 100vh; z-index: 9999;
  background: #fff; display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  transition: right 0.3s cubic-bezier(0.4,0,0.2,1);
}
.ai-drawer.open { right: 0; }

.ai-drag-handle {
  position: absolute; left: 0; top: 0; width: 6px; height: 100%;
  cursor: col-resize; background: transparent; z-index: 1;
  transition: background 0.15s;
}
.ai-drag-handle:hover, .ai-drag-handle:active {
  background: var(--c-primary, #1B5FA8);
}

.ai-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #e8eef6;
  background: #F8FAFC; flex-shrink: 0;
}

.ai-messages {
  flex: 1; overflow-y: auto; padding: 16px 18px;
  display: flex; flex-direction: column; gap: 14px;
}

.ai-welcome {
  text-align: center; padding: 40px 20px; opacity: 0.85;
}

.ai-context-badge {
  background: #EFF6FF; border: 1px solid #BFDBFE; border-radius: 6px;
  padding: 8px 12px; font-size: 12px; color: #1E40AF; align-self: center;
}

.ai-msg { display: flex; flex-direction: column; gap: 3px; }
.ai-msg-label { font-size: 11px; font-weight: 700; opacity: 0.5; text-transform: uppercase; }
.ai-msg--user .ai-msg-content {
  background: #EFF6FF; border-radius: 12px 12px 4px 12px;
  padding: 10px 14px; font-size: 13px; line-height: 1.6; align-self: flex-end;
  max-width: 90%; white-space: pre-wrap;
}
.ai-msg--assistant .ai-msg-content {
  background: #F8FAFC; border: 1px solid #e8eef6; border-radius: 12px 12px 12px 4px;
  padding: 12px 16px; font-size: 13px; line-height: 1.7; max-width: 100%;
}

.ai-citation {
  color: #1B5FA8; font-weight: 600; font-family: monospace; font-size: 11px;
  background: #EFF6FF; padding: 1px 5px; border-radius: 3px;
  text-decoration: none; cursor: pointer;
}
.ai-citation:hover { background: #DBEAFE; text-decoration: underline; }
.ai-citation-text {
  font-family: monospace; font-size: 11px; font-weight: 600;
  background: #F1F5F9; padding: 1px 5px; border-radius: 3px;
}

.ai-dots span {
  display: inline-block; animation: ai-dot-bounce 1.2s infinite ease-in-out;
  font-size: 16px; color: #94A3B8; margin: 0 2px;
}
.ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ai-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

.ai-disclaimer {
  padding: 6px 16px; background: #FFFBEB; border-top: 1px solid #FDE68A;
  font-size: 11px; color: #92400E; text-align: center; flex-shrink: 0;
}

.ai-input-bar {
  display: flex; gap: 8px; padding: 12px 16px;
  border-top: 1px solid #e8eef6; background: #F8FAFC; flex-shrink: 0;
  align-items: flex-end;
}
.ai-input {
  flex: 1; border: 1px solid #CBD8EA; border-radius: 8px;
  padding: 10px 12px; font-size: 13px; font-family: inherit;
  resize: none; outline: none; line-height: 1.5;
  max-height: 120px; min-height: 40px;
}
.ai-input:focus { border-color: var(--c-primary, #1B5FA8); box-shadow: 0 0 0 2px rgba(27,95,168,0.15); }
.ai-send-btn {
  width: 40px; height: 40px; border-radius: 8px;
  background: var(--c-primary, #1B5FA8); color: #fff;
  border: none; cursor: pointer; font-size: 16px; flex-shrink: 0;
  transition: background 0.15s;
}
.ai-send-btn:hover { background: #0F2B52; }
.ai-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Mobile: full width drawer */
@media (max-width: 768px) {
  .ai-drawer { width: 100% !important; }
  .ai-drag-handle { display: none; }
  .ai-fab { bottom: 16px; right: 16px; width: 48px; height: 48px; font-size: 22px; line-height: 48px; }
}
