:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --ink: #1a1a1a;
  --ink-soft: #555;
  --line: #e6e6e3;
  --accent: #B8533A;
  --accent-soft: #f3dfd6;
  --green: #2f9e6b;
  --green-soft: #def4e7;
  --gray: #9aa0a6;
  --gray-soft: #ececec;
  --red: #c2362b;
  --red-soft: #fadfdc;
  --amber: #b8860b;
  --amber-soft: #fbeec1;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 12px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; min-height: 100dvh; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
small { font-size: 12px; color: var(--ink-soft); }

/* TOPBAR */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: var(--accent); color: white; font-weight: 700;
  display: grid; place-items: center; font-size: 17px;
}
.brand h1 { font-size: 16px; }
.subtitle { font-size: 11px; color: var(--ink-soft); }

.quick-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft);
  padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 13px;
  transition: all .15s ease; font-family: inherit;
}
.chip:hover { border-color: var(--ink-soft); }
.chip.active { background: var(--ink); color: white; border-color: var(--ink); }

.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar-right select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--bg); font-family: inherit;
}

/* BANNER */
.banner {
  padding: 10px 20px; font-size: 13px; text-align: center;
  background: var(--amber-soft); color: var(--amber); border-bottom: 1px solid var(--line);
}
.banner.error { background: var(--red-soft); color: var(--red); }
.banner a { color: inherit; font-weight: 600; }

/* BUTTONS */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500;
  font-size: 14px; transition: transform .05s ease; font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { background: var(--red); color: white; border-color: var(--red); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.icon-btn {
  background: transparent; border: 0; font-size: 24px; cursor: pointer; line-height: 1;
  color: var(--ink-soft); padding: 4px 8px;
}

/* LAYOUT */
.layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px 20px;
  max-width: 1400px; margin: 0 auto;
}
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
}

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.panel-header {
  display: flex; gap: 8px; align-items: center; padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.panel-header input, .panel-header select {
  flex: 1; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 14px; font-family: inherit; background: var(--bg);
}
.panel-header h2 { flex: 1; text-align: center; font-size: 15px; text-transform: capitalize; }

/* VISITS LIST */
.visits-list { padding: 8px; max-height: 70vh; overflow-y: auto; }
@media (max-width: 920px) { .visits-list { max-height: none; } }

.visit-card {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm); margin-bottom: 6px;
  cursor: pointer; transition: background .15s ease;
  border-left: 3px solid var(--gray);
}
.visit-card:hover { background: var(--bg); }
.visit-card.status-pending    { border-left-color: var(--gray); }
.visit-card.status-confirmed  { border-left-color: var(--green); background: var(--green-soft); }
.visit-card.status-done       { border-left-color: var(--ink-soft); opacity: 0.75; }
.visit-card.status-cancelled  { border-left-color: var(--red); opacity: 0.55; text-decoration: line-through; }

.visit-time { text-align: right; }
.visit-time .day { font-weight: 600; font-size: 13px; }
.visit-time .hour { color: var(--ink-soft); font-size: 13px; }

.visit-info .client { font-weight: 600; font-size: 14px; line-height: 1.3; }
.visit-info .property { color: var(--ink-soft); font-size: 12px; margin-top: 2px; line-height: 1.3; }
.visit-info .meta { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }

.badge {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  background: var(--gray-soft); color: var(--ink-soft); font-weight: 500;
}
.badge.synced { background: var(--green-soft); color: var(--green); }
.badge.notified { background: var(--amber-soft); color: var(--amber); }
.badge.channel { background: var(--accent-soft); color: var(--accent); }
.badge.agent { background: #e8e6f3; color: #5a4ea8; }

.visit-actions { display: flex; flex-direction: column; gap: 4px; }
.visit-actions button {
  font-size: 11px; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-family: inherit;
}
.visit-actions button:hover { background: var(--bg); }
.empty { padding: 40px 20px; text-align: center; color: var(--ink-soft); font-size: 14px; }

/* CALENDAR */
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 1px; background: var(--line); padding: 1px;
}
.cal-cell { background: var(--surface); padding: 5px; min-height: 65px; font-size: 11px; position: relative; }
.cal-cell.head { background: var(--bg); font-weight: 600; text-align: center; min-height: auto; padding: 6px 4px; color: var(--ink-soft); }
.cal-cell.muted { background: var(--bg); color: var(--gray); }
.cal-cell.today .day-num {
  background: var(--accent); color: white; border-radius: 999px;
  width: 20px; height: 20px; display: inline-grid; place-items: center; font-weight: 600; font-size: 11px;
}
.day-num { font-weight: 500; font-size: 11px; }
.cal-dot {
  display: block; font-size: 10px; padding: 2px 4px; margin-top: 3px;
  border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer;
}
.cal-dot.pending   { background: var(--gray-soft);  color: var(--ink-soft); }
.cal-dot.confirmed { background: var(--green-soft); color: var(--green); }
.cal-dot.done      { background: var(--gray-soft);  color: var(--ink-soft); opacity: 0.7; }
.cal-dot.cancelled { background: var(--red-soft);   color: var(--red); text-decoration: line-through; }

