:root {
  color-scheme: light;
  --bg: #f5f9fa;
  --panel: #ffffff;
  --line: #d7e6e9;
  --text: #161f3f;
  --muted: #667386;
  --primary: #00a89d;
  --primary-strong: #121a55;
  --accent: #00a89d;
  --warning: #2b63b7;
  --danger: #b54036;
  --danger-bg: #fff1f0;
  --ok-bg: #e9fbf8;
  --blue-soft: #e9f7f6;
  --shadow: 0 14px 34px rgba(18, 26, 85, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background:
    linear-gradient(180deg, rgba(0, 168, 157, 0.10), rgba(18, 26, 85, 0.035) 260px, transparent 520px),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  min-height: 40px;
}

button:hover {
  background: #078d85;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: #eef7f8;
  color: var(--text);
  border: 1px solid #c9e3e6;
}

button.secondary:hover {
  background: #def0f2;
}

button.danger {
  background: var(--danger);
}

button.icon {
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  min-height: 40px;
}

select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #ffffff;
  min-height: 40px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 168, 157, 0.15);
  outline: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  min-height: 100vh;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 18px rgba(18, 26, 85, 0.07);
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand {
  font-weight: 700;
  letter-spacing: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary-strong);
  min-width: 0;
}

.brand img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand span {
  font-size: 18px;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-menu {
  position: relative;
  flex: 0 0 auto;
}

.nav-menu-button {
  min-width: 74px;
  height: 46px;
  min-height: 46px;
  padding: 0 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: #eef7f8;
  color: var(--primary-strong);
  border: 1px solid #bfe4e2;
}

.nav-menu-button:hover,
.nav-menu.open .nav-menu-button,
.nav-menu.active .nav-menu-button {
  background: var(--primary);
  color: #ffffff;
}

.nav-menu-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  font-weight: 700;
}

.nav-menu-label {
  font-size: 13px;
  font-weight: 700;
}

.nav-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 210px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  display: none;
  z-index: 20;
}

.monitoring-dropdown {
  width: 300px;
}

.nav-menu.open .nav-dropdown {
  display: grid;
  gap: 6px;
}

.nav-dropdown a,
.nav-dropdown button {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  color: var(--text);
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
}

.nav-dropdown a.active,
.nav-dropdown button:hover,
.nav-dropdown a:hover {
  background: var(--blue-soft);
  color: var(--primary-strong);
  border-color: #d7eeee;
}

.main {
  width: min(1180px, calc(100vw - 32px));
  margin: 24px auto;
}

.monitor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.monitor-card {
  min-height: 174px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
  display: grid;
  grid-template-rows: auto minmax(52px, 1fr) auto;
  gap: 8px;
  box-shadow: 0 8px 22px rgba(18, 26, 85, 0.07);
}

.monitor-card.writable {
  border-color: #a9deda;
}

.monitor-card.readonly .monitor-card-mode {
  background: #0d8f7f;
  border-color: #0d8f7f;
  color: #ffffff;
}

.monitor-card.writable .monitor-card-mode {
  background: #b54036;
  border-color: #b54036;
  color: #ffffff;
}

.monitor-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.monitor-card-id,
.monitor-card-mode {
  font-size: 12px;
  font-weight: 700;
  color: var(--primary-strong);
  white-space: nowrap;
}

.monitor-card-mode {
  border: 1px solid #cbe7e5;
  border-radius: 999px;
  padding: 3px 8px;
  background: #eefafa;
}

.monitor-card h2 {
  margin: 0;
  font-size: 13px;
  line-height: 1.25;
  letter-spacing: 0;
  overflow: hidden;
  overflow-wrap: anywhere;
  color: var(--text);
}

.monitor-card-read {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  overflow-wrap: anywhere;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-strong);
}

.monitor-value-error {
  border-radius: 6px;
  background: var(--danger);
  color: #ffffff;
  padding: 7px 8px;
}

.monitor-card-write {
  display: grid;
  grid-template-columns: 1fr;
  align-items: center;
}

.monitor-card-write input {
  min-height: 38px;
  padding: 7px 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-strong);
  text-align: center;
}

.monitor-empty {
  grid-column: 1 / -1;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(0, 168, 157, 0.16), transparent 360px),
    radial-gradient(circle at bottom right, rgba(18, 26, 85, 0.14), transparent 420px);
}

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

