/* NFCOTS Builder Guidebook — global styles
   Brand: deep navy + steel blue + red hazard accent. Matches the field server lesson template. */

:root {
  --c-navy: #1F3864;
  --c-navy-dark: #142446;
  --c-navy-bg: #0F1B2E;
  --c-steel: #2E75B6;
  --c-hazard: #C62828;
  --c-amber: #F9A825;
  --c-olive: #558B2F;
  --c-bg: #F5F5F5;
  --c-card: #FFFFFF;
  --c-meta: #E8EDF3;
  --c-text: #303030;
  --c-muted: #707070;
  --c-border: #D0D7E2;
  --c-shadow: 0 2px 4px rgba(0,0,0,0.12);
  --c-shadow-lg: 0 6px 24px rgba(0,0,0,0.18);
  --radius: 10px;
  --radius-sm: 6px;
}

* , *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
}

a { color: var(--c-steel); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Baseline list + paragraph styling (the global reset zeros padding, so we restore
   sane defaults for content that isn't inside a special container). */
ol, ul {
  padding-left: 26px;
  margin: 10px 0;
}
li { margin: 4px 0; line-height: 1.55; }
p { margin: 10px 0; }
p + ol, p + ul { margin-top: 6px; }
ol + p, ul + p, ol + button, ul + button,
ol + .btn, ul + .btn, ol + div, ul + div { margin-top: 14px; }

button, .btn {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--c-navy);
  background: var(--c-navy);
  color: #fff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  transition: background .15s, transform .05s;
}
button:hover, .btn:hover { background: var(--c-navy-dark); }
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary { background: #fff; color: var(--c-navy); }
button.secondary:hover, .btn.secondary:hover { background: var(--c-meta); }
button.danger, .btn.danger { background: var(--c-hazard); border-color: var(--c-hazard); }
button[disabled], .btn[disabled] { opacity: .55; cursor: not-allowed; }

input[type="text"], input[type="number"], input[type="url"], input[type="email"], select, textarea {
  font: inherit;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: #fff;
  color: var(--c-text);
  width: 100%;
}
textarea { font-family: ui-monospace, Consolas, Menlo, monospace; resize: vertical; min-height: 120px; }
label { font-size: 13px; font-weight: 600; color: var(--c-navy); display: block; margin-bottom: 4px; }
.help { font-size: 12px; color: var(--c-muted); margin-top: 4px; }

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  background: var(--c-navy);
  color: #fff;
  padding: 8px 16px;
  box-shadow: var(--c-shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar .logo {
  height: 44px;
  width: auto;
  flex-shrink: 0;
  /* Logo already contains NFCOTS wordmark, so visually anchors the bar */
}
.topbar .brand {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  border-left: 1px solid rgba(255,255,255,.18);
  padding-left: 12px;
}
.topbar .brand-title { font-size: 14px; font-weight: 600; letter-spacing: .3px; }
.topbar .brand-sub { font-size: 11px; opacity: .72; }
@media (max-width: 720px) {
  .topbar .logo { height: 38px; }
  .topbar .brand { padding-left: 8px; }
  .topbar .brand-title { font-size: 13px; }
  .topbar .brand-sub { display: none; }
  .topbar nav a { padding: 6px 7px; font-size: 12px; }
}
@media (max-width: 480px) {
  .topbar .brand { display: none; }
}
.topbar nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.topbar nav a {
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-decoration: none;
}
.topbar nav a:hover { background: rgba(255,255,255,.12); }
.topbar nav a.active { background: rgba(255,255,255,.2); }

#install-btn {
  background: var(--c-amber);
  color: #1a1a1a;
  border-color: var(--c-amber);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
}
#install-btn[hidden] { display: none; }

/* ── Layout ─────────────────────────────────────────────────────── */
.app {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 1fr;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}
@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: block; position: fixed; inset: 60px 0 0 0; z-index: 40; background: var(--c-card); overflow-y: auto; }
}
.sidebar {
  border-right: 1px solid var(--c-border);
  background: #fff;
  padding: 14px 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 56px);
  overflow-y: auto;
}
.sidebar h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--c-muted);
  padding: 14px 16px 4px;
}
.sidebar a {
  display: block;
  padding: 7px 16px;
  font-size: 14px;
  color: var(--c-text);
  border-left: 3px solid transparent;
}
.sidebar a:hover { background: var(--c-meta); text-decoration: none; }
.sidebar a.active { background: var(--c-meta); border-left-color: var(--c-steel); color: var(--c-navy); font-weight: 600; }

