:root {
  --navy: #10233a;
  --navy-2: #17324f;
  --navy-3: #1e4063;
  --teal: #1aa39a;
  --teal-2: #14857e;
  --teal-soft: #e6f6f4;
  --bg: #eef2f6;
  --card: #ffffff;
  --text: #152033;
  --muted: #5d6b7c;
  --border: #dce3ec;
  --shadow: 0 8px 24px rgba(16, 35, 58, 0.06);
  --green: #0f8a5f;
  --green-bg: #e6f6ee;
  --yellow: #b45309;
  --yellow-bg: #fff4e5;
  --red: #c24141;
  --red-bg: #fdecec;
  --blue: #2563eb;
  --blue-bg: #e8f0fe;
  --radius: 14px;
  --sidebar: 248px;
  --topbar: 72px;
  --font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.45;
}
a { color: var(--teal-2); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }
img { max-width: 100%; }

#app { min-height: 100vh; display: flex; }

/* Sidebar */
#sidebar {
  width: var(--sidebar);
  background: linear-gradient(180deg, var(--navy) 0%, #0c1b2d 100%);
  color: #d7e2ee;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  padding: 22px 16px 16px;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 4px 8px 22px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: #14314d; color: var(--teal);
  display: grid; place-items: center; flex-shrink: 0;
  box-shadow: inset 0 0 0 1px rgba(26,163,154,.35);
}
.brand strong { display: block; color: #fff; font-size: 15px; letter-spacing: .02em; }
.brand span { display: block; font-size: 11px; color: #8aa0b8; margin-top: 2px; }
#nav { display: flex; flex-direction: column; gap: 4px; }
#nav a {
  display: flex; align-items: center; gap: 10px;
  color: #c5d4e4; padding: 10px 12px; border-radius: 10px;
  text-decoration: none; font-weight: 500; font-size: 14.5px;
}
#nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
#nav a.active { background: rgba(26,163,154,.16); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.nav-ico { width: 18px; text-align: center; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 12px 8px; color: #7d93aa; font-size: 12px; }
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(8,16,28,.45); z-index: 35;
}

