/* ==========================================================================
   Casa Forte — base acessível
   Foco: legibilidade alta, alvos de toque grandes, contraste forte.
   ========================================================================== */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1c2430;
  --muted: #4d5b6b;
  --line: #d7d3ca;

  --brand: #1f4e79;
  --brand-strong: #16395a;
  --brand-soft: #e7eef6;
  --accent: #b4441b;
  --accent-soft: #fbeae2;
  --ok: #1c6b3f;
  --ok-soft: #e3f3e9;
  --danger: #a12020;

  --radius: 14px;
  --shadow: 0 2px 4px rgba(28, 36, 48, 0.06), 0 8px 20px rgba(28, 36, 48, 0.07);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  --font-size: 19px;

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: var(--font-size);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
}

/* Foco visível — crucial para acessibilidade */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0 0 0.4em;
  font-weight: 800;
  letter-spacing: -0.01em;
}

h1 {
  font-size: 2.1rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.2rem;
}

p {
  margin: 0 0 1em;
}

a {
  color: var(--brand);
  text-underline-offset: 3px;
}

/* ---------- Estrutura ---------- */

.page {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2.5rem);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.1rem, 2.5vw, 1.6rem);
}

.muted {
  color: var(--muted);
}

.lead {
  font-size: 1.25rem;
  color: var(--muted);
}

/* ---------- Botões ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  min-height: 52px;
  padding: 0.85rem 1.4rem;
  border-radius: 12px;
  border: 2px solid transparent;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.06s ease, background-color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-strong);
}

.btn-secondary {
  background: var(--surface);
  color: var(--brand);
  border-color: var(--brand);
}

.btn-secondary:hover {
  background: var(--brand-soft);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-xl {
  min-height: 68px;
  font-size: 1.35rem;
  padding: 1rem 1.8rem;
  width: 100%;
}

@media (min-width: 640px) {
  .btn-xl {
    width: auto;
    min-width: 260px;
  }
}

.btn-block {
  width: 100%;
}

.password-wrap {
  display: flex;
  gap: 0.6rem;
  align-items: stretch;
}

.password-wrap input {
  flex: 1;
}

.password-toggle {
  min-height: 52px;
  white-space: nowrap;
}

.inline-form {
  display: inline;
  margin: 0;
}

/* ---------- Formulários ---------- */

.field {
  display: grid;
  gap: 0.4rem;
  margin-bottom: 1.1rem;
}

.field label {
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  font: inherit;
  min-height: 52px;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
}

.help {
  font-size: 0.9rem;
  color: var(--muted);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 700;
  cursor: pointer;
}

.check input {
  width: 24px;
  height: 24px;
  min-height: auto;
}

.error {
  background: var(--accent-soft);
  color: var(--danger);
  border: 1px solid #e7b9a6;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
}

.success {
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid #b7dfc5;
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 1rem;
}

/* ---------- Cabeçalho do app ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1.2rem;
  border-bottom: 2px solid var(--line);
  margin-bottom: 1.6rem;
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-weight: 800;
  font-size: 1.2rem;
  color: var(--text);
  text-decoration: none;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--brand-soft);
  color: var(--brand-strong);
}

/* ---------- Grade de atalhos ---------- */

.grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr 1fr;
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.tile {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: flex-start;
  text-align: left;
  min-height: 120px;
  padding: 1.2rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.15s ease, transform 0.06s ease;
}

.tile:hover {
  border-color: var(--brand);
}

.tile:active {
  transform: translateY(1px);
}

.tile .tile-emoji {
  font-size: 2rem;
  line-height: 1;
}

.tile .tile-title {
  font-size: 1.25rem;
  font-weight: 800;
}

.tile .tile-desc {
  color: var(--muted);
  font-size: 1rem;
}

/* ---------- Boas-vindas ---------- */

.welcome {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.welcome-inner {
  width: 100%;
  max-width: 560px;
  text-align: center;
}

.welcome h1 {
  font-size: clamp(2.4rem, 8vw, 3.4rem);
  margin-bottom: 0.2rem;
}

.welcome .lead {
  font-size: 1.3rem;
  margin-bottom: 2rem;
}

.stack {
  display: grid;
  gap: 0.9rem;
}

/* ---------- Status ---------- */

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  font-size: 0.95rem;
}

.status.loading {
  background: var(--surface-2);
  color: var(--muted);
}

.status.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status.error {
  background: var(--accent-soft);
  color: var(--danger);
}

/* ---------- Utilidades ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
}

.spread {
  justify-content: space-between;
}

/* ---------- Lista de clientes ---------- */

