/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* CITCO Water Brand Colors */
  --primary: #0097A7;
  --primary-dark: #00838F;
  --primary-light: #4DD0E1;
  --secondary: #1565C0;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --success: #16A34A;
  --warning: #F59E0B;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --gray-900: #111827;
  --nav-bg: #003049;

  --header-height: 56px;
  --palette-height: 140px;
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.15);
}

html, body {
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--gray-800);
  background: var(--gray-100);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* Main Navigation */
.main-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--spacing-md);
  background: var(--nav-bg);
  color: white;
  flex-shrink: 0;
  height: 52px;
  gap: var(--spacing-md);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

.nav-logo {
  height: 32px;
  width: auto;
}

.nav-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 var(--spacing-xs);
}

.nav-app-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--primary-light);
  white-space: nowrap;
  text-decoration: none;
}

.nav-app-name:hover {
  color: white;
}

.nav-menu {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  flex: 1;
  justify-content: center;
}

.nav-link {
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.875rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-link:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.nav-link.active {
  color: white;
  background: var(--primary);
}

.nav-user {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
}

.user-info {
  text-align: right;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 500;
  color: white;
}

.user-role {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.6);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
  color: white;
}

/* Version Navigation (legacy) */
.version-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-xs) var(--spacing-md);
  background: var(--gray-700);
  color: white;
  flex-shrink: 0;
}

.version-nav-title {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-400);
}

.version-nav-links {
  display: flex;
  gap: var(--spacing-xs);
}

.version-link {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-300);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.version-link:hover {
  color: white;
  background: rgba(255,255,255,0.1);
}

.version-link.active {
  background: var(--primary);
  color: white;
}

/* Loads List View */
.loads-view {
  display: none;
  flex-direction: column;
  height: calc(100vh - 80px);
  height: calc(100dvh - 80px);
  background: var(--gray-50);
}

.loads-view.active {
  display: flex;
}

.loads-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--spacing-md);
  background: white;
  border-bottom: 1px solid var(--gray-200);
}

.loads-title {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-800);
}

.loads-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.loads-table-wrapper {
  flex: 1;
  overflow: auto;
  padding: var(--spacing-md);
}

.loads-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.loads-table th,
.loads-table td {
  padding: var(--spacing-sm) var(--spacing-md);
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.loads-table th {
  background: var(--gray-50);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.loads-table td {
  font-size: 0.875rem;
  color: var(--gray-700);
}

.loads-table tbody tr {
  cursor: pointer;
  transition: background 0.15s ease;
}

.loads-table tbody tr:hover {
  background: var(--gray-50);
}

.loads-table .status-badge {
  display: inline-flex;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 12px;
}

.status-badge.draft {
  background: var(--gray-100);
  color: var(--gray-600);
}

.status-badge.ready {
  background: #DCFCE7;
  color: #166534;
}

.status-badge.loading {
  background: #FEF3C7;
  color: #92400E;
}

.status-badge.complete {
  background: #DBEAFE;
  color: #1E40AF;
}

.utilization-bar {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.utilization-bar-track {
  flex: 1;
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  min-width: 60px;
}

.utilization-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.utilization-bar-text {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--gray-600);
  min-width: 36px;
}

/* Mobile nav adjustments */
@media (max-width: 768px) {
  .main-nav {
    padding: 0 var(--spacing-sm);
    height: 48px;
  }

  .nav-divider,
  .nav-app-name {
    display: none;
  }

  .nav-logo {
    height: 28px;
  }

  .nav-link {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8125rem;
  }

  .user-info {
    display: none;
  }

  .user-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.75rem;
  }

  .loads-table th,
  .loads-table td {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
  }

  .loads-table .hide-mobile {
    display: none;
  }
}

#app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
  height: calc(100dvh - 80px);
  overflow: hidden;
}

/* Info Bar Toggle (mobile hamburger) */
.info-bar-toggle {
  display: flex;
  padding: var(--spacing-xs) var(--spacing-md);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.info-bar-toggle .btn {
  gap: var(--spacing-xs);
}

@media (min-width: 600px) {
  .info-bar-toggle {
    display: none;
  }
}

/* Info Bar */
.info-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.info-bar.hidden-mobile {
  display: none;
}

.info-bar.show {
  display: grid;
}

@media (min-width: 600px) {
  .info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-xs) var(--spacing-sm);
  }

  .info-bar.hidden-mobile {
    display: flex;
  }
}

