:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f5;
  --ink: #18212b;
  --muted: #627080;
  --line: #d9e0e7;
  --brand: #225a70;
  --brand-strong: #123f52;
  --green: #17865a;
  --amber: #a96800;
  --red: #bd3429;
  --blue: #2a67b1;
  --shadow: 0 14px 35px rgba(22, 33, 43, 0.08);
  --radius: 8px;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
  --sans: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-color: rgba(98, 112, 128, 0.48) transparent;
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}

*::-webkit-scrollbar-thumb {
  min-height: 44px;
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(98, 112, 128, 0.48);
  background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(34, 90, 112, 0.68);
  background-clip: padding-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
}

.login-screen {
  height: 100dvh;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #173744;
}

.login-card {
  position: relative;
  display: grid;
  width: min(420px, 100%);
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 26px;
  box-shadow: var(--shadow);
}

.language-toggle {
  white-space: nowrap;
}

.login-language-toggle {
  justify-self: end;
  min-height: 30px;
  border: 1px solid #aac9d5;
  border-radius: 999px;
  padding: 4px 10px;
  background: #e9f3f6;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.login-logo {
  display: block;
  width: 76px;
  height: 76px;
}

.login-card h1 {
  margin: 0;
  font-size: 24px;
}

.login-card p {
  margin: 0;
  color: var(--muted);
}

.login-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 76px minmax(0, 1fr);
}

.sidebar {
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  color: #eef8fa;
  background: #173744;
}

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

.brand-home {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.brand-home:hover .brand-name,
.brand-home:focus-visible .brand-name {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.brand-home:focus-visible {
  border-radius: var(--radius);
  outline: 2px solid rgba(233, 243, 246, 0.72);
  outline-offset: 4px;
}

.sidebar-toggle {
  display: grid;
  width: 38px;
  height: 34px;
  min-height: 34px;
  place-items: center;
  margin-left: auto;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
  color: #eef8fa;
  font-size: 16px;
  font-weight: 800;
}

.sidebar-toggle:hover {
  border-color: rgba(255, 255, 255, 0.36);
  background: rgba(255, 255, 255, 0.14);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: var(--radius);
  background: #2d7085;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-mark.logo-mark {
  border: 0;
  background: transparent;
}

.brand-logo {
  display: block;
  width: 42px;
  height: 42px;
}

.brand-name {
  display: block;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.25;
}

.brand-subtitle {
  display: block;
  margin-top: 2px;
  color: #b6cdd4;
  font-size: 12px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: #ffffff;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-list {
  display: grid;
  flex: 1 1 auto;
  gap: 4px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-color: rgba(207, 226, 232, 0.5) transparent;
  scrollbar-width: thin;
}

.sidebar::-webkit-scrollbar,
.nav-list::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.sidebar::-webkit-scrollbar-thumb,
.nav-list::-webkit-scrollbar-thumb {
  border-width: 2px;
  background: rgba(207, 226, 232, 0.48);
  background-clip: padding-box;
}

.sidebar::-webkit-scrollbar-thumb:hover,
.nav-list::-webkit-scrollbar-thumb:hover {
  background: rgba(233, 243, 246, 0.74);
  background-clip: padding-box;
}

.nav-item {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  color: #d9e8ec;
  background: transparent;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.sidebar-collapsed .sidebar {
  padding-inline: 10px;
}

.sidebar-collapsed .brand {
  justify-content: center;
  padding-inline: 0;
}

.sidebar-collapsed .brand-text {
  display: none;
}

.sidebar-collapsed .sidebar-toggle {
  position: absolute;
  top: 62px;
  left: 10px;
  width: 56px;
  margin: 0;
  font-size: 16px;
}

.sidebar-collapsed .nav-list {
  margin-top: 28px;
}

.sidebar-collapsed .sidebar-user {
  justify-content: center;
  width: 56px;
  min-height: 34px;
  padding: 7px;
  font-size: 0;
}

.sidebar-collapsed .sidebar-user::before {
  content: attr(data-initials);
  display: grid;
  width: 28px;
  height: 24px;
  place-items: center;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.sidebar-collapsed .nav-item {
  grid-template-columns: 1fr;
  justify-items: center;
  padding: 7px;
  font-size: 0;
}

.sidebar-collapsed .nav-item .nav-icon {
  font-size: 18px;
}

.sidebar-collapsed .nav-item .nav-label {
  display: none;
}

.sidebar-collapsed .sidebar-footer span {
  display: none;
}

.nav-item .nav-icon {
  display: grid;
  width: 34px;
  height: 30px;
  place-items: center;
  border-radius: 0;
  background: transparent;
  color: #cce0e6;
  font-size: 17px;
  line-height: 1;
}

.nav-item .nav-label {
  min-width: 0;
  background: transparent;
}

.nav-item:hover {
  color: #fff;
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.06);
}

.nav-item.active {
  color: #fff;
  border-color: #8fd4e8;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 4px 0 0 #e9f3f6;
}

.nav-item.active .nav-icon {
  background: transparent;
  color: #ffffff;
}

.nav-logout {
  margin-top: 10px;
  border-color: rgba(255, 255, 255, 0.22);
}

.language-nav-item {
  margin-top: 10px;
}

.sidebar-footer {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 9px;
  margin-top: auto;
  padding: 12px 9px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius);
  color: #cfe2e8;
  font-size: 13px;
}

.health-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--amber);
}

