/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #f8fafc;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #1e293b;
  --muted:      #64748b;
  --primary:    #3b82f6;
  --primary-dk: #2563eb;
  --success:    #10b981;
  --danger:     #ef4444;
  --warn-bg:    #fef9c3;
  --warn-text:  #854d0e;
  --radius:     8px;
  --shadow:     0 1px 3px rgba(0,0,0,.08);
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

/* ── Navbar ── */
.navbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--primary);
  letter-spacing: -.3px;
  text-decoration: none;
}
.nav-brand:hover { opacity: .8; }

.nav-links { display: flex; gap: .5rem; }

.nav-links a {
  text-decoration: none;
  color: var(--muted);
  padding: .4rem .75rem;
  border-radius: var(--radius);
  font-size: .95rem;
  transition: background .15s, color .15s;
}
.nav-links a:hover { background: var(--bg); color: var(--text); }

/* ── Layout ── */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  border-radius: var(--radius);
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, opacity .15s;
}
.btn-primary  { background: var(--primary);  color: #fff; }
.btn-primary:hover  { background: var(--primary-dk); }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { opacity: .8; }

/* ── Flash messages ── */
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: .95rem;
}
.flash-success { background: #dcfce7; color: #166534; }
.flash-error   { background: #fee2e2; color: #991b1b; }

/* ── Chart sections ── */
.chart-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
}

.chart-header h2 { font-size: 1.1rem; font-weight: 600; }

.chart-controls { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.totals-toggle {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: .3rem .5rem;
}

.toggle-group, .range-group {
  display: flex;
  gap: 2px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
}

.toggle-btn, .range-btn {
  background: none;
  border: none;
  padding: .3rem .65rem;
  border-radius: 6px;
  font-size: .85rem;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.toggle-btn.active, .range-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.chart-wrapper {
  position: relative;
  height: 280px;
}

.discrepancy-notice {
  margin-top: .75rem;
  padding: .5rem .75rem;
  border-radius: var(--radius);
  font-size: .88rem;
}
.discrepancy-info { background: #eff6ff; color: #1d4ed8; }
.discrepancy-warn { background: var(--warn-bg); color: var(--warn-text); }

/* ── Entry form ── */
.date-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.date-row label { font-weight: 500; white-space: nowrap; }

.date-row input[type="date"] {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  width: auto;
}

.meter-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.meter-group h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}

.location-subgroup {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  margin-bottom: 1.25rem;
}
.location-subgroup:last-child { margin-bottom: 0; }

.location-subgroup h3 {
  font-size: .85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin-bottom: .75rem;
}

.unit-badge {
  font-size: .78rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: .1rem .45rem;
  border-radius: 99px;
}

.meter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.meter-card {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.meter-card label {
  font-size: .9rem;
  font-weight: 500;
  color: var(--text);
}

.last-reading {
  font-size: .78rem;
  color: var(--muted);
}

.input-row {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.input-row input[type="number"] {
  flex: 1;
  min-width: 0;
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color .15s;
}
.input-row input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
}
.input-row input.input-warn {
  border-color: var(--danger);
  background: #fff5f5;
}

.ocr-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.ocr-btn:hover { background: var(--border); color: var(--text); }
.ocr-btn:disabled { opacity: .5; cursor: wait; }

.warn-msg {
  font-size: .78rem;
  color: var(--danger);
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: .75rem;
  margin-top: 1.5rem;
}

/* ── History page ── */
.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .95rem;
}
.history-table th {
  text-align: left;
  padding: .65rem 1rem;
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.history-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.history-table tr:last-child td { border-bottom: none; }
.history-table tr:hover td { background: var(--bg); }

.meter-count {
  font-size: .85rem;
  font-weight: 500;
  padding: .15rem .5rem;
  border-radius: 99px;
}
.count-full    { background: #dcfce7; color: #166534; }
.count-partial { background: #fef9c3; color: #854d0e; }

.btn-sm { padding: .3rem .7rem; font-size: .85rem; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* ── Edit mode badge ── */
.edit-date-badge {
  font-size: .85rem;
  font-weight: 500;
  background: #eff6ff;
  color: var(--primary);
  border: 1px solid #bfdbfe;
  padding: .15rem .55rem;
  border-radius: 99px;
  vertical-align: middle;
  margin-left: .4rem;
}

/* ── Sign-out button in nav ── */
.btn-logout {
  background: none;
  border: none;
  padding: .4rem .75rem;
  border-radius: var(--radius);
  font-size: .95rem;
  cursor: pointer;
  color: var(--muted);
  transition: background .15s, color .15s;
}
.btn-logout:hover { background: var(--bg); color: var(--danger); }

/* ── Login page ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 1.5rem;
  text-align: center;
}

.field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: .9rem;
  font-weight: 500;
}

.field input {
  padding: .6rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color .15s;
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-full {
  width: 100%;
  justify-content: center;
  margin-top: .5rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .chart-header { flex-direction: column; }
  .chart-wrapper { height: 220px; }
  .meter-grid { grid-template-columns: 1fr 1fr; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 380px) {
  .meter-grid { grid-template-columns: 1fr; }
}
