:root {
  --bg: #f4f7fb;
  --ink: #12263a;
  --muted: #5b6d82;
  --primary: #0f4c81;
  --accent: #0ea5e9;
  --card: #ffffff;
  --border: #dce4ee;
  --top-h: 56px;
  --bottom-h: 62px;
  --side-w: 264px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; font-family: 'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }

/* Sticky Top Bar (56px) */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top-h); z-index: 40;
  background: #0f2c4c; color: #fff; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; background: transparent; color: #fff;
  font-size: 22px; border-radius: 10px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.brand { display: flex; align-items: center; gap: 9px; color: #fff; min-height: 44px; }
.brand-badge {
  width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #38bdf8, #0284c7);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 14px;
}
.brand span { display: flex; flex-direction: column; line-height: 1.15; }
.brand small { color: #b9d4ee; font-size: 11.5px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.pill { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: rgba(255,255,255,.14); color: #e6f2ff; }
.btn-top {
  min-height: 40px; padding: 0 12px; border-radius: 10px; background: #e0a526; color: #12263a;
  font-weight: 700; font-size: 13px; display: inline-flex; align-items: center; white-space: nowrap;
}

/* Sidebar / Mobile Slide-over Drawer */
.backdrop { position: fixed; inset: 0; background: rgba(10, 20, 35, .48); z-index: 45; }
.sidebar {
  position: fixed; top: var(--top-h); left: 0; bottom: 0; width: var(--side-w); z-index: 50;
  background: #fff; border-right: 1px solid var(--border); overflow-y: auto; padding: 12px 10px 80px;
  transform: translateX(-105%); transition: transform .22s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-group { margin-bottom: 16px; }
.group-title { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 6px 10px; }
.nav-item, .quay-btn {
  display: flex; align-items: center; gap: 9px; width: 100%; min-height: 44px; padding: 8px 10px;
  border-radius: 10px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 14px;
  text-align: left; cursor: pointer;
}
.nav-item:hover, .quay-btn:hover { background: #eef5fc; }
.nav-item.active, .quay-btn.active { background: #dff0ff; color: #0b4a82; font-weight: 700; }
.quay-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.quay-btn small { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }

/* Main area */
.main {
  position: fixed; top: var(--top-h); left: 0; right: 0;
  bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px));
  overflow: hidden;
}

/* 3D Hall View */
.view-3d { position: relative; width: 100%; height: 100%; background: #d9e8f5; }
#cong-canvas { width: 100%; height: 100%; display: block; touch-action: none; outline: none; }

.load-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(160deg, rgba(15,44,76,.88), rgba(14,116,144,.82)); z-index: 20;
}
.load-card { background: #fff; border-radius: 16px; padding: 24px 20px; max-width: 420px; width: 100%; text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.28); }
.load-icon { font-size: 42px; margin-bottom: 6px; }
.load-card h2 { margin: 4px 0 8px; font-size: 18px; color: var(--primary); }
.load-bar { height: 8px; border-radius: 999px; background: #e2eaf3; overflow: hidden; margin: 12px 0; }
.load-bar i { display: block; height: 100%; width: 12%; background: linear-gradient(90deg, #0ea5e9, #2563eb); transition: width .15s; }

.hud-hint {
  position: absolute; top: 10px; left: 10px; z-index: 10;
  background: rgba(15, 34, 58, .78); color: #fff; font-size: 12.5px; padding: 6px 12px; border-radius: 999px;
}

.quick-quays {
  position: absolute; top: 10px; right: 10px; z-index: 10; display: flex; gap: 6px; flex-wrap: wrap; max-width: 68%; justify-content: flex-end;
}
.quick-chip {
  min-height: 38px; padding: 4px 10px; border-radius: 999px; border: 1px solid rgba(255,255,255,.3);
  background: rgba(15, 44, 76, .82); color: #fff; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.quick-chip.on { background: #e0a526; color: #12263a; border-color: #e0a526; }

/* Touch D-pad for Mobile */
.touch-pad {
  position: absolute; left: 12px; bottom: 16px; z-index: 15; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.touch-mid { display: flex; gap: 6px; }
.touch-pad button {
  width: 48px; height: 48px; border-radius: 14px; border: 1px solid rgba(255,255,255,.35);
  background: rgba(15, 44, 76, .72); color: #fff; font-size: 18px; cursor: pointer; touch-action: none;
}
.touch-pad button:active { background: #0ea5e9; }

/* Proximity Banner */
.near-banner {
  position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 16;
  background: rgba(255,255,255,.96); border: 2px solid #0ea5e9; border-radius: 16px;
  padding: 10px 14px; display: flex; align-items: center; gap: 12px; max-width: calc(100% - 24px);
  box-shadow: 0 12px 30px rgba(0,0,0,.22);
}
.near-banner b { display: block; font-size: 14.5px; color: var(--primary); }
.near-banner small { color: var(--muted); font-size: 12px; }

/* Page Views (Procedures / Tickets) */
.page-view { height: 100%; overflow-y: auto; padding: 16px; }
.page-inner { max-width: 1120px; margin: 0 auto; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: #f1f5f9; color: var(--muted); }

/* Cheerful NPC Chat Sheet */
.chat-sheet {
  position: fixed; right: 12px; bottom: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px) + 8px);
  width: min(460px, calc(100vw - 24px)); max-height: 74vh; z-index: 35;
  background: #fff; border-radius: 18px; border: 1px solid var(--border);
  box-shadow: 0 18px 50px rgba(10, 28, 52, .28); display: flex; flex-direction: column; overflow: hidden;
}
.chat-hd {
  background: linear-gradient(135deg, #0f4c81, #0284c7); color: #fff;
  padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.chat-npc { display: flex; align-items: center; gap: 10px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.22); display: inline-flex; align-items: center; justify-content: center; font-size: 22px; }
.chat-npc b { display: block; font-size: 15px; }
.chat-npc small { font-size: 12px; opacity: .9; }
.chat-hd-actions { display: flex; gap: 6px; }
.chat-body { padding: 12px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 10px; background: #f8fafc; }
.msg { max-width: 92%; padding: 10px 12px; border-radius: 14px; font-size: 14px; line-height: 1.5; white-space: pre-line; }
.msg.npc { background: #fff; border: 1px solid var(--border); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.user { background: #0f4c81; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.checklist { margin: 8px 0 0; padding: 10px; background: #f0f9ff; border: 1px solid #bae6fd; border-radius: 10px; }
.checklist label { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; font-size: 13.5px; cursor: pointer; min-height: 32px; }
.chat-chips { padding: 8px 10px; display: flex; gap: 6px; overflow-x: auto; border-top: 1px solid var(--border); background: #fff; }
.chip {
  flex-shrink: 0; min-height: 38px; padding: 4px 11px; border-radius: 999px; border: 1px solid #bcd4ec;
  background: #f0f7ff; color: #0f4c81; font-size: 12.5px; cursor: pointer;
}
.chat-input-bar { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: #fff; }
.chat-input-bar input {
  flex: 1; min-height: 44px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; font-size: 16px;
}

/* Buttons & Inputs */
.btn-primary, .btn-ghost {
  min-height: 44px; padding: 0 14px; border-radius: 10px; font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { border: 0; background: #0f4c81; color: #fff; }
.btn-ghost { border: 1px solid var(--border); background: #fff; color: var(--ink); }
.btn-ghost.sm, .btn-primary.sm { min-height: 36px; padding: 0 10px; font-size: 12.5px; }
.chat-hd .btn-ghost { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.3); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13.5px; }
.field input, .field select, .field textarea {
  min-height: 44px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; font-size: 16px;
}
.small { font-size: 12.5px; }
.muted { color: var(--muted); }
.tag { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #e0f2fe; color: #0369a1; margin-right: 6px; }
.tag.ok { background: #dcfce7; color: #166534; }

/* Fixed Bottom Tab Bar (Mobile-First < 960px) */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--bottom-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #fff; border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(5, 1fr);
}
.bottom-bar .tab {
  border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 18px; cursor: pointer; min-height: 44px;
}
.bottom-bar .tab small { font-size: 11px; font-weight: 600; }
.bottom-bar .tab.active { color: var(--primary); }

.desktop-only { display: none; }

/* Desktop Enhancement (>= 960px) */
@media (min-width: 960px) {
  .mobile-only { display: none !important; }
  .desktop-only { display: inline-flex; }
  .sidebar { transform: translateX(0); padding-bottom: 20px; }
  .main { left: var(--side-w); bottom: 0; }
  .chat-sheet { bottom: 16px; right: 16px; }
  .touch-pad { display: none !important; }
}

/* Print / A4 PDF Preservation */
@media print {
  .noprint, .topbar, .sidebar, .backdrop, .bottom-bar, .chat-sheet { display: none !important; }
  .main { position: static !important; overflow: visible !important; }
  .page-view { display: block !important; overflow: visible !important; }
  body { background: #fff; }
}