.health-dot.good {
  background: var(--green);
}

.health-dot.bad {
  background: var(--red);
}

.main-shell {
  display: flex;
  height: 100dvh;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  flex-direction: column;
}

.global-status-strip {
  flex: 0 0 auto;
  z-index: 8;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
  padding: 7px 24px;
  border-bottom: 1px solid var(--line);
  background: #f9fbfc;
}

.global-status-item {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  background: var(--surface);
}

.global-status-item.good {
  border-color: #bfe7d4;
  color: #0f6a43;
  background: #e7f7ef;
}

.global-status-item.warn {
  border-color: #f1d69b;
  color: #7a5100;
  background: #fff6df;
}

.global-status-item.bad {
  border-color: #f0b9b2;
  color: #9c2018;
  background: #ffe8e5;
}

.global-status-action {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid #aac9d5;
  border-radius: 999px;
  padding: 3px 10px;
  background: #e9f3f6;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 800;
}

.global-status-action:hover,
.global-status-action:focus-visible {
  border-color: var(--brand);
  background: #d9ecf2;
  outline: none;
}

.global-status-action.is-running,
.action-button.is-running,
.primary-button.is-running,
.ghost-button.is-running {
  border-color: #bfe7d4;
  background: #e7f7ef;
  color: #0f6a43;
  cursor: wait;
}

.global-status-action:disabled,
.action-button:disabled,
.primary-button:disabled,
.ghost-button:disabled {
  opacity: 0.78;
}

.topbar {
  flex: 0 0 auto;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 78px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 248, 0.96);
  backdrop-filter: blur(10px);
}

.topbar-actions {
  display: none;
  align-items: center;
  gap: 10px;
}

#current-user {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.page-heading h1 {
  margin: 0 0 4px;
  font-size: 24px;
  line-height: 1.2;
  letter-spacing: 0;
}

.page-heading div {
  color: var(--muted);
  font-size: 13px;
}

