* { box-sizing: border-box; }

:root {
  --bg: #f4f5f7;
  --text: #1f2329;
  --muted: #777;
  --border: #e3e5e8;
  --card: #ffffff;
  --accent: #1f6feb;
  --accent-dark: #1a5fd0;
  --danger: #d33;
  --planned: #3d8bfd;
  --inProgress: #f4a261;
  --done: #2a9d8f;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-title { font-size: 20px; font-weight: 700; margin-right: auto; }
.logout-btn {
  margin-left: 10px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}
.logout-btn:hover { color: var(--danger); border-color: var(--danger); }
.user-select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: var(--bg);
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 20px 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: none;
  background: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 880px; margin: 0 auto; padding: 20px 16px 60px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.toolbar input[type="text"] {
  flex: 1 1 220px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.toolbar select {
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--card);
}

.btn-primary, .btn-secondary {
  padding: 9px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: #fdeaea; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

.total-card { display: flex; align-items: center; justify-content: space-between; }
.total-label { font-size: 14px; color: var(--muted); }
.total-value { font-size: 24px; font-weight: 700; }

.owner-breakdown { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.owner-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.owner-row strong { color: var(--text); font-weight: 600; font-size: 14px; }

#repair-footer { padding: 10px 14px; }
#repair-footer .total-label { font-size: 13px; }
#repair-footer .total-value { font-size: 14px; font-weight: 600; }

.list { display: flex; flex-direction: column; gap: 10px; }

.row-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.row-card:hover { border-color: #c8ccd2; }
.row-main { flex: 1; min-width: 0; }
.row-title-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-title { font-size: 15px; font-weight: 600; }
.row-sub { font-size: 13px; color: var(--muted); margin-top: 3px; }
.phone-link { color: var(--accent); font-weight: 600; text-decoration: none; }
.phone-link:hover { text-decoration: underline; }
.row-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.row-side { text-align: right; white-space: nowrap; font-size: 13px; }
.row-side .cost { font-weight: 700; font-size: 15px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-planned { background: var(--planned); }
.badge-inProgress { background: var(--inProgress); }
.badge-done { background: var(--done); }

.tag {
  font-size: 11px;
  color: #fff;
  background: #888;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.empty-msg { color: var(--muted); font-size: 14px; text-align: center; padding: 24px 0; }
.hidden { display: none !important; }

/* Модальное окно */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  padding: 22px 22px 18px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { font-size: 17px; margin: 0 0 16px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%;
  height: 40px;
  box-sizing: border-box;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  color-scheme: light;
}
.field textarea {
  height: auto;
  padding: 9px 11px;
  resize: vertical;
  min-height: 60px;
}
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23777'%3E%3Cpath d='M5.5 7.5l4.5 4.5 4.5-4.5' stroke='%23777' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions .spacer { flex: 1; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; font-size: 13px; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.top-list { margin: 0; padding-left: 0; list-style: none; }
.top-list li {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.top-list li:last-child { border-bottom: none; }
.top-list .muted { color: var(--muted); font-size: 14px; padding: 4px 0; }

.delta-up { color: var(--done); }
.delta-down { color: var(--danger); }

.stats-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 14px;
}
.stat-block .stat-label { font-size: 12px; color: var(--muted); }
.stat-block .stat-value { font-size: 19px; font-weight: 700; margin-top: 2px; }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2329;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
}

@media (max-width: 540px) {
  .row-card { flex-direction: column; }
  .row-side { text-align: left; }
}

/* ---------- Экран входа ---------- */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.login-box {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
}
.login-logo { font-size: 34px; font-weight: 800; color: var(--accent); }
.login-sub { color: var(--muted); font-size: 14px; margin: 8px 0 20px; }
.login-box input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 14px;
}
.login-btn { width: 100%; padding: 12px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; margin: 12px 0 0; }

/* ---------- Кнопки связи с клиентом ---------- */
.contact-btns { display: inline-flex; gap: 6px; margin-top: 6px; }
.contact-btn {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
}
.contact-btn.call { background: var(--accent); }
.contact-btn.wa { background: #25d366; }
.contact-btn:active { opacity: 0.8; }
