:root {
  --bg: #f6f8fb;
  --ink: #1d2433;
  --card: #ffffff;
  --accent: #0e7490;
  --accent-2: #0891b2;
  --muted: #6b7280;
  --danger: #b42318;
  --success: #1f7a4f;
  --shadow: 0 12px 40px rgba(8, 23, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 10%, #cffafe, transparent 38%),
    radial-gradient(circle at 92% 8%, #dbeafe, transparent 33%),
    linear-gradient(180deg, #f8fafc, #eef2ff 70%, #f8fafc);
  min-height: 100vh;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-family: "Fraunces", serif;
  letter-spacing: 0.3px;
}

.app-shell {
  width: min(1180px, 94vw);
  margin: 3rem auto;
  position: relative;
  z-index: 2;
}

.bg-shape {
  position: fixed;
  border-radius: 50%;
  filter: blur(48px);
  opacity: 0.4;
  z-index: 0;
  pointer-events: none;
}

.bg-shape-1 {
  width: 280px;
  height: 280px;
  background: #a7f3d0;
  top: -60px;
  left: -40px;
}

.bg-shape-2 {
  width: 340px;
  height: 340px;
  background: #bae6fd;
  bottom: -90px;
  right: -70px;
}

.card {
  background: var(--card);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  animation: slideIn 0.45s ease;
}

.login-card {
  width: min(480px, 96vw);
  margin: 9vh auto;
  padding: 2rem;
}

.subtitle {
  color: var(--muted);
  margin-top: -0.2rem;
}

.form-grid {
  display: grid;
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: #374151;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 116, 144, 0.17);
  outline: none;
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 0.7rem 0.95rem;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 700;
}

.btn-ghost {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-alert {
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
  font-weight: 700;
}

.hidden {
  display: none;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.btn-icon {
  min-width: 2.5rem;
  font-size: 1.05rem;
  padding: 0.58rem 0.75rem;
  line-height: 1;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.stat .value {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0;
}

.tabs-shell {
  margin-top: 1rem;
  display: grid;
  gap: 0.85rem;
}

.portal-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.portal-tab-panel > .card {
  box-shadow: none;
  border: 1px solid #e2e8f0;
}

.list {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.55rem;
}

.bill-warning {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(180, 35, 24, 0.12);
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.bill-paid {
  display: inline-block;
  margin-left: 0.45rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: rgba(31, 122, 79, 0.12);
  color: var(--success);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.income-charts {
  margin-top: 0.7rem;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.income-chart-block {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.65rem;
  background: #fbfdff;
}

.income-chart-block h4 {
  margin: 0 0 0.5rem;
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.95rem;
}

.income-chart {
  display: grid;
  gap: 0.4rem;
}

.income-chart-row {
  display: grid;
  grid-template-columns: 84px 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

.income-chart-label {
  font-size: 0.78rem;
  color: #475569;
}

.income-chart-track {
  height: 0.52rem;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.income-chart-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.income-chart-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f172a;
}

.filter-bar {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 0.6rem;
  align-items: end;
}

.bill-filter-bar {
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
}

.filter-meta {
  margin-top: 0.45rem;
}

.list-item {
  border: 1px solid #e2e8f0;
  background: #fbfdff;
  padding: 0.7rem;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  gap: 0.7rem;
  align-items: center;
}

.list-item strong {
  display: block;
}

.badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-weight: 700;
}

.badge-paid {
  background: #dcfce7;
  color: var(--success);
}

.badge-unpaid {
  background: #fee4e2;
  color: var(--danger);
}

.list-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-small {
  padding: 0.4rem 0.55rem;
  font-size: 0.8rem;
}

.btn-danger {
  background: #fee2e2;
  color: #991b1b;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal-content {
  position: relative;
  z-index: 1;
  width: min(860px, 96vw);
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.email-modal {
  max-width: 720px;
}

.email-modal-body {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.email-preview-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 0.5rem;
  align-items: center;
}

.email-preview-label {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.email-preview-value {
  font-weight: 600;
  color: #0f172a;
}

.email-preview-message {
  display: grid;
  gap: 0.4rem;
}

.email-preview-message textarea {
  resize: vertical;
  background: #f8fafc;
}

body.modal-open {
  overflow: hidden;
}

.bill-items-wrap {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 0.7rem;
  background: #f8fafc;
}

.bill-items {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.bill-item-row {
  display: grid;
  grid-template-columns: auto 2fr 1fr 1fr auto auto;
  gap: 0.45rem;
  align-items: end;
}

.bill-item-row input {
  width: 100%;
}

.bill-item-name-wrap {
  position: relative;
}

.bill-item-service-list {
  top: calc(100% + 0.2rem);
  left: 0;
  right: 0;
}

.technic-form textarea {
  resize: vertical;
}

.technic-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.technic-header-row .subtitle {
  margin: 0;
}

.technic-nvrs {
  display: grid;
  gap: 0.65rem;
}

.nvr-card {
  border: 1px solid #dbe3ef;
  border-radius: 12px;
  background: #ffffff;
  padding: 0.65rem;
  display: grid;
  gap: 0.55rem;
}

.nvr-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
}

.nvr-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.camera-list {
  display: grid;
  gap: 0.45rem;
}

.camera-row {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  background: #f8fafc;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 0.45rem;
  align-items: end;
}

.technic-summary {
  display: grid;
  gap: 0.25rem;
}

.technic-summary ul {
  margin: 0.2rem 0 0;
  padding-left: 1rem;
}

.bill-item-index {
  font-weight: 700;
  color: #334155;
  align-self: center;
}

.bill-item-total {
  font-size: 0.85rem;
  color: #0f172a;
  font-weight: 700;
  white-space: nowrap;
  align-self: center;
}

.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  right: 0;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.2);
  z-index: 30;
  max-height: 220px;
  overflow: auto;
}

.autocomplete-item {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  color: #0f172a;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
}

.autocomplete-item:last-child {
  border-bottom: 0;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: #ecfeff;
}

.autocomplete-item strong {
  display: block;
}

.autocomplete-item small {
  color: #475569;
}

@keyframes slideIn {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 980px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .income-charts {
    grid-template-columns: 1fr;
  }

  .bill-filter-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nvr-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .camera-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .app-shell {
    margin: 1rem auto 2rem;
  }

  .login-card {
    margin-top: 2rem;
    padding: 1.2rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .list-item {
    flex-direction: column;
    align-items: flex-start;
  }

  .bill-item-row {
    grid-template-columns: 1fr;
  }

  .nvr-grid,
  .camera-row {
    grid-template-columns: 1fr;
  }

  .filter-bar,
  .bill-filter-bar {
    grid-template-columns: 1fr;
  }
}