main {
  padding: 22px 28px;
  min-width: 0;
  max-width: 100%;
}
@media (max-width: 540px) {
  main { padding: 16px; }
}

/* ── Article / markdown rendered content ─────────────────────────── */
article.page h1 {
  font-size: 26px;
  color: var(--c-navy);
  margin-bottom: 6px;
  line-height: 1.2;
}
article.page h2 {
  font-size: 20px;
  color: var(--c-navy);
  margin: 24px 0 10px;
  border-bottom: 2px solid var(--c-meta);
  padding-bottom: 4px;
}
article.page h3 { font-size: 16px; color: var(--c-navy-dark); margin: 18px 0 6px; }
article.page h4 { font-size: 14px; color: #444; margin: 14px 0 4px; }
article.page p { margin: 10px 0; }
article.page ul, article.page ol { padding-left: 24px; margin: 10px 0; }
article.page li { margin: 4px 0; }
article.page strong { color: var(--c-navy); }
article.page hr { border: none; border-top: 1px solid var(--c-border); margin: 24px 0; }

article.page table {
  width: 100%;
  border-collapse: collapse;
  margin: 14px 0;
  font-size: 14px;
}
article.page th {
  background: var(--c-navy);
  color: #fff;
  padding: 8px 10px;
  text-align: left;
  border: 1px solid var(--c-navy);
}
article.page td {
  padding: 7px 10px;
  border: 1px solid var(--c-border);
  vertical-align: top;
}
article.page tr:nth-child(even) td { background: #FAFBFD; }

article.page blockquote {
  border-left: 4px solid var(--c-steel);
  padding: 8px 16px;
  background: #F0F4F8;
  margin: 14px 0;
  color: #444;
}
article.page code {
  background: #F0F2F5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 13px;
  font-family: ui-monospace, Consolas, Menlo, monospace;
}
article.page pre {
  background: #1F2937;
  color: #E2E8F0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
  margin: 12px 0;
  font-family: ui-monospace, Consolas, Menlo, monospace;
}
article.page pre code { background: none; color: inherit; padding: 0; }

/* ── Cards / callouts ─────────────────────────────────────────────── */
.card {
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 14px 0;
  box-shadow: var(--c-shadow);
}
.callout {
  border-left: 4px solid var(--c-steel);
  background: #EEF4FB;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin: 14px 0;
  font-size: 14px;
}
.callout.warn { border-color: var(--c-amber); background: #FFF7E6; }
.callout.danger { border-color: var(--c-hazard); background: #FCEDED; }
.callout.success { border-color: var(--c-olive); background: #ECF6E4; }
.callout strong:first-child { color: inherit; }

/* ── Hero / landing ─────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--c-navy-dark) 0%, var(--c-navy) 60%, var(--c-steel) 130%);
  color: #fff;
  padding: 36px 28px;
  border-radius: var(--radius);
  margin-bottom: 18px;
}
.hero h1 { font-size: 28px; margin-bottom: 8px; }
.hero p { opacity: .92; max-width: 640px; }
.hero .pill {
  display: inline-block;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.28);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-bottom: 10px;
}

/* ── Tool tiles ─────────────────────────────────────────────────── */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin: 14px 0;
}
.tile {
  display: block;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--c-text);
  text-decoration: none;
  transition: transform .08s, box-shadow .12s, border-color .12s;
}
.tile:hover {
  transform: translateY(-1px);
  text-decoration: none;
  border-color: var(--c-steel);
  box-shadow: var(--c-shadow-lg);
}
.tile-icon {
  width: 36px; height: 36px;
  background: var(--c-meta);
  color: var(--c-navy);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 8px;
}
.tile-title { font-size: 15px; font-weight: 700; color: var(--c-navy); }
.tile-desc { font-size: 13px; color: var(--c-muted); margin-top: 4px; }

/* ── Wizard (decision tree) ───────────────────────────────────────── */
.wizard {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
}
.wizard h3 { color: var(--c-navy); margin-bottom: 4px; }
.wizard .options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}
.wizard .opt {
  padding: 10px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  background: #FAFBFD;
  cursor: pointer;
  text-align: left;
  color: var(--c-text);
  font-size: 14px;
}
.wizard .opt:hover { border-color: var(--c-steel); }
.wizard .result {
  margin-top: 14px;
  background: var(--c-meta);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  border-left: 4px solid var(--c-olive);
}

/* ── Badges (lesson badges) ──────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  margin-right: 4px;
}
.badge-country { background: var(--c-navy); }
.badge-type { background: var(--c-steel); }
.badge-hazard { background: var(--c-hazard); }
.badge-era { background: #5D4037; }
.badge-status { background: var(--c-olive); }

/* ── Modals ──────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,27,46,.66);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 22px 24px;
  box-shadow: var(--c-shadow-lg);
}
.modal h2 { color: var(--c-navy); margin-bottom: 10px; }
.modal .actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

/* ── Footer ──────────────────────────────────────────────────────── */
footer.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--c-muted);
  border-top: 1px solid var(--c-border);
  background: #fff;
}
footer.app-footer a { color: var(--c-steel); }

