:root {
  --night: #0B1320;
  --blue: #2563FF;
  --slate: #6B7280;
  --light: #F3F4F6;
  --background: #F3F4F6;
  --surface: #ffffff;
  --surface-muted: #F3F4F6;
  --text: #0B1320;
  --muted: #6B7280;
  --line: #dde3ea;
  --primary: #2563FF;
  --primary-dark: #174BEF;
  --danger: #be123c;
  --warning: #a16207;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(11 19 32 / 8%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.auth-page {
  align-items: center;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 65%), rgb(243 244 246 / 92%)),
    var(--light);
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

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

.auth-card {
  margin: 0 auto;
  max-width: 480px;
  padding: 28px;
  width: 100%;
}

.brand {
  color: var(--night);
  font-size: 24px;
  font-weight: 800;
  margin: 0 0 8px;
}

.logo-on-dark img,
.logo-on-light img {
  display: block;
  object-fit: contain;
}

.auth-logo {
  align-items: center;
  border-radius: var(--radius);
  display: flex;
  height: 118px;
  justify-content: center;
  margin: 0 auto 22px;
  overflow: hidden;
  padding: 12px;
  width: 210px;
}

.auth-logo img {
  height: 94px;
  width: 160px;
}

.sidebar-logo {
  align-items: center;
  display: flex;
  height: 96px;
  justify-content: center;
  margin-bottom: 26px;
}

.sidebar-logo img {
  height: 76px;
  width: 128px;
}

.brand-logo {
  align-items: center;
  display: flex;
  height: 92px;
  justify-content: flex-start;
  margin: 0 0 10px;
  overflow: hidden;
  width: 170px;
}

.brand-logo img {
  height: 92px;
  object-position: left center;
  width: 138px;
}

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

.field {
  display: grid;
  gap: 7px;
  margin: 16px 0;
}

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

input {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

textarea {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 120px;
  padding: 9px 11px;
  resize: vertical;
  width: 100%;
}

select {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

input:focus {
  border-color: var(--primary);
  outline: 3px solid rgb(37 99 255 / 18%);
}

select:focus,
textarea:focus {
  border-color: var(--primary);
  outline: 3px solid rgb(37 99 255 / 18%);
}

.button {
  align-items: center;
  background: var(--primary);
  border: 0;
  border-radius: var(--radius);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
}

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

.button.secondary {
  background: var(--surface-muted);
  color: var(--text);
}

.button-small {
  min-height: 34px;
  padding: 7px 10px;
}

.button.danger {
  background: #fee2e2;
  color: var(--danger);
}

.button:disabled {
  cursor: progress;
  opacity: 0.7;
}

.secret-copy-row {
  align-items: center;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-top: 14px;
}

.secret-copy-row input {
  font-family: Consolas, "Courier New", monospace;
  min-width: 0;
}

.secret-panel {
  border-color: rgb(37 99 255 / 45%);
}

.postman-create-grid {
  grid-template-columns: minmax(220px, 1fr) auto;
}

.postman-device-row > div {
  display: grid;
  gap: 4px;
}

.postman-device-title {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.status-dot {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

.status-dot.active {
  background: #dcfce7;
  color: #166534;
}

.status-dot.revoked {
  background: var(--surface-muted);
  color: var(--muted);
}

.message {
  border-radius: var(--radius);
  margin-top: 14px;
  padding: 10px 12px;
}

.message.error {
  background: #ffe4e6;
  color: var(--danger);
}

.message.success {
  background: #e8efff;
  color: var(--primary-dark);
}

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

.sidebar {
  background: var(--night);
  color: #ffffff;
  padding: 24px 18px;
}

.sidebar .brand {
  margin-bottom: 28px;
}

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

.nav a,
.logout-button {
  border-radius: var(--radius);
  color: #dbe4f2;
  display: block;
  padding: 10px 12px;
  text-align: left;
}

.nav a:hover,
.logout-button:hover {
  background: rgb(37 99 255 / 18%);
  color: #ffffff;
}

.logout-form {
  margin-top: 18px;
}

.logout-button {
  background: transparent;
  border: 0;
  cursor: pointer;
  width: 100%;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 28px;
}

.page {
  padding: 28px;
}

.page-header {
  align-items: flex-end;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-header h1 {
  font-size: 28px;
  margin: 0;
}

.page-header p {
  color: var(--muted);
  margin: 4px 0 0;
}

.badge {
  background: #e8efff;
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 10px;
}

.metric-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 22px;
}

.metric {
  padding: 16px;
}

.metric-link {
  display: block;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.metric-link:hover,
.metric-link:focus {
  border-color: rgb(37 99 255 / 45%);
  box-shadow: 0 8px 18px rgb(11 19 32 / 10%);
  outline: 0;
  transform: translateY(-1px);
}

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

.metric strong {
  display: block;
  font-size: 30px;
  margin-top: 8px;
}

.panel {
  margin-bottom: 18px;
}

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

.panel-header-actions {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  font-size: 16px;
  margin: 0;
}

.panel-body {
  padding: 16px;
}

.list {
  display: grid;
  margin: 0;
  padding: 0;
}

.list-item {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 4px;
  list-style: none;
  padding: 14px 16px;
}

.list-item:last-child {
  border-bottom: 0;
}

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

.device-row {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.form-grid {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 14px;
}

.form-grid .field {
  margin: 0;
}

.form-section-title {
  color: var(--night);
  font-size: 13px;
  font-weight: 800;
  margin: 18px 0 10px;
  text-transform: uppercase;
}

.full-field {
  grid-column: 1 / -1;
}

.filter-grid {
  align-items: end;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto;
}

.filter-grid .field {
  margin: 0;
}

.task-filter-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px) auto auto auto auto;
}

.watcher-filter-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) minmax(160px, 220px) auto;
}

.bridge-filter-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) minmax(160px, 220px) auto;
}