.login-box::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--primary-strong), var(--primary));
}

.login-logo {
  width: 112px;
  height: 112px;
  object-fit: contain;
  display: block;
  margin: 0 auto 12px;
}

.login-box h1,
.page-title h1 {
  margin: 0;
  font-size: 25px;
}

.login-box h1 {
  text-align: center;
  color: var(--primary-strong);
}

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

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

.page-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

.filter-bar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  margin: 0 0 14px;
}

.filter-bar input,
.filter-bar select,
.filter-bar button {
  height: 42px;
  min-height: 42px;
}

.filter-bar button {
  align-self: end;
  padding-top: 0;
  padding-bottom: 0;
}

.point-filter-bar {
  grid-template-columns: minmax(180px, 240px) minmax(260px, 1fr) auto;
}

.point-filter-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.point-filter-actions button {
  white-space: nowrap;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin: 14px 0 0;
  color: var(--muted);
  flex-wrap: wrap;
}

.page-list {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.page-number {
  min-width: 40px;
  padding: 8px 10px;
}

.page-number.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  opacity: 1;
}

.page-ellipsis {
  min-width: 24px;
  text-align: center;
}

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

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

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

th {
  background: linear-gradient(180deg, #eefafa, #f4f6fb);
  color: var(--primary-strong);
  font-size: 13px;
  white-space: nowrap;
}

td {
  font-size: 14px;
}

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

#datalogReportResultGrid th,
#datalogReportResultGrid td {
  border-right: 1px solid var(--line);
}

#datalogReportResultGrid {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

#datalogReportResultGrid .report-col-stt {
  width: 46px;
}

#datalogReportResultGrid .report-col-time {
  width: 150px;
}

#datalogReportResultGrid .report-col-value {
  width: 64px;
}

#datalogReportResultGrid th,
#datalogReportResultGrid td {
  padding: 7px 6px;
  line-height: 1.2;
}

#datalogReportResultGrid th:nth-child(1),
#datalogReportResultGrid td:nth-child(1),
#datalogReportResultGrid th:nth-child(n+3),
#datalogReportResultGrid td:nth-child(n+3) {
  text-align: center;
}

#datalogReportResultGrid th:nth-child(n+3) {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 11px;
}

#datalogReportResultGrid td:nth-child(n+3) {
  white-space: nowrap;
  font-size: 12px;
}

#datalogReportResultGrid td.value-out-of-range {
  background: #fff2a8;
  color: #5f4700;
  font-weight: 700;
}

#datalogReportResultGrid th:last-child,
#datalogReportResultGrid td:last-child {
  border-right: 0;
}

.datalog-report-sheet {
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #cbdfe3;
  border-radius: 8px;
}

.datalog-report-head {
  display: grid;
  grid-template-columns: 92px minmax(260px, 1fr) 150px;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid #cbdfe3;
  background: linear-gradient(180deg, #ffffff, #f7fbfc);
}

.datalog-report-head img {
  width: 84px;
  height: 84px;
  object-fit: contain;
}

.datalog-report-head h2,
.datalog-report-head h3,
.datalog-report-head p {
  margin: 0;
  text-align: center;
}

.datalog-report-head h2 {
  color: var(--primary-strong);
  font-size: 20px;
  line-height: 1.25;
}

.datalog-report-head h3 {
  margin-top: 5px;
  color: #008f86;
  font-size: 15px;
  line-height: 1.3;
}

.datalog-report-head p {
  margin-top: 9px;
  color: var(--primary-strong);
  font-weight: 700;
}

.datalog-report-code {
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid #b8d8dc;
  border-radius: 6px;
  display: grid;
  align-content: center;
  gap: 6px;
  text-align: center;
  color: var(--text);
  background: #f7fbfc;
}

.datalog-report-code strong {
  font-size: 13px;
  color: var(--primary-strong);
}

.datalog-report-code span {
  color: var(--muted);
  font-size: 13px;
}

.datalog-report-scroll {
  overflow: auto;
}

.datalog-report-footer {
  width: 100%;
  margin-top: 14px;
  border-collapse: collapse;
  table-layout: fixed;
}

.datalog-report-footer th,
.datalog-report-footer td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: center;
  vertical-align: top;
}

