:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --text: #162033;
  --muted: #6c7688;
  --line: #dfe5ee;
  --brand: #146c94;
  --brand-2: #1f9a8a;
  --danger: #bd2f3a;
  --warn: #a46200;
  --shadow: 0 14px 36px rgba(22, 32, 51, .10);
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); }
a { color: inherit; text-decoration: none; }
button, .button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.ghost { background: transparent; color: #dbe8f4; border-color: rgba(255,255,255,.22); }
.full { width: 100%; }
.small { min-height: 34px; padding: 0 10px; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: #fff;
  font: inherit;
}
textarea { resize: vertical; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); min-height: 42px; }
.check input { width: 18px; min-height: 18px; }

.login-page {
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(20,108,148,.92), rgba(31,154,138,.78)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='900' height='700' viewBox='0 0 900 700'%3E%3Cg fill='none' stroke='rgba(255,255,255,.28)' stroke-width='2'%3E%3Cpath d='M90 90h720v460H90z'/%3E%3Cpath d='M160 170h210v120H160zM420 170h320v55H420zM420 260h320v55H420zM160 350h580v110H160z'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  align-items: center;
  gap: 48px;
  padding: 42px clamp(20px, 6vw, 90px);
}
.login-visual { color: #fff; max-width: 720px; }
.login-visual h1 { font-size: clamp(36px, 6vw, 72px); line-height: .96; margin: 10px 0 18px; letter-spacing: 0; }
.login-visual p { font-size: 19px; line-height: 1.55; max-width: 560px; color: rgba(255,255,255,.86); }
.eyebrow { text-transform: uppercase; font-size: 12px; letter-spacing: .12em; font-weight: 800; }
.login-credit {
  position: fixed;
  right: 18px;
  bottom: 12px;
  color: rgba(255,255,255,.68);
  font-size: 11px;
}
.login-card {
  background: rgba(255,255,255,.94);
  border: 1px solid rgba(255,255,255,.65);
  box-shadow: var(--shadow);
  border-radius: 8px;
  padding: 28px;
  display: grid;
  gap: 16px;
}
.login-card h2 { margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 13px; }

.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #162033;
  color: #fff;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--brand-2);
  display: grid;
  place-items: center;
  font-weight: 900;
}
.brand small { display: block; color: #aeb8c8; margin-top: 3px; }
.sidebar nav { display: grid; gap: 7px; }
.sidebar a {
  padding: 12px 13px;
  border-radius: 8px;
  color: #c8d2df;
  font-weight: 700;
}
.sidebar a.active, .sidebar a:hover { background: rgba(255,255,255,.10); color: #fff; }
.content { min-width: 0; padding: 28px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.topbar h1 { margin: 0; font-size: 28px; letter-spacing: 0; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.menu-button { display: none; }

.panel, .empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(22,32,51,.05);
  padding: 20px;
  margin-bottom: 18px;
}
.panel h2 { margin: 0 0 16px; font-size: 19px; }
.grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  align-items: end;
}
.form-grid.compact {
  grid-template-columns: repeat(5, minmax(130px, 1fr));
}
.inline-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.inline-form label { min-width: 150px; flex: 1; }
.report-controls {
  padding: 0;
  overflow: hidden;
}
.report-controls form {
  display: grid;
}
.report-control-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) repeat(4, minmax(150px, 1fr));
  gap: 14px;
  align-items: end;
  padding: 18px;
}
.report-model select {
  min-height: 48px;
  font-weight: 800;
}
.report-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  align-items: center;
  border-top: 1px solid var(--line);
  background: #f8fbfd;
  padding: 14px 18px;
}
.user-list { display: grid; gap: 14px; }
.user-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 12px;
  align-items: end;
}
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stats article {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}
.stats small { display: block; color: var(--muted); font-weight: 800; margin-bottom: 10px; }
.stats strong { font-size: 32px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }

.reading-list { display: grid; gap: 14px; }
.reading-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 16px;
}
.reading-card h3 { margin: 0 0 8px; }
.reading-card p { margin: 5px 0; color: var(--muted); }
.photo-box {
  background: #eef3f7;
  border-radius: 8px;
  min-height: 180px;
  max-height: 260px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
}
.photo-box img {
  width: 100%;
  height: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #eef3f7;
}

