/* BillWatch Energy — senior-friendly, offline-first */

:root {
  --accent: #1D4ED8;
  --accent-hover: #1E40AF;
  --accent-soft: #DBEAFE;
  --accent-ink: #1E3A8A;
  --bg: #F4F6F9;
  --surface: #FFFFFF;
  --surface-2: #EEF1F6;
  --text: #0F172A;
  --text-muted: #475569;
  --border: #CBD5E1;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --spike: #9A3412;
  --spike-soft: #FFEDD5;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 4px 16px rgba(15, 23, 42, 0.05);
  --shadow-lg: 0 8px 30px rgba(15, 23, 42, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --space: 1rem;
  --touch: 48px;
  --max: 920px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.5rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
}

.skip-link:focus {
  top: 0.5rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 0.85rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 1.4rem;
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.25;
  color: var(--accent-ink);
}

.tagline {
  margin: 0.15rem 0 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.main-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding-bottom: 0.65rem;
}

.nav-btn {
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.55rem 0.9rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  height: 1.5rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: #fff;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

.nav-btn.is-active .badge {
  background: #fff;
  color: var(--accent);
}

.nav-btn:not(.is-active) .badge {
  background: var(--danger);
  color: #fff;
}

/* Main */
.main {
  flex: 1;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2.5rem;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  color: var(--text);
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 40rem;
}

/* Stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 640px) {
  .stat-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  display: block;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.stat-card .stat-value {
  display: block;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.stat-card.stat-warn .stat-value {
  color: var(--warn);
}

.stat-card.stat-danger .stat-value {
  color: var(--danger);
}

.stat-card.stat-ok .stat-value {
  color: var(--success);
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  margin-bottom: 1.1rem;
  box-shadow: var(--shadow);
}

.panel-alert {
  border-color: #FDBA74;
  background: linear-gradient(180deg, #FFF7ED 0%, var(--surface) 55%);
}

.panel-danger {
  border-color: #FECACA;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.panel h3 {
  margin: 0 0 0.65rem;
  font-size: 1.1rem;
}

.panel-head h3 {
  margin: 0;
}

.panel-note {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  min-width: var(--touch);
  padding: 0.6rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-sm {
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--surface-2);
  border-color: #94A3B8;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #991B1B;
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
  padding: 0.35rem 0.5rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.file-btn {
  cursor: pointer;
  position: relative;
}

.icon-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  border: none;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Filters */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 640px) {
  .filter-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

.result-summary {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-weight: 600;
  color: var(--text);
}

.req {
  font-weight: 500;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.field textarea {
  min-height: 5rem;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 520px) {
  .field-row {
    grid-template-columns: 1fr 1fr;
  }
}

.check-label {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  min-height: var(--touch);
  padding: 0.5rem 0;
  cursor: pointer;
  font-weight: 500;
}

.check-label input {
  width: 1.35rem;
  height: 1.35rem;
  margin-top: 0.15rem;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.check-field {
  margin-top: 0.25rem;
}

.form-error {
  margin: 0.75rem 0 0;
  padding: 0.75rem;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-weight: 600;
}

/* Cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bill-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.65rem;
}

.bill-card.is-overdue {
  border-color: #FCA5A5;
  background: linear-gradient(180deg, #FEF2F2 0%, var(--surface) 40%);
}

.bill-card.is-spike {
  border-color: #FDBA74;
}

.bill-card-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  align-items: flex-start;
}

.bill-card-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.bill-card-amount {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-ink);
  white-space: nowrap;
}

.bill-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
}

.pill-type {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.pill-paid {
  background: var(--success-soft);
  color: var(--success);
}

.pill-unpaid {
  background: var(--warn-soft);
  color: var(--warn);
}

.pill-overdue {
  background: var(--danger-soft);
  color: var(--danger);
}

.pill-spike {
  background: var(--spike-soft);
  color: var(--spike);
}

.pill-sample {
  background: #E0E7FF;
  color: #3730A3;
}

.bill-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.15rem;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}

.empty-state p {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

/* Alerts & tips */
.alert-list,
.tip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.alert-item,
.tip-item {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.alert-item {
  background: var(--spike-soft);
  border-color: #FDBA74;
}

.alert-item strong,
.tip-item strong {
  display: block;
  margin-bottom: 0.2rem;
}

.tip-item {
  background: var(--accent-soft);
  border-color: #93C5FD;
}

/* Bar charts (CSS only) */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bar-row {
  display: grid;
  grid-template-columns: minmax(5.5rem, 7.5rem) 1fr auto;
  gap: 0.65rem;
  align-items: center;
}

.bar-label {
  font-weight: 600;
  font-size: 0.95rem;
}

.bar-track {
  height: 1.35rem;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  min-width: 0;
  transition: width 0.25s ease;
}

.bar-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  min-width: 4.5rem;
  text-align: right;
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(560px, calc(100vw - 1.5rem));
  width: 100%;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: var(--surface);
}

.modal.modal-sm {
  max-width: min(420px, calc(100vw - 1.5rem));
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem 0.65rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-body {
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-height: min(70vh, 560px);
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  padding: 0.85rem 1.15rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.detail-grid {
  display: grid;
  gap: 0.65rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0.5rem;
}

.detail-row dt {
  margin: 0;
  font-weight: 600;
  color: var(--text-muted);
}

.detail-row dd {
  margin: 0;
  font-weight: 500;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 200;
  background: var(--text);
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: min(90vw, 420px);
  text-align: center;
  font-weight: 600;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 1.1rem 1.25rem;
  text-align: center;
}

.app-footer p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Detail spike note */
.spike-callout {
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--spike-soft);
  border: 1px solid #FDBA74;
  color: var(--spike);
  font-weight: 600;
}