/* ── Builder-specific ────────────────────────────────────────────── */
.builder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 980px) {
  .builder-grid { grid-template-columns: 1fr; }
}
.section-card {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  margin: 10px 0;
  transition: opacity .12s, box-shadow .12s;
}
.section-card.dragging { opacity: .45; }
.section-card.drop-above { box-shadow: 0 -3px 0 0 var(--c-steel); }
.section-card.drop-below { box-shadow: 0 3px 0 0 var(--c-steel); }
.section-card .section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--c-meta);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.section-card .section-head input[type="text"] {
  font-weight: 600;
  color: var(--c-navy);
  background: transparent;
  border: none;
  padding: 4px 0;
}
.section-card .section-body { padding: 10px 12px; }
.section-card .section-controls {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.section-card .section-controls button {
  padding: 3px 8px;
  font-size: 12px;
  background: #fff;
  color: var(--c-navy);
  border-color: var(--c-border);
}
.preview-pane {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  max-height: 78vh;
  overflow-y: auto;
}
.preview-pane h1 { font-size: 20px; color: var(--c-navy); }
.preview-pane h2 { font-size: 16px; color: var(--c-navy); border-bottom: 2px solid var(--c-meta); padding-bottom: 4px; margin-top: 14px; }
.preview-pane h3 { font-size: 14px; margin-top: 10px; }
.preview-pane table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.preview-pane th { background: var(--c-navy); color: #fff; padding: 6px; text-align: left; }
.preview-pane td { padding: 6px; border: 1px solid var(--c-border); }
.preview-pane img { max-width: 100%; height: auto; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  padding: 10px;
  background: var(--c-meta);
  border-radius: var(--radius-sm);
}

/* ── Asset library ───────────────────────────────────────────────── */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.asset-card {
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 12px;
  display: flex;
  flex-direction: column;
}
.asset-card .thumb {
  height: 120px;
  background: var(--c-meta);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.asset-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.asset-card .meta { padding: 8px; }
.asset-card .meta-title { font-weight: 600; color: var(--c-navy); margin-bottom: 4px; }
.asset-card .actions { display: flex; gap: 4px; padding: 0 8px 8px; }
.asset-card .actions button { font-size: 11px; padding: 4px 8px; flex: 1; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
  align-items: end;
}
.filters > div { min-width: 140px; }

/* ── QR generator ─────────────────────────────────────────────────── */
.qr-result {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
}
#qr-canvas { background: #fff; padding: 8px; border: 1px solid var(--c-border); border-radius: var(--radius-sm); }

/* ── NFC writer ───────────────────────────────────────────────────── */
.nfc-status {
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--c-meta);
  margin: 12px 0;
  font-size: 14px;
}
.nfc-status.ok { background: #ECF6E4; border-left: 4px solid var(--c-olive); }
.nfc-status.err { background: #FCEDED; border-left: 4px solid var(--c-hazard); }

/* ── Utility ──────────────────────────────────────────────────────── */
/* ── Required-field validation ──────────────────────────────────── */
input.field-error, select.field-error, textarea.field-error {
  border-color: var(--c-hazard) !important;
  background: #FFF5F5 !important;
  box-shadow: 0 0 0 3px rgba(198, 40, 40, 0.12);
}

/* ── Tooltips ──────────────────────────────────────────────────── */
.tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--c-meta);
  color: var(--c-navy);
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
  cursor: help;
  position: relative;
  vertical-align: middle;
  user-select: none;
}
.tip::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #1F2937;
  color: #fff;
  padding: 7px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 400;
  white-space: normal;
  width: max-content;
  max-width: 280px;
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.tip:hover::after, .tip:focus::after { opacity: 1; visibility: visible; }

.hidden { display: none !important; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 1 1 auto; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mb-2 { margin-bottom: 12px; }
.gap-2 { gap: 12px; }
.text-muted { color: var(--c-muted); font-size: 13px; }
.right { text-align: right; }
