:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --blue: #0284c7;
  --teal: #0d9488;
  --amber: #d97706;
  --purple: #7c3aed;
  --rose: #e11d48;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header {
  background: linear-gradient(120deg, #093256, #0284c7, #0d9488);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 3px 10px rgba(15, 23, 42, 0.16);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: rgba(255,255,255,0.2);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  border: 1px solid rgba(255,255,255,0.35);
}
.brand h1 { margin: 0; font-size: 1.18rem; }
.brand small { opacity: 0.92; font-size: 0.8rem; }

.nav-tiles { display: flex; flex-wrap: wrap; gap: 8px; }
.nav-tile {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,0.28);
  background: rgba(255,255,255,0.14);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.nav-tile:hover { background: rgba(255,255,255,0.25); transform: translateY(-1px); }
.nav-tile.active {
  background: #fff;
  color: #093256;
  border-color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,0.14);
}

main { max-width: 1200px; margin: 18px auto; padding: 0 14px 44px; }
.panel { display: none; }
.panel.active { display: block; }

.section-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #f1f5f9;
  font-size: 1rem;
  font-weight: 800;
  color: #0f172a;
}

.chip-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #0369a1;
}

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(126px, 1fr));
  gap: 10px;
}

.icon-card {
  border: 2px solid #e2e8f0;
  border-radius: 14px;
  padding: 12px 8px;
  background: #f8fafc;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  min-height: 92px;
  transition: all 0.14s ease;
}

.icon-card:hover { transform: translateY(-2px); border-color: #94a3b8; }
.icon-card .glyph {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  background: #e2e8f0;
}
.icon-card .label { font-size: 0.8rem; font-weight: 700; color: #1e293b; line-height: 1.2; }

.icon-card.selected[data-tone="blue"] {
  background: #e0f2fe;
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.2);
}
.icon-card.selected[data-tone="blue"] .glyph { background: var(--blue); color: #fff; }

.icon-card.selected[data-tone="teal"] {
  background: #ccfbf1;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.2);
}
.icon-card.selected[data-tone="teal"] .glyph { background: var(--teal); color: #fff; }

.shade-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(15, 23, 42, 0.22);
  box-shadow: inset 0 2px 4px rgba(255,255,255,0.6);
}

.shade-btn {
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 8px 6px;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  font-size: 0.8rem;
  color: #1e293b;
  transition: all 0.14s ease;
}
.shade-btn.selected {
  border-color: var(--blue);
  background: #f0f9ff;
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.22);
}
.shades-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: 8px; }