.mobile-list { display: grid; gap: 12px; }
.task-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 5px;
  box-shadow: 0 4px 16px rgba(22,32,51,.05);
}
.task-card small { color: var(--brand); font-weight: 800; }
.task-card strong { font-size: 18px; }
.task-card span { color: var(--muted); }
.task-card em { color: var(--warn); font-style: normal; font-weight: 800; }
.tech-reading { max-width: 680px; margin: 0 auto; }
.tech-reading h2 { font-size: 28px; margin-bottom: 4px; }
.prev-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  background: #f8fbfd;
  border-radius: 8px;
  padding: 16px;
  margin: 16px 0;
}
.prev-box span { color: var(--muted); font-weight: 800; }
.prev-box strong { font-size: 26px; }
.preview {
  display: none;
  width: 100%;
  max-height: 300px;
  object-fit: contain;
  background: #eef3f7;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.preview[src] { display: block; }
.camera-control {
  display: grid;
  gap: 8px;
}
.camera-control span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
.camera-control small {
  color: var(--muted);
}
.file-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.camera-button {
  min-height: 54px;
  background: var(--brand-2);
  border-color: var(--brand-2);
  color: #fff;
}
.alert {
  border: 1px solid #f0c47a;
  background: #fff8eb;
  color: #7a4a00;
  border-radius: 8px;
  padding: 12px;
  margin: 12px 0;
}
.danger-zone { border-color: rgba(189,47,58,.3); }
.report-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.report-head img { max-width: 130px; max-height: 70px; object-fit: contain; }
.report-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfd;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.report-context strong {
  font-size: 16px;
}
.report-context span {
  color: var(--muted);
  font-weight: 800;
}
.report-page {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin: 0 0 18px;
  background: #fff;
}
.cessionario-report-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, .7fr);
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
  margin-bottom: 16px;
}
.cessionario-report-head small {
  color: var(--brand);
  font-weight: 900;
}
.cessionario-report-head h2 {
  margin: 4px 0;
  font-size: 26px;
}
.cessionario-report-head p {
  margin: 4px 0;
  color: var(--muted);
}
.meter-report-grid {
  display: grid;
  gap: 14px;
}
.meter-report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, .65fr) minmax(220px, 1fr);
  gap: 14px;
  page-break-inside: avoid;
}
.meter-report-info small {
  display: block;
  color: var(--brand);
  font-weight: 900;
  margin-bottom: 8px;
}
.meter-report-info strong {
  display: block;
  font-size: 30px;
  margin-bottom: 10px;
}
.meter-report-info p {
  margin: 5px 0;
  color: var(--muted);
}
.meter-report-photo {
  height: 240px;
  background: #eef3f7;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
}
.meter-report-photo img {
  width: 100%;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
  background: #eef3f7;
}
.annual-report {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
}
.annual-head {
  margin-bottom: 12px;
}
.annual-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
}
.annual-table {
  min-width: 820px;
}
.annual-table th:first-child {
  width: 130px;
}
.annual-table td strong {
  display: block;
  font-size: 18px;
  margin-bottom: 4px;
}
.annual-table td small,
.annual-empty {
  color: var(--muted);
  font-weight: 700;
}
.annual-table tbody th {
  color: var(--text);
  text-transform: none;
  letter-spacing: 0;
  font-size: 14px;
}

.toast {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 20;
  background: #173b2e;
  color: #fff;
  padding: 13px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 36px));
}
.toast.danger { background: var(--danger); }

@media (max-width: 900px) {
  .login-wrap { grid-template-columns: 1fr; gap: 22px; }
  .login-card { max-width: 520px; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 270px;
    z-index: 10;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .content { padding: 18px; }
  .menu-button { display: inline-flex; }
  .topbar { align-items: flex-start; justify-content: flex-start; }
  .grid.two, .stats { grid-template-columns: 1fr; }
  .form-grid, .form-grid.compact { grid-template-columns: 1fr; }
  .report-control-grid { grid-template-columns: 1fr 1fr; }
  .user-card { grid-template-columns: 1fr; }
  .reading-card { grid-template-columns: 1fr; }
  .cessionario-report-head, .meter-report-card { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .login-wrap { padding: 22px 16px; }
  .login-visual h1 { font-size: 38px; }
  .login-visual p { font-size: 16px; }
  .login-credit { position: static; padding: 0 16px 14px; text-align: center; }
  .login-card, .panel, .empty { padding: 16px; }
  .content { padding: 14px; }
  .topbar h1 { font-size: 23px; }
  .inline-form { display: grid; grid-template-columns: 1fr; }
  .inline-form label { min-width: 0; }
  .report-control-grid { grid-template-columns: 1fr; padding: 16px; }
  .report-actions { display: grid; grid-template-columns: 1fr; padding: 14px 16px; }
  button, .button { width: 100%; }
  .sticky-filter {
    position: sticky;
    top: 0;
    z-index: 2;
  }
}

@media print {
  body { background: #fff; }
  .sidebar, .topbar, .no-print, .toast, button, form { display: none !important; }
  .app-shell { display: block; }
  .content { padding: 0; }
  .panel { border: 0; box-shadow: none; }
  .report-context {
    border: 0;
    border-bottom: 1px solid #dfe5ee;
    border-radius: 0;
    background: #fff;
    padding: 0 0 10px;
  }
  .reading-card { page-break-inside: avoid; }
  .photo-box {
    min-height: 220px;
    max-height: none;
  }
  .photo-box img {
    height: auto;
    max-height: 320px;
    object-fit: contain;
  }
  .annual-report {
    border: 0;
    padding: 0;
  }
  .annual-table-wrap {
    border: 0;
    overflow: visible;
  }
  .annual-table {
    min-width: 0;
    font-size: 12px;
  }
  .annual-table th,
  .annual-table td {
    padding: 8px 6px;
  }
  .report-page {
    border: 0;
    padding: 0;
    margin: 0;
    page-break-after: always;
    break-after: page;
  }
  .report-page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
  .cessionario-report-head {
    grid-template-columns: minmax(0, 1fr) minmax(220px, .7fr);
  }
  .meter-report-card {
    grid-template-columns: minmax(0, .65fr) minmax(220px, 1fr);
    padding: 8px;
    gap: 10px;
    page-break-inside: avoid;
  }
  .meter-report-info strong {
    font-size: 24px;
    margin-bottom: 6px;
  }
  .meter-report-info p {
    margin: 3px 0;
  }
  .meter-report-photo {
    height: 260px;
    max-height: 260px;
    overflow: hidden;
  }
  .meter-report-photo img {
    height: 100%;
    max-height: 260px;
    object-fit: contain;
  }
}