.info-field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.info-field-wide {
  grid-column: 1 / -1;
}

@media (min-width: 600px) {
  .info-field {
    min-width: 80px;
    flex: 1;
  }

  .info-field-wide {
    min-width: 120px;
    flex: 2;
  }
}

.info-field label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.info-field input,
.info-field select {
  padding: 8px 10px;
  font-size: 0.875rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-sm);
  background: white;
  box-sizing: border-box;
  min-height: 48px;
}

.info-field input:focus,
.info-field select:focus {
  outline: none;
  border-color: var(--primary);
}

.info-field-checkboxes {
  grid-column: 1 / -1;
}

@media (min-width: 600px) {
  .info-field-checkboxes {
    min-width: auto;
    flex: 0 0 auto;
  }
}

.checkbox-group {
  display: flex;
  gap: var(--spacing-xs);
  align-items: center;
  flex-wrap: wrap;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
  white-space: nowrap;
  min-height: 48px;
  box-sizing: border-box;
  transition: all 0.15s;
  user-select: none;
  touch-action: manipulation;
}

.checkbox-item:has(input:checked) {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.checkbox-item input[type="checkbox"],
.checkbox-item input[type="radio"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: white;
  min-height: auto;
}

.checkbox-item input[type="radio"] {
  border-radius: 50%;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 var(--spacing-md);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

/* Max Weight Toggle */
.max-weight-toggle {
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  margin-left: var(--spacing-sm);
  cursor: pointer;
  font-size: 0.6875rem;
  color: var(--gray-600);
  user-select: none;
  touch-action: manipulation;
}

.max-weight-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.max-weight-toggle span {
  display: none;
}

@media (min-width: 400px) {
  .max-weight-toggle span {
    display: inline;
  }
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.utilization {
  display: flex;
  align-items: baseline;
  gap: var(--spacing-xs);
}

#utilizationPercent {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
}

.utilization-label {
  font-size: 0.875rem;
  color: var(--gray-500);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 0.9375rem;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  min-width: 44px;
}

.btn:active {
  transform: scale(0.96);
}

.btn:disabled {
  opacity: 0.4;
  pointer-events: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:active {
  background: var(--primary-dark);
}

.btn-outline {
  background: white;
  border: 1px solid var(--gray-300);
  color: var(--gray-700);
}

.btn-outline:active {
  background: var(--gray-100);
}

.btn-icon {
  padding: var(--spacing-sm);
  background: transparent;
  color: var(--gray-600);
}

.btn-icon:active {
  background: var(--gray-100);
}

.btn-sm {
  padding: var(--spacing-xs) var(--spacing-sm);
  font-size: 0.875rem;
  min-height: 36px;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

/* Main Grid Area */
.main {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--spacing-sm);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  min-height: 0; /* Allow flex shrinking */
}

.grid-wrapper {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--spacing-sm);
  min-height: min-content;
}

/* Zoom Controls */
.zoom-controls {
  position: fixed;
  bottom: calc(var(--palette-height) + var(--spacing-sm));
  right: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-xs);
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 50;
}

@media (min-width: 768px) {
  .zoom-controls {
    bottom: calc(var(--palette-height) + var(--spacing-sm) + 40px);
  }
}

.zoom-level {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-600);
  min-width: 40px;
  text-align: center;
}

.zoom-controls .btn-icon {
  min-height: 36px;
  min-width: 36px;
}

.grid-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: var(--spacing-sm);
  padding: var(--spacing-md);
}

/* Deck labels (front/back) */
.deck-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xs);
  padding: var(--spacing-sm) var(--spacing-lg);
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-radius: var(--radius-sm);
  user-select: none;
  flex-shrink: 0;
}

.deck-label-front {
  background: var(--gray-700);
  color: white;
}

.deck-label-front svg {
  stroke: white;
}

.deck-label-back {
  background: var(--gray-200);
  color: var(--gray-600);
}

.deck-label-back svg {
  stroke: var(--gray-500);
}

