:root {
  --page: #1e1e1e;
  --surface: #262626;
  --surface-soft: #2c2c2e;
  --surface-raised: #303032;
  --ink: #dfdfe2;
  --ink-strong: #f4f4f6;
  --muted: #96979c;
  --muted-soft: #6f7075;
  --line: #38383b;
  --line-soft: #2f2f31;
  --brand: #8577f2;
  --brand-strong: #6a5cd6;
  --accent: #b7aaff;
  --blue: #6ea8fe;
  --green: #5ec698;
  --amber: #e0af5a;
  --red: #ea7a6e;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 90% -10%, rgba(133, 119, 242, 0.16), transparent 30rem),
    radial-gradient(circle at -10% 60%, rgba(133, 119, 242, 0.07), transparent 34rem),
    var(--page);
}

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

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(133, 119, 242, 0.38);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-frame {
  width: min(100%, 1320px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 16px calc(32px + env(safe-area-inset-bottom));
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  margin: 0 -16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(30, 30, 30, 0.82);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--brand), var(--brand-strong));
  color: #fff;
  font-size: 20px;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(101, 88, 214, 0.35);
}

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

.brand strong {
  font-size: 17px;
  color: var(--ink-strong);
  letter-spacing: -0.01em;
}

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

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

.connection {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #616266;
}

.connection[data-state="online"] .connection-dot {
  background: #45d497;
  box-shadow: 0 0 0 4px rgba(69, 212, 151, 0.16);
}

.connection[data-state="offline"] .connection-dot {
  background: #ea7a6e;
  box-shadow: 0 0 0 4px rgba(234, 122, 110, 0.16);
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--brand);
  color: var(--accent);
}

