:root {
  color-scheme: light;
  --bg: #f7f7f4;
  --text: #172026;
  --muted: #66727c;
  --line: #d9e0e4;
  --panel: #ffffff;
  --accent: #1b817b;
  --accent-dark: #14645f;
  --warm: #ffb21a;
  --shadow: 0 18px 45px rgba(23, 32, 38, 0.10);
}

* {
  box-sizing: border-box;
}

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

body:has(.app-shell:not([hidden])) {
  background:
    radial-gradient(circle at 95% 0%, rgba(255, 178, 26, 0.12), transparent 28%),
    linear-gradient(180deg, #fbfbf8 0%, #f4f6f5 100%);
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 32px;
  padding: 0 12px;
}

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

button.danger {
  background: #b42f2f;
}

button.danger:hover {
  background: #8f2020;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 34px;
  padding: 0 10px;
}

.shell {
  margin: 0 auto;
  max-width: 1760px;
  padding: 22px clamp(12px, 2.4vw, 36px);
  width: 100%;
}

.app-shell {
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  background: rgba(255, 255, 255, 0.78);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-filter {
  border-top: 1px solid var(--line);
  margin-top: auto;
  padding-top: 16px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 10px;
  min-height: 42px;
}

.brand-mark {
  align-items: center;
  background: var(--warm);
  border-radius: 8px;
  color: var(--text);
  display: inline-flex;
  font-size: 13px;
  font-weight: 800;
  height: 34px;
  justify-content: center;
  width: 34px;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav button {
  background: transparent;
  border-radius: 8px;
  color: var(--muted);
  justify-content: flex-start;
  min-height: 38px;
  padding: 0 12px;
  text-align: left;
}

.side-nav button:hover {
  background: #edf7f6;
  color: var(--accent);
}

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

.main-area {
  min-width: 0;
  padding: 20px clamp(16px, 2vw, 32px) 36px;
}

.login-view {
  align-items: center;
  background: var(--bg);
  display: flex;
  inset: 0;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  position: fixed;
  z-index: 10;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
  max-width: 420px;
  padding: 26px;
  width: 100%;
}

.error {
  color: #a32323;
  font-size: 13px;
}

.topbar,
.filters,
.panel-title {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.topbar {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(23, 32, 38, 0.06);
  margin-bottom: 22px;
  padding: 16px 18px;
}

.eyebrow {
  color: var(--warm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
}

h2 {
  font-size: 18px;
}

p,
label,
td {
  color: var(--muted);
}

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

.auth,
.filters,
.top-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.auth span,
.top-actions span {
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.company-switcher {
  min-width: 210px;
}

.sidebar-filter .company-switcher {
  min-width: 0;
  width: 100%;
}

.section-heading {
  margin: 4px 0 12px;
}

.admin-section {
  margin-bottom: 24px;
}

.filters {
  justify-content: flex-start;
  margin: 24px 0;
}

label {
  display: grid;
  font-size: 13px;
  gap: 6px;
}

.metrics {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 18px;
}

.dashboard-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.dashboard-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: grid;
  gap: 12px;
  min-height: 170px;
  padding: 18px;
  text-align: center;
}

.dashboard-card p {
  line-height: 1.45;
}

.dashboard-card button {
  align-self: end;
  justify-self: center;
}

.dashboard-events-panel {
  margin-top: 18px;
}

.dashboard-events-panel table {
  min-width: 980px;
}

.admin-stack {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
  margin-bottom: 24px;
}

.inline-form,
.stack-form {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 12px 16px;
}

.inline-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.admin-toolbar {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 260px);
  padding: 12px 16px;
}

.inline-form button {
  min-width: 110px;
}

.icon-button {
  min-width: 38px !important;
  padding: 0 10px;
}

.range-control {
  position: relative;
}

.range-control > button {
  background: white;
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
  justify-content: flex-start;
  width: 100%;
}

.range-picker {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  left: 0;
  min-width: 260px;
  padding: 12px;
  position: absolute;
  top: calc(100% + 8px);
  z-index: 30;
}

.notice {
  background: #edf7f6;
  border-bottom: 1px solid var(--line);
  color: #0b4d4f;
  font-family: Consolas, monospace;
  font-size: 13px;
  padding: 12px 16px;
  word-break: break-all;
}

.inline-check {
  align-items: center;
  display: flex;
  gap: 8px;
  min-height: 34px;
}

.inline-check input {
  min-height: auto;
}

.detail-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 16px;
}

.company-detail-layout {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.35fr) minmax(240px, 0.75fr);
  padding: 16px;
}

.company-settings-form {
  display: grid;
  gap: 16px;
}

.settings-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.settings-card h3 {
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  margin: -2px 0 14px;
  padding-bottom: 10px;
}

.settings-check-grid {
  display: grid;
  gap: 10px 16px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-check-grid label {
  align-items: center;
  display: flex;
  gap: 8px;
}

.settings-field-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.inline-notice {
  background: #edf7f6;
  border: 1px solid #b9dcda;
  border-radius: 8px;
  color: #0b4d4f;
  font-size: 13px;
  margin-bottom: 12px;
  padding: 10px 12px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(23, 32, 38, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 28px;
  position: fixed;
  z-index: 20;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 56px);
  max-width: min(1480px, calc(100vw - 48px));
  overflow: auto;
  width: 100%;
}

.wide-modal {
  max-width: min(1520px, calc(100vw - 48px));
}

.small-modal {
  max-width: min(520px, calc(100vw - 48px));
}

.detail-grid h3 {
  font-size: 15px;
  margin: 0 0 10px;
}

.checkbox-list {
  display: grid;
  gap: 10px;
}

.checkbox-list label {
  align-items: center;
  display: flex;
  gap: 8px;
}

.checkbox-list input {
  min-height: auto;
}

.compact-list {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 8px;
  margin-top: 12px;
}

.compact-list article {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

[data-company-row],
[data-agent-machine-id],
[data-user-row] {
  cursor: pointer;
}

[data-company-row]:hover,
[data-agent-machine-id]:hover,
[data-user-row]:hover {
  background: #f4fbfa;
}

.user-kpis {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 16px;
}

.user-kpis article {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  padding: 12px;
}

.user-kpis span {
  color: var(--muted);
  font-size: 12px;
}

.user-kpis strong {
  font-size: 18px;
}

.compact-kpis {
  gap: 8px;
  padding: 10px 16px 0;
}

.compact-kpis + .compact-kpis {
  padding-top: 8px;
}

.presence-kpis {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.activity-kpis {
  grid-template-columns: 1.2fr 1.2fr 0.8fr;
}

.kpi-card {
  min-width: 0;
}

.compact-kpis .kpi-card {
  gap: 3px;
  min-height: 52px;
  padding: 8px 10px;
}

.compact-kpis .kpi-card span {
  font-size: 11px;
  line-height: 1.2;
}

.compact-kpis .kpi-card strong {
  font-size: 16px;
  line-height: 1.2;
  min-width: 0;
  overflow-wrap: anywhere;
}

.kpi-subtext {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.timeline {
  background: #f1f3f3;
  border: 1px solid var(--line);
  border-radius: 999px;
  display: flex;
  height: 28px;
  margin: 0 16px 8px;
  overflow: visible;
  position: relative;
}

.timeline-scale {
  color: var(--muted);
  display: flex;
  font-size: 12px;
  justify-content: space-between;
  padding: 8px 16px 5px;
}

.timeline-tooltip {
  background: #172026;
  border-radius: 8px;
  color: white;
  font-size: 12px;
  padding: 6px 8px;
  pointer-events: none;
  position: fixed;
  z-index: 50;
}

.mini-timeline {
  background: #eef2f2;
  border-radius: 999px;
  display: flex;
  height: 12px;
  min-width: 120px;
  overflow: hidden;
}

.timeline-segment {
  display: block;
  height: 100%;
}

.timeline-segment:first-child {
  border-bottom-left-radius: 999px;
  border-top-left-radius: 999px;
}

.timeline-marker {
  background: #172026;
  bottom: -3px;
  display: block;
  pointer-events: auto;
  position: absolute;
  top: -3px;
  width: 2px;
  z-index: 3;
}

.timeline-marker::after {
  background: #172026;
  border-radius: 999px;
  content: "";
  height: 6px;
  left: -2px;
  position: absolute;
  top: -4px;
  width: 6px;
}

.timeline-marker::before {
  color: #172026;
  content: attr(data-marker-label);
  font-size: 11px;
  font-weight: 700;
  left: 50%;
  position: absolute;
  top: -22px;
  transform: translateX(-50%);
  white-space: nowrap;
}

.state-active {
  background: #2f9e44;
}

.state-idle {
  background: #ffb21a;
}

.state-off {
  background: #d94a4a;
}

.state-stale {
  background: #879191;
}

.state-nodata {
  background: #dfe6e6;
}

.status-badge {
  border-radius: 999px;
  color: white;
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 8px;
  white-space: nowrap;
}

.status-main {
  font-size: 13px;
  letter-spacing: 0;
  min-width: 54px;
  padding: 6px 10px;
  text-align: center;
}

.status-detail {
  color: var(--muted);
  display: inline-block;
  font-size: 12px;
  margin-left: 8px;
  vertical-align: middle;
}

.status-ok {
  background: #2f9e44;
  color: #ffffff;
}

.status-warning {
  background: #ffb21a;
  color: #172026;
}

.status-danger {
  background: #b4232f;
  color: #ffffff;
}

.status-neutral {
  background: #879191;
  color: #ffffff;
}

.legend {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 14px;
  padding: 0 16px 16px;
}

.legend span {
  align-items: center;
  display: flex;
  gap: 6px;
}

.legend i {
  border-radius: 999px;
  display: inline-block;
  height: 10px;
  width: 10px;
}

.event-filter-bar {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 13px;
  gap: 10px 14px;
  margin: 0 16px;
  padding: 12px 0;
}

.event-filter-bar > span {
  color: var(--text);
  font-weight: 700;
}

.event-filter-bar label {
  align-items: center;
  display: flex;
  gap: 6px;
}

.event-filter-bar input {
  min-height: auto;
}

.event-pager {
  align-items: center;
  border-top: 1px solid var(--line);
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 10px;
  justify-content: flex-end;
  margin: 0 16px;
  padding: 0 0 12px;
}

.event-pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

.metrics article {
  display: grid;
  gap: 8px;
  padding: 18px;
}

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

.metrics strong {
  font-size: 30px;
}

.metrics small {
  color: var(--muted);
  font-size: 12px;
}

.panel {
  margin-bottom: 18px;
  overflow: visible;
}

.panel-title {
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

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

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

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

td button {
  margin: 2px 3px 2px 0;
}

th {
  color: var(--text);
  font-weight: 700;
}

@media (max-width: 1200px) {
  .presence-kpis {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

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

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

  .sidebar {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    height: auto;
    padding: 12px 14px;
    position: static;
  }

  .sidebar-filter {
    margin-top: 0;
    padding-top: 10px;
  }

  .side-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .side-nav button {
    flex: 0 0 auto;
  }

  .main-area {
    padding: 14px;
  }

  .topbar,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .auth,
  .top-actions {
    flex-direction: column;
    width: 100%;
  }

  .auth button,
  .top-actions button,
  .filters select,
  .filters label,
  .company-switcher {
    width: 100%;
  }

  .metrics,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .admin-stack,
  .admin-toolbar,
  .inline-form,
  .company-detail-layout,
  .settings-check-grid,
  .settings-field-grid,
  .detail-grid,
  .user-kpis {
    grid-template-columns: 1fr;
  }

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

  .activity-kpis {
    grid-template-columns: 1fr;
  }
}
