/* ============================================================
   JUBILEU — Design System Oficial
   Grafite #606062 | Laranja #F07335 | Creme #F2EBDF | Platina #E6E7E8
   ============================================================ */

:root {
  --grafite: #606062;
  --grafite-dark: #3e3e40;
  --grafite-mid: #4a4a4c;
  --laranja: #F07335;
  --laranja-dark: #d45c20;
  --laranja-soft: rgba(240, 115, 53, 0.12);
  --creme: #F2EBDF;
  --platina: #E6E7E8;
  --branco: #ffffff;
  --texto: #2c2c2e;
  --texto-muted: #6b6b6e;
  --cinza: #757575;
  --amarelo: #F57F17;
  --laranja-status: #E65100;
  --verde: #2E7D32;
  --vermelho: #C62828;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 18px rgba(60, 60, 62, 0.08);
  --shadow-lg: 0 12px 40px rgba(60, 60, 62, 0.14);
  --header-h: 56px;
  --letreiro-h: 36px;
  --nav-h: 64px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --transition: 0.25s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--creme);
  background-image:
    radial-gradient(ellipse at 0% 0%, rgba(240, 115, 53, 0.06), transparent 50%),
    radial-gradient(ellipse at 100% 100%, rgba(96, 96, 98, 0.06), transparent 45%);
  color: var(--texto);
  min-height: 100dvh;
  line-height: 1.45;
}

a { color: var(--laranja); text-decoration: none; }
a:hover { color: var(--laranja-dark); }

img { max-width: 100%; display: block; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------- Layout shell ---------- */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: linear-gradient(135deg, var(--grafite-dark), var(--grafite));
  color: #fff;
  min-height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  box-shadow: 0 2px 12px rgba(0,0,0,.18);
}

.app-header .brand {
  display: flex;
  align-items: center;
  gap: .65rem;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: .02em;
}

.app-header .brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--laranja);
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 800;
  color: #fff;
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.app-header .user-chip {
  display: flex;
  align-items: center;
  gap: .45rem;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  padding: .3rem .65rem .3rem .3rem;
  color: #fff;
  cursor: pointer;
  transition: var(--transition);
}

.app-header .user-chip:hover { background: rgba(255,255,255,.18); }

.app-header .user-chip img,
.app-header .user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--platina);
}

.letreiro {
  background: var(--grafite-mid);
  color: #fff;
  height: var(--letreiro-h);
  overflow: hidden;
  position: relative;
  border-bottom: 2px solid var(--laranja);
}

.letreiro-track {
  display: inline-block;
  white-space: nowrap;
  padding: .55rem 0;
  animation: marquee 28s linear infinite;
  font-size: .88rem;
  font-weight: 500;
}

.letreiro-track span {
  display: inline-block;
  padding-right: 4rem;
}

.letreiro-track strong { color: var(--laranja); }

@keyframes marquee {
  0% { transform: translateX(100vw); }
  100% { transform: translateX(-100%); }
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1rem 5.5rem;
}

.app-main.wide { max-width: 1400px; }

/* ---------- Cards / Glass ---------- */
.card {
  background: rgba(255,255,255,.88);
  border: 1px solid var(--platina);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.card + .card { margin-top: 1rem; }

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--grafite-dark);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--grafite-dark);
  margin-bottom: .35rem;
}

.section-sub {
  color: var(--texto-muted);
  font-size: .9rem;
  margin-bottom: 1rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 48px;
  padding: .65rem 1.15rem;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
  text-decoration: none;
  user-select: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--laranja);
  color: #fff;
  box-shadow: 0 4px 14px rgba(240, 115, 53, .35);
}
.btn-primary:hover { background: var(--laranja-dark); color: #fff; }

.btn-secondary {
  background: var(--grafite);
  color: #fff;
}
.btn-secondary:hover { background: var(--grafite-dark); color: #fff; }

.btn-ghost {
  background: transparent;
  color: var(--grafite);
  border: 1px solid var(--platina);
}
.btn-ghost:hover { background: var(--platina); color: var(--texto); }

.btn-danger {
  background: var(--vermelho);
  color: #fff;
}

.btn-success {
  background: var(--verde);
  color: #fff;
}

.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: .4rem .85rem; font-size: .9rem; }
.btn-icon {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 12px;
}

.btn:disabled, .btn.disabled {
  opacity: .45;
  pointer-events: none;
}

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1rem; }

.form-label {
  display: block;
  font-weight: 500;
  font-size: .88rem;
  color: var(--grafite-dark);
  margin-bottom: .35rem;
}