.datalog-report-footer th {
  font-size: 13px;
  color: var(--primary-strong);
  background: #f3fbfc;
  font-weight: 700;
}

.datalog-report-footer td {
  height: 86px;
  color: var(--muted);
  background: #ffffff;
}

.link {
  border: 0;
  background: none;
  color: #008f86;
  padding: 0;
  min-height: 0;
  text-decoration: underline;
  cursor: pointer;
}

.link:hover {
  background: none;
}

.status {
  margin: 12px 0;
  color: var(--muted);
  padding-left: 12px;
  border-left: 4px solid var(--accent);
}

.alert {
  padding: 11px 12px;
  border-radius: 6px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #ffd2cc;
}

.ok-note {
  display: inline-block;
  padding: 11px 12px;
  border-radius: 6px;
  background: var(--ok-bg);
  color: #087b73;
  border: 1px solid #bce9e4;
}

.empty {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(9, 20, 30, 0.38);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 5;
}

.modal {
  width: min(520px, 100%);
  background: #ffffff;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 22px;
}

.wide-modal {
  width: min(860px, 100%);
}

.auto-files-modal {
  max-height: calc(100vh - 36px);
  display: flex;
  flex-direction: column;
}

.auto-files-scroll {
  max-height: min(62vh, 560px);
  overflow: auto;
}

.auto-files-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.modal h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

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

.check-row {
  display: flex;
  gap: 9px;
  align-items: center;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.time-filter-toggle {
  align-items: center;
}

.time-filter-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  text-decoration: none;
}

.button-link:hover {
  background: var(--primary-strong);
}

.point-picker {
  max-height: 58vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.point-search {
  margin: 0 0 12px;
}

.point-check-all {
  margin: 0 0 10px;
  font-weight: 700;
}

.point-row {
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
}

.point-row:last-child {
  border-bottom: 0;
}

.point-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.note-input {
  min-width: 150px;
}

@media print {
  body {
    background: #ffffff;
  }

  .topbar,
  .page-title .toolbar,
  .status,
  .pagination {
    display: none !important;
  }

  .main {
    width: 100%;
    margin: 0;
  }

  .table-wrap {
    border: 0;
    overflow: visible;
  }

  table {
    min-width: 0;
  }

  .datalog-report-sheet {
    border: 0;
    border-radius: 0;
  }

  .datalog-report-scroll {
    overflow: visible;
  }

  .note-input {
    border: 0;
    box-shadow: none;
    padding: 0;
  }
}

.admin-panel {
  margin-top: 24px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.admin-panel h2 {
  margin: 0;
  font-size: 20px;
}

.admin-panel p {
  margin: 6px 0 0;
  color: var(--muted);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-top: 14px;
}

#storageForm {
  grid-template-columns: minmax(180px, auto) minmax(180px, 1fr) minmax(180px, 1fr) auto;
}

.system-switch {
  min-height: 42px;
}

.danger-zone {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
}

.backup-tools {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.backup-tools h3 {
  margin: 0;
  font-size: 16px;
}

.backup-tools .settings-grid {
  grid-template-columns: auto minmax(220px, 1fr) auto;
}

.reset-database-row {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

@media (max-width: 720px) {
  .topbar {
    height: auto;
    padding: 14px;
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .nav {
    width: 100%;
    flex-wrap: wrap;
  }

  .brand span {
    white-space: normal;
  }

  .nav-menu {
    flex: 1 1 calc(50% - 8px);
  }

  .nav-menu-button {
    width: 100%;
  }

  .nav-dropdown {
    right: 0;
    width: min(240px, calc(100vw - 28px));
  }

  .page-title {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar button {
    flex: 1;
  }

  .pagination {
    justify-content: stretch;
    align-items: stretch;
    flex-direction: column;
  }

  .settings-grid,
  .danger-zone,
  .filter-bar {
    grid-template-columns: 1fr;
  }

  .point-filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .datalog-report-head {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .datalog-report-title-block,
  .datalog-report-code {
    width: 100%;
  }

  .datalog-report-footer th,
  .datalog-report-footer td {
    padding: 8px 6px;
    font-size: 12px;
  }
}
