:root {
  --blue-50: #eff8ff;
  --blue-100: #dbeefe;
  --blue-300: #93c9fb;
  --blue-500: #3b93f0;
  --blue-600: #2472d6;
  --blue-700: #1b5bb0;
  --blue-900: #0f2f57;
  --ink: #10233f;
  --muted: #5b7089;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-border: rgba(255, 255, 255, 0.65);
  --glass-shadow: 0 8px 32px rgba(31, 84, 148, 0.15);
  --radius: 20px;
  --page-bg: linear-gradient(160deg, #eaf4ff 0%, #dcecff 40%, #cfe4ff 100%);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Prompt", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

/* ---------- background orbs ---------- */
.bg-orbs {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
}
.orb-a { width: 380px; height: 380px; top: -120px; left: -100px; background: var(--blue-300); }
.orb-b { width: 460px; height: 460px; top: 30%; right: -160px; background: var(--blue-500); opacity: 0.35; }
.orb-c { width: 320px; height: 320px; bottom: -140px; left: 20%; background: #a9d6ff; }

/* ---------- top navbar ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 50;
  margin: 14px 14px 0;
  border-radius: 22px;
}
.topnav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--blue-900);
  white-space: nowrap;
}
.brand-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: #fff;
  font-size: 1rem;
}
.brand-thin { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 0.9rem; }

.nav-links {
  display: flex;
  gap: 6px;
  background: rgba(255,255,255,0.4);
  padding: 6px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.6);
}
.nav-link {
  border: none;
  background: transparent;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--blue-900);
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  white-space: nowrap;
}
.nav-link:hover { background: rgba(59, 147, 240, 0.15); }
.nav-link.active {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: #fff;
  box-shadow: 0 6px 16px rgba(36, 114, 214, 0.35);
}

.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.4);
  cursor: pointer;
}
.nav-toggle span {
  width: 20px;
  height: 2px;
  background: var(--blue-900);
  margin: 0 auto;
  border-radius: 2px;
}

/* ---------- main layout ---------- */
.app-main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.view { display: none; animation: fadeIn 0.35s ease; }
.view.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-head { margin-bottom: 22px; }
.view-head h1 { margin: 0 0 4px; font-size: 1.7rem; color: var(--blue-900); }
.muted { color: var(--muted); margin: 0; font-size: 0.95rem; }

/* ---------- cards / grid ---------- */
.card { padding: 22px; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
}

.meter-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.meter-card .mc-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.meter-card .mc-name { font-weight: 700; font-size: 1.05rem; color: var(--blue-900); }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--blue-100);
  color: var(--blue-700);
}
.badge.business { background: #e6f7ee; color: #1a8f56; }
.mc-period { color: var(--muted); font-size: 0.85rem; }
.mc-total {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--blue-700);
}
.mc-total small { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
.mc-units { font-size: 0.85rem; color: var(--muted); }

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  border-radius: var(--radius);
  grid-column: 1 / -1;
}

/* ---------- forms ---------- */
.calc-layout, .meters-layout {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { font-size: 0.85rem; font-weight: 600; color: var(--blue-900); }
.hint { color: var(--muted); font-size: 0.78rem; }

input, select {
  width: 100%;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(59, 147, 240, 0.3);
  background: rgba(255,255,255,0.7);
  font-size: 0.95rem;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}
input:focus, select:focus {
  border-color: var(--blue-500);
  box-shadow: 0 0 0 3px rgba(59, 147, 240, 0.2);
}

.form-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

.btn {
  border: none;
  padding: 11px 20px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--blue-500), var(--blue-700));
  color: #fff;
  box-shadow: 0 8px 20px rgba(36, 114, 214, 0.35);
}
.btn-primary:hover { box-shadow: 0 10px 24px rgba(36, 114, 214, 0.45); }
.btn-ghost {
  background: rgba(59, 147, 240, 0.12);
  color: var(--blue-700);
}
.btn-ghost:hover { background: rgba(59, 147, 240, 0.2); }
.btn-danger {
  background: rgba(220, 60, 60, 0.12);
  color: #c22;
  padding: 6px 12px;
  font-size: 0.8rem;
}
.btn-small {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, color 0.15s ease;
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:active { transform: scale(0.92); }
.icon-btn + .icon-btn { margin-left: 6px; }
.icon-btn-edit {
  color: var(--blue-600);
}
.icon-btn-edit:hover { background: rgba(59, 147, 240, 0.15); }
.icon-btn-delete {
  color: var(--muted);
}
.icon-btn-delete:hover { background: rgba(220, 60, 60, 0.12); color: #c22; }

/* ---------- result card ---------- */
.result-card { min-height: 260px; }
.result-title { font-size: 1.1rem; font-weight: 700; color: var(--blue-900); margin-bottom: 4px; }
.result-sub { color: var(--muted); font-size: 0.85rem; margin-bottom: 16px; }

.tier-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 0.85rem; }
.tier-table th, .tier-table td { text-align: right; padding: 6px 8px; }
.tier-table th:first-child, .tier-table td:first-child { text-align: left; }
.tier-table thead th { color: var(--muted); font-weight: 600; border-bottom: 1px solid rgba(59,147,240,0.2); }
.tier-table tbody tr:hover { background: rgba(59,147,240,0.06); }

.summary-line {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.92rem;
}
.summary-line.total {
  border-top: 2px solid rgba(59,147,240,0.25);
  margin-top: 8px;
  padding-top: 12px;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--blue-700);
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 480px; }
thead th {
  text-align: left;
  font-size: 0.8rem;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid rgba(59,147,240,0.2);
  white-space: nowrap;
}
tbody td {
  padding: 12px;
  border-bottom: 1px solid rgba(59,147,240,0.1);
  font-size: 0.9rem;
  white-space: nowrap;
}
tbody tr:hover { background: rgba(59,147,240,0.06); }

.filter-card { margin-bottom: 18px; max-width: 320px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--blue-900);
  color: #fff;
  padding: 12px 22px;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #b23434; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .calc-layout, .meters-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .nav-toggle { display: flex; }
  .nav-links {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    left: 0;
    flex-direction: column;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(18px);
    border-radius: 18px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,0.6);
    box-shadow: var(--glass-shadow);
    display: none;
    gap: 4px;
  }
  .nav-links.open { display: flex; }
  .nav-link { text-align: left; width: 100%; }
  .field-row { grid-template-columns: 1fr; }
  .view-head h1 { font-size: 1.4rem; }
}

@media (max-width: 480px) {
  .topnav { margin: 8px 8px 0; }
  .app-main { padding: 20px 12px 50px; }
  .brand-thin { display: none; }
}
