/* ==========================================================================
   AcetaView - Minimalist iPad Touch Grid & Dual 3D Viewports
   ========================================================================== */

:root {
  --bg-primary: #0a0c10;
  --bg-secondary: #13161c;
  --bg-card: rgba(22, 26, 32, 0.9);
  --bg-card-hover: rgba(36, 42, 51, 0.95);
  --border-color: rgba(255, 255, 255, 0.12);
  --border-active: #48c79c;
  
  --text-main: #ffffff;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --accent-cyan: #48c79c;
  --accent-cyan-glow: rgba(72, 199, 156, 0.35);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --touch-target-size: 48px;
  --border-radius: 18px;
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  line-height: 1.5;
}

/* Unified Top Header Navigation Bar */
.app-header {
  height: 56px;
  flex-shrink: 0;
  background: rgba(18, 22, 28, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  position: relative;
  z-index: 100;
}

.header-left {
  display: flex;
  align-items: center;
}

.header-center {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
}

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

.btn-view-option {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
}

.btn-view-option.active {
  background: rgba(72, 199, 156, 0.18);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.btn {
  height: 40px;
  padding: 0 18px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-color: var(--border-color);
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--accent-cyan);
}

.btn-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.btn-toggle.active {
  background: rgba(72, 199, 156, 0.18);
  color: var(--accent-cyan);
  border-color: var(--accent-cyan);
}

.case-nav-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-nav {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon-nav:active {
  background: rgba(255, 255, 255, 0.16);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.btn-icon-nav:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: var(--border-color);
  color: var(--text-muted);
}

.case-select-dropdown {
  height: 40px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 10px;
  padding: 0 16px;
  font-weight: 800;
  font-size: 1.05rem;
  outline: none;
  text-align: center;
}

.mode-switch-group {
  display: flex;
  background: rgba(0, 0, 0, 0.4);
  padding: 3px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
}

/* Home View - 10 Minimalist Touch Grid */
.view-section {
  display: none;
  height: calc(100vh - 56px);     /* fallback */
  height: calc(100dvh - 56px);    /* mobile: excludes browser chrome (address bar) */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.view-section.active {
  display: block;
}

#homeView {
  padding: 28px;
  max-width: 1400px;
  margin: 0 auto;
}

.home-hero {
  margin-bottom: 24px;
}

.home-title {
  font-size: 2rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: #ffffff;
}

.cases-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.case-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 28px 20px;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 140px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.case-card-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.case-num {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--accent-cyan);
  letter-spacing: 0.1em;
  opacity: 0.85;
}

.case-title {
  font-size: 1.8rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #ffffff;
}

.case-card:hover, .case-card:active {
  background: var(--bg-card-hover);
  border-color: var(--accent-cyan);
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 28px rgba(72, 199, 156, 0.2);
}

.case-card:active .case-title {
  color: var(--accent-cyan);
}

/* Case Viewer Workspace Layout */
.case-viewer-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 56px);     /* fallback */
  height: calc(100dvh - 56px);    /* mobile: excludes browser chrome */
  width: 100%;
  overflow: hidden;
}

.viewer-workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #000000;
  display: flex;
  overflow: hidden;
}

/* 2D Viewport Grid (2-View or 3-View Fit) */
.view-2d-layout {
  display: grid;
  gap: 8px;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}

/* 2-View Fit Mode (Default) */
.view-2d-layout.mode-2view {
  grid-template-columns: repeat(2, 1fr);
}

.view-2d-layout.mode-2view #viewportSlot3 {
  display: none !important;
}

/* 3-View Fit Mode */
.view-2d-layout.mode-3view {
  grid-template-columns: repeat(3, 1fr);
}

.view-2d-layout.mode-3view #viewportSlot3 {
  display: flex !important;
}

/* Plane Selector Segmented Control in Viewport Header */
.plane-selector-group {
  display: inline-flex;
  align-items: center;
  background: rgba(10, 12, 16, 0.85);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.btn-plane-toggle {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

.btn-plane-toggle:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.05);
}

.btn-plane-toggle.active {
  background: rgba(72, 199, 156, 0.2);
  color: var(--accent-cyan);
  border-color: rgba(72, 199, 156, 0.4);
  font-weight: 800;
}