.hero {
  display: grid;
  gap: 18px;
  padding: 34px 0 26px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 19ch;
  margin-bottom: 10px;
  color: var(--ink-strong);
  font-size: clamp(28px, 8vw, 46px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

h2 {
  margin-bottom: 0;
  color: var(--ink-strong);
  font-size: 20px;
  letter-spacing: -0.02em;
}

.lead {
  max-width: 650px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.55;
}

.primary-button,
.secondary-button,
.success-button,
.danger-button,
.text-button {
  min-height: 46px;
  border-radius: 12px;
  font-weight: 700;
}

.one-time-device-code {
  display: block;
  overflow-wrap: anywhere;
  padding: 16px;
  border: 1px solid var(--brand);
  border-radius: 12px;
  background: rgba(133, 119, 242, 0.14);
  color: var(--accent);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 15px;
  font-weight: 700;
  user-select: all;
}

.primary-button {
  border: 1px solid transparent;
  background: linear-gradient(160deg, var(--brand), var(--brand-strong));
  color: #fff;
  box-shadow: 0 10px 26px rgba(101, 88, 214, 0.32);
}

.primary-button:hover {
  filter: brightness(1.06);
}

.hero > .primary-button {
  width: 100%;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button:hover {
  border-color: var(--muted-soft);
}

.success-button {
  border: 1px solid rgba(94, 198, 152, 0.4);
  background: rgba(94, 198, 152, 0.16);
  color: var(--green);
}

.danger-button {
  border: 1px solid rgba(234, 122, 110, 0.35);
  background: rgba(234, 122, 110, 0.12);
  color: var(--red);
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
}

.primary-button,
.secondary-button,
.success-button,
.danger-button {
  padding: 0 17px;
}

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

.workspace {
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.workspace-sidebar,
.workspace-rail {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
}

.workspace-main {
  min-width: 0;
}

.device-section,
.department-section,
.status-section,
.assignments-section {
  margin-bottom: 0;
}

.assignments-section {
  margin-bottom: 28px;
}

.department-list {
  display: flex;
  gap: 8px;
  margin: 0 -4px;
  padding: 4px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.department-item {
  display: grid;
  flex: 0 0 auto;
  gap: 4px;
  min-width: 172px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  scroll-snap-align: start;
}

.department-item:not([data-business-unit]) {
  opacity: 0.78;
}

.department-item[aria-checked="true"] {
  border-color: var(--brand);
  background: linear-gradient(165deg, rgba(133, 119, 242, 0.22), rgba(133, 119, 242, 0.06));
}

.department-name {
  color: var(--ink-strong);
  font-size: 13px;
  font-weight: 750;
}

.department-desc {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.department-status {
  margin-top: 2px;
  color: var(--muted-soft);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  justify-content: flex-end;
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.search-field {
  display: block;
  margin: 0 0 13px;
}

.search-field input {
  min-height: 44px;
}

.status-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.status-line {
  margin: 0;
  color: var(--ink-strong);
  font-size: 13px;
  font-weight: 700;
}

.status-flags {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.status-flag {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.status-flag-value {
  margin-left: auto;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted-soft);
}

.status-dot[data-on="true"] {
  background: #45d497;
  box-shadow: 0 0 0 4px rgba(69, 212, 151, 0.16);
}

.status-dot[data-on="false"] {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(234, 122, 110, 0.14);
}

.status-flag-info {
  color: var(--muted-soft);
}

.status-flag-info:first-of-type {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
}

.status-flag-info .status-flag-value {
  color: var(--ink);
  font-weight: 650;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 13px;
}

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

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

.device-card {
  position: relative;
  display: grid;
  min-height: 134px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.device-card[aria-checked="true"] {
  border-color: var(--brand);
  background: linear-gradient(165deg, rgba(133, 119, 242, 0.22), rgba(133, 119, 242, 0.06));
  color: var(--ink-strong);
  box-shadow: var(--shadow);
}

.device-letter {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--accent);
  font-weight: 800;
}

.device-card[aria-checked="true"] .device-letter {
  background: var(--brand);
  color: #fff;
}

.device-copy {
  align-self: end;
  min-width: 0;
}

.device-copy strong,
.device-copy small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-copy strong {
  font-size: 14px;
}

.device-copy small {
  margin-top: 4px;
  color: var(--muted-soft);
  font-size: 10px;
}

.device-card[aria-checked="true"] .device-copy small {
  color: rgba(244, 244, 246, 0.62);
}

.device-status {
  position: absolute;
  top: 15px;
  right: 15px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #5b5c60;
}

.device-status.is-online {
  background: #45d497;
  box-shadow: 0 0 0 4px rgba(69, 212, 151, 0.16);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(76px, 1fr));
  gap: 8px;
  margin: 0 -4px 30px;
  overflow-x: auto;
  padding: 4px;
}

.summary-card {
  min-width: 78px;
  min-height: 78px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  text-align: left;
}

.summary-card strong,
.summary-card span {
  display: block;
}

.summary-card strong {
  margin-top: 8px;
  color: var(--ink-strong);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.summary-card span {
  font-size: 10px;
  font-weight: 700;
}

.summary-card.is-active {
  border-color: var(--brand);
  background: rgba(133, 119, 242, 0.12);
}

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

.assignment-card {
  display: grid;
  gap: 10px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.assignment-card:hover {
  border-color: var(--muted-soft);
}

.assignment-topline,
.assignment-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.assignment-title {
  color: var(--ink-strong);
  font-size: 16px;
  line-height: 1.3;
}

.assignment-result {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.assignment-device,
.assignment-time,
.assignment-priority {
  color: var(--muted-soft);
  font-size: 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.status-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge[data-tone="blue"] {
  background: rgba(110, 168, 254, 0.14);
  color: var(--blue);
}

.status-badge[data-tone="amber"] {
  background: rgba(224, 175, 90, 0.16);
  color: var(--amber);
}

.status-badge[data-tone="green"] {
  background: rgba(94, 198, 152, 0.16);
  color: var(--green);
}

.status-badge[data-tone="red"] {
  background: rgba(234, 122, 110, 0.16);
  color: var(--red);
}

.empty-state {
  padding: 30px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.device-grid .empty-state {
  grid-column: 1 / -1;
}

.empty-state strong {
  color: var(--ink-strong);
}

.empty-state p {
  margin: 7px 0 18px;
  font-size: 13px;
}

.login-shell {
  display: grid;
  min-height: calc(100dvh - 84px);
  place-items: center;
  padding: 28px 0;
}

.login-card {
  width: min(100%, 430px);
  padding: 26px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.stack-form label,
.review-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-raised);
  color: var(--ink-strong);
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-soft);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
}

textarea {
  min-height: 90px;
  resize: vertical;
  line-height: 1.45;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

.check-row {
  display: flex !important;
  align-items: flex-start;
  gap: 11px !important;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  color: var(--ink) !important;
}

.check-row input {
  width: 20px;
  min-height: 20px;
  margin: 1px 0 0;
}

.check-row span,
.check-row strong,
.check-row small {
  display: block;
}

.check-row small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 500;
}

.full-width {
  width: 100%;
}

.form-message {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 650;
}

.sheet {
  width: 100%;
  max-width: none;
  height: auto;
  max-height: calc(100dvh - 24px);
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: transparent;
  color: var(--ink);
}

.sheet::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(3px);
}

.sheet-card {
  max-height: calc(100dvh - 24px);
  overflow: auto;
  padding: 22px 18px calc(20px + env(safe-area-inset-bottom));
  border: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  background: var(--page);
}

.sheet-head {
  position: sticky;
  z-index: 2;
  top: -22px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: -4px -2px 18px;
  padding: 4px 2px 12px;
  background: linear-gradient(var(--page) 80%, rgba(30, 30, 30, 0));
}

.sheet-head h2 {
  color: var(--ink-strong);
}

.sheet-actions,
.review-actions {
  display: grid;
  grid-template-columns: 1fr 1.5fr;
  gap: 10px;
  margin-top: 18px;
}

.review-form {
  display: grid;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.review-actions {
  grid-template-columns: 1fr 1fr;
}

.review-actions .danger-button {
  grid-column: 1 / -1;
}

.detail-block {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.detail-block + .detail-block {
  margin-top: 10px;
}

.detail-block h3 {
  margin: 0 0 9px;
  color: var(--ink-strong);
  font-size: 15px;
}

.detail-block p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.detail-block pre {
  overflow-x: auto;
  max-width: 100%;
  margin: 9px 0 0;
  padding: 11px;
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.detail-meta div {
  padding: 11px;
  border-radius: 11px;
  background: var(--surface-raised);
}

.detail-meta span,
.detail-meta strong {
  display: block;
}

.detail-meta span {
  margin-bottom: 4px;
  color: var(--muted-soft);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.detail-meta strong {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 12px;
}

.artifact-list {
  display: grid;
  gap: 7px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.artifact-list a {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

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

.team-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}

.team-identity {
  min-width: 0;
}

.team-identity strong,
.team-identity small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.team-identity strong {
  max-width: 46vw;
  color: var(--ink-strong);
  font-size: 13px;
}

.team-identity small {
  margin-top: 3px;
  color: var(--muted-soft);
  font-size: 11px;
}

.team-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.team-meta span {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.team-role[data-role="owner"] {
  background: rgba(133, 119, 242, 0.16);
  color: var(--accent);
}

.team-status[data-status="active"] {
  background: rgba(94, 198, 152, 0.16);
  color: var(--green);
}

.team-status[data-status="revoked"] {
  background: rgba(234, 122, 110, 0.16);
  color: var(--red);
}

.team-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.snapshot-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 11px;
  color: var(--muted-soft);
}

.snapshot-sources span {
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface);
  white-space: nowrap;
}

.snapshot-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--muted);
}

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

.snapshot-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 14px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}

.snapshot-identity {
  min-width: 0;
}

.snapshot-identity strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 46vw;
  color: var(--ink-strong);
  font-size: 13px;
}

.snapshot-identity small {
  display: block;
  margin-top: 3px;
  color: var(--muted-soft);
  font-size: 11px;
}

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

.snapshot-value {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.snapshot-badge {
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.snapshot-badge[data-tone="red"] {
  background: rgba(234, 122, 110, 0.16);
  color: var(--red);
}

.snapshot-badge[data-tone="green"] {
  background: rgba(94, 198, 152, 0.16);
  color: var(--green);
}

.snapshot-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

@media (min-width: 560px) {
  .kpi-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.kpi-tile {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}

.kpi-tile-label {
  display: block;
  color: var(--muted-soft);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.kpi-tile-value {
  display: block;
  margin-top: 6px;
  color: var(--ink-strong);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-tile-value[data-tone="red"] {
  color: var(--red);
}

.chart-panel {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface-raised);
}

.chart-panel-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.chart-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border-radius: 999px;
  background: var(--surface);
}

.chart-tab {
  padding: 5px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.chart-tab[aria-pressed="true"] {
  background: var(--brand);
  color: #fff;
}

.chart-container {
  width: 100%;
  overflow-x: auto;
}

.chart-container svg {
  display: block;
  width: 100%;
  height: auto;
}

.chart-empty {
  margin: 24px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.budget-amount {
  margin-bottom: 10px;
  color: var(--ink-strong);
  font-size: 28px;
  font-weight: 700;
}

.budget-amount small {
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
}

.budget-bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface);
  overflow: hidden;
}

.budget-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--brand);
  transition: width 0.3s ease;
}

.budget-bar-fill[data-tone="amber"] {
  background: var(--amber);
}

.budget-bar-fill[data-tone="red"] {
  background: var(--red);
}

.budget-meta {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.priority-create-form {
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}

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

.priority-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}

.priority-toggle {
  flex: 0 0 auto;
  border: none;
  appearance: none;
}

.priority-content,
.priority-edit-form {
  flex: 1 1 200px;
  min-width: 0;
}

.priority-title {
  display: block;
  overflow-wrap: anywhere;
  color: var(--ink-strong);
  font-size: 13px;
}

.priority-note {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.priority-edit-form {
  display: grid;
  gap: 8px;
}

.priority-edit-form input,
.priority-edit-form textarea {
  min-height: 40px;
}

.priority-edit-form textarea {
  min-height: 60px;
}

.priority-edit-actions {
  display: flex;
  gap: 8px;
}

.priority-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 6px;
  margin-left: auto;
}

.priority-actions .icon-button {
  width: 34px;
  height: 34px;
  font-size: 14px;
}

.mailbox-columns {
  display: grid;
  gap: 12px;
  margin-bottom: 18px;
}

.mailbox-block h3 {
  margin: 0 0 7px;
  color: var(--ink-strong);
  font-size: 12px;
  font-weight: 700;
}

.mailbox-text {
  max-height: 220px;
  margin: 0;
  overflow: auto;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-raised);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  z-index: 80;
  right: 16px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 16px;
  max-width: 480px;
  margin: auto;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-raised);
  color: var(--ink-strong);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

@media (min-width: 560px) {
  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .hero {
    grid-template-columns: 1fr auto;
    align-items: end;
  }

  .hero > .primary-button {
    width: auto;
  }

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

  .sheet {
    width: min(620px, calc(100% - 32px));
    margin: auto;
    border-radius: 20px;
  }

  .sheet-card {
    border-radius: 20px;
    padding: 25px;
  }

  .sheet-head {
    top: -25px;
    margin: -4px -4px 18px;
    padding: 4px 4px 12px;
  }
}

@media (min-width: 820px) {
  .app-frame {
    padding-right: 28px;
    padding-left: 28px;
  }

  .app-header {
    margin: 0 -28px;
    padding-right: 28px;
    padding-left: 28px;
  }

  .device-grid {
    grid-template-columns: repeat(2, minmax(220px, 340px));
  }

  .summary-grid {
    grid-template-columns: repeat(4, 150px);
    justify-content: start;
  }

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

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

@media (min-width: 980px) {
  .workspace {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr) 260px;
    align-items: start;
    gap: 26px;
  }

  .workspace-sidebar,
  .workspace-rail {
    position: sticky;
    top: 90px;
  }

  .department-list {
    flex-direction: column;
    overflow-x: visible;
  }

  .department-item {
    min-width: 0;
    width: 100%;
  }

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

  .workspace-main .summary-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .workspace-main .assignment-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1240px) {
  .workspace-main .assignment-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: no-preference) {
  .device-card,
  .assignment-card,
  .summary-card,
  .primary-button,
  .secondary-button {
    transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease;
  }

  .device-card:active,
  .assignment-card:active,
  .primary-button:active,
  .secondary-button:active {
    transform: scale(0.985);
  }
}

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

.agent-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  width: 100%;
}

.agent-card:hover {
  border-color: var(--muted-soft);
}

.agent-card-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted-soft);
}

.agent-card-dot.is-ok {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(94, 198, 152, 0.16);
}

.agent-card-dot.is-error {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(234, 122, 110, 0.14);
}

.agent-card-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.agent-card-role {
  color: var(--ink-strong);
  font-weight: 600;
}

.agent-card-status {
  color: var(--muted);
  font-size: 0.85em;
}

.agents-detail-status {
  color: var(--muted);
  margin-top: 2px;
}

.agents-detail-tabs {
  flex-wrap: wrap;
  margin-top: 14px;
}

.agents-view-tabs {
  margin-bottom: 12px;
}

.agents-search {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 13px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 14px;
}

.agents-search::placeholder {
  color: var(--muted-soft);
}

.agents-empty-search {
  color: var(--muted-soft);
  text-align: center;
  padding: 20px 0;
}

.agents-graph {
  display: flex;
  justify-content: center;
  padding: 8px 0 4px;
}

.agents-graph-svg {
  width: 100%;
  max-width: 460px;
  height: auto;
}

.agents-graph-edge {
  stroke: var(--line);
  stroke-width: 1.5;
}

.agents-graph-core {
  fill: var(--brand);
  filter: drop-shadow(0 0 10px rgba(133, 119, 242, 0.55));
}

.agents-graph-core-label {
  fill: var(--ink-strong);
  font-size: 12px;
  font-weight: 700;
}

.agents-graph-node {
  cursor: pointer;
}

.agents-graph-node:focus-visible .agents-graph-dot {
  stroke: var(--accent);
  stroke-width: 2;
}

.agents-graph-dot {
  fill: var(--surface-raised);
  stroke: var(--line);
  stroke-width: 1.5;
  transition: transform 0.15s ease;
}

.agents-graph-node:hover .agents-graph-dot {
  transform-box: fill-box;
  transform-origin: center;
  transform: scale(1.08);
}

.agents-graph-dot.is-ok {
  fill: rgba(94, 198, 152, 0.18);
  stroke: var(--green);
}

.agents-graph-dot.is-error {
  fill: rgba(234, 122, 110, 0.18);
  stroke: var(--red);
}

.agents-graph-dot.is-idle {
  fill: var(--surface-raised);
  stroke: var(--muted-soft);
}

.agents-graph-label {
  fill: var(--muted);
  font-size: 10px;
}

.knowledge-sources {
  display: grid;
  gap: 8px;
}

.knowledge-source-row {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}

.knowledge-source-title {
  color: var(--ink-strong);
  font-weight: 600;
}

.knowledge-source-desc {
  color: var(--ink);
  font-size: 0.9em;
  margin-top: 3px;
}

.knowledge-source-meta {
  color: var(--muted);
  font-size: 0.8em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.agents-detail-section {
  margin-top: 16px;
}

.agents-detail-section h4 {
  color: var(--muted);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}

.agents-detail-section ul {
  display: grid;
  gap: 4px;
  padding-left: 18px;
  color: var(--ink);
}

.agents-empty-item {
  color: var(--muted-soft);
  list-style: none;
  padding-left: -18px;
  margin-left: -18px;
}

.agents-runs-list {
  display: grid;
  gap: 6px;
}

.agents-run-row {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 0.9em;
}

.agents-runs-loading {
  color: var(--muted-soft);
  font-size: 0.9em;
}
