/* ── Reset e base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand:       #1a3a6b;
  --brand-light: #e8edf5;
  --text-1:      #111;
  --text-2:      #555;
  --text-3:      #888;
  --border:      #e4e4e4;
  --surface:     #f7f7f7;
  --white:       #fff;
  --ok:          #15803d;
  --ok-bg:       #dcfce7;
  --warn:        #92400e;
  --warn-bg:     #fef3c7;
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text-1);
  background: var(--surface);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── Header ───────────────────────────────────────────── */
.site-header {
  background: var(--brand);
  color: var(--white);
  padding: 0 1.25rem;
  height: 52px;
  display: flex;
  align-items: center;
}
.header-inner {
  display: flex;
  align-items: baseline;
  gap: 12px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}
.header-logo {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.2px;
}
.header-sub {
  font-size: 12px;
  opacity: 0.65;
}

/* ── Main ─────────────────────────────────────────────── */
#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem;
}

/* ── Loading ──────────────────────────────────────────── */
#view-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 0;
  gap: 1rem;
}
.loading-spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-3); font-size: 13px; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-ok   { background: var(--ok-bg);   color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-info { background: var(--brand-light); color: var(--brand); }
.badge-gray { background: #efefef; color: var(--text-2); }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-2);
  transition: background 0.1s;
}
.btn:hover { background: var(--surface); }
.btn-primary {
  background: var(--brand);
  color: var(--white);
  border-color: var(--brand);
}
.btn-primary:hover { opacity: 0.9; }

/* ── Ficha ────────────────────────────────────────────── */
.ficha {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.ficha-header {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.ficha-header-main { display: flex; gap: 1rem; align-items: flex-start; }
.ficha-icon { font-size: 2rem; line-height: 1; margin-top: 2px; }
.ficha-id { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.ficha-nome { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; line-height: 1.2; }
.ficha-modelo { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.ficha-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.qr-wrap img, #qr-canvas canvas { border-radius: var(--radius-sm); }
.qr-label { font-size: 10px; color: var(--text-3); white-space: nowrap; }

/* ── Seções da ficha ──────────────────────────────────── */
.ficha-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-3);
  margin-bottom: 12px;
}

/* ── Fields grid ──────────────────────────────────────── */
.fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
}
@media (max-width: 480px) { .fields-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 2px; }
.field-label { font-size: 11px; color: var(--text-3); }
.field-val { font-size: 14px; font-weight: 500; color: var(--text-1); }
.field-val--warn { color: var(--warn); }

/* ── Histórico ────────────────────────────────────────── */
.historico { display: flex; flex-direction: column; }
.hist-item {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.hist-item:last-child { border-bottom: none; }
.hist-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.hist-dot--green { background: var(--ok); }
.hist-dot--amber { background: #d97706; }
.hist-body { display: flex; flex-direction: column; gap: 2px; }
.hist-date { font-size: 11px; color: var(--text-3); }
.hist-desc { font-size: 13px; color: var(--text-1); }
.empty-hist { font-size: 13px; color: var(--text-3); padding: 8px 0; }

/* ── Footer da ficha ──────────────────────────────────── */
.ficha-footer {
  padding: 1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.ficha-url {
  font-size: 11px;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ── Lista geral ──────────────────────────────────────── */
.list-page { display: flex; flex-direction: column; gap: 1rem; }

.list-header {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
}
.list-header h1 { font-size: 18px; font-weight: 600; margin-bottom: 1rem; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: .875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-num { font-size: 22px; font-weight: 600; }
.stat-label { font-size: 12px; color: var(--text-3); }
.stat-ok { color: var(--ok); }
.stat-warn { color: #d97706; }

.list-cols {
  display: grid;
  grid-template-columns: 28px 52px 1fr 110px 80px;
  gap: 8px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.list-body {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.list-row {
  display: grid;
  grid-template-columns: 28px 52px 1fr 110px 80px;
  gap: 8px;
  padding: 12px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  cursor: pointer;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface); }
.list-icon { font-size: 18px; }
.list-num { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.list-name { display: flex; flex-direction: column; gap: 1px; }
.list-name strong { font-size: 13px; font-weight: 500; }
.list-name small { font-size: 11px; color: var(--text-3); }
.list-local { font-size: 12px; color: var(--text-2); }

@media (max-width: 520px) {
  .list-cols, .list-row { grid-template-columns: 28px 44px 1fr 72px; }
  .list-local { display: none; }
}

/* ── Empty / Error ────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
.empty-icon { font-size: 2.5rem; }
.empty-state h2 { font-size: 16px; font-weight: 600; }
.empty-state p { font-size: 13px; color: var(--text-2); max-width: 320px; }