.cal-legend {
  display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 12px;
  font-size: 11px; color: var(--ink-soft); border-top: 1px solid var(--line);
}
.cal-legend span { display: flex; align-items: center; gap: 4px; }
.dot { width: 8px; height: 8px; border-radius: 999px; display: inline-block; }
.dot.pending   { background: var(--gray); }
.dot.confirmed { background: var(--green); }
.dot.done      { background: var(--ink-soft); }
.dot.cancelled { background: var(--red); }

/* MODAL */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: grid; place-items: center; z-index: 50; padding: 12px;
  animation: fadeIn .15s ease;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--surface); border-radius: var(--radius);
  width: 100%; max-width: 600px; max-height: 92vh; max-height: 92dvh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1;
}
form { padding: 14px 18px; display: flex; flex-direction: column; gap: 11px; }
form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
form input, form select, form textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: var(--bg); color: var(--ink);
}
form input:focus, form select:focus, form textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.input-with-action { display: flex; gap: 6px; }
.input-with-action input { flex: 1; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 11px; }
@media (max-width: 600px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.form-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }

.post-visit-block {
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px;
  background: var(--bg); display: flex; flex-direction: column; gap: 8px;
}
.post-visit-block h4 { font-size: 13px; color: var(--ink-soft); }
.post-visit-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.pv-item { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.pv-item.sent { background: var(--green-soft); color: var(--green); border-color: transparent; }

.hidden { display: none !important; }

/* TOAST */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 10px 18px;
  border-radius: var(--radius-sm); box-shadow: var(--shadow); z-index: 100;
  font-size: 14px; animation: slideUp .2s ease; max-width: 90vw;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ============ LOGIN ============ */
.login-screen {
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(135deg, #B8533A 0%, #9a4530 100%);
  display: grid; place-items: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  padding: 40px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--accent); color: white; font-weight: 700;
  display: grid; place-items: center; font-size: 32px;
  margin: 0 auto 16px;
  box-shadow: 0 8px 20px rgba(184, 83, 58, 0.3);
}
.login-card h1 {
  font-size: 22px; margin-bottom: 4px; color: var(--ink);
}
.login-subtitle {
  font-size: 14px; color: var(--ink-soft); margin-bottom: 24px;
}
#login-form {
  display: flex; flex-direction: column; gap: 12px;
  padding: 0;
}
#login-form input {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
}
#login-form input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.login-submit {
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
}
.login-error {
  background: var(--red-soft);
  color: var(--red);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}

/* ============ PENDIENTES (Agente Recordador) ============ */
.count-badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  background: var(--accent); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700;
  margin-left: 4px;
}
.count-badge.hidden { display: none; }

.pendientes-modal-content { max-width: 640px; }
.pendientes-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; }
.pendientes-intro {
  font-size: 13px; color: var(--ink-soft);
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: var(--radius-sm);
}
.pendientes-intro strong { color: var(--accent); }

.pendientes-form {
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.pendientes-form h4 { font-size: 13px; color: var(--ink-soft); margin: 0; }
.pendientes-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--ink-soft); }
.pendientes-form input,
.pendientes-form select,
.pendientes-form textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--ink);
}
.pendientes-form input:focus,
.pendientes-form select:focus,
.pendientes-form textarea:focus {
  outline: 2px solid var(--accent-soft); border-color: var(--accent);
}
.pendientes-form button[type="submit"] { margin-top: 4px; }

.pendientes-list-head {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: 4px; border-top: 1px solid var(--line);
}
.pendientes-list-head h4 { font-size: 14px; }
.pendientes-actions-head { display: flex; gap: 6px; }

.pendientes-list { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow-y: auto; }

.pendiente-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.pendiente-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 2px;
}
.pendiente-tag {
  background: var(--accent); color: #fff;
  padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
}
.pendiente-meta { color: var(--ink-soft); font-size: 11px; }
.pendiente-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.pendiente-contact { font-size: 13px; color: var(--ink-soft); }
.pendiente-notes {
  font-size: 13px; color: var(--ink); font-style: italic;
  background: var(--bg); padding: 6px 10px;
  border-radius: 4px; border-left: 2px solid var(--accent);
  margin-top: 2px;
}
.pendiente-next { font-size: 12px; color: var(--ink-soft); margin-top: 4px; }
.pendiente-actions { display: flex; gap: 6px; margin-top: 8px; }
.btn.small.success {
  background: var(--green); color: #fff; border-color: var(--green);
}
.btn.small.success:hover { filter: brightness(1.05); }