/* 3D Layout (2 Columns for Dual Viewports) */
.view-3d-layout {
  width: 100%;
  height: 100%;
  min-height: 0;
}

.view-3d-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 8px;
}

.viewport-box {
  background: #000000;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.viewport-header {
  height: 38px;
  flex-shrink: 0;
  background: rgba(20, 24, 30, 0.9);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  font-weight: 800;
}

.viewport-title {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-cyan);
}

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

.btn-fullscreen {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-fullscreen:hover, .btn-fullscreen:active {
  color: var(--accent-cyan);
  transform: scale(1.15);
}

/* Fullscreen Viewport Mode */
body.has-fullscreen .app-header {
  display: none !important;
}

.viewport-box.fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  z-index: 99999 !important;
  border-radius: 0 !important;
  border: none !important;
  background: #000000 !important;
}

.viewport-box.fullscreen .viewport-header {
  height: 44px !important;
  padding: 0 14px !important;
  background: rgba(18, 22, 28, 0.95) !important;
  border-bottom: 1px solid var(--border-color) !important;
}

.viewport-box.fullscreen .viewport-title {
  font-size: 0.9rem !important;
}

.viewport-box.fullscreen .btn-fullscreen {
  width: 40px !important;
  height: 40px !important;
  font-size: 1.25rem !important;
  color: var(--accent-cyan) !important;
  background: rgba(72, 199, 156, 0.15) !important;
  border-radius: 8px !important;
}

.viewport-box.fullscreen .slice-badge {
  font-size: 0.85rem !important;
}

.viewport-canvas-container {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: grab;
}

.viewport-canvas-container:active,
.viewport-canvas-container.active-dragging {
  cursor: grabbing;
}

canvas.ct-canvas {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pan-y;
}

.viewport-controls {
  height: 4px;
  flex-shrink: 0;
  background: transparent;
  border-top: none;
  display: flex;
  align-items: center;
  padding: 0;
}

.slice-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 0;
  background: linear-gradient(to right, var(--accent-cyan) 0%, var(--accent-cyan) var(--progress, 0%), rgba(255, 255, 255, 0.12) var(--progress, 0%), rgba(255, 255, 255, 0.12) 100%);
  outline: none;
  cursor: pointer;
}

/* Hide circular thumb knob completely — YouTube progress bar style */
.slice-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 0;
  height: 0;
  opacity: 0;
}

.slice-slider::-moz-range-thumb {
  width: 0;
  height: 0;
  opacity: 0;
  border: none;
}

.slice-badge {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 60px;
  text-align: right;
}

.touch-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(8px);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}


/* ==========================================
   RESPONSIVE — Tablet (≤900px)
   ========================================== */
@media (max-width: 900px) {
  .btn-toggle span {
    font-size: 0.85rem;
  }
}

/* ==========================================
   RESPONSIVE — Mobile Phone (≤600px)
   ========================================== */
