/* ============================================================================
   GoGG Universal CAD & Technical Drawing Viewer — Dedicated View-Only Layout
   ============================================================================ */

:root {
  --cad-studio-height: 800px;
  --cad-bg-deep: #060a12;
  --cad-bg-panel: #0b1220;
  --cad-bg-card: #111a2e;
  --cad-border: rgba(56, 189, 248, 0.18);
  --cad-cyan: #38bdf8;
  --cad-red: #f43f5e;
  --cad-emerald: #10b981;
  --cad-amber: #f59e0b;
  --cad-purple: #a855f7;
  --cad-text: #f1f5f9;
  --cad-muted: #94a3b8;
  --cad-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
}

.cad-page-container {
  max-width: 1260px;
  width: min(100% - 32px, 1260px);
  margin: 0 auto;
  padding: 0 0 30px;
  box-sizing: border-box;
}

.cad-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 12px;
  padding: 14px 20px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(8, 13, 26, 0.98));
  border: 1px solid var(--cad-border);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.cad-hero-left {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.cad-hero-icon {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(56, 189, 248, 0.2));
  border: 1px solid rgba(16, 185, 129, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.45rem;
  flex-shrink: 0;
}

.cad-hero-title {
  margin: 0;
  font-size: 1.32rem;
  font-weight: 800;
  color: var(--cad-text);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.cad-badge-ver {
  font-size: 0.72rem;
  font-family: var(--cad-mono);
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(16, 185, 129, 0.45);
  color: #6ee7b7;
  white-space: nowrap;
}

.cad-hero-desc {
  margin: 4px 0 0;
  font-size: 0.84rem;
  color: var(--cad-muted);
}

.cad-hero-badges {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: nowrap;
  flex-shrink: 0;
  margin-left: auto;
}

@media (max-width: 980px) {
  .cad-hero {
    flex-wrap: wrap;
  }
  .cad-hero-badges {
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-left: 0;
  }
}

.cad-format-pill {
  padding: 5px 11px;
  border-radius: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--cad-mono);
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
}

/* Language Switcher Dropdown (Matching Melsec Monitor & Port Tester) */
.lang-switcher-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 8px;
  padding: 3px 8px;
}

.lang-switcher-wrap select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") no-repeat right 4px center;
  color: var(--cad-text);
  border: none;
  font-size: 12px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  padding: 2px 20px 2px 4px;
}

.lang-switcher-wrap select option {
  background: var(--cad-bg-card);
  color: var(--cad-text);
}

.cad-studio-outer-panel {
  background: var(--cad-bg-panel);
  border: 1px solid rgba(56, 189, 248, 0.22);
  border-radius: 14px;
  padding: 16px;
  height: var(--cad-studio-height, 800px);
  min-height: 480px;
  max-height: var(--cad-studio-height, 800px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.cad-studio-grid {
  flex: 1 1 0%;
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  align-items: stretch;
  height: 100%;
  max-height: 100%;
  min-height: 0;
}

.cad-studio-resizer {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 24px;
  margin-top: 2px;
  margin-bottom: 16px;
  cursor: ns-resize;
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 20;
  transition: opacity 0.15s ease;
}

.cad-studio-resizer .cad-resizer-line {
  flex: 1;
  height: 1px;
  background: rgba(56, 189, 248, 0.16);
  transition: background 0.18s ease, height 0.18s ease, box-shadow 0.18s ease;
}

.cad-studio-resizer .cad-resizer-handle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 12px;
  margin: 0 10px;
  border-radius: 999px;
  background: #0f172a;
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: #94a3b8;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--cad-mono);
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.cad-studio-resizer:hover .cad-resizer-line,
.cad-studio-resizer.is-dragging .cad-resizer-line {
  background: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.35);
}

.cad-studio-resizer:hover .cad-resizer-handle,
.cad-studio-resizer.is-dragging .cad-resizer-handle {
  border-color: #38bdf8;
  color: #e0f2fe;
  background: #132238;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

body.cad-resizing,
body.cad-resizing * {
  cursor: ns-resize !important;
  user-select: none !important;
}

@media (max-width: 1180px) {
  .cad-studio-outer-panel {
    height: auto;
    max-height: none;
  }
  .cad-studio-grid {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
  }
  .cad-studio-resizer {
    display: none;
  }
}

.cad-panel {
  background: #070d19;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.cad-panel-header {
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--cad-text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.cad-dropzone {
  margin: 12px;
  padding: 16px 12px;
  border: 2px dashed rgba(56, 189, 248, 0.4);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.65);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cad-dropzone:hover,
.cad-dropzone.dragover {
  border-color: var(--cad-emerald);
  background: rgba(16, 185, 129, 0.1);
}

.cad-dropzone-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--cad-text);
  margin-bottom: 4px;
}

.cad-dropzone-sub {
  font-size: 0.72rem;
  color: var(--cad-muted);
}

.cad-file-list-section {
  margin: 0 12px 10px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 10px;
  background: rgba(10, 17, 32, 0.85);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.cad-file-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
  font-size: 0.73rem;
  font-weight: 700;
  color: #e2e8f0;
}

.cad-file-list-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cad-mini-btn {
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.8);
  color: #cbd5e1;
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--cad-mono);
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-mini-btn:hover {
  border-color: var(--cad-cyan);
  color: #fff;
}

