:root {
  --bg: #0F172A;
  --card: #1E293B;
  --card-alt: #172554;
  --input: #0F172A;
  --border: #334155;
  --text: #F8FAFC;
  --muted: #94A3B8;
  --accent: #38BDF8;
  --primary: #2563EB;
  --success: #059669;
  --amber: #B45309;
  --danger: #DC2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom, 20px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #111827;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  background: var(--primary);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 6px 9px;
  border-radius: 8px;
}

.brand-title { font-size: 15px; font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--muted); }

.offline-pill {
  font-size: 11px;
  font-weight: 600;
  color: #4ADE80;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.35);
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.card-accent {
  background: #172554;
  border-color: #1D4ED8;
}

.card-title {
  margin: 0 0 10px 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 480px) {
  .grid-2.stack-mobile { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 11.5px; color: var(--muted); font-weight: 600; }

input, select, textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text);
  font-size: 15px;
}

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

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  border-color: transparent;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

button {
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #273549;
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
}

button:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); border-color: #3B82F6; }
.btn-success { background: var(--success); border-color: #10B981; }
.btn-amber { background: var(--amber); border-color: #D97706; }
.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.5); color: #FCA5A5; }
.btn-small { min-height: 34px; padding: 5px 10px; font-size: 12px; flex: 0 0 auto; }

.chips {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 8px;
  padding: 4px 0 8px 0;
}

.chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
}

.chip.active {
  background: var(--primary);
  border-color: #60A5FA;
  color: #fff;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 6px 0 10px 0;
}

.radio-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 14px;
  cursor: pointer;
}

.radio-item input[type="radio"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
}

.cad-box {
  width: 100%;
  height: 225px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0D1117;
}

#cadCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: var(--input);
  border-radius: 8px;
  font-size: 13.5px;
}

.result-label { color: var(--muted); font-weight: 500; }
.result-val { color: #4ADE80; font-weight: 700; font-family: ui-monospace, Consolas, monospace; font-size: 14.5px; }

.warning-banner {
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid #F59E0B;
  color: #FDE68A;
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}

.error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid #EF4444;
  color: #FECACA;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.saved-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.saved-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}

.saved-info { flex: 1; min-width: 0; }
.saved-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-meta { font-size: 11.5px; color: var(--muted); }

.subtabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.subtab-btn {
  flex: 1;
  min-height: 36px;
  font-size: 12.5px;
  padding: 6px 8px;
}

.subtab-btn.active { background: var(--primary); border-color: #60A5FA; }

details summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  margin-top: 8px;
}

.status-toast {
  text-align: center;
  font-size: 12px;
  color: var(--accent);
  min-height: 18px;
}

#printSheet { display: none; }

@media print {
  body { background: #fff; color: #000; padding: 0; }
  .topbar, .container { display: none !important; }
  #printSheet {
    display: block !important;
    padding: 16px;
    font-family: Arial, sans-serif;
    color: #0F172A;
  }
  .print-header {
    background: #162447;
    color: #fff;
    padding: 14px 16px;
    border-radius: 6px;
    margin-bottom: 14px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-item {
    border: 1px solid #CBD5E1;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 14px;
    page-break-inside: avoid;
  }
  .print-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px 14px;
    font-size: 12px;
    margin-top: 4px;
  }
  .print-subhead {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #334155;
  }
  .print-inputs {
    background: #F1F5F9;
    border: 1px solid #CBD5E1;
    border-radius: 5px;
    padding: 6px 10px;
    margin-top: 8px;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .print-inputs-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 4px 12px;
    font-size: 11.5px;
    margin-top: 3px;
  }
  .print-kv { display: flex; justify-content: space-between; border-bottom: 1px solid #E2E8F0; padding: 3px 0; }
  .print-cad { margin-top: 10px; border: 1px solid #334155; border-radius: 6px; overflow: hidden; height: 210px; background: #0D1117; }
  .print-cad img { width: 100%; height: 100%; display: block; object-fit: contain; }
  .license-overlay { display: none !important; }
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.license-pill {
  min-height: 28px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.license-pill.lic-ok {
  background: rgba(22, 163, 74, 0.22);
  border: 1px solid #22C55E;
  color: #BBF7D0;
}

.license-pill.lic-warn {
  background: rgba(217, 119, 6, 0.22);
  border: 1px solid #F59E0B;
  color: #FDE68A;
}

.license-pill.lic-lock {
  background: rgba(220, 38, 38, 0.22);
  border: 1px solid #EF4444;
  color: #FECACA;
}

.license-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.license-modal {
  width: 100%;
  max-width: 460px;
  background: #1E293B;
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65);
  max-height: 92vh;
  overflow-y: auto;
}

.license-banner {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.4;
}

.license-banner.ok { background: rgba(22, 163, 74, 0.16); border: 1px solid #22C55E; color: #DCFCE7; }
.license-banner.warn { background: rgba(217, 119, 6, 0.18); border: 1px solid #F59E0B; color: #FEF3C7; }
.license-banner.err { background: rgba(220, 38, 38, 0.18); border: 1px solid #EF4444; color: #FEE2E2; }

.license-meta-box {
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.app-footer {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 10px 4px 18px 4px;
}

.pole-toggle-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pole-toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: #E2E8F0;
  cursor: pointer;
}

.pole-toggle-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
}

.cb-pill {
  min-height: 28px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--muted);
  cursor: pointer;
}

.cb-pill.active {
  background: rgba(86, 180, 233, 0.22);
  border-color: #56B4E9;
  color: #E0F2FE;
}

/* Okabe-Ito High-Contrast Colour-Blind Safe Palette */
body.cb-mode .result-val {
  color: #56B4E9;
}

body.cb-mode .offline-pill {
  color: #56B4E9;
  background: rgba(86, 180, 233, 0.14);
  border-color: rgba(86, 180, 233, 0.45);
}

body.cb-mode .license-pill.lic-ok,
body.cb-mode .license-banner.ok {
  background: rgba(2, 132, 199, 0.24);
  border: 1.5px solid #56B4E9;
  color: #E0F2FE;
}

body.cb-mode .license-pill.lic-warn,
body.cb-mode .license-banner.warn,
body.cb-mode .warning-banner {
  background: rgba(230, 159, 0, 0.20);
  border: 1.5px dashed #E69F00;
  color: #FEF3C7;
}

body.cb-mode .license-pill.lic-lock,
body.cb-mode .license-banner.err,
body.cb-mode .error-banner {
  background: rgba(204, 121, 167, 0.22);
  border: 1.5px solid #CC79A7;
  color: #FCE7F3;
}