.deck-grid {
  display: grid;
  gap: 2px;
  background: var(--gray-300);
  padding: 2px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  max-width: 100%;
  max-height: 100%;
  position: relative;
  touch-action: none;
}

.deck-grid.deck-locked {
  cursor: not-allowed;
}

.deck-grid.deck-locked .placed-cargo {
  cursor: pointer;
}

.deck-grid.deck-locked .resize-handle,
.deck-grid.deck-full .resize-handle {
  display: none;
}

.grid-cell {
  background: white;
  border-radius: 2px;
  min-width: 0;
  min-height: 0;
  position: relative;
  transition: background 0.1s ease;
}

.grid-cell.valid-target {
  background: rgba(34, 197, 94, 0.3);
}

.grid-cell.invalid-target {
  background: rgba(239, 68, 68, 0.3);
}

.grid-cell.occupied {
  background: transparent;
}

/* Placed Cargo */
.placed-cargo {
  position: absolute;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  z-index: 10;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.placed-cargo.selected {
  border: 3px solid var(--gray-800);
  box-shadow: 0 0 0 2px white, var(--shadow-lg);
  z-index: 20;
}

.placed-cargo.dragging {
  opacity: 0.5;
  pointer-events: none;
}

.placed-cargo.resizing {
  opacity: 0.5;
}

/* Resize handles */
.resize-handle {
  position: absolute;
  width: 36px;
  height: 36px;
  background: white;
  border: 2px solid var(--gray-700);
  border-radius: 6px;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: nwse-resize;
  touch-action: none;
  box-shadow: var(--shadow-md);
}

.resize-handle svg {
  width: 16px;
  height: 16px;
  stroke: var(--gray-600);
  pointer-events: none;
}

.placed-cargo.selected .resize-handle {
  display: flex;
}

.resize-handle.handle-se {
  bottom: -18px;
  right: -18px;
  cursor: nwse-resize;
}

/* Single handle mode - just SE corner for simplicity */
.placed-cargo.selected .resize-handle.handle-se {
  display: flex;
}

@media (max-width: 768px) {
  .resize-handle {
    width: 44px;
    height: 44px;
    bottom: -22px;
    right: -22px;
  }

  .resize-handle svg {
    width: 20px;
    height: 20px;
  }
}

/* Drag preview floating element */
.drag-preview {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.85;
  box-shadow: var(--shadow-lg);
  border: 2px solid rgba(255,255,255,0.5);
  transform: scale(1.05);
}

.placed-cargo .cargo-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  padding: 2px 4px;
  text-align: center;
  word-break: break-word;
  line-height: 1.2;
}

/* Ghost preview */
.ghost-preview {
  position: absolute;
  border-radius: 4px;
  pointer-events: none;
  z-index: 5;
  opacity: 0.6;
  border: 2px dashed currentColor;
}

.ghost-preview.valid {
  background: rgba(34, 197, 94, 0.4);
  border-color: #16A34A;
}

.ghost-preview.invalid {
  background: rgba(239, 68, 68, 0.4);
  border-color: #DC2626;
}

/* Bottom Palette */
.palette {
  background: white;
  border-top: 1px solid var(--gray-200);
  padding: var(--spacing-xs) var(--spacing-sm);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 60;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

@media (min-width: 600px) {
  .palette {
    padding: var(--spacing-sm) var(--spacing-md);
  }
}

.palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--spacing-xs);
}

@media (min-width: 600px) {
  .palette-header {
    margin-bottom: var(--spacing-sm);
  }
}

.palette-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

@media (min-width: 600px) {
  .palette-title {
    font-size: 0.875rem;
  }
}

.cargo-list {
  display: flex;
  gap: var(--spacing-sm);
  overflow-x: auto;
  padding-bottom: var(--spacing-xs);
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}

.cargo-list::-webkit-scrollbar {
  height: 4px;
}

.cargo-list::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 2px;
}

.cargo-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--spacing-xs);
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  min-width: 56px;
  cursor: grab;
  transition: all 0.15s ease;
  scroll-snap-align: start;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

@media (min-width: 600px) {
  .cargo-item {
    padding: var(--spacing-sm);
    min-width: 72px;
    border-radius: var(--radius-md);
  }
}

.cargo-item:active {
  cursor: grabbing;
  transform: scale(0.95);
}