.cad-mini-btn.active {
  background: rgba(14, 165, 233, 0.24);
  border-color: rgba(56, 189, 248, 0.6);
  color: #7dd3fc;
}

.cad-file-list {
  max-height: 145px;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cad-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: rgba(15, 23, 42, 0.6);
  font-family: var(--cad-mono);
  font-size: 0.73rem;
  color: #cbd5e1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.cad-file-item:hover {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.3);
}

.cad-file-item.active {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.25), rgba(16, 185, 129, 0.16));
  border-color: rgba(56, 189, 248, 0.65);
  color: #f8fafc;
  font-weight: 700;
}

.cad-file-item-left {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.cad-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cad-file-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.67rem;
  color: #94a3b8;
  flex-shrink: 0;
}

.cad-file-remove {
  background: transparent;
  border: none;
  color: #64748b;
  font-size: 0.82rem;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.cad-file-remove:hover {
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.15);
}

.cad-control-block {
  padding: 8px 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.12);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cad-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cad-select,
.cad-input {
  background: #060b14;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: 7px;
  color: var(--cad-text);
  padding: 6px 9px;
  font-size: 0.76rem;
  font-family: var(--cad-mono);
  flex: 1;
  min-width: 0;
}

.cad-btn {
  padding: 6px 11px;
  border-radius: 7px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  background: rgba(30, 41, 59, 0.85);
  color: var(--cad-text);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.cad-btn:hover {
  border-color: var(--cad-cyan);
  background: rgba(56, 189, 248, 0.15);
}

.cad-btn.primary {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.28), rgba(56, 189, 248, 0.18));
  border-color: rgba(56, 189, 248, 0.55);
  color: #7dd3fc;
}

.cad-layer-list {
  max-height: 155px;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
}

.cad-layer-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.65);
  font-size: 0.75rem;
  font-family: var(--cad-mono);
}

.cad-layer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.cad-layer-swatch {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

.cad-entity-wrap {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.cad-entity-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--cad-mono);
  font-size: 0.71rem;
}

.cad-entity-table th {
  position: sticky;
  top: 0;
  background: #0d1627;
  color: var(--cad-muted);
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.18);
}

.cad-entity-table td {
  padding: 5px 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.06);
  color: #cbd5e1;
  cursor: pointer;
}

.cad-entity-table tr:hover td {
  background: rgba(56, 189, 248, 0.12);
}

.cad-entity-table tr.active-ent td {
  background: rgba(245, 158, 11, 0.22);
  color: #fde68a;
  font-weight: 700;
}

.cad-canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 12px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.cad-canvas-stage {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  background: #040811;
  overflow: hidden;
  user-select: none;
}

#cad-nano-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.cad-hud-tl {
  position: absolute;
  top: 32px;
  left: 48px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

.cad-hud-tr {
  position: absolute;
  top: 32px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  z-index: 10;
}

.cad-hud-br {
  position: absolute;
  bottom: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  z-index: 10;
}

