:root {
  --bg: #f4f7fb;
  --bg-elev: #ffffff;
  --ink: #1a2433;
  --muted: #5c6b7a;
  --line: #d5deea;
  --brand: #1e2a3a;
  --brand-2: #2f4156;
  --brand-3: #3d5168;
  --accent: #e67e22;
  --accent-2: #f5a623;
  --ok: #1f7a4c;
  --nc: #b42318;
  --na: #6b7280;
  --nv: #9a6700;
  --warn: #b54708;
  --shadow: 0 10px 30px rgba(30, 42, 58, 0.10);
  --radius: 14px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(47, 65, 86, 0.14), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, rgba(230, 126, 34, 0.08), transparent 50%),
    linear-gradient(180deg, #eef3f9 0%, var(--bg) 40%, #e8eef6 100%);
  min-height: 100vh;
}

a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: grid; grid-template-columns: 270px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, #1a2433 0%, #1e2a3a 45%, #243447 100%);
  color: #e8eef6;
  padding: 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .75rem;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 20px rgba(0,0,0,.18);
}
.sidebar-brand .brand-logo {
  width: 100%;
  height: auto;
  max-height: 56px;
  object-fit: contain;
  display: block;
}

.side-nav { display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.side-nav a {
  color: #c9d5e4; padding: .7rem .85rem; border-radius: 10px;
  text-decoration: none; font-weight: 500;
}
.side-nav a:hover, .side-nav a.active {
  background: rgba(245, 166, 35, 0.16);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-section {
  margin-top: .75rem; padding: .5rem .85rem .25rem;
  font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; opacity: .6;
}
.sidebar-user {
  border-top: 1px solid rgba(255,255,255,.12);
  padding-top: .85rem;
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
}
.sidebar-user strong { display: block; font-size: .9rem; }
.sidebar-user small { opacity: .7; font-size: .75rem; }

.main-wrap { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 1rem;
  padding: 1rem 1.5rem; background: rgba(255,255,255,.78);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 1.25rem; flex: 1; }
.menu-toggle { display: none; border: 0; background: var(--bg); padding: .45rem .7rem; border-radius: 8px; font-size: 1.1rem; }
.content { padding: 1.25rem 1.5rem 2rem; }
.app-footer { padding: 1rem 1.5rem; color: var(--muted); font-size: .85rem; border-top: 1px solid var(--line); }

.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem;
}
.card + .card { margin-top: 1rem; }
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem; margin-bottom: 1rem;
}
.card-header h2 { margin: 0; font-size: 1.05rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; right: -20px; top: -20px;
  width: 80px; height: 80px; border-radius: 50%;
  background: radial-gradient(circle, rgba(230,126,34,.18), transparent 70%);
}
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.8rem; font-weight: 700; margin-top: .2rem; font-family: var(--mono); color: var(--brand); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid transparent; border-radius: 10px; padding: .6rem 1rem;
  font-weight: 600; cursor: pointer; text-decoration: none; font-family: inherit;
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-accent { background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #1a1205; }
.btn-secondary { background: #e8eef6; color: var(--brand); border-color: var(--line); }
.btn-danger { background: #fdecec; color: var(--nc); border-color: #f5c2c0; }
.btn-ghost { background: transparent; color: #e8eef6; border-color: rgba(255,255,255,.25); }
.btn-sm { padding: .4rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .9rem 1rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: .85rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: .65rem .75rem; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(47,65,86,.28); border-color: var(--brand-2);
}
textarea { min-height: 90px; resize: vertical; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: .7rem .8rem; border-bottom: 1px solid var(--line); text-align: left; font-size: .92rem; }
th { background: #eef3f9; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: #f7faff; }
.mono { font-family: var(--mono); font-size: .85rem; }

.badge {
  display: inline-flex; align-items: center; padding: .2rem .55rem;
  border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: uppercase;
}
.badge-ok { background: #e8f7ee; color: var(--ok); }
.badge-nc { background: #fdecec; color: var(--nc); }
.badge-na { background: #eef0f2; color: var(--na); }
.badge-nv { background: #fff7e8; color: var(--nv); }
.badge-warn { background: #fff4e8; color: var(--warn); }

.alert { padding: .85rem 1rem; border-radius: 12px; margin-bottom: 1rem; font-weight: 500; }
.alert-ok { background: #e8f7ee; color: #14532d; border: 1px solid #b7e4c7; }
.alert-error { background: #fdecec; color: #7f1d1d; border: 1px solid #f5c2c0; }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; margin-bottom: 1rem; }
.filters input, .filters select { min-width: 160px; }

.checklist-system {
  margin: 1.25rem 0 .5rem; padding: .45rem .7rem;
  background: linear-gradient(90deg, rgba(30,42,58,.1), transparent);
  border-left: 4px solid var(--accent); font-weight: 700; font-size: .9rem;
}
.status-group { display: flex; gap: .35rem; flex-wrap: wrap; }
.status-group label {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .25rem .45rem; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: .78rem; font-weight: 700;
}
.status-group input { width: auto; }
.status-group .c { color: var(--ok); }
.status-group .nc { color: var(--nc); }
.status-group .na { color: var(--na); }
.status-group .nv { color: var(--nv); }

.legend {
  display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem;
  padding: .75rem; background: #eef3f9; border-radius: 10px; font-size: .85rem;
}
.btn-block-mobile { width: auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.empty { padding: 2rem; text-align: center; color: var(--muted); }

/* Auth */
.auth-body {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    linear-gradient(135deg, rgba(26,36,51,.94), rgba(47,65,86,.82)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.auth-card {
  width: min(440px, 100%); background: #fff; border-radius: 20px;
  padding: 2rem; box-shadow: 0 25px 60px rgba(0,0,0,.28);
}
.auth-logo {
  display: block;
  width: min(280px, 100%);
  height: auto;
  margin: 0 auto 1rem;
  object-fit: contain;
}
.brand-mark {
  display: inline-block; font-family: var(--mono); font-weight: 700;
  background: var(--brand); color: #fff; padding: .35rem .7rem; border-radius: 8px;
  margin-bottom: .75rem; letter-spacing: .06em;
}
.auth-card h1 { margin: 0 0 .35rem; font-size: 1.5rem; color: var(--brand); text-align: center; }
.auth-card .subtitle { color: var(--muted); margin: 0 0 1.25rem; text-align: center; }
.install-log { padding-left: 1.1rem; color: var(--muted); }

/* Identificação inspeção */
.form-ident {
  border: 2px solid var(--brand); border-radius: 12px; overflow: hidden; margin-bottom: 1.25rem;
}
.form-ident .title-bar {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  color: #fff; padding: .75rem 1rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
}
.form-ident .title-bar h2 { margin: 0; font-size: 1rem; letter-spacing: .02em; }
.form-ident .body { padding: 1rem; background: #fff; }
.form-ident .meta { font-size: .8rem; opacity: .85; }

.foto-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem;
}
.foto-grid figure {
  margin: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff;
}
.foto-grid img { width: 100%; height: 110px; object-fit: cover; display: block; }
.foto-grid figcaption { padding: .4rem .5rem; font-size: .75rem; color: var(--muted); }

.foto-upload-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .9rem 1rem;
}
.foto-upload-item {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  padding: .85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
}
.foto-upload-item label { font-size: .88rem; line-height: 1.35; }
.foto-preview {
  display: flex;
  align-items: center;
  gap: .65rem;
}
.foto-preview img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.kpi-bar {
  height: 10px; background: #e5ebf3; border-radius: 999px; overflow: hidden; margin-top: .4rem;
}
.kpi-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--brand-2), var(--accent)); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(290px, 86vw); z-index: 40;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .form-grid, .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .foto-upload-list { grid-template-columns: 1fr; }
  .topbar { padding: .85rem 1rem; }
  .topbar h1 { font-size: 1.05rem; }
  .topbar-actions .btn { display: none; }
  .content { padding: .85rem .8rem 5.5rem; }
  .card { padding: .85rem; }
  .card-header {
    flex-direction: column;
    align-items: stretch;
    gap: .65rem;
  }
  .card-header h2 { font-size: .98rem; line-height: 1.3; }

  .filters { flex-direction: column; }
  .filters input, .filters select { min-width: 0; width: 100%; }

  /* Tabelas viram cartões só no celular */
  .table-wrap {
    overflow: visible;
    border: 0;
  }
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap th,
  .table-wrap td,
  .table-wrap tr {
    display: block;
    width: 100%;
  }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: .75rem;
    margin-bottom: .65rem;
    background: #fff;
  }
  .table-wrap td {
    border: 0;
    padding: .25rem 0;
    font-size: .9rem;
  }
  .table-wrap td::before {
    content: attr(data-label);
    display: block;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: .1rem;
  }
  .table-wrap td.actions {
    padding-top: .55rem;
    margin-top: .35rem;
    border-top: 1px solid var(--line);
  }
  .table-wrap td.empty::before { display: none; }
  .table-wrap .actions .btn { flex: 1; justify-content: center; }

  /* Checklist: cartão limpo no celular */
  .checklist-table tr.chk-system-row {
    border: 0;
    padding: 0;
    margin: .85rem 0 .35rem;
    background: transparent;
  }
  .checklist-table tr.chk-system-row td {
    padding: 0;
  }
  .checklist-table tr.chk-system-row td::before { display: none; }
  .checklist-table .checklist-system {
    margin: 0;
    position: sticky;
    top: 56px;
    z-index: 5;
    background-color: #eef3f9;
    border-radius: 0 8px 8px 0;
  }
  .checklist-table tr.chk-data-row td[data-label="Sistema"] { display: none; }
  .checklist-table tr.chk-data-row td[data-label="Código"] {
    font-weight: 700;
    color: var(--brand);
  }
  .checklist-table tr.chk-data-row td[data-label="Item"] {
    font-size: .95rem;
    line-height: 1.4;
    margin-bottom: .35rem;
  }
  .checklist-table tr.chk-data-row td[data-label="Status"]::before,
  .checklist-table tr.chk-data-row td[data-label="Observação"]::before {
    margin-top: .35rem;
  }
  .checklist-table .status-touch {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .35rem;
  }
  .checklist-table .status-touch label {
    justify-content: center;
    padding: .75rem .2rem;
    min-height: 44px;
    font-size: .9rem;
    border-width: 2px;
  }
  .checklist-table .status-touch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
  }
  .checklist-table .status-touch label:has(input:checked) {
    box-shadow: inset 0 0 0 2px currentColor;
  }
  .checklist-table .status-touch .c:has(input:checked) { background: #e8f7ee; }
  .checklist-table .status-touch .nc:has(input:checked) { background: #fdecec; }
  .checklist-table .status-touch .na:has(input:checked) { background: #eef0f2; }
  .checklist-table .status-touch .nv:has(input:checked) { background: #fff7e8; }
  .checklist-table input[name^="item_obs"] { width: 100%; }

  .form-ident { margin-bottom: .9rem; }
  .form-ident .title-bar {
    flex-direction: column;
    align-items: flex-start;
    padding: .8rem;
  }
  .form-ident .title-bar h2 { font-size: .88rem; line-height: 1.35; }
  .form-ident .body { padding: .8rem; }

  .legend { font-size: .78rem; gap: .5rem; }
  .stat .value { font-size: 1.45rem; }

  .btn-block-mobile { width: 100%; }
  .form-actions-sticky {
    position: sticky;
    bottom: 0;
    z-index: 15;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(6px);
    padding: .65rem 0 .2rem;
    border-top: 1px solid var(--line);
    flex-direction: column;
  }

  .app-footer { font-size: .75rem; padding: .75rem 1rem; }
}

@media (max-width: 480px) {
  .checklist-table .status-touch { grid-template-columns: repeat(2, 1fr); }
  .checklist-table .status-touch label { min-height: 48px; font-size: 1rem; }
}

/* Mobile app */
.mobile-shell { max-width: 480px; margin: 0 auto; min-height: 100vh; background: #fff; }
.mobile-header {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; padding: 1rem 1.1rem;
  position: sticky; top: 0; z-index: 10;
}
.mobile-header .mobile-brand {
  display: flex; align-items: center; gap: .65rem; margin-bottom: .45rem;
}
.mobile-header .mobile-brand img {
  width: 36px; height: 36px; border-radius: 50%; background: #fff; padding: 2px;
}
.mobile-header h1 { margin: 0; font-size: 1.1rem; }
.mobile-list a {
  display: block; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.mobile-list a:active { background: #eef3f9; }
.mobile-list strong { display: block; }
.mobile-list small { color: var(--muted); }
.mobile-fab {
  position: fixed; right: 1rem; bottom: 1.25rem;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #1a1205; border: 0; border-radius: 999px;
  padding: .9rem 1.2rem; font-weight: 700; box-shadow: var(--shadow); text-decoration: none;
}
.chk-mobile-item {
  border-bottom: 1px solid var(--line); padding: .85rem 0;
}
.chk-mobile-item .code { font-family: var(--mono); font-size: .75rem; color: var(--muted); }