.mailer-settings-grid {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}

.mailer-test-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) auto;
}

.mailer-log-filter-grid {
  grid-template-columns: minmax(220px, 1fr) minmax(160px, 220px) minmax(160px, 220px) auto;
}

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

.check-field input {
  min-height: auto;
  width: auto;
}

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

.invite-box {
  background: #e8efff;
  border: 1px solid rgb(37 99 255 / 18%);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
  padding: 14px 16px;
}

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

.readonly-link {
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
}

.user-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

.user-main,
.client-main {
  min-width: 0;
}

.user-title,
.user-meta,
.user-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.user-title {
  margin-bottom: 2px;
}

.user-meta {
  margin-top: 6px;
}

.inline-form {
  margin: 0;
}

.status-pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

.status-pill.status-active {
  background: #dcfce7;
  color: #166534;
}

.status-pill.status-pending {
  background: #fef3c7;
  color: #92400e;
}

.status-pill.status-disabled {
  background: #e5e7eb;
  color: var(--slate);
}

.client-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

.client-status-active {
  background: #dcfce7;
  color: #166534;
}

.client-status-prospect {
  background: #e8efff;
  color: var(--primary-dark);
}

.client-status-paused {
  background: #fef3c7;
  color: #92400e;
}

.client-status-archived {
  background: #e5e7eb;
  color: var(--slate);
}