@media (max-width: 600px) {
  /* Header: 46px height with clean balanced touch targets */
  .app-header {
    height: 46px;
    padding: 0 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }

  /* Hide text labels on Home button — icon only */
  .btn-secondary span {
    display: none;
  }
  .btn-secondary {
    width: 34px;
    height: 32px;
    padding: 0;
    font-size: 0.85rem;
    border-radius: 8px;
    min-width: unset;
  }

  /* Hide text labels on mode toggle — icons only */
  .btn-toggle span {
    display: none;
  }
  .btn-toggle {
    width: 34px;
    height: 32px;
    padding: 0;
    font-size: 0.85rem;
    border-radius: 8px;
    min-width: unset;
  }

  .btn-view-option {
    width: 34px;
    height: 32px;
    font-size: 0.85rem;
    border-radius: 8px;
  }

  /* Dropdown compact */
  .case-select-dropdown {
    height: 32px;
    font-size: 0.82rem;
    padding: 0 6px;
    max-width: 100px;
    border-radius: 8px;
  }

  /* Prev/Next buttons compact */
  .btn-icon-nav {
    width: 32px;
    height: 32px;
    font-size: 0.82rem;
    border-radius: 8px;
  }
  .case-nav-group {
    gap: 4px;
  }

  /* Account for notch/home indicator at bottom */
  .case-viewer-container {
    height: calc(100dvh - 46px);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .view-section {
    height: calc(100dvh - 46px);
  }

  /* Home view — tighter padding */
  #homeView {
    padding: 12px;
  }
  .cases-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .case-card {
    min-height: 80px;
    padding: 14px 10px;
  }
  .case-title {
    font-size: 1.2rem;
  }

  /* Viewport header — sleek 34px height matching desktop styling */
  .viewport-header {
    height: 34px;
    font-size: 0.8rem;
    padding: 0 8px;
  }

  .plane-selector-group {
    padding: 1px;
    gap: 1px;
    border-radius: 6px;
  }

  .btn-plane-toggle {
    font-size: 0.72rem;
    padding: 3px 7px;
    border-radius: 5px;
  }

  .slice-badge {
    font-size: 0.75rem;
    min-width: 44px;
  }

  .btn-fullscreen {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  /* Slider bar thinner */
  .slice-slider {
    height: 3px;
  }

  /* Viewport controls area compact */
  .viewport-controls {
    height: 4px;
    padding: 0;
  }

  /* 2D Layout — Vertical Stacking */
  .view-2d-layout {
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 6px;
    height: 100%;
    overflow: hidden;
  }

  /* 2-View Mode: 2 equal vertical rows fitting 100% of the screen */
  .view-2d-layout.mode-2view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  /* 3-View Mode: 3 equal vertical rows fitting 100% of the screen */
  .view-2d-layout.mode-3view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }

  /* 3D Layout — Vertical Stacking */
  .view-3d-layout {
    height: 100%;
    overflow: hidden;
  }

  .view-3d-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 6px;
    padding: 6px;
    height: 100%;
    overflow: hidden;
  }

  /* Viewport border radius */
  .viewport-box {
    border-radius: 10px;
  }
}

/* ==========================================
   RESPONSIVE — Very Small (≤375px, SE etc.)
   ========================================== */
@media (max-width: 375px) {
  .case-select-dropdown {
    max-width: 85px;
    font-size: 0.75rem;
  }
  .btn-icon-nav {
    width: 28px;
    height: 28px;
  }
  .cases-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

/* ==========================================
   CONFIDENTIAL ADMIN METADATA MODAL
   ========================================== */
.admin-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.admin-modal-container {
  background: #13161c;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  width: 100%;
  max-width: 950px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 30px rgba(72, 199, 156, 0.15);
  animation: adminModalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes adminModalFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.admin-modal-header {
  height: 54px;
  flex-shrink: 0;
  background: rgba(22, 26, 32, 0.95);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

.admin-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--accent-cyan);
}

.admin-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.admin-modal-close:hover, .admin-modal-close:active {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.1);
}

.admin-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.admin-modal-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.6;
}

.admin-cases-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-case-item {
  background: rgba(22, 26, 32, 0.7);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 100px 1.2fr 1fr 1.5fr;
  gap: 12px;
  align-items: center;
  transition: border-color 0.2s ease;
}

.admin-case-item:focus-within {
  border-color: var(--accent-cyan);
  background: rgba(22, 26, 32, 0.95);
}

.admin-case-tag {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 6px;
}

.admin-input-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.admin-input-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-input {
  background: #0a0c10;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  color: #ffffff;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.admin-input:focus {
  border-color: var(--accent-cyan);
  box-shadow: 0 0 8px var(--accent-cyan-glow);
}

.admin-modal-footer {
  height: 60px;
  flex-shrink: 0;
  background: rgba(22, 26, 32, 0.95);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 20px;
  gap: 12px;
}

.btn-save-admin {
  background: var(--accent-cyan);
  color: #000000;
  font-weight: 800;
  border-radius: 10px;
  padding: 0 20px;
  height: 40px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

.btn-save-admin:hover, .btn-save-admin:active {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px var(--accent-cyan-glow);
}

.admin-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #13161c;
  border: 1px solid var(--accent-cyan);
  color: var(--accent-cyan);
  padding: 10px 20px;
  border-radius: 30px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 1000000;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8), 0 0 20px var(--accent-cyan-glow);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 768px) {
  .admin-case-item {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }
}

/* ==========================================
   SAFE AREA — iPhone notch/home indicator
   ========================================== */
@supports (padding: max(0px)) {
  .app-header {
    padding-top: env(safe-area-inset-top, 0px);
  }
}
