:root {
  --at-primary: #0f79f3;
  --at-accent: #00b69b;
  --at-card: #ffffff;
  --at-muted: #697689;
  --at-border: #e7e2e2;
  --at-soft: #eff3f9;
  --at-danger: #e74c3c;
  --at-warning: #d88a16;
  --at-font: "Outfit", sans-serif;
  --at-shadow: 0 10px 32px rgba(39, 56, 83, .06);
  --at-shadow-lift: 0 16px 40px rgba(39, 56, 83, .10);
}

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

body {
  margin: 0;
  background: var(--at-soft);
  color: #1f2937;
  font-family: var(--at-font);
  font-size: 100%;
}

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

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.standard-theme {
  min-height: 100vh;
  background: var(--at-soft);
  color: #1f2937;
}

.page-shell {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: grid;
  align-content: start;
  justify-items: start;
  gap: 22px;
  min-height: calc(100vh - 36px);
  margin: 18px 0 18px 18px;
  border: 1px solid var(--at-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 10px 32px rgba(39, 56, 83, .08);
  padding: 22px;
}

.brand-logo {
  display: block;
  width: 210px;
  max-width: 100%;
  height: auto;
}

.kicker {
  margin: 0 0 3px;
  color: var(--at-primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 18px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
h2,
h3 {
  color: #111827;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 38px;
}

h2 {
  margin-bottom: 6px;
  font-size: 26px;
  line-height: 34px;
}

h3 {
  margin-bottom: 6px;
  font-size: 20px;
  line-height: 28px;
}

.sidebar nav {
  display: grid;
  gap: 6px;
  width: 100%;
  align-self: start;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 42px;
  border-radius: 12px;
  color: #475569;
  padding: 9px 10px;
  font-size: 15px;
  transition: background .18s ease, color .18s ease;
}

.sidebar nav a:hover,
.sidebar nav a.is-active {
  background: #f1f2fd;
  color: var(--at-primary);
}

.sidebar nav i,
.stat i,
.reading-box i,
.button-secondary i,
.table-action i {
  color: var(--at-primary);
}

.sidebar-note {
  align-self: start;
  margin: 0;
  color: var(--at-muted);
  font-size: 13px;
  line-height: 20px;
}

.content {
  min-width: 0;
  padding: 22px 30px 60px;
}

.content-narrow {
  max-width: 780px;
}

.content-wide {
  max-width: 1240px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  border: 1px solid var(--at-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--at-shadow);
  padding: 18px 22px;
}

.topbar-help,
.section-help,
.subcopy {
  margin-bottom: 0;
  color: var(--at-muted);
  font-size: 14px;
  line-height: 22px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.panel,
.quick-modal {
  border: 1px solid var(--at-border);
  border-radius: 18px;
  background: var(--at-card);
  box-shadow: var(--at-shadow);
}

.panel {
  min-width: 0;
  margin-bottom: 24px;
  padding: 22px;
}

.panel:hover {
  box-shadow: var(--at-shadow-lift);
}

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

.stack,
.form-grid {
  display: grid;
  gap: 18px;
}

.settings-grid,
.operation-grid {
  display: grid;
  gap: 16px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.operation-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.operation-grid .action-row,
.form-actions,
.operation-note,
#meterErr,
#operationErr {
  grid-column: 1 / -1;
}

.compact-field,
.field-gap {
  display: grid;
  gap: 8px;
}

label,
.label {
  color: #475569;
  font-size: 14px;
  font-weight: 700;
  line-height: 22px;
}

.compact-field span,
.field-gap span,
.stat-label,
.section-label,
th,
.hint,
.info-date,
.empty,
.meter-code {
  color: var(--at-muted);
  font-size: 14px;
  line-height: 22px;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 10px;
  align-self: end;
  min-height: 44px;
  color: #475569;
  font-size: 14px;
  font-weight: 700;
}

.checkbox-field input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--at-primary);
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--at-border);
  border-radius: 12px;
  background: #fff;
  color: #111827;
  padding: 9px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(15, 121, 243, .55);
  box-shadow: 0 0 0 4px rgba(15, 121, 243, .10);
  outline: 0;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  padding-right: 76px;
  font-size: 28px;
  line-height: 36px;
}

.unit {
  position: absolute;
  top: 50%;
  right: 14px;
  transform: translateY(-50%);
  color: var(--at-muted);
  font-weight: 700;
  pointer-events: none;
}

.reading-box,
.stat {
  border: 1px solid var(--at-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--at-shadow);
  padding: 20px;
}

.reading-box {
  display: grid;
  gap: 6px;
  background: #f8fafc;
}

.reading-box i,
.stat i {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: #f1f2fd;
  font-size: 20px;
}

.reading-box > span:first-of-type {
  margin-top: 8px;
  color: var(--at-muted);
  font-size: 14px;
  font-weight: 700;
}

.reading-value {
  display: block;
  color: #111827;
  font-size: 24px;
  font-weight: 700;
  line-height: 32px;
}

.hint {
  min-height: 22px;
}

.hint.warn,
.error-text,
.danger-link {
  color: var(--at-danger);
}

.button-primary,
.button-secondary,
.button-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 12px;
  cursor: pointer;
  padding: 10px 22px;
  font-size: 16px;
  line-height: 20px;
  white-space: nowrap;
  transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}

