:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #52606d;
  --border: #d9e2ec;
  --accent: #1f6feb;
  --success: #1f9d55;
  --danger: #d64545;
  --info: #3b82f6;
  --warning: #f59e0b;
  --offline: #6b7280;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
}

.nav {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.nav a,
.userbox a,
.actions a {
  text-decoration: none;
  color: var(--accent);
}

.userbox {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.container {
  max-width: 1200px;
  margin: 24px auto;
  padding: 0 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.page-grid {
  display: grid;
  gap: 16px;
}

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

.stat-card h2 {
  margin: 0 0 8px 0;
  font-size: 2rem;
}

.auth-wrap {
  min-height: 70vh;
  display: grid;
  place-items: center;
}

.auth-card {
  width: 100%;
  max-width: 420px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.button-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
}

.input {
  width: 100%;
  padding: 14px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 1rem;
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

.form-card {
  max-width: 950px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 16px;
}

.checkbox-grid {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 16px 0;
}

.checkbox-wrap {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin: 0;
}

.button {
  display: inline-block;
  margin-top: 16px;
  padding: 10px 14px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  text-decoration: none;
}

.button.secondary {
  background: #6b7280;
}

.button.small {
  margin-top: 0;
  padding: 8px 10px;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.flash {
  padding: 12px 14px;
  border-radius: 8px;
  color: white;
}

.flash-success { background: var(--success); }
.flash-danger { background: var(--danger); }
.flash-info { background: var(--info); }

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

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

th {
  font-size: 0.92rem;
  color: var(--muted);
}

code {
  background: #eef2f7;
  padding: 2px 6px;
  border-radius: 6px;
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.card-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.reading-value {
  font-size: 2rem;
  font-weight: 700;
  margin: 12px 0 16px;
}

.reading-unit {
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}

.meta-list {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
}

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

.alarm-badge {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.alarm-active_low {
  background: var(--warning);
}

.alarm-active_high {
  background: var(--danger);
}

.alarm-offline {
  background: var(--offline);
}

.alarm-overdue {
  background: var(--warning);
}

.alarm-normal {
  background: var(--success);
}

.maintenance-section {
  margin-top: 20px;
}

.inline-form {
  display: inline;
}

.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

.keypad-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  z-index: 9999;
}

.keypad-overlay.hidden {
  display: none;
}

.keypad-modal {
  width: 100%;
  max-width: 760px;
  background: #fff;
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.keypad-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.keypad-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.keypad-close {
  border: none;
  background: transparent;
  font-size: 1.3rem;
  cursor: pointer;
}

.keypad-display {
  width: 100%;
  min-height: 76px;
  margin-bottom: 12px;
  padding: 14px;
  font-size: 1.2rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  resize: none;
}

.keyboard-wrap {
  display: grid;
  gap: 10px;
}

.keyboard-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: nowrap;
}

.keypad-key {
  border: none;
  border-radius: 12px;
  padding: 16px 14px;
  min-width: 56px;
  font-size: 1.05rem;
  background: #e5e7eb;
  cursor: pointer;
  flex: 1 1 0;
}

.keypad-key:active {
  transform: scale(0.98);
}

.keypad-action {
  background: #dbeafe;
}

.keypad-wide {
  flex: 3 1 0;
}

.keypad-space {
  flex: 4 1 0;
}

.keypad-shift,
.keypad-backspace {
  flex: 1.4 1 0;
}

@media (max-width: 700px) {
  .container {
    padding: 0 10px;
  }

  .card {
    padding: 16px;
  }

  .input {
    padding: 16px 14px;
    font-size: 1.05rem;
  }

  .keypad-modal {
    max-width: 100%;
  }

  .keypad-key {
    min-width: 0;
    padding: 16px 8px;
    font-size: 1rem;
  }
}

.widget-actions {
  margin-top: 12px;
}

.compact-meta {
  margin-top: 8px;
}

.history-controls {
  margin-top: 10px;
}

.history-card {
  margin-top: 20px;
}

.chart-shell {
  width: 100%;
  overflow-x: auto;
}

.history-chart {
  width: 100%;
  min-height: 360px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.axis-line {
  stroke: #94a3b8;
  stroke-width: 1.5;
}

.grid-line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

.axis-label {
  fill: #64748b;
  font-size: 12px;
}

.history-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
}

.history-point {
  fill: var(--accent);
  cursor: pointer;
}

.home-pick-card {
  cursor: pointer;
}

.history-controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.history-subcard {
  padding: 16px;
}