.cad-hud-box {
  background: rgba(7, 12, 23, 0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 8px;
  padding: 6px 11px;
  font-family: var(--cad-mono);
  font-size: 0.72rem;
  color: var(--cad-text);
}

.cad-stats-footer {
  padding: 9px 14px;
  background: rgba(10, 16, 30, 0.95);
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  font-family: var(--cad-mono);
  font-size: 0.73rem;
  color: var(--cad-muted);
}

/* ============================================================================
   Mobile & Tablet Responsive Overrides (Prevents Panel Overflow & Collapse)
   ============================================================================ */
@media (max-width: 1180px) {
  .cad-studio-outer-panel {
    height: auto !important;
    max-height: none !important;
  }
  .cad-studio-grid {
    grid-template-columns: 1fr;
    height: auto !important;
    max-height: none !important;
  }
  .cad-panel {
    height: auto !important;
    max-height: none !important;
    min-width: 0;
  }
  /* Show 2D CAD Drawing Viewport at the top on mobile/tablet (like Trajectory) */
  section.cad-panel {
    order: -1;
  }
  .cad-canvas-stage {
    flex: none !important;
    height: 440px !important;
    min-height: 360px !important;
  }
  .cad-entity-wrap {
    flex: none !important;
    height: 220px !important;
    max-height: 240px !important;
    overflow-x: auto !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}

@media (max-width: 768px) {
  html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
  }
  .cad-page-container {
    width: calc(100% - 16px) !important;
    padding: 8px 0 28px !important;
    overflow-x: hidden;
  }
  .cad-hero {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 14px;
    gap: 10px;
    overflow: hidden;
  }
  .cad-hero-left {
    width: 100%;
    align-items: flex-start;
    gap: 10px;
  }
  .cad-hero-icon {
    width: 38px;
    height: 38px;
    font-size: 1.2rem;
    border-radius: 10px;
  }
  .cad-hero-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    font-size: 1.15rem;
    width: 100%;
    min-width: 0;
  }
  .cad-badge-ver {
    white-space: normal !important;
    border-radius: 6px !important;
    padding: 3px 8px;
    font-size: 0.68rem;
    line-height: 1.35;
    max-width: 100%;
    box-sizing: border-box;
    word-break: break-word;
  }
  .cad-hero-badges {
    width: 100%;
    flex-wrap: wrap !important;
    justify-content: flex-start;
    gap: 6px;
    margin-left: 0;
  }
  .cad-format-pill {
    padding: 4px 8px;
    font-size: 0.68rem;
  }
  .cad-hero-badges .lang-switcher-wrap {
    margin-left: auto;
  }
  .cad-studio-outer-panel {
    padding: 8px !important;
    border-radius: 12px;
  }
  .cad-panel-header {
    padding: 8px 10px;
    font-size: 0.75rem;
    flex-wrap: wrap;
    gap: 4px;
  }
  .cad-dropzone {
    margin: 8px;
    padding: 12px 10px;
  }
  .cad-dropzone-title {
    font-size: 0.78rem;
  }
  .cad-dropzone-sub {
    font-size: 0.68rem;
    word-break: break-word;
  }
  .cad-control-block {
    padding: 8px 10px;
  }
  .cad-control-block .cad-row {
    flex-wrap: wrap;
    gap: 6px;
  }
  .cad-control-block .cad-select {
    flex: 1 1 180px;
    min-width: 0;
  }
  .cad-canvas-toolbar {
    padding: 8px 10px;
    gap: 6px;
  }
  .cad-canvas-toolbar .cad-row:first-child {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 5px;
  }
  .cad-canvas-toolbar .cad-btn {
    width: 100%;
    justify-content: center;
    padding: 6px 6px;
    font-size: 0.7rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .cad-canvas-stage {
    height: 360px !important;
    min-height: 320px !important;
  }
  .cad-hud-tl {
    top: 8px;
    left: 8px;
    max-width: calc(100% - 16px);
  }
  .cad-hud-tr {
    top: 66px;
    left: 8px;
    right: 8px;
  }
  .cad-hud-br {
    bottom: 8px;
    left: 8px;
    right: 8px;
    justify-content: space-between;
  }
  .cad-hud-box {
    padding: 4px 8px;
    font-size: 0.64rem;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    box-sizing: border-box;
  }
  #cad-ruler-card {
    min-width: 0 !important;
    width: 100%;
    white-space: normal;
  }
  .cad-stats-footer {
    padding: 8px 10px;
    gap: 6px 12px;
    font-size: 0.68rem;
  }
  .ms-guide-section {
    padding: 18px 14px !important;
  }
  .ms-guide-section h2 {
    font-size: 1.2rem !important;
  }
  .ms-guide-section h3 {
    font-size: 1rem !important;
  }
}
