:root {
  --bg: #eef3f7;
  --panel: #ffffff;
  --panel-2: #f7fafc;
  --text: #18212f;
  --muted: #667085;
  --line: #d9dee8;
  --primary: #0f766e;
  --primary-2: #115e59;
  --success: #14804a;
  --danger: #b42318;
  --warning: #b54708;
  --shadow: 0 8px 22px rgba(20, 30, 50, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

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

.sidebar {
  background: #13202b;
  color: #f8fafc;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: var(--primary);
  font-weight: 700;
}

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

.brand small,
.sidebar-foot {
  color: #b9c4d4;
}

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

.nav a {
  color: #dbe3ee;
  padding: 11px 12px;
  border-radius: 8px;
  font-weight: 600;
}

.nav a.active,
.nav a:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.12);
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-foot a {
  color: #ffffff;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17202d;
}

.login-panel {
  width: min(420px, 100%);
  background: #ffffff;
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--text);
  margin-bottom: 18px;
}

.login-hint {
  margin: 14px 0 0;
  color: var(--muted);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
  min-height: 60px;
}

.menu-button {
  display: none;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-size: 20px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

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

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-actions form {
  margin: 0;
}

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

.panel,
.toolbar-panel {
  padding: 15px;
  margin-bottom: 16px;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  padding: 16px;
}

.stat span,
.mini-stats span,
.muted {
  color: var(--muted);
}

.stat strong {
  display: block;
  font-size: 30px;
  margin-top: 6px;
}

.stat.danger strong {
  color: var(--danger);
}

.grid-two,
.workspace {
  display: grid;
  gap: 16px;
}

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

.workspace {
  grid-template-columns: minmax(0, 1fr) 360px;
  align-items: start;
}

.workspace .side:first-child {
  order: 0;
}

.wide {
  min-width: 0;
}

.side {
  min-width: 0;
}

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

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

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

th {
  color: #344054;
  background: var(--panel-2);
  font-size: 13px;
  position: sticky;
  top: 0;
  z-index: 1;
}

td small {
  display: block;
  color: var(--muted);
  margin-top: 4px;
}

.accounts-table td:first-child {
  min-width: 220px;
}

.snippet {
  max-width: 420px;
  color: #475467;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #edf2f7;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.badge.active {
  color: var(--success);
  background: #e7f6ee;
}

.badge.disabled {
  color: #475467;
  background: #eef1f5;
}

.badge.error {
  color: var(--danger);
  background: #fee4e2;
}

.button,
.icon-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--text);
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.button.small,
.icon-button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 13px;
}

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

.filter-form,
.inline-form,
.message-search {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

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

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 600;
}

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

input,
select {
  min-height: 38px;
  border: 1px solid #cfd6e3;
  border-radius: 8px;
  background: #ffffff;
  padding: 8px 10px;
  color: var(--text);
}

.filter-form input[type="search"] {
  min-width: 260px;
}

.message-search label {
  min-width: 160px;
  flex: 1;
}

.message-search button {
  flex: 0 0 auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 250px;
}

.actions form {
  margin: 0;
}

.edit-row td {
  background: #f8fbfd;
}

.inline-form input,
.inline-form select {
  min-width: 130px;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.empty.large {
  min-height: 220px;
  display: grid;
  place-items: center;
}

.error-text,
.alert {
  color: var(--danger);
}

.alert {
  background: #fff1f0;
  border: 1px solid #fecdca;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.success-alert {
  color: var(--success);
  background: #ecfdf3;
  border-color: #abefc6;
}

.hint-block {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

code,
.code-block {
  background: #f1f5f9;
  border: 1px solid #dbe3ee;
  border-radius: 8px;
}

code {
  padding: 8px;
  display: block;
  word-break: break-all;
}

.code-block {
  padding: 14px;
  overflow-x: auto;
}

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

.mini-stats div {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.mini-stats strong {
  display: block;
  font-size: 22px;
  margin-top: 4px;
}

.settings-list,
.message-meta dl {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 10px;
  margin: 0;
}

.settings-list dt,
.message-meta dt {
  color: var(--muted);
  font-weight: 700;
}

.settings-list dd,
.message-meta dd {
  margin: 0;
  word-break: break-all;
}

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

.scope-list.compact {
  display: flex;
  flex-wrap: wrap;
}

.scope-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  margin: 0 4px 4px 0;
  border-radius: 8px;
  background: #eef6f8;
  color: var(--primary-2);
  font-size: 12px;
  font-weight: 700;
}

.provider-pill {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 2px 8px;
  border-radius: 7px;
  background: #f2f4f7;
  color: #344054;
  font-size: 12px;
  font-weight: 700;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
}

.disabled-link {
  pointer-events: none;
  opacity: 0.5;
}

.mobile-overlay {
  display: none;
}

.message-detail h2 {
  margin: 0 0 14px;
}

.mail-body {
  margin: 18px 0 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  min-height: 260px;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    box-shadow: 18px 0 38px rgba(0, 0, 0, 0.22);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
  }

  body.sidebar-open .mobile-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .menu-button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .nav a {
    text-align: left;
  }

  .workspace,
  .grid-two,
  .stat-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .topbar {
    display: flex;
    align-items: flex-start;
  }

  .topbar h1 {
    font-size: 21px;
  }

  .topbar p {
    font-size: 13px;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .filter-form > *,
  .message-search label,
  .message-search button,
  .stack-form button {
    width: 100%;
  }

  .settings-list,
  .message-meta dl {
    grid-template-columns: 1fr;
  }

  .pagination {
    justify-content: center;
    flex-wrap: wrap;
  }
}
