:root {
  color-scheme: light;
  --paper: #f4eee4;
  --panel: rgba(255, 251, 246, 0.88);
  --ink: #1c1917;
  --muted: #78716c;
  --brand: #8a4b2a;
  --brand-dark: #5e341e;
  --accent: #c78d3d;
  --line: rgba(122, 91, 64, 0.16);
  --green: #15803d;
  --shadow: 0 18px 50px rgba(81, 53, 29, 0.08);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", "Segoe UI", Tahoma, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at -10% -20%, rgba(199, 141, 61, 0.22), transparent 55%),
    radial-gradient(900px 420px at 110% 0%, rgba(138, 75, 42, 0.12), transparent 46%),
    linear-gradient(180deg, #f8f1e6 0%, #efe4d2 48%, #e8d7bc 100%);
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 252, 247, 0.78);
  backdrop-filter: blur(18px);
}

.app-header-inner {
  max-width: 80rem;
  margin: 0 auto;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-brand {
  min-width: 0;
}

.app-kicker {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--brand);
  font-weight: 700;
}

.app-title {
  margin: 0.1rem 0 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
}

.app-nav-link,
.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.85rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 650;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease, opacity .12s ease;
}

.app-nav-link {
  background: rgba(255,255,255,.72);
  color: var(--ink);
  border-color: var(--line);
}

.app-nav-link:hover,
.btn-secondary:hover { background: #fff; transform: translateY(-1px); }

.app-nav-link.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  box-shadow: 0 8px 20px rgba(94, 52, 30, 0.18);
}

.btn-primary:hover { opacity: .92; transform: translateY(-1px); }
.btn-primary:disabled,
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: rgba(255,255,255,.82);
  color: var(--ink);
  border-color: var(--line);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.user-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.78);
  padding: 0.45rem 0.9rem;
  font-size: 0.82rem;
  color: #57534e;
  white-space: nowrap;
}

.kpi-card {
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -18px;
  top: -18px;
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: rgba(199, 141, 61, 0.12);
}

.field,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="month"],
input[type="date"],
input[type="number"],
input[type="search"],
select,
textarea {
  font-family: inherit;
}

.badge-pago { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
.badge-sem { background: #f1f5f9; color: #64748b; border: 1px solid #e2e8f0; }
.badge-atraso { background: #fef3c7; color: #b45309; border: 1px solid #fcd34d; }
.badge-nunca { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
.badge-instalacao { background: #e7e5e4; color: #57534e; border: 1px solid #d6d3d1; }

.kpi-filter { cursor: pointer; transition: transform .12s, box-shadow .12s; }
.kpi-filter:hover { transform: translateY(-2px); }
.kpi-filter.is-active { box-shadow: 0 0 0 2px var(--brand); }

.chip {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.82);
  border-radius: 999px;
  padding: .35rem .85rem;
  font-size: .75rem;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}
.chip.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

tr.linha-cliente { cursor: pointer; }
tr.linha-cliente:hover td { background: rgba(199,141,61,.07); }
tr.row-atraso td { background: rgba(245, 158, 11, 0.07); }
tr.row-nunca td { background: rgba(239, 68, 68, 0.05); }
tr.row-instalacao td { background: rgba(120, 113, 108, 0.06); }
th.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
th.th-sort:hover { color: var(--brand); }
#detalheOverlay { transition: opacity .18s; }

.app-spinner {
  width: 2.4rem;
  height: 2.4rem;
  border: 3px solid rgba(138, 75, 42, 0.18);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: app-spin .75s linear infinite;
  flex-shrink: 0;
}

.app-spinner.is-sm {
  width: 1.1rem;
  height: 1.1rem;
  border-width: 2px;
}

@keyframes app-spin {
  to { transform: rotate(360deg); }
}

.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(28, 25, 23, 0.38);
  backdrop-filter: blur(8px);
}

.app-loading-overlay.is-hidden {
  display: none;
}

.app-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  max-width: 26rem;
  width: 100%;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1.6rem;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.4rem;
}

.app-loading-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

@media (max-width: 900px) {
  .app-header-inner { flex-direction: column; align-items: stretch; }
  .app-nav { justify-content: flex-start; }
}
