/* ==========================================================
   Plannect Mobile - Field Industrial Technical Dark Theme
   Design System Tokens based on Stitch Mobile Viewer
   ========================================================== */

:root {
  --canvas-base: #0b0f17;
  --surface-1: #0f172a;
  --surface-2: #1e293b;
  --surface-3: #334155;
  --border-subtle: #1e293b;
  --border-focus: #334155;
  
  --primary-orange: #f97316;
  --primary-orange-glow: rgba(249, 115, 22, 0.25);
  --blueprint-cyan: #06b6d4;
  --inspection-green: #10b981;
  --warning-amber: #f59e0b;
  --defect-crimson: #ef4444;
  --defect-bg: rgba(239, 68, 68, 0.15);

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --hitbox-min: 48px;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--canvas-base);
  color: var(--text-main);
  font-family: var(--font-sans);
}

.font-mono {
  font-family: var(--font-mono);
}

/* App Viewport Container */
#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* --- Top Header Navigation Bar --- */
.app-header {
  height: 56px;
  background-color: var(--surface-1);
  border-bottom: 1px solid var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  z-index: 20;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.brand-badge {
  background: var(--primary-orange);
  color: #0b0f17;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.project-meta {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.project-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.project-sub {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Sheet Selector Dropdown */
.sheet-select-btn {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  color: var(--blueprint-cyan);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 38px;
}

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

.icon-btn:active, .sheet-select-btn:active {
  background: var(--surface-3);
  transform: scale(0.96);
}

/* --- Viewport Canvas Area --- */
.canvas-container {
  flex: 1;
  position: relative;
  background-color: var(--canvas-base);
  touch-action: none;
  overflow: hidden;
}

#floorPlanCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* Floating CAD Control Rail (Right Side) */
.floating-cad-tools {
  position: absolute;
  right: 14px;
  bottom: 80px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 15;
}

.cad-tool-btn {
  width: 48px;
  height: 48px;
  background-color: var(--surface-1);
  border: 1px solid var(--surface-3);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
}

.cad-tool-btn:active {
  background-color: var(--surface-2);
  border-color: var(--primary-orange);
  transform: scale(0.95);
}

.cad-tool-btn.highlight {
  color: var(--primary-orange);
}

/* Bottom HUD Readout (Scale & Coords) */
.hud-readout {
  position: absolute;
  left: 14px;
  bottom: 80px;
  background-color: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid var(--surface-3);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--blueprint-cyan);
  z-index: 15;
  display: flex;
  gap: 12px;
  pointer-events: none;
}

/* --- Bottom Sheet Drawer System --- */
.bottom-sheet-root {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 30;
}

.sheet-scrim {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  pointer-events: auto;
  display: none;
  transition: opacity 0.2s ease;
}

.sheet-drawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface-2);
  border-top: 1px solid var(--surface-3);
  border-radius: 16px 16px 0 0;
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  will-change: transform;
}

/* 3 Drawer Stops */
.sheet-drawer.hidden {
  transform: translateY(105%);
}

.sheet-drawer.collapsed {
  transform: translateY(calc(100% - 68px));
  height: 60vh;
}

.sheet-drawer.half {
  transform: translateY(calc(100% - 46vh));
  height: 46vh;
}

.sheet-drawer.full {
  transform: translateY(calc(100% - 86vh));
  height: 86vh;
}

/* Handle Header */
.sheet-handle-zone {
  padding: 8px 16px 12px 16px;
  cursor: grab;
  flex-shrink: 0;
}

.drag-indicator {
  width: 40px;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  margin: 0 auto 10px auto;
}

.sheet-peek-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.peek-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
}

.zone-color-tag {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary-orange);
  flex-shrink: 0;
}

.peek-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.peek-sub {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.peek-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.peek-progress-pill {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--inspection-green);
  color: var(--inspection-green);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.sheet-action-btn {
  background: var(--surface-3);
  border: none;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
}

/* Body */
.sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Zone Metrics Grid */
.zone-metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-card {
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.metric-label {
  font-size: 9px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.metric-val {
  font-size: 18px;
  font-weight: 700;
  font-family: var(--font-mono);
}

.text-primary { color: var(--primary-orange); }
.text-defect { color: var(--defect-crimson); }

/* Filter Chips & Search */
.sheet-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  cursor: pointer;
}

.chip.active {
  background: var(--primary-orange);
  color: #0b0f17;
  font-weight: 600;
  border-color: var(--primary-orange);
}

.chip-defect.active {
  background: var(--defect-crimson);
  color: #ffffff;
  border-color: var(--defect-crimson);
}

.search-input-wrap {
  width: 100%;
}

.search-input {
  width: 100%;
  background: var(--surface-1);
  border: 1.5px solid var(--surface-3);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}

.search-input:focus {
  border-color: var(--primary-orange);
}

/* Tasks List */
.tasks-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-card.is-defect {
  border: 1.5px solid var(--defect-crimson);
  background: rgba(239, 68, 68, 0.05);
}

.task-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.task-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge-worktype {
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid var(--blueprint-cyan);
  color: var(--blueprint-cyan);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.badge-defect {
  background: var(--defect-bg);
  border: 1px solid var(--defect-crimson);
  color: var(--defect-crimson);
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.badge-priority {
  background: var(--surface-3);
  color: var(--text-secondary);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.task-percent {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

.task-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.3;
}

.progress-track {
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary-orange);
  border-radius: 3px;
}

.fill-defect {
  background: var(--defect-crimson);
}

.task-meta-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-secondary);
}

.task-notes {
  font-size: 12px;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}

.empty-task-notice {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px 0;
}

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-dialog {
  background: var(--surface-2);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--surface-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.file-drop-zone {
  border: 2px dashed var(--surface-3);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.file-drop-zone:hover {
  border-color: var(--primary-orange);
  background: rgba(249, 115, 22, 0.05);
}

.sheet-item-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--surface-3);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
}

.sheet-item-btn.active {
  border-color: var(--primary-orange);
  background: rgba(249, 115, 22, 0.1);
}

/* --- Non-scaling CAD Pin Node & Markups --- */
#cad-viewport {
  background-color: #070d1b !important;
  background-image: radial-gradient(rgba(255, 255, 255, 0.07) 1px, transparent 1px) !important;
  background-size: 24px 24px !important;
  touch-action: none;
}

.cad-pin-node {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  z-index: 25;
  transform: translate(-50%, -50%) scale(var(--cad-inv-scale, 1));
  transform-origin: 50% 50%;
  will-change: transform;
}

.cad-pin-node.is-selected {
  z-index: 40;
}

.cad-pin-node:hover {
  z-index: 45;
}

.pin-label-tag {
  user-select: none;
  pointer-events: none;
  white-space: nowrap;
}

.cad-markup-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: auto;
  overflow: visible;
}

.cad-markup-shape {
  cursor: pointer;
  transition: opacity 0.15s;
}

.cad-markup-shape:hover {
  fill-opacity: 0.4 !important;
}

/* --- Responsive Bottom Drawer: Full-width on mobile portrait, 350px (matching Right Drawer) on iPad/tablet or landscape --- */
#drawer-preview {
  width: 100%;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (min-width: 640px), (orientation: landscape) and (min-width: 500px), (min-aspect-ratio: 1/1) {
  #bottom-dock-container {
    align-items: flex-end !important;
  }
  #drawer-preview {
    width: 350px !important;
    max-width: calc(100vw - 1rem) !important;
    margin-right: 1rem !important;
    margin-bottom: 0.5rem !important;
    border-radius: 1rem !important;
    border: 1px solid rgba(167, 139, 125, 0.3) !important;
  }
}