.arch-block {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 8px;
  margin-bottom: 10px;
}
.arch-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 800;
  color: var(--muted);
  margin-bottom: 6px;
}
.teeth-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; overflow-x: auto; }
.tooth-btn {
  padding: 5px 2px 4px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  min-height: 60px;
  transition: all 0.14s ease;
}
.tooth-btn:hover { border-color: var(--blue); transform: translateY(-1px); }
.tooth-btn svg { width: 24px; height: 30px; }
.tooth-shape { fill: #f8fafc; stroke: #334155; stroke-width: 1.8; transition: 0.14s; }
.tooth-num { font-size: 0.72rem; font-weight: 800; color: #1e293b; }

.tooth-btn.selected {
  background: #dcfce7;
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.22);
}
.tooth-btn.selected .tooth-shape { fill: var(--teal); stroke: #115e59; }
.tooth-btn.selected .tooth-num { color: #115e59; }

.summary-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #0c4a6e;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}
.shade-notes-row { margin-top: 12px; margin-bottom: 0; }
.attachments-row { margin-top: 12px; }
.clinical-notes-row { margin-top: 6px; }
.order-form-actions { display: flex; flex-wrap: wrap; gap: 10px; }

label { display: block; font-size: 0.82rem; font-weight: 700; margin-bottom: 4px; color: #334155; }
input[type="text"], input[type="date"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  font-family: inherit;
  background: #fff;
}
textarea { min-height: 68px; resize: vertical; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 11px;
  border: none;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.14s ease;
}
.btn-sm { padding: 6px 11px; font-size: 0.78rem; border-radius: 9px; }
.btn-primary { background: linear-gradient(135deg, #0284c7, #0f4c81); color: #fff; }
.btn-success { background: linear-gradient(135deg, #0d9488, #0f766e); color: #fff; }
.btn-danger { background: #e11d48; color: #fff; }
.btn-outline { background: #fff; color: #0f172a; border: 1.5px solid var(--border); }
.btn-outline:hover { background: #f8fafc; }

.voice-box {
  background: #fdf4ff;
  border: 1.5px solid #e9d5ff;
  border-radius: 14px;
  padding: 12px;
  margin-top: 10px;
}
.voice-alert { font-size: 0.8rem; color: #6b21a8; margin-top: 6px; font-weight: 600; }
.voice-controls, .qr-scan-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.voice-controls { margin-top: 6px; }
#clear-audio-btn { display: none; }
#audio-record-status { font-size: 0.8rem; color: #475569; }
#new-order-audio-preview { width: 100%; margin-top: 8px; display: none; }

/* Tarjeta de escaneo rápido / lectura de QR */
.qr-scan-card {
  background: linear-gradient(135deg, #eff6ff, #f0fdf4);
  border: 2px solid #0284c7;
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}
#active-case-viewer { margin-top: 12px; }
.active-case-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.active-case-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#view-case-title { font-size: 1.02rem; color: #093256; }
#qr-scan-status, #view-case-sub { font-size: 0.82rem; color: #475569; }
#lab-case-audio-player { width: 100%; margin-top: 10px; display: none; }
#lab-case-notes-preview { margin: 6px 0 0; font-size: 0.86rem; color: #1e293b; }
.scan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
  margin: 10px 0;
}
.scan-field {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.84rem;
}
.scan-field small { display: block; color: var(--muted); font-size: 0.72rem; font-weight: 700; }

#qr-camera-video {
  width: 100%;
  max-width: 340px;
  border-radius: 12px;
  border: 2px solid #0284c7;
  display: none;
  margin-top: 10px;
}

.media-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 10px; margin-top: 10px; }
.media-thumb {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  background: #f8fafc;
  font-size: 0.76rem;
  text-align: center;
}
.media-thumb img, .media-thumb video {
  width: 100%;
  height: 88px;
  object-fit: cover;
  border-radius: 7px;
  margin-bottom: 4px;
}
.media-file-icon { padding: 22px 6px; }
.media-file-icon-stl { font-weight: 800; color: #0284c7; }
#stl-viewer-box {
  display: none;
  width: 100%;
  height: 230px;
  background: #0f172a;
  border-radius: 12px;
  margin-top: 10px;
  overflow: hidden;
}

.label-order-row { max-width: 460px; }
.label-print-actions { text-align: center; margin-top: 12px; }
.label-preview-wrap { display: flex; justify-content: center; padding: 12px 0; }
.qr-sticker {
  width: 325px;
  border: 2px dashed #334155;
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  color: #000;
}
.sticker-top {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #cbd5e1;
  padding-bottom: 6px;
  margin-bottom: 8px;
  font-size: 0.84rem;
  font-weight: 800;
}
.sticker-body { display: flex; gap: 10px; align-items: center; }
.sticker-meta { font-size: 0.8rem; flex: 1; }
.sticker-meta p { margin: 2px 0; }

.backup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.backup-import { margin: 0; }
#import-json-input { display: none; }
.orders-table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { padding: 10px 8px; border-bottom: 1px solid #e2e8f0; text-align: left; vertical-align: middle; }
th { background: #f8fafc; font-weight: 800; color: #334155; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  background: #e0f2fe;
  color: #0369a1;
}
.badge-voice { background: #dcfce7; color: #166534; }
.orders-empty { text-align: center; color: var(--muted); }
.attachments-empty { color: var(--muted); }
input.tray-input { width: 105px; }
.order-row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

@media print {
  header, nav, .no-print, .section-card:not(.printable-card) { display: none !important; }
  body { background: #fff; }
  main { margin: 0; padding: 0; }
  .printable-card { border: none; box-shadow: none; padding: 0; }
  .qr-sticker { border: 1px solid #000; }
}
