:root {
  color-scheme: dark;
  --bg:       #0b1220;
  --panel:    #121a2b;
  --card:     #172033;
  --line:     #26324d;
  --text:     #e7edf8;
  --muted:    #9aabc7;
  --accent:   #4ea1ff;
  --accent-2: #7c5cff;
  --danger:   #ff6b6b;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); overflow: hidden; display: flex; flex-direction: column; }
button, input { font: inherit; }

.app-shell { --sidebar-width: 520px; display: grid; grid-template-columns: var(--sidebar-width) 10px 1fr; flex: 1; min-height: 0; padding: 12px; gap: 0; background: radial-gradient(circle at top, #17213a, var(--bg) 60%); box-sizing: border-box; }
.panel { background: rgba(18, 26, 43, 0.85); border: 1px solid var(--line); border-radius: 16px; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45); backdrop-filter: blur(12px); min-width: 320px; box-sizing: border-box; height: 100%; }
.sidebar-resizer { position: relative; cursor: col-resize; user-select: none; width: 10px; }
.sidebar-resizer::before { content: ""; position: absolute; top: 10%; bottom: 10%; left: 50%; width: 2px; transform: translateX(-50%); background: rgba(231,237,248,0.12); border-radius: 1px; transition: background 0.2s; }
.sidebar-resizer:hover::before { background: var(--accent); }
.viewer-wrap { display: flex; flex-direction: column; position: relative; background: rgba(18, 26, 43, 0.85); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45); backdrop-filter: blur(12px); height: 100%; box-sizing: border-box; }
#viewer { flex: 1; min-height: 0; width: 100%; position: relative; }
.viewer-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); background: rgba(16, 24, 41, 0.4); flex-wrap: wrap; gap: 8px; }
.viewer-header-info h2 { font-size: 14px; font-weight: bold; margin: 0; color: var(--text); }
.viewer-header-info p { font-size: 11px; margin: 2px 0 0 0; color: var(--muted); }
.viewer-controls { display: flex; gap: 4px; flex-wrap: wrap; }
.viewer-controls button { padding: 4px 8px; font-size: 11px; border-radius: 4px; background: #1b2740; border: 1px solid var(--line); color: var(--text); cursor: pointer; transition: background 0.2s, border-color 0.2s; }
.viewer-controls button:hover { background: #26324d; border-color: var(--accent); }
.tooltip { position: absolute; pointer-events: none; z-index: 20; padding: 8px 10px; border-radius: 10px; background: rgba(4,9,17,0.92); border: 1px solid rgba(170,188,229,0.3); color: var(--text); font-size: 12px; line-height: 1.4; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35); max-width: 240px; }

h1, h2, h3 { margin: 0 0 8px; }
p { margin: 0; color: var(--muted); }
.card { margin-top: 10px; padding: 8px 10px; background: rgba(23,32,51,0.92); border: 1px solid var(--line); border-radius: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.row-actions { display: flex; gap: 6px; }

/* Strategy selector */
.strategy-selector { display: flex; flex-direction: column; gap: 4px; }
.radio-label { display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.radio-label:hover { background: rgba(78,161,255,0.08); }
.radio-label input[type="radio"] { accent-color: var(--accent); width: 14px; height: 14px; flex-shrink: 0; }

/* Package list */
.package-list { display: grid; gap: 4px; margin-top: 6px; max-height: 380px; overflow-y: auto; padding-right: 4px; }
.package-row { display: flex; flex-direction: column; gap: 4px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #101829; }
.package-row.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.package-row-header { display: flex; gap: 6px; align-items: center; width: 100%; }
.package-row-header input[data-field="name"] { flex: 1.2; min-width: 85px; font-weight: bold; border-color: transparent; background: transparent; padding: 4px 6px; font-size: 12px; border-radius: 4px; }
.package-row-header input[data-field="name"]:focus { border-color: var(--line); background: #0c1322; }
.package-row-header .package-fields { flex: 3; min-width: 170px; }
.package-row-header input,
.package-row-header select { padding: 4px 6px; font-size: 12px; border-radius: 4px; }
.package-row-body { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; border-top: 1px solid var(--line); padding-top: 6px; }
.package-body-row { display: flex; gap: 6px; align-items: flex-end; width: 100%; }
.package-body-row .dimension-label { flex: 1; }
.toggle-expand-btn { background: #1b2740; border: 1px solid var(--line); padding: 2px; font-size: 8px; border-radius: 4px; cursor: pointer; color: var(--text); display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; flex-shrink: 0; }
.toggle-expand-btn:hover { background: #26324d; }
.danger-btn { background: rgba(255, 107, 107, 0.15); border: 1px solid var(--danger); color: var(--danger); padding: 3px 6px; font-size: 11px; font-weight: bold; border-radius: 4px; cursor: pointer; height: 24px; }
.danger-btn:hover { background: var(--danger); color: #fff; }
.package-fields { display: grid; gap: 6px; min-width: 0; width: 100%; }
.package-fields.box      { grid-template-columns: repeat(4, minmax(0,1fr)); }
.package-fields.cylinder { grid-template-columns: repeat(3, minmax(0,1fr)); }
.dimension-label { display: grid; gap: 2px; font-size: 11px; color: var(--muted); }
.dimension-label span { font-weight: 700; letter-spacing: 0.04em; color: var(--text); }
.package-fields .dimension-label { display: flex; align-items: center; gap: 4px; }
.package-fields .dimension-label span { flex-shrink: 0; }
.rotation-row { display: grid; gap: 2px; font-size: 11px; color: var(--muted); }
.rotation-row span { font-weight: 700; color: var(--text); }

input, select { padding: 5px 8px; border-radius: 6px; border: 1px solid var(--line); background: #0c1322; color: var(--text); width: 100%; min-width: 0; }
button { padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: #1b2740; color: var(--text); cursor: pointer; }
button.primary { width: 100%; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; font-weight: 700; font-size: 14px; padding: 8px; }

.status { margin-top: 10px; color: var(--muted); }
.details { color: var(--muted); white-space: pre-wrap; line-height: 1.5; }
.danger { color: var(--danger); }

/* Loading spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.loading-spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--muted); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: middle; margin-right: 6px; }

.mobile-tabs-header {
  display: none;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px;
  gap: 8px;
  width: 100%;
  box-sizing: border-box;
}
.mobile-tabs-header button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  background: #1b2740;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}
.mobile-tabs-header button.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(78, 161, 255, 0.25);
}

@media (max-width: 1000px) {
  .mobile-tabs-header {
    display: flex;
  }
  .app-shell {
    grid-template-columns: 1fr !important;
    padding: 8px;
    height: auto;
  }
  .sidebar-resizer {
    display: none !important;
  }
  .app-shell.show-settings .panel {
    display: flex !important;
    height: 100%;
  }
  .app-shell.show-settings .viewer-wrap {
    display: none !important;
  }
  .app-shell.show-viewer .panel {
    display: none !important;
  }
  .app-shell.show-viewer .viewer-wrap {
    display: flex !important;
    height: 100%;
    overflow-y: auto;
  }
  #viewer {
    height: 50vh;
    min-height: 350px;
    flex: none !important;
  }
  
  /* Touch target sizes and layout improvements */
  button {
    padding: 10px 16px;
    font-size: 14px;
  }
  input, select {
    padding: 8px 12px;
    font-size: 14px;
  }
  .viewer-controls button {
    padding: 6px 10px;
    font-size: 12px;
  }
  
  /* Responsive package row layout */
  .package-row-header {
    flex-wrap: wrap;
    gap: 8px;
  }
  .package-row-header input[data-field="name"] {
    flex: 1;
    min-width: 0;
    font-size: 14px !important;
    padding: 6px 8px !important;
  }
  .package-row-header .package-fields {
    flex: 1 1 100%;
    width: 100%;
  }
  .package-fields input,
  .package-fields select {
    padding: 6px 4px !important;
    font-size: 12px !important;
    text-align: center;
  }
  .toggle-expand-btn {
    width: 32px;
    height: 32px;
    font-size: 12px !important;
  }
  .package-list {
    max-height: 45vh;
  }
  
  /* Instruction display */
  .desktop-instruction {
    display: none !important;
  }
  .mobile-instruction {
    display: inline !important;
  }

  /* Playback controls button adjustments */
  .playback-controls button {
    padding: 8px 12px !important;
    font-size: 13px !important;
  }
}

.grid-buttons { display: grid; grid-template-columns: 3fr 2fr; gap: 8px; }
.csv-help { margin-top: 8px; padding: 8px; background: rgba(38,50,77,0.3); border: 1px solid var(--line); border-radius: 6px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.csv-help code { color: var(--accent); font-family: monospace; font-size: 11px; }

input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(5, 10, 20, 0.8);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  animation: fadeIn 0.25s ease-out;
}
.modal-content {
  background: rgba(22, 33, 56, 0.98);
  border: 1px solid var(--line);
  border-radius: 16px;
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  animation: scaleIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 {
  font-size: 18px;
  font-weight: bold;
  margin: 0;
  color: #ffb340;
}
.close-x {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.close-x:hover {
  color: var(--text);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
}
.modal-section {
  margin-bottom: 20px;
}
.modal-section h3 {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 8px;
  color: var(--text);
}
.modal-section p {
  margin-bottom: 10px;
  color: var(--text);
}
.modal-section ul {
  padding-left: 20px;
  margin: 8px 0;
}
.modal-section li {
  margin-bottom: 8px;
  color: var(--text);
}
.features-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
@media (max-width: 600px) {
  .features-grid {
    grid-template-columns: 1fr;
  }
}
.feature-item {
  background: rgba(38, 50, 77, 0.25);
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: center;
}
.modal-footer button {
  min-width: 150px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
