:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------------------------------- login --------------------------------- */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, #e0e7ff 0%, transparent 60%),
              radial-gradient(900px 500px at 110% 110%, #dbeafe 0%, transparent 55%), var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.08);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-dot {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #4338ca);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  font-weight: 700;
}

/* --------------------------------- layout -------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand-mark { padding: 0 8px 16px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: none;
  color: var(--muted);
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.nav-item:hover { background: #f9fafb; color: var(--ink); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-item .badge { margin-left: auto; }

.sidebar-foot {
  margin-top: auto;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.who { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
  flex: 0 0 32px;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar h1 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.topbar .spacer { flex: 1; }

.view { padding: 22px 26px 60px; max-width: 1280px; width: 100%; }

/* --------------------------------- pieces -------------------------------- */

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

.card-head {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-body { padding: 18px; }

.grid { display: grid; gap: 14px; }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.two { grid-template-columns: 1.4fr 1fr; }
.grid.halves { grid-template-columns: 1fr 1fr; }

.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 12.5px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.stat .value.warn { color: var(--red); }
.stat .value.good { color: var(--green); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-weight: 500;
  font-size: 14px;
  text-decoration: none;
  color: var(--ink);
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #4338ca; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.danger { color: var(--red); border-color: #fecaca; background: var(--red-soft); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  outline: none;
}
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.input { resize: vertical; min-height: 74px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); font-weight: 500; margin-bottom: 5px; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: #f3f4f6;
  color: #374151;
}
.badge.new { background: var(--blue-soft); color: var(--blue); }
.badge.contacted { background: #f5f3ff; color: #6d28d9; }
.badge.qualified { background: #ecfeff; color: #0e7490; }
.badge.visit_scheduled { background: var(--amber-soft); color: var(--amber); }
.badge.visit_done { background: #fef3c7; color: #92400e; }
.badge.negotiation { background: #fff7ed; color: #c2410c; }
.badge.booked { background: var(--green-soft); color: var(--green); }
.badge.lost { background: #f3f4f6; color: #6b7280; }
.badge.hot { background: var(--red-soft); color: var(--red); }
.badge.warm { background: var(--amber-soft); color: var(--amber); }
.badge.cold { background: var(--blue-soft); color: var(--blue); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; background: #fbfbfd; }
tbody tr:hover { background: #fbfbfe; }
tbody tr.clickable { cursor: pointer; }
td.name { font-weight: 600; }

.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.filters .input { width: auto; min-width: 130px; }
.filters .search { flex: 1 1 220px; }

.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-size: 13.5px; }
.bar-row .name { width: 120px; color: var(--muted); flex: 0 0 120px; }
.bar-track { flex: 1; height: 8px; background: #f1f2f6; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 99px; }
.bar-row .count { width: 34px; text-align: right; font-weight: 600; }

/* --------------------------------- drawer -------------------------------- */

.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(17, 24, 39, 0.35); z-index: 40;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%);
  background: var(--card); z-index: 50; box-shadow: -12px 0 32px rgba(16, 24, 40, 0.12);
  display: flex; flex-direction: column;
}
.drawer-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 10px; }
.drawer-body { padding: 18px 20px 40px; overflow-y: auto; flex: 1; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 20px; border-left: 2px solid var(--line); margin-left: 4px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px;
  border-radius: 50%; background: #c7d2fe; border: 2px solid #fff;
}
.timeline li.hot-dot::before { background: var(--red); }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .what { font-size: 14px; margin-top: 2px; }

/* --------------------------------- modal --------------------------------- */

.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.4); z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--card); border-radius: 16px; width: min(620px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 48px rgba(16, 24, 40, 0.2); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* --------------------------------- toast --------------------------------- */

.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 20px rgba(0,0,0,0.2); }
.toast.err { background: var(--red); }
.toast.ok { background: #065f46; }

/* --------------------------------- mobile -------------------------------- */

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; width: 100%;
    flex: none; flex-direction: row; justify-content: space-around; padding: 8px 6px;
    border-right: none; border-top: 1px solid var(--line); z-index: 30;
  }
  .sidebar .brand-mark, .sidebar-foot { display: none; }
  .nav-item { flex-direction: column; gap: 3px; font-size: 11px; padding: 6px 4px; text-align: center; justify-content: center; }
  .nav-item .badge { margin-left: 0; }
  .main { padding-bottom: 68px; }
  .view { padding: 16px 14px 40px; }
  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 16px; }
  .grid.two, .grid.halves { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
  th.hide-sm, td.hide-sm { display: none; }
}

/* ---------------------------- PHP build extras --------------------------- */

details > summary::-webkit-details-marker { display: none; }
details > summary::marker { display: none; content: ""; }
details[open] > summary { border-bottom: 1px solid var(--line); }
.card-head h2 { display: inline; }
a.nav-item { text-decoration: none; }
.login-card h2, .login-card p { text-align: left; }
.check-row { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; align-items: flex-start; }
.check-row:last-child { border-bottom: none; }
.check-ok { color: var(--green); font-weight: 700; }
.check-bad { color: var(--red); font-weight: 700; }
code { background: #f3f4f6; padding: 2px 6px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }

/* ------------------------------ small extras ----------------------------- */

details > summary::-webkit-details-marker { display: none; }
details > summary::marker { display: none; content: ""; }
details[open] > summary { border-bottom: 1px solid var(--line); }
.card-head h2 { display: inline; }
a.nav-item { text-decoration: none; }
code { background: #f3f4f6; padding: 2px 6px; border-radius: 5px; font-size: 12.5px; word-break: break-all; }