.cargo-item.dragging {
  opacity: 0.5;
}

.cargo-item .preview {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (min-width: 600px) {
  .cargo-item .preview {
    width: 40px;
    height: 40px;
    margin-bottom: var(--spacing-xs);
  }
}

.cargo-item .name {
  font-size: 0.5625rem;
  font-weight: 600;
  color: var(--gray-700);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50px;
}

@media (min-width: 600px) {
  .cargo-item .name {
    font-size: 0.6875rem;
    max-width: 60px;
  }
}

.cargo-item .size {
  font-size: 0.5rem;
  color: var(--gray-500);
}

@media (min-width: 600px) {
  .cargo-item .size {
    font-size: 0.5625rem;
  }
}

.cargo-item.selected {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
}

.cargo-item .preview {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  margin-bottom: var(--spacing-xs);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cargo-item .preview-grid {
  display: grid;
  gap: 1px;
  width: 100%;
  height: 100%;
}

.cargo-item .preview-cell {
  background: currentColor;
  border-radius: 2px;
}


.cargo-item .drag-handle {
  position: absolute;
  left: 2px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 32px;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--gray-400);
  cursor: grab;
  touch-action: none;
}

.cargo-item .drag-handle:active {
  cursor: grabbing;
}

/* Show drag handle on touch devices */
@media (pointer: coarse) {
  .cargo-item .drag-handle {
    display: flex;
  }
  
  .cargo-item {
    padding-left: 24px;
  }
}

.cargo-item .edit-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  padding: 0;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  border-radius: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s ease;
}

.cargo-item .edit-btn:hover {
  opacity: 1;
}

.cargo-item .edit-btn svg {
  width: 10px;
  height: 10px;
  color: var(--gray-600);
}

/* Empty state in cargo list */
.cargo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--spacing-md);
  color: var(--gray-400);
  font-size: 0.875rem;
}

/* Placement Actions (floating) */
.placement-actions {
  position: fixed;
  bottom: calc(var(--palette-height) + var(--spacing-md));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm);
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.placement-actions.hidden {
  display: none;
}

.placement-buttons {
  display: flex;
  gap: var(--spacing-sm);
}

/* Quick note input */
.quick-note {
  width: 100%;
  min-width: 200px;
}

.quick-note input {
  width: 100%;
  padding: var(--spacing-sm);
  font-size: 0.875rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: var(--gray-50);
  transition: border-color 0.15s, background 0.15s;
}

.quick-note input:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

.quick-note input::placeholder {
  color: var(--gray-400);
}

@media (max-width: 380px) {
  .quick-note {
    min-width: 180px;
  }

  .quick-note input {
    font-size: 0.8125rem;
    padding: var(--spacing-xs);
  }

  .btn-action {
    padding: var(--spacing-xs) var(--spacing-sm);
    min-width: 55px;
  }

  .btn-action svg {
    width: 20px;
    height: 20px;
  }

  .btn-action span {
    font-size: 0.625rem;
  }
}

.btn-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--gray-100);
  border-radius: var(--radius-md);
  min-width: 70px;
}

.btn-action span {
  font-size: 0.75rem;
}

.btn-action.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  max-height: 90vh;
  overflow-y: auto;
  background: white;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--spacing-lg);
  animation: slideUp 0.25s ease;
}

.modal-confirm {
  text-align: center;
}

.confirm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto var(--spacing-md);
  background: var(--warning);
  border-radius: 50%;
  color: white;
}

.modal-confirm h2 {
  margin-bottom: var(--spacing-xs);
}

.modal-confirm p {
  color: var(--gray-600);
  font-size: 0.9375rem;
  margin-bottom: var(--spacing-lg);
  line-height: 1.5;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.modal-content h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: var(--spacing-lg);
  color: var(--gray-800);
}

.modal-close {
  position: absolute;
  top: var(--spacing-md);
  right: var(--spacing-md);
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-100);
  border: none;
  border-radius: 50%;
  color: var(--gray-600);
  cursor: pointer;
}

.modal-close:active {
  background: var(--gray-200);
}

.modal-actions {
  display: flex;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-lg);
}

.modal-actions .btn {
  flex: 1;
}

/* Preset buttons */
.preset-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-lg);
}