.shell { margin-left: var(--sidebar); flex: 1; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  min-height: var(--topbar);
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  background: rgba(238,242,246,.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid transparent;
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.icon-btn {
  display: none; border: 1px solid var(--border); background: #fff;
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer; color: var(--navy);
}
.content { padding: 8px 24px 48px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 9px 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-2); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-ghost { background: #fff; color: var(--navy); border: 1px solid var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-warn { background: var(--yellow-bg); color: var(--yellow); border: 1px solid #f3d5a8; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }

/* Cards / KPI */
.kpis {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 16px 14px; box-shadow: var(--shadow); min-width: 0;
}
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; letter-spacing: -.03em; color: var(--navy); }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.warn .value { color: var(--yellow); }
.kpi.danger .value { color: var(--red); }
.kpi.ok .value { color: var(--green); }
.kpi.teal .value { color: var(--teal-2); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.card-hd {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.card-hd h2 { margin: 0; font-size: 15px; }
.card-bd { padding: 8px 0; }
.card-bd.pad { padding: 16px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 11px 16px; font-size: 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #f7fafc; }
.mono { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--navy); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: #eef2f6; color: var(--muted);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-teal { background: var(--teal-soft); color: var(--teal-2); }
.badge-gray { background: #eef2f6; color: #526070; }

/* Toolbar / forms */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.search {
  flex: 1; min-width: 180px; border: 1px solid var(--border); background: #fff;
  border-radius: 10px; padding: 9px 12px; outline: none;
}
.search:focus, select:focus, input:focus, textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px rgba(26,163,154,.18);
}
select.filter {
  border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 9px 12px;
}
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field input, .field select, .field textarea {
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--text);
}
.field textarea { min-height: 92px; resize: vertical; }
.req::after { content: " *"; color: var(--red); }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }

/* Equipment header */
.eq-hero {
  display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start;
  margin-bottom: 16px;
}
.eq-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.meta-box {
  background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px;
}
.meta-box span { display: block; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.meta-box strong { display: block; margin-top: 4px; font-size: 14px; font-weight: 600; }
.qr-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; text-align: center; width: 210px; box-shadow: var(--shadow);
}
.qr-card img { width: 170px; height: 170px; display: block; margin: 0 auto 8px; }
.qr-card p { margin: 0 0 10px; font-size: 12px; color: var(--muted); }

.tabs { display: flex; gap: 6px; margin: 8px 0 14px; flex-wrap: wrap; }
.tab {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted);
}
.tab.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.empty {
  text-align: center; padding: 36px 16px; color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.banner {
  border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner-ok { background: var(--green-bg); color: #146047; }
.banner-warn { background: var(--yellow-bg); color: #8a4308; }

.sig-preview {
  background: #fff; border: 1px dashed var(--border); border-radius: 12px; padding: 8px;
  display: inline-block;
}
.sig-preview img { height: 88px; display: block; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10, 18, 32, .5);
  z-index: 60; display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 16px 16px 8px 8px; width: min(560px, 100%);
  padding: 18px 18px 16px; box-shadow: 0 24px 60px rgba(0,0,0,.25); max-height: 92vh; overflow: auto;
}
.modal-card h3 { margin: 0 0 6px; }
.modal-card p.hint { margin: 0 0 12px; color: var(--muted); font-size: 13px; }
.sig-wrap {
  border: 1px solid var(--border); border-radius: 12px; background: #fafbfc;
  touch-action: none; overflow: hidden;
}
.sig-wrap canvas { display: block; width: 100%; height: 180px; cursor: crosshair; }

/* Toasts */
.toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 80;
  display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100% - 32px));
}
.toast {
  background: var(--navy); color: #fff; padding: 12px 14px; border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 14px;
}
.toast.err { background: #8f2d2d; }
.toast.ok { background: #146047; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: #fff; border-radius: 999px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
}
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.upload-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.file-pill { font-size: 12px; color: var(--muted); }

.muted { color: var(--muted); }
.right { text-align: right; }

/* QR scanner */
.scan-cta {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, #10233a 0%, #1a4a4a 100%);
  color: #fff; border-radius: var(--radius); padding: 16px 18px;
  margin-bottom: 16px; text-decoration: none; box-shadow: var(--shadow);
}
.scan-cta:hover { text-decoration: none; filter: brightness(1.06); }
.scan-cta .scan-ico {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  background: rgba(26,163,154,.22); color: #7ee0d6;
  display: grid; place-items: center; font-size: 22px;
}
.scan-cta strong { display: block; font-size: 16px; }
.scan-cta span { display: block; font-size: 13px; color: #b7c9d8; margin-top: 2px; font-weight: 400; }

.scanner {
  background: #0b1726; border-radius: 18px; overflow: hidden;
  position: relative; aspect-ratio: 3 / 4; max-height: min(68vh, 560px);
  box-shadow: var(--shadow);
}
.scanner video, .scanner canvas.scan-layer {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
.scanner canvas.scan-layer { pointer-events: none; }
.scan-frame {
  position: absolute; inset: 18% 14%;
  border: 2px solid rgba(126,224,214,.85); border-radius: 16px;
  box-shadow: 0 0 0 999px rgba(8,16,28,.38);
  pointer-events: none;
}
.scan-frame::before, .scan-frame::after {
  content: ""; position: absolute; width: 22px; height: 22px; border: 3px solid #7ee0d6;
}
.scan-frame::before { top: -3px; left: -3px; border-right: 0; border-bottom: 0; border-radius: 8px 0 0 0; }
.scan-frame::after { right: -3px; bottom: -3px; border-left: 0; border-top: 0; border-radius: 0 0 8px 0; }
.scan-status {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 14px 14px; color: #e8f0f6; font-size: 13px; text-align: center;
  background: linear-gradient(transparent, rgba(8,16,28,.82));
}
.scan-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.scan-result { margin-top: 16px; }
.scan-result .eq-line { font-size: 18px; margin: 0 0 4px; }
.os-pick {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin: 8px 0;
  background: #fff;
}
.os-pick .btn { flex-shrink: 0; }

/* Equipment preview after QR */
.preview-wrap { max-width: 720px; margin: 0 auto; }
.preview-hero {
  background: #fff; border: 1px solid var(--border); border-radius: 18px;
  padding: 20px 20px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.preview-hero .code { font-family: var(--mono); font-size: 26px; letter-spacing: .03em; margin: 8px 0 4px; }
.preview-hero h2 { margin: 0; font-size: 18px; font-weight: 600; }
.preview-facts {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px;
}
.choice-grid { display: grid; gap: 10px; margin: 14px 0; }
.choice {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border: 1px solid var(--border); border-radius: 16px;
  padding: 16px 16px; text-decoration: none; color: inherit; cursor: pointer;
  text-align: left; width: 100%; box-shadow: var(--shadow);
}
.choice:hover { text-decoration: none; border-color: var(--teal); }
.choice .ico {
  width: 48px; height: 48px; border-radius: 14px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 20px; font-weight: 700;
  background: var(--teal-soft); color: var(--teal-2);
}
.choice.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.choice.primary .ico { background: rgba(26,163,154,.25); color: #7ee0d6; }
.choice strong { display: block; font-size: 16px; }
.choice span { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; font-weight: 400; }
.choice.primary span { color: #b7c9d8; }
.ip-chip {
  display: inline-flex; margin: 4px 6px 4px 0; padding: 8px 12px;
  border-radius: 999px; border: 1px solid var(--border); background: #fff;
  cursor: pointer; font-family: var(--mono); font-size: 13px;
}
.ip-chip:hover { border-color: var(--teal); }
.warn-box {
  background: var(--yellow-bg); color: #8a4308; border-radius: 12px; padding: 12px 14px; font-size: 14px;
}
.url-box {
  font-family: var(--mono); font-size: 13px; background: #f4f7fa; border-radius: 10px;
  padding: 10px 12px; word-break: break-all;
}

/* Print QR */
@media print {
  #sidebar, .topbar, .topbar-actions, .btn, nav { display: none !important; }
  .shell { margin: 0; }
  .content { padding: 0; }
}

@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .eq-meta { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .eq-hero { grid-template-columns: 1fr; }
  .qr-card { width: 100%; }
}
@media (max-width: 780px) {
  #sidebar {
    transform: translateX(-105%);
    transition: transform .2s ease;
    box-shadow: 12px 0 40px rgba(0,0,0,.25);
  }
  #sidebar.open { transform: none; }
  .shell { margin-left: 0; }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; }
  .content { padding: 8px 14px 40px; }
  .topbar { padding: 10px 14px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar-title h1 { font-size: 18px; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    background: #fff; border: 1px solid var(--border); border-radius: 12px;
    margin: 0 8px 10px; padding: 8px 12px; width: auto;
  }
  .table td {
    display: flex; justify-content: space-between; gap: 12px;
    border: 0; padding: 6px 0; text-align: right;
  }
  .table td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase;
    letter-spacing: .04em; text-align: left;
  }
  .modal-overlay { align-items: flex-end; }
}

@media (min-width: 781px) {
  .modal-overlay { align-items: center; }
  .modal-card { border-radius: 16px; }
}

.user-box { margin-bottom: 10px; color: #c5d4e4; font-size: 13px; }
.user-box strong { display: block; color: #fff; }
.user-box .muted { color: #8aa0b8; font-size: 12px; }
.user-box .btn { margin-top: 8px; width: 100%; }

.login-wrap {
  min-height: 70vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card { width: min(420px, 100%); }
.login-card h2 { margin: 0 0 6px; }
body.login-mode #sidebar, body.login-mode .topbar { display: none !important; }
body.login-mode .shell { margin-left: 0; }
body.login-mode .content { padding: 16px; }

body.campo-mode #sidebar { display: none !important; }
body.campo-mode #backdrop { display: none !important; }
body.campo-mode #menu-btn { display: none !important; }
body.campo-mode .shell { margin-left: 0; }
body.campo-mode .topbar { padding-left: 16px; }

#nav a[hidden] { display: none !important; }

.photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.photo-thumb {
  width: 92px; height: 92px; border-radius: 10px; object-fit: cover;
  border: 1px solid var(--line, #d7e0ea); background: #fff; display: block;
}
.photo-item { position: relative; }
.photo-item button {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border: 0;
  border-radius: 50%; background: #10233a; color: #fff; font-size: 14px; line-height: 22px;
  cursor: pointer; padding: 0;
}
.photo-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* Calendário de manutenções */
.cal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, .9fr);
  gap: 16px;
  align-items: start;
}
.cal-board {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.cal-toolbar h2 { margin: 0; font-size: 18px; letter-spacing: -.02em; }
.cal-nav-btns { display: flex; gap: 6px; align-items: center; }
.cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 8px 10px 0;
}
.cal-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 6px 0 8px;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  padding: 0 10px 12px;
}
.cal-day {
  min-height: 86px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  padding: 8px 8px 6px;
  cursor: pointer;
  text-align: left;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}
.cal-day:hover { border-color: var(--teal); }
.cal-day.outside { opacity: .38; background: #f7f9fb; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--teal); }
.cal-day.selected {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}
.cal-day.selected .cal-num { color: #fff; }
.cal-day.selected .cal-count { color: #d7e2ee; }
.cal-num { font-weight: 700; font-size: 14px; color: var(--navy); }
.cal-count { font-size: 11px; font-weight: 600; color: var(--muted); }
.cal-dots { display: flex; gap: 4px; margin-top: auto; flex-wrap: wrap; }
.cal-dot {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--teal);
  font-style: normal;
}
.cal-dot.proxima { background: var(--yellow); }
.cal-dot.atrasada { background: var(--red); }
.cal-dot.em_dia { background: var(--green); }
.cal-legend {
  display: flex; gap: 14px; flex-wrap: wrap;
  padding: 0 16px 14px; font-size: 12px; color: var(--muted);
}
.cal-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cal-panel { min-width: 0; }
.cal-panel .card-hd h2 { font-size: 15px; }
.cal-eq {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  text-decoration: none; color: inherit;
}
.cal-eq:last-child { border-bottom: 0; }
.cal-eq:hover { background: #f7fafc; text-decoration: none; }
.cal-eq .code { font-family: var(--mono); font-weight: 700; color: var(--navy); }
.cal-eq .where { font-size: 13px; color: var(--muted); }
.cal-eq .go { margin-left: auto; flex-shrink: 0; }

@media (max-width: 980px) {
  .cal-layout { grid-template-columns: 1fr; }
  .cal-day { min-height: 64px; padding: 6px; border-radius: 10px; }
  .cal-num { font-size: 13px; }
}