.task-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.watcher-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.bridge-row {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

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

.mail-row {
  grid-template-columns: minmax(0, 1fr);
}

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

.watcher-level-info {
  background: #e8efff;
  color: var(--primary-dark);
}

.bridge-status-received,
.bridge-status-accepted {
  background: #e8efff;
  color: var(--primary-dark);
}

.bridge-status-processed {
  background: #dcfce7;
  color: #166534;
}

.bridge-status-rejected {
  background: #fef3c7;
  color: #92400e;
}

.bridge-status-failed {
  background: #fee2e2;
  color: var(--danger);
}

.mail-status-sent {
  background: #dcfce7;
  color: #166534;
}

.mail-status-failed {
  background: #fee2e2;
  color: var(--danger);
}

.watcher-level-audit {
  background: #dcfce7;
  color: #166534;
}

.watcher-level-warning {
  background: #fef3c7;
  color: #92400e;
}

.watcher-level-error,
.watcher-level-critical {
  background: #fee2e2;
  color: var(--danger);
}

.watcher-level-security {
  background: var(--night);
  color: #ffffff;
}

.task-status-open {
  background: #e8efff;
  color: var(--primary-dark);
}

.task-status-in_progress {
  background: #dcfce7;
  color: #166534;
}

.task-status-waiting {
  background: #fef3c7;
  color: #92400e;
}

.task-status-done {
  background: #e5e7eb;
  color: var(--slate);
}

.task-status-cancelled {
  background: #fee2e2;
  color: var(--danger);
}

.task-priority-low {
  background: #e5e7eb;
  color: var(--slate);
}

.task-priority-normal {
  background: #e8efff;
  color: var(--primary-dark);
}

.task-priority-high {
  background: #fef3c7;
  color: #92400e;
}

.task-priority-urgent {
  background: #fee2e2;
  color: var(--danger);
}

.subscription-status-none,
.subscription-status-ended {
  background: #e5e7eb;
  color: var(--slate);
}

.subscription-status-pending {
  background: #fef3c7;
  color: #92400e;
}

.subscription-status-active {
  background: #dcfce7;
  color: #166534;
}

.subscription-status-paused {
  background: #fee2e2;
  color: var(--danger);
}

.detail-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.detail-grid div {
  display: grid;
  gap: 4px;
}

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

.detail-grid strong {
  font-size: 15px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.compact-actions {
  margin-top: 0;
}

.text-link {
  color: var(--primary-dark);
  font-weight: 800;
}

.metadata-box {
  background: var(--surface-muted);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0;
  max-width: 100%;
  overflow-x: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.preserve-lines {
  margin: 0;
  white-space: pre-wrap;
}

.note-form {
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 16px;
}

.communication-thread {
  display: grid;
  gap: 12px;
}

.communication-empty {
  background: var(--surface-muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 4px;
  padding: 14px;
}

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

.communication-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  max-width: min(780px, 84%);
  padding: 12px;
}

.communication-message-inbound {
  background: #ffffff;
  justify-self: start;
}

.communication-message-outbound {
  background: #e8efff;
  border-color: rgb(37 99 255 / 20%);
  justify-self: end;
}

.communication-message-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.communication-reply {
  color: var(--primary-dark);
  font-size: 13px;
  font-weight: 800;
  margin-left: auto;
}

.communication-language,
.communication-meta {
  color: var(--muted);
  font-size: 13px;
}

.communication-body {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.communication-translation {
  border-left: 3px solid var(--primary);
  display: grid;
  gap: 6px;
  padding-left: 10px;
}

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

.communication-direction-inbound {
  background: #dcfce7;
  color: #166534;
}

.communication-direction-outbound {
  background: #e8efff;
  color: var(--primary-dark);
}

.email-compose {
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 16px;
}

.email-compose-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 14px;
}

.email-compose-header div {
  display: grid;
  gap: 4px;
}

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

.event-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
}

.event-item {
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr);
  list-style: none;
  padding: 12px;
}

.event-item p {
  color: var(--text);
  margin: 6px 0;
}

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

.event-type {
  background: #e8efff;
  border-radius: 999px;
  color: var(--primary-dark);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 3px 8px;
}

.event-type-note {
  background: var(--surface-muted);
  color: var(--night);
}

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

  .sidebar {
    padding: 18px;
  }

  .page-header,
  .panel-header-actions,
  .device-row,
  .form-grid,
  .filter-grid,
  .user-row,
  .client-row,
  .task-row,
  .watcher-row,
  .bridge-row,
  .mail-row,
  .event-item {
    display: grid;
    grid-template-columns: 1fr;
  }

  .communication-message {
    max-width: 100%;
  }

  .communication-reply {
    margin-left: 0;
  }
}