.btn-preset {
  padding: var(--spacing-md);
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn-preset:active {
  border-color: var(--primary);
  background: rgba(37, 99, 235, 0.1);
}

/* Custom size */
.custom-size {
  padding-top: var(--spacing-md);
  border-top: 1px solid var(--gray-200);
}

.custom-size label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: var(--spacing-sm);
}

.size-inputs {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.size-inputs input {
  flex: 1;
  max-width: 80px;
  touch-action: manipulation;
}

.size-inputs span {
  color: var(--gray-400);
  font-weight: 500;
}

/* Form elements */
.form-group {
  margin-bottom: var(--spacing-md);
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: var(--spacing-xs);
}

.form-row {
  display: flex;
  gap: var(--spacing-md);
}

.form-row .form-group {
  flex: 1;
}

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  padding: var(--spacing-sm) var(--spacing-md);
  font-size: 1rem;
  border: 2px solid var(--gray-200);
  border-radius: var(--radius-sm);
  background: white;
  transition: border-color 0.15s;
  min-height: 48px;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Note indicator on placed cargo */
.placed-cargo .note-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  background: rgba(255,255,255,0.9);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

.placed-cargo .note-indicator svg {
  width: 10px;
  height: 10px;
  stroke: var(--gray-600);
}

/* Color picker */
.color-picker {
  display: flex;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:active {
  transform: scale(0.9);
}

.color-swatch.selected {
  border-color: var(--gray-800);
  box-shadow: 0 0 0 2px white, 0 0 0 4px var(--gray-300);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--palette-height) + var(--spacing-lg));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--gray-800);
  color: white;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 500;
  z-index: 300;
  animation: fadeIn 0.2s ease;
}

.toast.hidden {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Utility */
.hidden {
  display: none !important;
}

/* Tablet/Desktop adjustments */
@media (min-width: 768px) {
  :root {
    --palette-height: 120px;
  }

  .modal-content {
    border-radius: var(--radius-lg);
    margin-bottom: var(--spacing-lg);
  }

  .cargo-item {
    min-width: 100px;
  }

  .cargo-item .edit-btn {
    opacity: 1;
  }
}

@media (min-width: 1024px) {
  .main {
    padding: var(--spacing-lg);
  }
}

/* Small mobile */
@media (max-width: 380px) {
  :root {
    --spacing-md: 12px;
  }

  .info-bar {
    padding: var(--spacing-xs) var(--spacing-sm);
    gap: var(--spacing-xs);
  }

  .info-field label {
    font-size: 0.5625rem;
  }

  .info-field input,
  .info-field select {
    padding: var(--spacing-xs);
    font-size: 0.875rem;
    min-height: 36px;
  }

  .checkbox-item {
    padding: 6px 10px;
    font-size: 0.75rem;
  }

  .header {
    padding: 0 var(--spacing-sm);
  }

  .btn {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8125rem;
    min-height: 40px;
    min-width: 40px;
  }

  .utilization {
    flex-direction: column;
    align-items: center;
    gap: 0;
  }

  #utilizationPercent {
    font-size: 1rem;
  }

  .utilization-label {
    font-size: 0.625rem;
  }
}

/* Landscape phone */
@media (max-height: 500px) {
  :root {
    --header-height: 44px;
    --palette-height: 90px;
  }

  .info-bar {
    padding: var(--spacing-xs) var(--spacing-sm);
  }

  .info-field input,
  .info-field select {
    min-height: 30px;
    padding: 4px 8px;
  }

  .palette-header {
    margin-bottom: 2px;
  }

  .cargo-item {
    padding: var(--spacing-xs);
    min-width: 70px;
  }

  .cargo-item .preview {
    width: 30px;
    height: 30px;
  }

  .deck-label {
    padding: 2px var(--spacing-sm);
    font-size: 0.625rem;
  }
}

/* Very short screens (landscape phone) */
@media (max-height: 400px) {
  :root {
    --palette-height: 70px;
    --header-height: 40px;
  }

  .info-bar {
    padding: 4px var(--spacing-sm);
    gap: 4px;
  }

  .info-field input,
  .info-field select {
    min-height: 28px;
    padding: 2px 6px;
    font-size: 0.75rem;
  }
}
