/* ============================================================
   CRM — César Santana Imóveis
   ============================================================ */
:root {
  --brand: #1a5f7a;
  --brand-2: #13788f;
  --brand-dark: #0e2a37;
  --accent: #f4a261;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --text: #0f172a;
  --muted: #64748b;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --sidebar-w: 244px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --font-head: "Poppins", var(--font);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* ===================== AUTH (setup / login) ===================== */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(26, 95, 122, 0.25), transparent),
    radial-gradient(900px 500px at -10% 110%, rgba(244, 162, 97, 0.18), transparent),
    var(--brand-dark);
}

.auth__card {
  width: 100%;
  max-width: 410px;
  background: var(--card);
  border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  padding: 38px 34px;
  animation: rise 0.4s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.auth__logo {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--brand);
  text-align: center;
  margin-bottom: 4px;
}
.auth__logo span { color: var(--accent); }
.auth__title { text-align: center; font-family: var(--font-head); font-size: 1.25rem; margin-top: 14px; }
.auth__sub { text-align: center; color: var(--muted); font-size: 0.9rem; margin: 6px 0 24px; }

/* ===================== Form fields ===================== */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 6px; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26, 95, 122, 0.12);
}
.field textarea { resize: vertical; min-height: 76px; }
.field__row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ===================== Buttons ===================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.92rem;
  transition: transform 0.12s, background 0.15s, box-shadow 0.15s, opacity 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--primary { background: var(--brand); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--brand-2); }
