:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #172026;
  --muted: #64727d;
  --line: #d9e1e5;
  --brand: #087f8c;
  --brand-dark: #055d66;
  --accent: #d96c3f;
  --ok: #287d3c;
  --warn: #9b5f00;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(22, 36, 44, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

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

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
}

.brand-text {
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
}

.brand-subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.session {
  display: flex;
  align-items: center;
  gap: 10px;
}

.session-name {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 22px clamp(16px, 4vw, 40px) 38px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}

.login-panel {
  width: min(440px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel h1,
.section-title h1,
.section-title h2,
.panel h2,
.panel h3 {
  margin: 0;
}

.login-panel p,
.section-title p {
  margin: 8px 0 0;
  color: var(--muted);
}

.field-grid {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #33424b;
  font-size: 13px;
  font-weight: 700;
}

.input,
.select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #cbd5da;
  border-radius: 7px;
  outline: 0;
}

.input:focus,
.select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.15);
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 9px 13px;
  border-radius: 7px;
  font-weight: 800;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.button:active {
  transform: translateY(1px);
}

.button-primary {
  background: var(--brand);
  color: #fff;
}

.button-primary:hover {
  background: var(--brand-dark);
}

.button-secondary {
  background: #eef4f5;
  color: #12333a;
  border: 1px solid #cddcde;
}

.button-secondary:hover {
  background: #e3eff1;
}

.button-danger {
  background: #fff2ef;
  color: var(--danger);
  border: 1px solid #f1b8ae;
}

.button-ghost {
  background: transparent;
  color: var(--muted);
}

.button-icon {
  width: 40px;
  padding: 0;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 18px 0;
  padding: 4px;
  overflow-x: auto;
  background: #e9eff1;
  border-radius: 8px;
}

.tab {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 6px;
  color: #40505a;
  background: transparent;
  font-weight: 800;
  white-space: nowrap;
}

.tab.active {
  background: #fff;
  color: var(--brand-dark);
  box-shadow: 0 1px 5px rgba(24, 35, 43, 0.08);
}

.grid {
  display: grid;
  gap: 18px;
}

.grid.two {
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
}

.users-admin-grid {
  grid-template-columns: minmax(260px, 0.75fr) minmax(0, 1.55fr);
  align-items: start;
}

.user-home {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.secondary-meters {
  margin-top: 18px;
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stat {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-align: left;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.stat small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.stat-clickable {
  cursor: pointer;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.stat-clickable:hover {
  border-color: var(--brand);
  box-shadow: 0 8px 20px rgba(8, 127, 140, 0.12);
}

.stat-clickable:active {
  transform: translateY(1px);
}

.consumption-list {
  display: grid;
  gap: 10px;
}

.consumption-row {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) repeat(3, minmax(120px, 1fr)) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.consumption-row strong {
  display: block;
  margin-top: 3px;
  font-size: 20px;
}

.apartment-name {
  font-size: 18px;
  font-weight: 900;
}

.row-action {
  display: flex;
  justify-content: flex-end;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.qr-box {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 12px;
  background: #f8fbfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.qr-box img {
  width: 160px;
  height: 160px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: #f6fbfb;
}

.selected-row td {
  background: #e9f5f6;
}

.danger-text {
  color: var(--danger);
}

.trend {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  margin-right: 5px;
  font-weight: 900;
}

.trend-up {
  color: var(--danger);
}

.trend-down {
  color: var(--ok);
}

.trend-same {
  color: var(--muted);
}

.chart-panel {
  margin: 18px 0;
  padding: 16px;
  background: #f8fbfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.line-chart-wrap {
  overflow: hidden;
  padding-bottom: 4px;
}

.line-chart {
  display: block;
  width: 100%;
  height: 260px;
  background: #eef4f5;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.chart-grid {
  stroke: #d5e0e3;
  stroke-width: 1;
}

.chart-area {
  fill: rgba(8, 127, 140, 0.11);
}

.chart-line {
  fill: none;
  stroke: var(--brand);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-point {
  fill: #fff;
  stroke: var(--brand-dark);
  stroke-width: 3;
}

.chart-y-label,
.chart-x-label,
.chart-days,
.chart-value {
  fill: var(--muted);
  font-size: 12px;
}

.chart-value {
  fill: var(--ink);
  font-weight: 800;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
  background: #fff;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: #f1f5f6;
  color: #3b4b54;
  font-size: 13px;
}

tr:last-child td {
  border-bottom: 0;
}

.thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eef2f3;
}

.reading-list {
  display: grid;
  gap: 12px;
}

.reading-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.reading-card img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 7px;
  background: #eef2f3;
}

.reading-value {
  font-size: 24px;
  font-weight: 900;
}

.file-drop {
  display: grid;
  gap: 10px;
  padding: 18px;
  border: 1px dashed #a7b8bf;
  border-radius: 8px;
  background: #f8fbfb;
}

.preview {
  display: none;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f3;
}

.preview.visible {
  display: block;
}

.notice {
  margin-top: 12px;
  padding: 11px 12px;
  border-radius: 7px;
  background: #fff8ea;
  color: #65400b;
  border: 1px solid #efd39b;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #e9f5f6;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 800;
}

.empty {
  padding: 22px;
  border: 1px dashed #b8c6cc;
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfc;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .session {
    width: 100%;
    justify-content: space-between;
  }

  .grid.two {
    grid-template-columns: 1fr;
  }

  .users-admin-grid {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .consumption-row {
    grid-template-columns: 1fr 1fr;
  }

  .consumption-row > :first-child,
  .row-action {
    grid-column: 1 / -1;
  }

  .row-action {
    justify-content: stretch;
  }

  .row-action .button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .login-panel,
  .panel {
    padding: 16px;
  }

  .main {
    padding-top: 14px;
  }

  .brand-title {
    font-size: 16px;
  }

  .reading-card {
    grid-template-columns: 72px 1fr;
  }

  .reading-card img {
    width: 72px;
    height: 72px;
  }

  .actions .button {
    flex: 1 1 auto;
  }

  .consumption-row {
    grid-template-columns: 1fr;
  }
}
