:root {
  color-scheme: light;
  --ink: #16202a;
  --muted: #647282;
  --line: #d8e0e8;
  --panel: #ffffff;
  --canvas: #f4f7fa;
  --nav: #101923;
  --nav-soft: #1a2633;
  --blue: #2563eb;
  --teal: #0f766e;
  --green: #15803d;
  --amber: #b45309;
  --red: #b91c1c;
  --violet: #6d28d9;
  --shadow: 0 18px 42px rgba(20, 31, 43, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

button,
input,
select {
  font: inherit;
}

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

[hidden] {
  display: none !important;
}

.auth-gate {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, #1a2633, var(--nav));
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(380px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.auth-brand {
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.auth-brand span {
  color: var(--muted);
}

.auth-card h1 {
  font-size: 22px;
}

.auth-sub {
  margin: -8px 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.auth-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.auth-field input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.auth-card .primary-action {
  margin-top: 4px;
  width: 100%;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.session-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 42px;
  padding: 0 6px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 24px 18px;
  color: #e8eef5;
  background: var(--nav);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand strong {
  display: block;
  font-size: 20px;
}

.brand span,
.tenant-card span,
.tenant-card small {
  color: #9fb0c1;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #e8f4ff;
}

.brand-mark svg {
  width: 30px;
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  color: #c9d5e2;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  color: #ffffff;
  background: var(--nav-soft);
  border-color: rgba(255, 255, 255, 0.08);
}

.tenant-card {
  display: grid;
  gap: 6px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: var(--nav-soft);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

h2 {
  font-size: 18px;
}

h3 {
  margin-bottom: 6px;
  font-size: 15px;
}

.topbar-actions {
  display: flex;
  align-items: end;
  gap: 12px;
}

.search {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.search input {
  width: min(360px, 36vw);
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.primary-action,
.ghost-action {
  height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  cursor: pointer;
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.primary-action {
  color: #fff;
  border: 1px solid #174dc0;
  background: var(--blue);
}

.ghost-action {
  color: var(--ink);
  border: 1px solid var(--line);
  background: #fff;
}

.content {
  display: grid;
  gap: 18px;
}

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

.grid.metrics {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.3fr) minmax(340px, 0.7fr);
}

.panel,
.metric,
.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.metric {
  display: grid;
  gap: 10px;
  min-height: 128px;
  padding: 16px;
}

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

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

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

.metric .trend.good {
  color: var(--green);
}

.metric .trend.warn {
  color: var(--amber);
}

.metric .trend.bad {
  color: var(--red);
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok {
  color: #075b2c;
  background: #dcfce7;
}

.pill.warn {
  color: #7a3c00;
  background: #fef3c7;
}

.pill.bad {
  color: #7f1d1d;
  background: #fee2e2;
}

.pill.info {
  color: #164b8f;
  background: #dbeafe;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.segmented {
  display: inline-flex;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef3f7;
}

.segmented button {
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.segmented button.active {
  background: #fff;
  box-shadow: 0 1px 4px rgba(20, 31, 43, 0.12);
}

.record-list {
  display: grid;
  gap: 12px;
}

.record-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 14px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.risk-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.risk-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--amber), var(--red));
}

.automation-grid {
  grid-template-columns: repeat(3, minmax(210px, 1fr));
}

.script-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.script-card code {
  display: block;
  padding: 10px;
  overflow-x: auto;
  color: #dbeafe;
  border-radius: 8px;
  background: #0b1220;
}

.inventory-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.inventory-sidebar {
  position: sticky;
  top: 18px;
}

.endpoint-selector-list {
  display: grid;
  gap: 8px;
}

.endpoint-selector {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 74px;
  padding: 11px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.endpoint-selector strong,
.endpoint-selector span,
.endpoint-selector small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.endpoint-selector span,
.endpoint-selector small {
  color: var(--muted);
}

.endpoint-selector.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.inventory-detail {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.inventory-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.inventory-panel {
  box-shadow: none;
}

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

.field-row {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.field-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field-row strong {
  overflow-wrap: anywhere;
  font-size: 14px;
}

.compact-table th,
.compact-table td {
  padding: 9px 8px;
  font-size: 13px;
}

.toolbar-cluster {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.download-menu {
  position: relative;
}

.download-menu summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  user-select: none;
}

.download-menu summary::-webkit-details-marker {
  display: none;
}

.download-menu summary::marker {
  content: "";
}

.download-menu-list {
  position: absolute;
  right: 0;
  z-index: 20;
  display: grid;
  gap: 4px;
  min-width: 260px;
  margin-top: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.download-menu-list a {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
}

.download-menu-list a small {
  color: var(--muted);
}

.download-menu-list a:hover {
  background: #eef3f7;
}

.control-tag {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f5f9;
  font-size: 11px;
  font-weight: 700;
}

.ai-plan {
  margin: 0;
  padding: 14px;
  overflow-x: auto;
  white-space: pre-wrap;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.empty-state {
  display: grid;
  gap: 8px;
  padding: 40px 24px;
  text-align: center;
}

.empty-state p,
.muted-note {
  margin: 0;
  color: var(--muted);
}

.empty-state p {
  max-width: 560px;
  margin: 0 auto;
}

.muted-note {
  padding: 10px 2px;
  font-size: 14px;
}

.toast {
  display: none;
  padding: 12px 14px;
  color: #063f3a;
  border: 1px solid #99f6e4;
  border-radius: 8px;
  background: #ccfbf1;
}

.toast.show {
  display: block;
}

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

  .sidebar {
    position: static;
  }

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

  .grid.metrics,
  .grid.two,
  .automation-grid,
  .inventory-layout,
  .inventory-grid,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .inventory-sidebar {
    position: static;
  }

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

  .search input {
    width: 100%;
  }
}