.form-control {
  width: 100%;
  min-height: 48px;
  padding: .65rem .9rem;
  border: 1.5px solid var(--platina);
  border-radius: var(--radius-sm);
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
  outline: none;
  border-color: var(--laranja);
  box-shadow: 0 0 0 3px var(--laranja-soft);
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

.form-hint {
  font-size: .8rem;
  color: var(--texto-muted);
  margin-top: .3rem;
}

.form-row {
  display: grid;
  gap: 1rem;
}

@media (min-width: 720px) {
  .form-row.cols-2 { grid-template-columns: 1fr 1fr; }
  .form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* ---------- Login ---------- */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    linear-gradient(160deg, rgba(62,62,64,.92), rgba(96,96,98,.75)),
    radial-gradient(circle at 20% 20%, rgba(240,115,53,.35), transparent 40%),
    var(--grafite-dark);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.95);
  border-radius: 20px;
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255,255,255,.4);
}

.login-brand {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-brand .logo {
  width: 72px;
  height: 72px;
  margin: 0 auto .85rem;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--laranja), var(--laranja-dark));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1.6rem;
  font-weight: 800;
  box-shadow: 0 8px 24px rgba(240,115,53,.4);
}

.login-brand h1 {
  font-size: 1.45rem;
  color: var(--grafite-dark);
  font-weight: 700;
}

.login-brand p {
  color: var(--texto-muted);
  font-size: .9rem;
  margin-top: .25rem;
}

/* ---------- Metrics / Dashboard ---------- */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin-bottom: 1rem;
}

@media (min-width: 900px) {
  .metrics-grid { grid-template-columns: repeat(3, 1fr); }
  .metrics-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

.metric-card {
  background: #fff;
  border: 1px solid var(--platina);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--laranja);
}

.metric-card .label {
  font-size: .78rem;
  color: var(--texto-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.metric-card .value {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--grafite-dark);
  margin-top: .2rem;
  line-height: 1.1;
}

.metric-card .hint {
  font-size: .78rem;
  color: var(--texto-muted);
  margin-top: .25rem;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

table.data th,
table.data td {
  padding: .75rem .65rem;
  text-align: left;
  border-bottom: 1px solid var(--platina);
}

table.data th {
  font-weight: 600;
  color: var(--grafite);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  background: rgba(230,231,232,.35);
}

table.data tr:hover td { background: rgba(240,115,53,.04); }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
  color: #fff;
}

.badge-cinza { background: var(--cinza); }
.badge-amarelo { background: var(--amarelo); }
.badge-laranja { background: var(--laranja-status); }
.badge-verde { background: var(--verde); }
.badge-vermelho { background: var(--vermelho); }

/* ---------- Fiscal bottom nav ---------- */
.fiscal-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 90;
  background: rgba(255,255,255,.95);
  border-top: 1px solid var(--platina);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-around;
  padding: .4rem .35rem calc(.4rem + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.06);
}

.fiscal-nav button {
  flex: 1;
  max-width: 72px;
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .2rem;
  cursor: pointer;
  padding: .25rem;
  color: var(--texto-muted);
  font-size: .65rem;
  font-weight: 600;
}

.fiscal-nav .dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--cinza);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: .7rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  transition: transform var(--transition);
}

.fiscal-nav button:active .dot { transform: scale(0.92); }

.fiscal-nav .ocorrencia .dot {
  background: var(--grafite);
}

/* ---------- SOS FAB ---------- */
.sos-fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-h) + 20px);
  z-index: 95;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--laranja);
  color: #fff;
  font-weight: 800;
  font-size: .85rem;
  letter-spacing: .04em;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(240,115,53,.5);
  animation: sos-pulse 1.8s ease-in-out infinite;
}

.sos-fab:active { transform: scale(0.95); }

@keyframes sos-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240,115,53,.55), 0 6px 22px rgba(240,115,53,.45); }
  50% { box-shadow: 0 0 0 14px rgba(240,115,53,0), 0 6px 22px rgba(240,115,53,.45); }
}

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(46,46,48,.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  transition: opacity .25s ease;
}

.modal-overlay.open {
  display: flex;
  opacity: 1;
}

@media (min-width: 720px) {
  .modal-overlay { align-items: center; }
}

.modal {
  background: #fff;
  border: 1px solid var(--platina);
  border-radius: 18px 18px 14px 14px;
  width: 100%;
  max-width: 520px;
  max-height: 88dvh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(24px);
  transition: transform .25s ease;
  padding: 1.25rem;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: .5rem;
}

.modal-header h3 {
  font-size: 1.1rem;
  color: var(--grafite-dark);
}

.modal-close {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: var(--platina);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

/* ---------- Alerts ---------- */
.alert {
  padding: .85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: .92rem;
  border: 1px solid transparent;
}

.alert-error {
  background: #fdecea;
  color: #8b1a1a;
  border-color: #f5c6c2;
}

.alert-success {
  background: #e8f5e9;
  color: #1b5e20;
  border-color: #c8e6c9;
}

.alert-warning {
  background: #fff8e1;
  color: #e65100;
  border-color: #ffe082;
}

.alert-info {
  background: #eceff1;
  color: var(--grafite-dark);
  border-color: var(--platina);
}

/* ---------- Emergency overlay (gestor) ---------- */
.emergencia-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(198, 40, 40, .92);
  color: #fff;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  animation: emerg-blink 1s ease-in-out infinite alternate;
}