.inline-filter input,
.inline-filter select,
.limit-input {
  height: 34px;
  min-width: 90px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px 24px 34px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

.metric {
  min-width: 0;
  min-height: 62px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-bad {
  border-color: #f3b6b1;
  background: #fff7f6;
}

.metric-bad .metric-value,
.metric-bad .metric-label {
  color: var(--red);
}

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

.metric-icon {
  color: #8ca0ad;
  font-size: 13px;
  line-height: 1;
}

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

.metric-clickable {
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.metric-clickable:hover,
.metric-clickable:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 16px 32px rgba(12, 51, 63, 0.14);
  outline: none;
  transform: translateY(-1px);
}

.metric-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric-value {
  margin-top: 3px;
  font-size: 21px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0;
}

.metric-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.15;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 54px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.panel-header h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
}

.link-row a {
  color: var(--brand);
  text-decoration: none;
}

.link-row a:hover {
  text-decoration: underline;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.wide-panel {
  grid-column: 1 / -1;
}

.flash-change {
  animation: flash-change 2.6s ease-out;
}

@keyframes flash-change {
  0% {
    background-color: #fff1b8;
  }
  100% {
    background-color: inherit;
  }
}

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

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

.data-form,
.inline-form {
  padding: 0 14px 14px;
}

.data-form .panel-header {
  margin: 0 -14px 12px;
}

label {
  display: grid;
  gap: 5px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

label input,
label select,
label textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.field-label {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

.permission-option {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px 10px;
  color: var(--ink);
}

.permission-option input {
  width: auto;
}

.code-input,
pre,
code {
  font-family: var(--mono);
}

.code-input {
  min-height: 120px;
}

.inline-form {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 10px;
  padding-top: 12px;
}

.inline-form label {
  min-width: 220px;
  margin: 0;
}

.control-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.inline-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.inline-filter input {
  width: 86px;
}

.member-group-select {
  min-height: 34px;
  min-width: 260px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

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

.primary-button,
.action-button,
.ghost-button,
.icon-button {
  min-height: 34px;
  border-radius: var(--radius);
  font-weight: 700;
}

.primary-button,
.action-button {
  border: 1px solid var(--brand-strong);
  background: var(--brand);
  color: #fff;
  padding: 8px 12px;
}

.action-button {
  background: #1d6274;
}

.action-button.danger {
  border-color: #8e2018;
  background: var(--red);
}

.inline-action-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--brand-strong);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.inline-action-button:hover {
  background: var(--surface-2);
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 7px 11px;
}

.compact-button {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
}

.icon-button {
  min-width: 42px;
}

.primary-button:hover,
.action-button:hover {
  filter: brightness(0.95);
}

.ghost-button:hover,
.icon-button:hover {
  background: var(--surface-2);
}

.tabbar {
  display: flex;
  gap: 6px;
  margin: 16px 0 10px;
}

.tab {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  padding: 7px 12px;
  font-weight: 700;
}

.tab.active {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

.tab-panel {
  display: none;
}

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

.table-wrap {
  overflow: auto;
  max-height: 520px;
}

.data-table-controls,
.data-table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.data-table-controls {
  border-bottom: 1px solid var(--line);
}

.data-table-footer {
  border-top: 1px solid var(--line);
}

.data-table-length,
.data-table-search,
.data-table-select-all {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.data-table-length select,
.data-table-search input {
  width: auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
}

.data-table-search input {
  width: min(260px, 38vw);
}

.data-table-select-all {
  margin-right: auto;
  white-space: nowrap;
}

.data-table-pagination {
  display: flex;
  align-items: center;
  gap: 8px;
}

.data-table-page {
  min-width: 58px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.data-table-page-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.sort-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 24px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  font: inherit;
  font-weight: 800;
  text-transform: uppercase;
}

.sort-button::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 6px solid #a2acb6;
}

.sort-button.asc::after {
  border-top: 0;
  border-bottom: 6px solid var(--brand);
}

.sort-button.desc::after {
  border-top-color: var(--brand);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f8fafb;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

td {
  line-height: 1.35;
}

.data-table th.actions-cell,
.data-table td.actions-cell {
  position: sticky;
  right: 0;
  z-index: 2;
  min-width: 104px;
  width: 104px;
  max-width: 104px;
  background: #fff;
  box-shadow: -1px 0 0 var(--line);
}

.data-table th.actions-cell {
  z-index: 4;
  background: #f8fafb;
}

.data-table tr.offensive-row td.actions-cell {
  background: #fff4f3;
}

.data-table tr.offensive-row td {
  border-bottom-color: #f3c4bf;
  background: #fff4f3;
}

.data-table tr.offensive-row td:first-child {
  box-shadow: inset 4px 0 0 var(--red);
}

.cell-muted {
  color: var(--muted);
}

.cell-id {
  font-family: var(--mono);
  font-size: 12px;
}

.cell-code,
.cell-event-id,
.cell-hash {
  font-family: var(--mono);
  font-size: 12px;
}

.code-chip,
.table-error-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: top;
}

.code-chip {
  white-space: nowrap;
}

.table-error-text {
  overflow-wrap: anywhere;
}

.event-table {
  table-layout: fixed;
  min-width: 860px;
}

.event-table th,
.event-table td {
  max-width: none;
  overflow: hidden;
}

.event-table .cell-event-id {
  width: 220px;
  max-width: 220px;
}

.event-table .cell-hash {
  width: 120px;
  max-width: 120px;
}

.event-table .cell-code {
  width: 96px;
  max-width: 96px;
}

.event-table .cell-error {
  width: 220px;
  max-width: 220px;
}

.row-actions {
  min-width: 82px;
}

.action-menu {
  position: relative;
  z-index: 5;
  width: max-content;
}

.action-menu summary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--brand-strong);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 800;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

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

.action-menu summary::after {
  content: "...";
  margin-left: 6px;
  color: var(--muted);
  letter-spacing: 0;
}

.action-menu[open] summary {
  border-color: var(--brand);
  background: #eef6f8;
}

.action-menu-content {
  display: grid;
  gap: 7px;
  min-width: 210px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 12px 28px rgba(22, 33, 43, 0.12);
}

.menu-field {
  display: grid;
  gap: 6px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}

.menu-field:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.menu-field label {
  display: grid;
  gap: 4px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
}

.menu-field select,
.menu-field input {
  height: 30px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 8px;
}

.menu-action {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 6px 9px;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
}

.menu-action:hover {
  background: var(--surface-2);
}

.menu-action.danger {
  border-color: #f0c7c2;
  color: var(--red);
}

.menu-action.danger:hover {
  background: #fff0ee;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 31, 42, 0.48);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: min(620px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(10, 20, 30, 0.28);
}

.json-modal {
  width: min(920px, 100%);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 58px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfd;
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
}

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

.modal-form {
  padding: 6px 16px 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #e7edf1;
  color: #31414e;
  font-size: 12px;
  font-weight: 750;
}

.pill.good {
  background: #dff2ea;
  color: #116947;
}

.pill.warn {
  background: #fff1d6;
  color: #8a5400;
}

.pill.bad {
  background: #fde2df;
  color: #a1251c;
}

.pill.info {
  background: #e2edf9;
  color: #23588f;
}

.pill.agent {
  background: #e7ddfb;
  color: #5b2b91;
}

.pill.customer {
  background: #dff2ea;
  color: #116947;
}

.pill.neutral {
  background: #e7edf1;
  color: #31414e;
}

.pill.dark {
  background: #25313b;
  color: #ffffff;
}

.pill-list {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-panel {
  margin-top: 14px;
}

.chat-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 14px;
  margin-top: 14px;
  align-items: start;
}

.chat-workspace .chat-panel {
  margin-top: 0;
}

.chat-analysis-panel {
  position: sticky;
  top: 14px;
}

.chat-view {
  height: calc(100vh - 245px);
  min-height: 420px;
  overflow: auto;
  padding: 18px;
  background: #edf3f1;
}

.chat-day {
  width: fit-content;
  margin: 10px auto;
  border-radius: 999px;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chat-message {
  width: min(680px, 78%);
  margin: 8px 0;
  border: 1px solid rgba(24, 33, 43, 0.08);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--chat-bubble-bg, #ffffff);
  box-shadow: 0 6px 18px rgba(24, 33, 43, 0.06);
}

.chat-message.outgoing {
  margin-left: auto;
}

.chat-message.unknown {
  background: #f7f8fa;
}

.chat-message.highlight {
  outline: 3px solid rgba(29, 98, 116, 0.38);
  box-shadow: 0 0 0 6px rgba(29, 98, 116, 0.12);
}

.chat-message.offensive {
  border-color: #ef9a9a;
  box-shadow: 0 0 0 3px rgba(190, 38, 27, 0.12), 0 8px 20px rgba(190, 38, 27, 0.1);
}

.chat-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.chat-meta .sender-name {
  color: var(--ink);
  font-weight: 800;
}

.chat-text {
  margin-top: 7px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.45;
}

.transcript-text {
  color: #41606f;
  font-style: italic;
}

.chat-media {
  max-width: min(520px, 100%);
  margin-top: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
}

.chat-media-image,
.chat-media-video {
  display: block;
  width: 100%;
  max-height: 380px;
  object-fit: contain;
  background: #f8fafb;
}

.chat-media-audio {
  display: block;
  width: 100%;
  min-width: 280px;
  padding: 8px;
}

.chat-media a {
  display: inline-flex;
  padding: 10px 12px;
  color: var(--brand-strong);
  font-weight: 800;
}

.chat-media.media-error {
  padding: 10px 12px;
  color: var(--red);
  font-weight: 800;
}

.chat-media-description {
  margin-top: 8px;
  border-left: 3px solid var(--brand);
  padding: 8px 10px;
  background: rgba(29, 98, 116, 0.08);
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.42;
}

.chat-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.chat-action-button {
  min-height: 24px;
  border: 1px solid var(--brand);
  border-radius: 999px;
  background: #ffffff;
  color: var(--brand);
  padding: 3px 9px;
  font-size: 12px;
  font-weight: 800;
}

.chat-analysis {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.analysis-title {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 16px;
  font-weight: 850;
  line-height: 1.3;
}

.analysis-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.analysis-participants {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.analysis-participant {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  padding: 5px 9px;
  font-size: 12px;
}

.analysis-participant-role {
  color: var(--muted);
  font-weight: 800;
}

.analysis-participant strong,
.analysis-person {
  font-weight: 900;
}

.analysis-person-customer {
  color: #047857;
}

.analysis-person-agent {
  color: #6d28d9;
}

.analysis-person-unknown {
  color: var(--ink);
}

.analysis-summary {
  margin: 0;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.45;
}

.analysis-facts {
  display: grid;
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.analysis-facts div {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  font-size: 12px;
}

.analysis-facts span {
  color: var(--muted);
  font-weight: 800;
}

.analysis-facts strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.analysis-list {
  display: grid;
  gap: 7px;
}

.analysis-list h3 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.analysis-details summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 850;
}

.analysis-details .json-view {
  max-height: 260px;
  margin-top: 8px;
}

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

.profile-picture {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #e9f1f3;
  color: var(--brand-strong);
  font-size: 10px;
  font-weight: 900;
}

.profile-picture img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sender-phone {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.thread-summary {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.thread-title {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.muted-text {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.person-tag {
  border-radius: 999px;
  padding: 2px 7px;
  background: #fff1d6;
  color: #7b4c00;
  font-size: 11px;
  font-weight: 800;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  font-size: 13px;
}

.json-view {
  overflow: auto;
  max-height: 420px;
  margin: 0;
  padding: 14px;
  background: #101820;
  color: #d9eef0;
  font-size: 12px;
  line-height: 1.45;
}

.json-modal-content {
  max-height: min(680px, calc(100vh - 140px));
  border-radius: 0;
}

.table-details {
  min-width: 260px;
}

.table-details summary {
  cursor: pointer;
  color: var(--brand-strong);
  font-weight: 850;
}

.table-details .json-view {
  max-width: min(720px, 70vw);
  max-height: 360px;
  margin-top: 8px;
}

.failure-error {
  margin-bottom: 8px;
  border-left: 3px solid var(--red);
  padding: 7px 9px;
  background: #fff0ee;
  color: var(--red);
  overflow-wrap: anywhere;
  font-size: 12px;
  font-weight: 800;
}

.key-value {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1px;
  background: var(--line);
}

.key-value div {
  padding: 10px 12px;
  background: #fff;
}

.key-value div:nth-child(odd) {
  color: var(--muted);
  font-weight: 700;
}

#toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  display: none;
  max-width: 520px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #18212b;
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 13px;
}

#toast.show {
  display: block;
}

#toast.error {
  background: #8e2018;
}

[dir="rtl"] body {
  direction: rtl;
}

[dir="rtl"] input,
[dir="rtl"] select,
[dir="rtl"] textarea {
  text-align: right;
}

[dir="rtl"] .json-view,
[dir="rtl"] code,
[dir="rtl"] pre,
[dir="rtl"] .cell-id {
  direction: ltr;
  text-align: left;
}

[dir="rtl"] .nav-item {
  text-align: right;
}

[dir="rtl"] .sidebar-toggle {
  margin-left: 0;
  margin-right: auto;
}

[dir="rtl"] .nav-item.active {
  box-shadow: inset -4px 0 0 #e9f3f6;
}

[dir="rtl"] .data-table th,
[dir="rtl"] .data-table td {
  text-align: right;
}

[dir="rtl"] .data-table th.actions-cell,
[dir="rtl"] .data-table td.actions-cell,
[dir="rtl"] .metric-value {
  text-align: start;
}

[dir="rtl"] .action-menu-content {
  right: auto;
  left: 0;
}

[dir="rtl"] .chat-message.outgoing {
  margin-left: 0;
  margin-right: auto;
}

[dir="rtl"] .chat-message.incoming {
  margin-right: 0;
  margin-left: auto;
}

@media (max-width: 1300px) {
  .metric-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .metric {
    min-height: 60px;
    padding: 7px 8px;
  }

  .metric-value {
    font-size: 19px;
  }

  .metric-note {
    font-size: 8px;
  }

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

@media (max-width: 900px) {
  body {
    min-width: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    max-height: none;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
  }

  .sidebar-collapsed .sidebar {
    padding-inline: 10px;
  }

  .brand,
  .sidebar-collapsed .brand {
    min-width: 42px;
    justify-content: center;
    padding: 0;
    border-bottom: 0;
  }

  .brand-text,
  .sidebar-collapsed .brand-text,
  .sidebar-toggle,
  .sidebar-collapsed .sidebar-toggle,
  .sidebar-user,
  .sidebar-collapsed .sidebar-user,
  .sidebar-footer {
    display: none;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .nav-list {
    display: flex;
    grid-template-columns: none;
    gap: 6px;
    min-height: 0;
    margin: 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    padding: 0 2px 2px;
  }

  .sidebar-collapsed .nav-list {
    margin-top: 0;
  }

  .nav-item,
  .sidebar-collapsed .nav-item {
    flex: 0 0 auto;
    grid-template-columns: 1fr;
    justify-items: center;
    width: 44px;
    min-height: 40px;
    padding: 6px;
    font-size: 0;
  }

  .nav-item .nav-icon,
  .sidebar-collapsed .nav-item .nav-icon {
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  .nav-item .nav-label,
  .sidebar-collapsed .nav-item .nav-label {
    display: none;
  }

  .nav-item.active {
    box-shadow: inset 0 -3px 0 #e9f3f6;
  }

  .main-shell {
    height: 100%;
    min-height: 0;
  }

  .global-status-strip {
    flex-wrap: nowrap;
    gap: 6px;
    min-height: 32px;
    overflow-x: auto;
    padding: 6px 12px;
  }

  .global-status-item,
  .global-status-action {
    flex: 0 0 auto;
    max-width: 82vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    min-height: auto;
    padding: 10px 12px;
  }

  .topbar-actions {
    justify-content: space-between;
  }

  .page-heading h1 {
    font-size: 22px;
  }

  .content {
    padding: 12px;
  }

  .control-strip {
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  .control-strip .action-button,
  .control-strip .ghost-button,
  .control-strip .primary-button {
    min-width: max-content;
  }

  .inline-filter,
  .inline-form {
    align-items: stretch;
    width: 100%;
  }

  .inline-filter {
    flex-direction: column;
    gap: 5px;
  }

  .inline-filter input,
  .inline-filter select,
  .limit-input,
  .member-group-select {
    width: 100%;
    min-width: 0;
  }

  .inline-form label {
    width: 100%;
    min-width: 0;
  }

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

  .dashboard-grid,
  .split-layout,
  .chat-workspace,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 76px;
  }

  .panel-header {
    align-items: stretch;
    flex-direction: column;
    min-height: auto;
  }

  .panel-header .row-actions,
  .row-actions {
    width: 100%;
  }

  .chat-analysis-panel {
    position: static;
  }

  .chat-view {
    height: min(58dvh, 520px);
    min-height: 300px;
    padding: 10px;
  }

  .chat-message,
  .chat-message.outgoing {
    width: 96%;
  }

  .chat-message.outgoing {
    margin-left: 4%;
  }

  .chat-meta {
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .chat-media-audio {
    min-width: 0;
  }

  .data-table-controls,
  .data-table-footer {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
  }

  .data-table-length,
  .data-table-search,
  .data-table-select-all,
  .data-table-search input {
    width: 100%;
  }

  .data-table-pagination {
    justify-content: space-between;
  }

  table {
    font-size: 12px;
  }

  .data-table {
    min-width: 720px;
  }

  th,
  td {
    max-width: 260px;
    padding: 8px 9px;
  }

  .data-table th.actions-cell,
  .data-table td.actions-cell {
    min-width: 90px;
    width: 90px;
    max-width: 90px;
  }

  .thread-title {
    max-width: 220px;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
  }

  .modal-actions {
    flex-wrap: wrap;
  }

  .key-value,
  .analysis-facts div,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .table-details .json-view {
    max-width: 78vw;
  }
}

@media (max-width: 600px) {
  .global-status-strip {
    padding-inline: 8px;
  }

  .topbar {
    padding-inline: 10px;
  }

  .topbar-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  #current-user {
    width: 100%;
  }

  .content {
    padding: 10px 8px 18px;
  }

  .metric-grid {
    gap: 6px;
  }

  .metric {
    min-height: 70px;
    padding: 8px;
  }

  .metric-value {
    font-size: 20px;
  }

  .metric-note {
    font-size: 9px;
  }

  .dashboard-grid {
    gap: 10px;
    margin-top: 10px;
  }

  .panel-header {
    padding: 10px;
  }

  .tabbar {
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .tab {
    flex: 0 0 auto;
  }

  .control-strip {
    overflow-x: auto;
  }

  .chat-workspace {
    gap: 10px;
  }

  .chat-view {
    height: min(56dvh, 480px);
    min-height: 280px;
  }

  .chat-message,
  .chat-message.outgoing {
    width: 100%;
    margin-left: 0;
  }

  .chat-text {
    font-size: 13px;
  }

  .profile-picture {
    width: 24px;
    height: 24px;
    flex-basis: 24px;
  }

  .data-table-search input {
    min-width: 0;
  }

  .data-table-page {
    min-width: 42px;
  }

  .action-menu-content {
    right: 0;
    left: auto;
    min-width: 190px;
  }

  #toast {
    right: 10px;
    bottom: 10px;
    left: 10px;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .brand-mark {
    width: 34px;
    height: 34px;
    font-size: 13px;
  }

  .nav-item,
  .sidebar-collapsed .nav-item {
    width: 40px;
    min-height: 38px;
  }

  .nav-item .nav-icon,
  .sidebar-collapsed .nav-item .nav-icon {
    font-size: 17px;
  }

  .control-strip .action-button,
  .control-strip .ghost-button,
  .control-strip .primary-button {
    min-width: 0;
    white-space: nowrap;
  }

  .login-screen {
    padding: 14px;
  }

  .login-card {
    padding: 20px;
  }

  .login-logo {
    width: 64px;
    height: 64px;
  }
}