.btn--block { width: 100%; }
.btn--ghost { background: #fff; border: 1px solid var(--border); color: var(--text); }
.btn--ghost:hover { background: #f8fafc; }
.btn--danger { background: var(--red-bg); color: var(--red); }
.btn--danger:hover { background: #fecaca; }
.btn--sm { padding: 7px 12px; font-size: 0.82rem; border-radius: 8px; }
.btn--accent { background: var(--accent); color: #5b3a13; }
.btn--accent:hover { filter: brightness(1.05); }

.form-error {
  background: var(--red-bg);
  color: var(--red);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.85rem;
  margin-bottom: 14px;
}

/* ===================== App layout ===================== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--brand-dark);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}
.sidebar__logo {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.25rem;
  color: #fff;
  padding: 22px 22px 18px;
}
.sidebar__logo span { color: var(--accent); }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; flex: 1; }
.sidebar__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 0.93rem;
  color: #cbd5e1;
  transition: background 0.15s, color 0.15s;
}
.sidebar__link:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.sidebar__link.active { background: var(--brand); color: #fff; }
.sidebar__link .ico { width: 20px; text-align: center; }
.sidebar__foot { padding: 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sidebar__user { font-size: 0.82rem; color: #94a3b8; padding: 0 6px 10px; }
.sidebar__user strong { display: block; color: #e2e8f0; font-size: 0.9rem; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 64px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar__title { font-family: var(--font-head); font-weight: 600; font-size: 1.15rem; }
.topbar__spacer { flex: 1; }
.topbar__burger {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
}

.content { padding: 26px 24px 60px; max-width: 1180px; width: 100%; }

/* ===================== Stat cards ===================== */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 26px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.stat__label { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat__value { font-family: var(--font-head); font-size: 1.75rem; font-weight: 700; margin-top: 6px; }
.stat__value small { font-size: 1rem; font-weight: 600; color: var(--muted); }

/* ===================== Section / cards ===================== */
.section-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.section-head h2 { font-family: var(--font-head); font-size: 1.2rem; }
.section-head .spacer { flex: 1; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-input {
  flex: 1;
  min-width: 180px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}
.search-input:focus { outline: none; border-color: var(--brand); }

/* Tabela responsiva */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: 0.92rem; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.12s; cursor: pointer; }
.table tbody tr:hover { background: #f8fafc; }
.table .muted { color: var(--muted); font-size: 0.85rem; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge--green { background: var(--green-bg); color: var(--green); }
.badge--amber { background: var(--amber-bg); color: var(--amber); }
.badge--red { background: var(--red-bg); color: var(--red); }
.badge--blue { background: var(--blue-bg); color: var(--blue); }
.badge--gray { background: #e2e8f0; color: #475569; }

/* Property grid (no detalhe do cliente) */
.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.prop-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.15s, transform 0.15s;
}
.prop-card:hover { box-shadow: var(--shadow); transform: translateY(-3px); }
.prop-card__img { aspect-ratio: 16/10; background: #e2e8f0 center/cover no-repeat; position: relative; }
.prop-card__badge { position: absolute; top: 8px; left: 8px; }
.prop-card__body { padding: 13px 14px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.prop-card__price { font-family: var(--font-head); font-weight: 700; color: var(--brand); font-size: 1.05rem; }
.prop-card__title { font-weight: 600; font-size: 0.95rem; }
.prop-card__meta { color: var(--muted); font-size: 0.82rem; }
.prop-card__actions { display: flex; gap: 6px; padding: 0 14px 13px; }

/* Detalhe do cliente */
.detail-head {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.avatar {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.detail-head__info { flex: 1; min-width: 200px; }
.detail-head__info h2 { font-family: var(--font-head); font-size: 1.4rem; }
.detail-head__contacts { display: flex; gap: 18px; flex-wrap: wrap; color: var(--muted); font-size: 0.88rem; margin-top: 6px; }
.detail-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.back-link { color: var(--muted); font-size: 0.88rem; display: inline-flex; gap: 5px; margin-bottom: 14px; }
.back-link:hover { color: var(--brand); }

/* Empty state */
.empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}
.empty__icon { font-size: 2.6rem; margin-bottom: 8px; }

/* ===================== Modal ===================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
  animation: fade 0.18s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--card);
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  animation: rise 0.22s ease;
}
.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--card);
}
.modal__head h3 { font-family: var(--font-head); font-size: 1.15rem; }
.modal__close { background: none; border: none; font-size: 1.4rem; color: var(--muted); line-height: 1; }
.modal__body { padding: 22px 24px; }
.modal__foot { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--card); }

/* ===================== Toast ===================== */
.toast-wrap {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--brand-dark);
  color: #fff;
  padding: 12px 22px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  animation: rise 0.2s ease;
}
.toast--error { background: var(--red); }
.toast--ok { background: var(--green); }

/* ===================== Image upload preview ===================== */
.img-drop {
  border: 2px dashed var(--border);
  border-radius: 12px;
  aspect-ratio: 16/9;
  display: grid;
  place-items: center;
  color: var(--muted);
  background-size: cover;
  background-position: center;
  cursor: pointer;
  font-size: 0.85rem;
  text-align: center;
  transition: border-color 0.15s;
}
.img-drop:hover { border-color: var(--brand); }
.img-drop.has-image { border-style: solid; }
.img-drop.has-image span { display: none; }

/* ===================== Galeria de fotos (até 20) ===================== */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.img-thumb {
  position: relative;
  aspect-ratio: 1/1;
  border-radius: 10px;
  background-size: cover;
  background-position: center;
  background-color: var(--border);
  overflow: hidden;
}
.img-thumb__del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.img-thumb__del:hover { background: var(--red, #dc2626); }
.img-thumb__cover {
  position: absolute;
  bottom: 4px;
  left: 4px;
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
}
.img-thumb--add {
  border: 2px dashed var(--border);
  background: none;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.img-thumb--add:hover { border-color: var(--brand); color: var(--brand); }

/* loading */
.loader { display: grid; place-items: center; padding: 60px; color: var(--muted); }
.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===================== Responsivo ===================== */
.sidebar__backdrop { display: none; }

@media (max-width: 860px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.28s ease;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.3);
  }
  .app.nav-open .sidebar { transform: translateX(0); }
  .app.nav-open .sidebar__backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 35;
  }
  .main { margin-left: 0; }
  .topbar__burger { display: block; }
  .content { padding: 18px 16px 70px; }
  .field__row { grid-template-columns: 1fr; }
  .detail-head { flex-direction: column; align-items: flex-start; }

  /* Tabela vira cartões no mobile */
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { display: none; }
  .table tr {
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    padding: 6px 4px;
  }
  .table td { border: none; padding: 7px 14px; display: flex; justify-content: space-between; gap: 12px; }
  .table td::before {
    content: attr(data-label);
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    font-weight: 600;
  }
  .table td.cell-actions { justify-content: flex-end; }
  .table td.cell-actions::before { display: none; }
}
