:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --text: #111827;
  --muted: #667085;
  --line: #d7dde5;
  --line-soft: #e7ebf0;
  --primary: #0f766e;
  --primary-dark: #0b5f59;
  --blue: #2563eb;
  --amber: #b7791f;
  --red: #b42318;
  --green: #067647;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 230px),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.25;
  font-weight: 750;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
  font-weight: 750;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.2);
  outline-offset: 2px;
}

.shell {
  width: 100%;
  margin: 0;
  padding: 16px 22px 28px;
}

.topbar {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px;
  background: #e9eef3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.tab-button,
.tab-link {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  padding: 0 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.tab-button.active,
.tab-link.active {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(15, 118, 110, 0.22);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.user-chip {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  max-width: 220px;
  padding: 0 10px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu {
  position: relative;
}

.user-menu-button {
  width: auto;
  min-width: 150px;
  max-width: 270px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 11px 0 6px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.user-menu-button:hover,
.user-chip:hover {
  border-color: #b9c3d0;
  box-shadow: 0 4px 12px rgba(17, 24, 39, 0.06);
}

.user-menu-caret {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}

.profile-initial {
  width: 25px;
  height: 25px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--blue));
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}

#currentUser {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 700;
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  min-width: 190px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.user-menu-panel button {
  width: 100%;
  height: 36px;
  display: block;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 6px;
  text-align: left;
  font-weight: 650;
}

.user-menu-panel button:hover {
  background: #eef6ff;
}

.status-strip,
.status {
  min-height: 34px;
  display: flex;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px 11px;
  color: #1e3a8a;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.35;
}

.status-strip.error,
.status.error,
.login-message.error,
.error {
  color: var(--red);
}

.status-strip.error,
.status.error {
  background: #fff4f2;
  border-color: #fecdca;
}

.filters {
  display: grid;
  grid-template-columns: minmax(230px, 1.1fr) minmax(280px, 1.25fr) minmax(130px, 0.56fr) minmax(155px, 0.66fr) minmax(104px, auto) minmax(126px, auto);
  gap: 10px;
  align-items: end;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.03);
}

.filters-clients {
  grid-template-columns: minmax(220px, 1fr) minmax(140px, 190px) minmax(104px, auto);
}

label {
  display: grid;
  gap: 6px;
  color: #475467;
  font-size: 13px;
  font-weight: 650;
}

input, select, textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
}

input, select, button {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 72px;
  padding: 9px 10px;
  resize: vertical;
}

input::placeholder {
  color: #98a2b3;
}

input:hover, select:hover, textarea:hover {
  border-color: #b9c3d0;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font-weight: 750;
}

button:hover {
  background: var(--primary-dark);
}

.quick-range {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: #edf1f5;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.range-button {
  height: 32px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 750;
}

.range-button:hover {
  color: var(--primary);
  background: rgba(255, 255, 255, 0.65);
}

.range-button.active {
  color: var(--primary);
  background: var(--surface);
  border-color: var(--line);
  box-shadow: 0 1px 3px rgba(17, 24, 39, 0.08);
}

.custom-range {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.date-time-control {
  display: grid;
  grid-template-columns: minmax(128px, 1fr) 90px;
  gap: 6px;
}

.export-button {
  background: var(--blue);
  white-space: nowrap;
}

.export-button:hover {
  background: #1d4ed8;
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

.cards {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.cards article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.cards article {
  position: relative;
  min-height: 94px;
  display: grid;
  align-content: space-between;
  gap: 10px;
  padding: 14px;
  overflow: hidden;
}

.cards article::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--primary);
}

.cards article:nth-child(2)::before { background: var(--blue); }
.cards article:nth-child(3)::before { background: var(--amber); }
.cards article:nth-child(4)::before { background: #7c3aed; }
.cards article:nth-child(5)::before { background: var(--green); }
.cards article:nth-child(6)::before { background: #475467; }

.cards span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.cards strong {
  color: var(--text);
  font-size: 22px;
  line-height: 1.12;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.cards-ops {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.cards-ops strong {
  color: var(--primary);
}

.panel {
  padding: 14px;
  margin-bottom: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 16px;
}

.chart {
  min-height: 260px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(76px, 1fr);
  gap: 10px;
  align-items: end;
  padding: 18px 2px 6px;
  overflow-x: auto;
  overflow-y: hidden;
  border-top: 1px solid var(--line-soft);
}

.bar-wrap {
  display: grid;
  grid-template-rows: 42px 180px 18px;
  gap: 6px;
  align-items: end;
  min-width: 76px;
}

.bar-value {
  align-self: end;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  word-break: break-word;
}

.bar {
  width: 100%;
  min-height: 4px;
  border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--blue), var(--primary));
}

.bar-label {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  white-space: nowrap;
}

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

tbody tr:nth-child(even) {
  background: #fbfcfd;
}

tbody tr:hover {
  background: #f2f7ff;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: #475467;
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 800;
}

td:last-child,
th:last-child {
  text-align: right;
}

td.wrap {
  min-width: 220px;
  max-width: 520px;
  white-space: normal;
  overflow-wrap: anywhere;
}

.client-state,
.log-level {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.client-state.online {
  color: var(--green);
  background: #dcfae6;
}

.client-state.offline {
  color: var(--red);
  background: #fee4e2;
}

.log-level {
  color: #344054;
  background: #eaecf0;
}

.log-level.error {
  color: var(--red);
  background: #fee4e2;
}

.log-level.warning {
  color: #b54708;
  background: #fef0c7;
}

.small-action {
  width: auto;
  min-width: 68px;
  height: 30px;
  margin: 2px;
  padding: 0 9px;
  background: #eef2f6;
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 750;
}

.small-action:hover {
  color: var(--primary);
  background: #ffffff;
  border-color: #b9c3d0;
}

.user-form,
.password-form {
  display: grid;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.user-form {
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(100px, auto);
}

.password-form {
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(130px, auto);
}

.otp-panel {
  display: grid;
  gap: 10px;
}

.otp-setup {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  color: #1e3a8a;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  font-size: 13px;
}

.otp-setup code {
  display: block;
  padding: 8px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  word-break: break-all;
}

.otp-qr {
  width: 192px;
  height: 192px;
  justify-self: center;
  padding: 8px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.update-form {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(130px, 0.7fr) minmax(150px, 0.7fr) minmax(220px, 1.2fr) 140px;
  gap: 10px;
  align-items: end;
}

.update-notes {
  grid-column: 1 / -2;
}

.update-current {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 14px;
  padding: 10px 12px;
  color: #1e3a8a;
  background: #eef6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  font-size: 13px;
}

.check-line {
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
}

.check-line input {
  width: 18px;
  height: 18px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15, 118, 110, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(37, 99, 235, 0.10), transparent 40%),
    var(--bg);
}

.login-panel {
  width: min(430px, 100%);
  display: grid;
  gap: 15px;
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.12);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.login-mark {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: #ffffff;
  background: linear-gradient(135deg, var(--primary), var(--blue));
  border-radius: var(--radius);
  font-size: 19px;
  font-weight: 850;
}

.login-panel h1 {
  font-size: 23px;
}

.login-panel p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.login-message {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 1180px) {
  .filters {
    grid-template-columns: minmax(240px, 1fr) minmax(280px, 1.2fr) minmax(140px, 0.7fr);
  }

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

  .cards-ops {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .shell {
    padding: 12px;
  }

  .topbar {
    min-height: 0;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

  .tab-button,
  .tab-link {
    width: 100%;
  }

  .filters,
  .filters-clients,
  .grid,
  .user-form,
  .password-form,
  .update-form {
    grid-template-columns: 1fr;
  }

  .update-notes {
    grid-column: auto;
  }

  .custom-range {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 640px) {
  body {
    background: var(--bg);
  }

  .shell {
    padding: 10px;
  }

  .top-actions {
    width: 100%;
  }

  .user-menu,
  .user-menu-button,
  .user-chip,
  .top-actions > button {
    width: 100%;
  }

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

  .custom-range {
    grid-template-columns: 1fr;
  }

  .date-time-control {
    grid-template-columns: minmax(0, 1fr) 90px;
  }

  input, select, button {
    height: 40px;
  }

  .cards,
  .cards-ops {
    gap: 8px;
  }

  .cards article {
    min-height: 86px;
    padding: 12px;
  }

  .cards strong {
    font-size: 18px;
  }

  .panel,
  .filters {
    padding: 12px;
    margin-bottom: 12px;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .chart {
    grid-auto-columns: minmax(72px, 72px);
    min-height: 250px;
    gap: 8px;
  }

  .bar-wrap {
    min-width: 72px;
    grid-template-rows: 44px 170px 18px;
  }

  .bar-value {
    font-size: 11px;
  }

  th, td {
    padding: 9px 8px;
  }

  .login-shell {
    padding: 14px;
  }

  .login-panel {
    padding: 20px;
  }
}

@media (max-width: 420px) {
  .cards,
  .cards-ops {
    grid-template-columns: 1fr;
  }
}