.button-primary {
  border: 0;
  background: var(--at-primary);
  color: #fff;
  box-shadow: 0 10px 22px rgba(15, 121, 243, .20);
}

.button-primary i {
  color: currentColor;
}

.button-primary:hover {
  background: #0b66cf;
}

.button-primary:disabled {
  background: #a7c8ee;
  color: #fff;
  cursor: not-allowed;
  box-shadow: none;
}

.button-secondary {
  border: 1px solid var(--at-border);
  background: #fff;
  color: #475569;
}

.button-secondary:hover {
  border-color: rgba(15, 121, 243, .28);
  background: #f1f2fd;
  color: var(--at-primary);
}

.button-danger {
  border: 1px solid rgba(231, 76, 60, .30);
  background: #fff;
  color: var(--at-danger);
}

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

.button-row,
.toolbar-panel,
.action-row,
.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.button-row {
  align-items: stretch;
}

.button-row .button-primary,
.button-row .button-secondary {
  flex: 1 1 210px;
}

.inline-link {
  width: fit-content;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.tab {
  min-height: 38px;
  border: 1px solid var(--at-border);
  border-radius: 10px;
  background: #fff;
  color: #475569;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 18px;
}

.tab:hover,
.tab.is-active {
  border-color: rgba(15, 121, 243, .28);
  background: #f1f2fd;
  color: var(--at-primary);
}

.mobile-meter {
  display: none;
  margin-bottom: 16px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat {
  min-height: 124px;
}

.stat .stat-label {
  display: block;
  margin-top: 14px;
}

.stat strong {
  display: block;
  margin-top: 2px;
  color: #111827;
  font-size: 24px;
  font-weight: 700;
  line-height: 32px;
}

.chart-frame {
  position: relative;
  min-width: 0;
  min-height: 300px;
}

.table-frame {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--at-border);
  border-radius: 14px;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid #eef2f7;
  padding: 12px 14px;
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  line-height: 22px;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
}

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

tr:hover td {
  background: #fbfdff;
}

.mono {
  font-variant-numeric: tabular-nums;
}

.delta {
  color: #0d7e61;
  font-weight: 700;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  background: #eef2f7;
  color: #475569;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 16px;
}

.status-badge.is-ok {
  background: #eafbf2;
  color: #0d7e61;
}

.status-badge.is-muted {
  background: #eef2f7;
  color: #475569;
}

.empty {
  padding: 38px 18px;
  text-align: center;
}

.table-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--at-border);
  border-radius: 10px;
  background: #fff;
  color: #475569;
  cursor: pointer;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
}

.table-action:hover {
  border-color: rgba(15, 121, 243, .28);
  background: #f1f2fd;
  color: var(--at-primary);
}

.table-action.danger-link {
  color: var(--at-danger);
}

.table-action.danger-link:hover,
.danger-link:hover {
  border-color: rgba(231, 76, 60, .30);
  background: #fff7f7;
  color: var(--at-danger);
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, .42);
  padding: 20px;
}

.overlay.show {
  display: flex;
}

.quick-modal {
  width: min(460px, 92vw);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
}

.wide-modal {
  width: min(760px, 94vw);
}

.modal-close {
  width: 38px;
  min-width: 38px;
  justify-content: center;
  padding: 7px;
}

.modal-body {
  margin-bottom: 20px;
  color: #475569;
  font-size: 14px;
  line-height: 24px;
}

.modal-body b {
  color: #111827;
}

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

.modal-actions button {
  flex: 1;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 300;
  border-radius: 14px;
  box-shadow: 0 14px 28px rgba(39, 56, 83, .16);
  padding: 12px 18px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
}

.toast.ok {
  background: var(--at-accent);
}

.toast.err {
  background: var(--at-danger);
}

@media (max-width: 1180px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    display: grid;
  }

  .tabs {
    justify-content: flex-start;
  }
}

@media (max-width: 980px) {
  .page-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    min-height: auto;
    margin: 0;
    border-radius: 0 0 18px 18px;
  }

  .sidebar nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content {
    padding: 18px;
  }
}

@media (max-width: 680px) {
  .tabs {
    display: none;
  }

  .mobile-meter {
    display: grid;
  }

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

  .settings-grid,
  .operation-grid {
    grid-template-columns: 1fr;
  }

  .modal-actions,
  .button-row,
  .action-row {
    display: grid;
  }

  .button-row .button-primary,
  .button-row .button-secondary,
  .inline-link {
    width: 100%;
  }
}

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

  .sidebar nav {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 26px;
    line-height: 34px;
  }
}
