:root {
  --primary: #1b3d33;
  --accent: #2d8f5b;
  --bg: #f3f7f5;
  --card: #fff;
  --line: #d7e4de;
  --muted: #5f726b;
  --danger: #b3261e;
  --ok: #1b7a4a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: #16312a;
}
a { color: inherit; text-decoration: none; }
h1, h2, h3 { font-family: Manrope, sans-serif; letter-spacing: -0.02em; }

.portal-shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.portal-nav {
  background: linear-gradient(180deg, #1b3d33, #0f2922);
  color: #e8f2ed;
  padding: 1.25rem 1rem;
}
.portal-nav-head {
  display: flex; align-items: flex-start; gap: .5rem;
  margin-bottom: 1.5rem; padding: 0 .5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.portal-brand {
  display: flex; flex-direction: column; gap: .35rem; flex: 1; min-width: 0;
}
.portal-brand img { width: 110px; height: 42px; object-fit: cover; object-position: center 64%; border-radius: 8px; }
.portal-brand span { font-size: .78rem; opacity: .75; }
.portal-nav nav { display: flex; flex-direction: column; gap: .25rem; }
.portal-nav a {
  padding: .7rem .85rem; border-radius: 10px; font-weight: 600; font-size: .92rem;
  color: rgba(255,255,255,.78);
}
.portal-nav a:hover, .portal-nav a.is-active { background: rgba(45,143,91,.35); color: #fff; }
.portal-nav .nav-danger { color: #ffc9c2; margin-top: 1rem; }

.portal-nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 10px; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,.2); background: rgba(255,255,255,.08);
  color: #fff; cursor: pointer;
}
.portal-nav-toggle span {
  display: block; width: 18px; height: 2px; background: #fff; position: relative;
}
.portal-nav-toggle span::before,
.portal-nav-toggle span::after {
  content: ""; position: absolute; left: 0; width: 18px; height: 2px; background: #fff;
}
.portal-nav-toggle span::before { top: -6px; }
.portal-nav-toggle span::after { top: 6px; }

.portal-main { padding: 1.5rem 1.75rem 2.5rem; min-width: 0; }
.portal-top h1 { margin: 0; font-size: 1.6rem; color: var(--primary); }
.portal-top p { margin: .25rem 0 0; color: var(--muted); }
.portal-content { margin-top: 1.25rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 1.25rem 1.35rem; margin-bottom: 1rem;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.stat strong { display: block; font-size: 1.5rem; color: var(--primary); margin-top: .25rem; }
.stat span { color: var(--muted); font-size: .85rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 42px; padding: 0 1rem; border-radius: 10px; border: 1px solid transparent;
  font-weight: 700; cursor: pointer; background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.05); }
.btn-outline { background: #fff; border-color: var(--line); color: var(--primary); }
.btn-danger { background: var(--danger); }
.btn-sm { min-height: 32px; padding: 0 .65rem; font-size: .75rem; }
.btn.is-disabled, a.btn.is-disabled {
  opacity: .45; pointer-events: none; cursor: not-allowed;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem .5rem; border-bottom: 1px solid var(--line); text-align: left; font-size: .92rem; }
.table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; }

.badge {
  display: inline-flex; padding: .2rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 700; background: #e8f5ef; color: var(--ok);
}
.badge.warn { background: #fff3cd; color: #8a6d00; }
.badge.danger { background: #fdecea; color: var(--danger); }
.badge.muted { background: #eef1f0; color: var(--muted); }

.field { margin-bottom: .9rem; }
.field label { display: block; font-size: .8rem; font-weight: 700; margin-bottom: .3rem; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: .65rem .8rem; border: 1px solid var(--line);
  border-radius: 10px; font: inherit; background: #fff;
}
.field textarea { min-height: 110px; resize: vertical; }

.login-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(160deg, #1b3d33, #0f2922 55%, #245a48);
  padding: 1.5rem;
}
.login-card {
  width: min(420px, 100%); background: #fff; border-radius: 18px; padding: 1.75rem;
  box-shadow: 0 24px 60px rgba(0,0,0,.25);
}
.login-brand {
  display: flex; justify-content: center; margin: 0 0 1.15rem;
  padding-bottom: 1.1rem; border-bottom: 1px solid var(--line);
}
.login-brand img {
  width: 160px; height: 64px; object-fit: cover; object-position: center 64%;
  border-radius: 10px; display: block;
}
.login-card h1 { margin: 0 0 .35rem; color: var(--primary); font-size: 1.35rem; }
.login-card p { margin: 0 0 1.25rem; color: var(--muted); }
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; font-weight: 600; }
.alert-error { background: #fdecea; color: var(--danger); }
.alert-ok { background: #e8f5ef; color: var(--ok); }

.contrato-body { line-height: 1.55; font-size: .95rem; }
.contrato-body h1 { font-size: 1.35rem; }
.contrato-body h2 { font-size: 1.05rem; margin-top: 1.2rem; }
.sign-pad {
  border: 1px dashed var(--line); border-radius: 12px; background: #fafcfa;
  height: 160px; touch-action: none; cursor: crosshair; width: 100%;
}
.pix-box {
  font-family: ui-monospace, monospace; font-size: .78rem; word-break: break-all;
  background: #f6faf8; border: 1px solid var(--line); border-radius: 10px; padding: .75rem;
}

.licenca-uso { min-width: 140px; }
.licenca-uso-meta { display: flex; align-items: center; gap: .4rem; font-size: .9rem; margin-bottom: .35rem; }
.licenca-bar {
  height: 8px; border-radius: 999px; background: #e8eeeb; overflow: hidden;
}
.licenca-bar > span {
  display: block; height: 100%; border-radius: 999px; background: var(--accent);
}
.licenca-bar > span.is-warn { background: #c9a227; }
.licenca-bar > span.is-danger { background: var(--danger); }

.admin-toolbar, .listagem-toolbar {
  display: flex; gap: .75rem; flex-wrap: wrap;
  margin-bottom: 1rem; align-items: center; justify-content: space-between;
}
.listagem-search {
  display: flex; gap: .5rem; flex: 1; min-width: min(100%, 220px);
}
.listagem-search input {
  flex: 1; min-height: 42px; padding: .5rem .8rem;
  border: 1px solid var(--line); border-radius: 10px; font: inherit;
}
.listagem-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.listagem-card { overflow: hidden; }
.table-responsive, .listagem-table-wrap {
  width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.table-responsive > .table { min-width: 640px; }
.td-actions { white-space: nowrap; }
.inline-form {
  display: inline-flex; gap: .35rem; flex-wrap: wrap;
  align-items: center; margin-bottom: .35rem;
}
.inline-form select {
  min-height: 32px; border: 1px solid var(--line);
  border-radius: 8px; font-size: .8rem;
}
.checks { display: grid; gap: .5rem; }
.checks label { display: flex; gap: .55rem; align-items: center; font-weight: 600; color: #16312a; }
.inline-valor { width: 110px; min-height: 36px; margin-left: auto; }

.gerig-list-pagination {
  display: flex; flex-wrap: wrap; align-items: center;
  justify-content: space-between; gap: .65rem;
  margin-top: .85rem; padding: .35rem 0 .15rem;
  border-top: 1px solid var(--line);
}
.gerig-list-pageinfo { font-size: .82rem; color: var(--muted); }
.gerig-list-pager {
  display: inline-flex; align-items: center; gap: .45rem; flex-wrap: wrap;
}
.gerig-list-page-label {
  font-size: .85rem; font-weight: 650; color: #16312a;
  min-width: 3.5rem; text-align: center;
}
.gerig-list-page-size label {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .82rem; color: var(--muted); font-weight: 600;
}
.gerig-list-page-size select {
  min-height: 32px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; background: #fff;
}
.gerig-list-page-nums {
  display: inline-flex; align-items: center; gap: .25rem;
}
.gerig-list-page-num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 32px; height: 32px; padding: 0 .4rem;
  border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--primary); font-size: .82rem; font-weight: 700;
}
.gerig-list-page-num.is-current {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.gerig-list-page-icon { min-width: 32px; padding: 0 .45rem; font-size: 1rem; line-height: 1; }

/* Dual list: tabela no desktop, cards no mobile */
.listagem-desktop { display: block; }
.listagem-mobile { display: none; }

.gerig-list-cards {
  display: flex; flex-direction: column; gap: .65rem;
}
.gerig-list-card {
  display: flex; align-items: center; gap: .75rem;
  width: 100%; text-align: left;
  padding: .9rem 1rem; border-radius: 16px;
  border: 1px solid var(--line); background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  cursor: pointer; font: inherit; color: inherit;
}
.gerig-list-card:active { transform: scale(.992); }
.gerig-list-card-main { display: flex; align-items: flex-start; gap: .75rem; flex: 1; min-width: 0; }
.gerig-list-card-body { min-width: 0; flex: 1; }
.gerig-list-card-name { font-weight: 750; color: #16312a; line-height: 1.25; }
.gerig-list-card-meta { font-size: .82rem; color: var(--muted); margin-top: .15rem; word-break: break-word; }
.gerig-list-card-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .45rem; }
.gerig-list-chip {
  display: inline-flex; align-items: center; gap: .25rem;
  padding: .18rem .5rem; border-radius: 999px;
  background: #f3f6f4; color: var(--muted);
  font-size: .72rem; font-weight: 650;
}
.gerig-list-card-chevron {
  color: #9bb0a6; font-size: 1.25rem; flex-shrink: 0; line-height: 1;
}
.gerig-list-empty {
  padding: 1.25rem; text-align: center; color: var(--muted); font-weight: 600;
}

/* Bottom sheet */
body.gerig-sheet-open { overflow: hidden; }
.gerig-sheet {
  position: fixed; inset: 0; z-index: 1090;
  pointer-events: none; visibility: hidden;
}
.gerig-sheet.is-open { pointer-events: auto; visibility: visible; }
.gerig-sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 35, 28, 0.45);
  opacity: 0; transition: opacity .22s ease;
}
.gerig-sheet.is-open .gerig-sheet-backdrop { opacity: 1; }
.gerig-sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: min(88vh, 640px); background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -12px 40px rgba(7, 67, 54, 0.18);
  transform: translateY(110%);
  transition: transform .28s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.gerig-sheet.is-open .gerig-sheet-panel { transform: translateY(0); }
.gerig-sheet-handle {
  width: 2.5rem; height: .28rem; border-radius: 999px;
  background: #d5ddd9; margin: .55rem auto .15rem;
}
.gerig-sheet-header {
  display: flex; align-items: flex-start; gap: .85rem;
  padding: .65rem 1rem .95rem; border-bottom: 1px solid var(--line);
}
.gerig-sheet-heading { min-width: 0; flex: 1; }
.gerig-sheet-title {
  margin: 0; font-size: 1.05rem; font-weight: 750; color: #16312a; line-height: 1.25;
}
.gerig-sheet-subtitle {
  margin: .15rem 0 0; font-size: .82rem; color: var(--muted);
}
.gerig-sheet-close {
  border: 0; background: #eef3f0; width: 36px; height: 36px;
  border-radius: 999px; cursor: pointer; font-size: 1.1rem; color: var(--muted);
  flex-shrink: 0;
}
.gerig-sheet-actions {
  display: flex; flex-direction: column; padding: .35rem .75rem 1rem; overflow: auto;
}
.gerig-sheet-divider { height: 1px; background: var(--line); margin: .35rem 0; }
.gerig-sheet-action {
  display: flex; align-items: center; gap: .65rem;
  width: 100%; min-height: 48px; padding: .65rem .75rem;
  border: 0; border-radius: 12px; background: transparent;
  font: inherit; font-weight: 650; color: #16312a; text-align: left; cursor: pointer;
}
.gerig-sheet-action:hover { background: #f4faf7; }
.gerig-sheet-action.is-primary { color: var(--accent); }
.gerig-sheet-action.is-danger { color: var(--danger); }
a.gerig-sheet-action { text-decoration: none; }

/* Side drawer (desktop) / bottom sheet (mobile) */
body.gerig-drawer-open { overflow: hidden; }
.gerig-drawer {
  position: fixed; inset: 0; z-index: 1100;
  pointer-events: none; visibility: hidden;
}
.gerig-drawer.is-open { pointer-events: auto; visibility: visible; }
.gerig-drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 35, 28, 0.45);
  opacity: 0; transition: opacity .22s ease;
}
.gerig-drawer.is-open .gerig-drawer-backdrop { opacity: 1; }
.gerig-drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(480px, 100%);
  background: #fff;
  box-shadow: -12px 0 40px rgba(7, 67, 54, 0.16);
  transform: translateX(104%);
  transition: transform .28s cubic-bezier(0.22, 1, 0.36, 1);
  display: flex; flex-direction: column;
}
.gerig-drawer.is-open .gerig-drawer-panel { transform: translateX(0); }
.gerig-drawer-header {
  display: flex; align-items: flex-start; gap: .85rem;
  padding: 1rem 1.1rem .9rem; border-bottom: 1px solid var(--line);
}
.gerig-drawer-heading { min-width: 0; flex: 1; }
.gerig-drawer-title {
  margin: 0; font-size: 1.1rem; font-weight: 750; color: #16312a; line-height: 1.25;
}
.gerig-drawer-subtitle {
  margin: .2rem 0 0; font-size: .82rem; color: var(--muted);
}
.gerig-drawer-close {
  border: 0; background: #eef3f0; width: 36px; height: 36px;
  border-radius: 999px; cursor: pointer; font-size: 1.1rem; color: var(--muted);
  flex-shrink: 0;
}
.gerig-drawer-body {
  flex: 1; overflow: auto; padding: 1rem 1.1rem 1.25rem;
}
.gerig-drawer-loading { color: var(--muted); font-weight: 600; }
.gerig-drawer-actions { display: flex; flex-direction: column; }
.gerig-drawer-form .field { margin-bottom: .75rem; }
.gerig-drawer-footer {
  display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap;
  margin-top: 1rem; padding-top: .85rem; border-top: 1px solid var(--line);
}
.gerig-action-group {
  display: inline-flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end;
}

@media (max-width: 720px) {
  .gerig-drawer-panel {
    top: auto; left: 0; right: 0; width: 100%;
    max-height: min(92vh, 720px);
    border-radius: 20px 20px 0 0;
    transform: translateY(110%);
  }
  .gerig-drawer.is-open .gerig-drawer-panel { transform: translateY(0); }
}

@media (max-width: 900px) {
  .portal-shell { grid-template-columns: 1fr; }
  .portal-nav { position: sticky; top: 0; z-index: 30; padding-bottom: .75rem; }
  .portal-nav-toggle { display: inline-flex; }
  .portal-nav-head { margin-bottom: 0; border-bottom: 0; padding-bottom: 0; }
  .portal-nav nav {
    display: none; flex-direction: column; gap: .25rem;
    margin-top: .85rem; padding-top: .75rem;
    border-top: 1px solid rgba(255,255,255,.12);
  }
  .portal-nav.is-open nav { display: flex; }
  .portal-main { padding: 1rem 1rem 2rem; }
  .portal-top h1 { font-size: 1.3rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .admin-toolbar, .listagem-toolbar { align-items: stretch; }
  .listagem-actions { width: 100%; }
  .listagem-actions .btn { flex: 1; }
  .listagem-desktop { display: none !important; }
  .listagem-mobile { display: block !important; }
  .gerig-list-pagination { flex-direction: column; align-items: stretch; }
  .gerig-list-pager { justify-content: center; }
}

@media (max-width: 576px) {
  .card { padding: 1rem; border-radius: 12px; }
  .listagem-search { flex-direction: column; }
  .gerig-list-page-num { min-width: 28px; height: 28px; font-size: .78rem; }
}