.emergencia-overlay.show { display: flex; }

.emergencia-overlay h2 {
  font-size: 2rem;
  margin-bottom: .5rem;
}

.emergencia-overlay p { font-size: 1.05rem; opacity: .95; margin: .25rem 0; }

@keyframes emerg-blink {
  from { background: rgba(198, 40, 40, .92); }
  to { background: rgba(240, 115, 53, .92); }
}

/* ---------- Barraca detail ---------- */
.barraca-hero {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.barraca-foto {
  width: 88px;
  height: 88px;
  border-radius: 14px;
  object-fit: cover;
  background: var(--platina);
  flex-shrink: 0;
}

.info-list {
  display: grid;
  gap: .45rem;
  font-size: .92rem;
}

.info-list dt {
  font-size: .75rem;
  color: var(--texto-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.info-list dd {
  font-weight: 600;
  color: var(--texto);
  margin-bottom: .35rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1rem;
}

.search-box {
  display: flex;
  gap: .5rem;
  width: 100%;
}

.search-box .form-control { flex: 1; }

/* ---------- Sidebar desktop (admin/gestor) ---------- */
@media (min-width: 960px) {
  .with-sidebar {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 0;
    min-height: calc(100dvh - var(--header-h));
  }
  .sidebar {
    background: linear-gradient(180deg, var(--grafite-dark), var(--grafite));
    color: #fff;
    padding: 1.25rem .85rem;
    position: sticky;
    top: var(--header-h);
    height: calc(100dvh - var(--header-h));
    overflow-y: auto;
  }
  .sidebar a {
    display: flex;
    align-items: center;
    gap: .55rem;
    color: rgba(255,255,255,.85);
    padding: .7rem .85rem;
    border-radius: 10px;
    margin-bottom: .25rem;
    font-weight: 500;
    font-size: .92rem;
    transition: var(--transition);
  }
  .sidebar a:hover, .sidebar a.active {
    background: rgba(240,115,53,.25);
    color: #fff;
  }
  .sidebar a.active {
    border-left: 3px solid var(--laranja);
  }
  .sidebar-content { padding: 1.25rem; }
}

.sidebar { display: none; }
@media (min-width: 960px) { .sidebar { display: block; } }

.mobile-nav-links {
  display: flex;
  gap: .5rem;
  overflow-x: auto;
  padding-bottom: .5rem;
  margin-bottom: .75rem;
}

.mobile-nav-links a {
  flex-shrink: 0;
  background: #fff;
  border: 1px solid var(--platina);
  border-radius: 999px;
  padding: .45rem .9rem;
  color: var(--grafite);
  font-size: .82rem;
  font-weight: 600;
}

.mobile-nav-links a.active {
  background: var(--laranja);
  border-color: var(--laranja);
  color: #fff;
}

@media (min-width: 960px) {
  .mobile-nav-links { display: none; }
}

/* ---------- Empty / helpers ---------- */
.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--texto-muted);
}

.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--texto-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

.qr-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  padding: 1rem;
}

.qr-box canvas, .qr-box img {
  border: 8px solid #fff;
  box-shadow: var(--shadow);
  border-radius: 8px;
}

#qr-reader {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  border-radius: var(--radius);
  overflow: hidden;
}

/* ---------- Alvará diploma ---------- */
.alvara-doc {
  background: #fff;
  border: 6px double var(--grafite);
  padding: 2rem 1.5rem;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.alvara-doc::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid var(--laranja);
  pointer-events: none;
}

.alvara-doc .brasao {
  text-align: center;
  margin-bottom: 1rem;
}

.alvara-doc h1 {
  text-align: center;
  font-size: 1.35rem;
  color: var(--grafite-dark);
  letter-spacing: .04em;
  margin-bottom: .75rem;
}

.alvara-doc .corpo {
  font-size: .95rem;
  line-height: 1.7;
  text-align: justify;
}

.alvara-doc .check {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: 1rem 0;
  font-weight: 700;
  color: var(--verde);
}

.alvara-doc .dados {
  margin: 1rem 0;
  padding: 1rem;
  background: var(--creme);
  border-radius: 8px;
}

.alvara-doc .assinatura {
  margin-top: 2rem;
  text-align: center;
  font-size: .85rem;
  color: var(--texto-muted);
}

@media print {
  body { background: #fff; }
  .app-header, .letreiro, .no-print, .sos-fab, .fiscal-nav { display: none !important; }
  .app-main { padding: 0; max-width: none; }
  .alvara-doc { box-shadow: none; }
}

/* ---------- PWA install hint ---------- */
.install-hint {
  position: fixed;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 150;
  background: var(--grafite-dark);
  color: #fff;
  padding: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: none;
}

.install-hint.show { display: block; }