.search {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.search input {
  flex: 1;
  font: inherit;
  min-height: 52px;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.client-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.client-list li + li {
  border-top: 1px solid var(--line);
}

.client-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1rem;
  min-height: 64px;
  text-decoration: none;
  color: var(--text);
}

.client-row:hover {
  background: var(--brand-soft);
}

.client-name {
  font-weight: 700;
  font-size: 1.1rem;
}

.client-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.2rem;
}

.pagination .btn {
  min-height: 48px;
}

.empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--muted);
}

/* ---------- Ficha ---------- */

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin: 1rem 0 1.4rem;
}

.detail-section {
  margin-bottom: 1rem;
}

.kv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}

@media (min-width: 640px) {
  .kv {
    grid-template-columns: 180px 1fr;
  }
}

.kv dt {
  color: var(--muted);
  font-weight: 700;
}

.kv dd {
  margin: 0;
}

.plain {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.phone-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border-radius: 10px;
}

.phone-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.phone-actions .btn {
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-size: 1rem;
}

/* ---------- Pedidos ---------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1.2rem;
}

.filters input[type="search"],
.filters select {
  font: inherit;
  min-height: 52px;
  padding: 0.6rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.filters input[type="search"] {
  flex: 1 1 260px;
}

.order-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.badge-status {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-status.orcamento {
  background: #eef2f7;
  color: #1f4e79;
}

.badge-status.pedido {
  background: #e7f0fb;
  color: #1d4ed8;
}

.badge-status.faturado {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge-status.cancelado {
  background: var(--accent-soft);
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.98rem;
}

.items-table th,
.items-table td {
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.items-table th {
  background: var(--surface-2);
  font-weight: 700;
}

.items-table .num {
  text-align: right;
  white-space: nowrap;
}

/* ---------- Agenda ---------- */

.text-danger {
  color: var(--danger);
}

.agenda-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.agenda-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.8rem;
  padding: 0.7rem 0.8rem;
  background: var(--surface-2);
  border-radius: 10px;
}

.agenda-time {
  font-weight: 800;
  font-size: 1.05rem;
  min-width: 56px;
}

.agenda-body {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.agenda-title {
  font-weight: 700;
}

.agenda-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.agenda-actions .btn {
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-size: 1rem;
}

.badge-status.pendente {
  background: #e7f0fb;
  color: #1d4ed8;
}

.badge-status.concluido {
  background: var(--ok-soft);
  color: var(--ok);
}

/* ---------- Autocomplete de cliente ---------- */

.autocomplete .ac-selected {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  background: var(--brand-soft);
  border-radius: 10px;
}

.autocomplete .ac-results {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  overflow: hidden;
}

.autocomplete .ac-results button {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.8rem;
  background: none;
  border: 0;
  font: inherit;
  cursor: pointer;
  color: var(--text);
}

.autocomplete .ac-results button:hover {
  background: var(--brand-soft);
}

/* ---------- Admin ---------- */

.section-title {
  margin-top: 2rem;
  margin-bottom: 0.8rem;
}

.stat {
  text-decoration: none;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.stat-num {
  font-size: 2.2rem;
  font-weight: 800;
  line-height: 1;
}

.stat-label {
  color: var(--muted);
  font-weight: 600;
}

.user-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.user-row {
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
}

.user-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 220px;
}

.user-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.user-controls select,
.user-controls input {
  font: inherit;
  min-height: 44px;
  padding: 0.4rem 0.6rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
}

.user-controls input {
  width: 200px;
}

.user-form .btn {
  min-height: 44px;
  padding: 0.4rem 0.9rem;
  font-size: 1rem;
}

.badge.ativo {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.inativo {
  background: var(--accent-soft);
  color: var(--danger);
}

/* ---------- Configuração / saúde ---------- */

.config-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.config-row:last-child {
  border-bottom: 0;
}

.config-ok {
  color: var(--ok);
  font-weight: 700;
}

.config-warn {
  color: var(--danger);
  font-weight: 700;
}

/* ---------- Vincular pedidos ---------- */

.link-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
  margin-top: 0.6rem;
}

.link-form .field {
  flex: 1 1 240px;
  margin-bottom: 0;
}

/* ---------- Formulário de pedido ---------- */

.item-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem;
  margin-bottom: 0.8rem;
  background: var(--surface);
}

.item-card .field {
  margin-bottom: 0.7rem;
}

.order-total {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  background: var(--brand-soft);
  border-radius: 12px;
  margin: 1rem 0;
  font-size: 1.15rem;
}

.order-total strong {
  font-size: 1.5rem;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1rem;
}

output {
  display: inline-block;
  min-height: 52px;
  padding: 0.6rem 0.8rem;
  font-weight: 700;
}

@media print {
  .no-print,
  .topbar,
  .actions {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .page {
    max-width: none;
    padding: 0;
  }

  .card {
    box-shadow: none;
    border: 1px solid #bbb;
  }
}
