* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  color: #101828;
  background: #eef3f8;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.admin-login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background:
    linear-gradient(135deg, rgba(37, 99, 235, 0.18), transparent 34%),
    radial-gradient(circle at 82% 20%, rgba(20, 184, 166, 0.16), transparent 28%),
    #f7fafc;
}

.login-card {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid #dbe6f4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #fff;
  background: #2563eb;
  font-weight: 900;
}

.login-card h1 {
  margin: 20px 0 8px;
  font-size: 30px;
}

.login-card p {
  margin: 0 0 24px;
  color: #667085;
  line-height: 1.7;
}

label {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
  color: #344054;
  font-size: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #d0d9e8;
  border-radius: 6px;
  padding: 11px 12px;
  color: #101828;
  background: #fff;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-error {
  min-height: 20px;
  margin: -4px 0 12px !important;
  color: #d92d20 !important;
}

.login-card button,
.primary {
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  color: #fff;
  background: #2563eb;
  font-weight: 800;
  box-shadow: 0 10px 22px rgba(37, 99, 235, 0.22);
}

.login-card button {
  width: 100%;
}

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

.root-sidebar {
  padding: 48px 0 20px;
  background: #fff;
  color: #13233a;
  border-right: 1px solid #e6edf5;
  box-shadow: 8px 0 26px rgba(15, 23, 42, 0.04);
}

.root-brand {
  min-height: 56px;
  padding: 0 32px;
  margin-bottom: 48px;
  color: #1594df;
}

.root-brand strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 27px;
  font-weight: 900;
  letter-spacing: 0;
}

.nav-item {
  width: 100%;
  border: 0;
  border-radius: 0;
  min-height: 50px;
  padding: 0 32px 0 52px;
  text-align: left;
  color: #13233a;
  background: transparent;
  font-size: 17px;
  font-weight: 500;
}

.nav-item.active,
.nav-item:hover {
  color: #13233a;
  background: #f2f4f7;
  box-shadow: inset 4px 0 0 #1594df;
}

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

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

.eyebrow {
  display: block;
  color: #2563eb;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.root-topbar h1 {
  margin: 4px 0 0;
  font-size: 30px;
}

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

.ghost-link,
.top-actions button,
.ghost {
  border: 1px solid #cfd9ea;
  border-radius: 6px;
  padding: 10px 14px;
  color: #1d4ed8;
  background: #fff;
  text-decoration: none;
  font-weight: 800;
}

.top-actions button {
  color: #d92d20;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

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

.metric-grid article,
.relation-board,
.table-wrap,
.settings-grid {
  border: 1px solid #dce6f3;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.06);
}

.metric-grid article {
  padding: 18px;
}

.metric-grid span,
.metric-grid small {
  color: #667085;
}

.metric-grid strong {
  display: block;
  margin: 8px 0;
  font-size: 34px;
}

.relation-board {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(340px, 1.2fr);
  gap: 22px;
  padding: 24px;
}

.relation-board h2,
.section-head h2 {
  margin: 0 0 8px;
}

.relation-board p,
.section-head p {
  margin: 0;
  color: #667085;
  line-height: 1.7;
}

.flow-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.flow-line span {
  border: 1px solid #cbd7e8;
  border-radius: 6px;
  padding: 11px 12px;
  background: #f8fbff;
  font-weight: 800;
}

.flow-line i {
  width: 28px;
  height: 2px;
  background: #2563eb;
}

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

.section-head.slim {
  align-items: end;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 15px 16px;
  border-bottom: 1px solid #e4ebf5;
  text-align: left;
  vertical-align: middle;
}

th {
  color: #475467;
  background: #f8fafc;
  font-size: 14px;
}

td {
  background: #fff;
}

.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
}

.status-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #12b76a;
}

.status-dot.disabled::before {
  background: #98a2b3;
}

.storage-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid #d7e3f4;
  border-radius: 999px;
  padding: 0 10px;
  color: #1d4ed8;
  background: #f4f8ff;
  font-size: 13px;
  font-weight: 800;
}

.storage-badge.cache {
  color: #047857;
  border-color: #bde7d5;
  background: #ecfdf5;
}

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

.row-actions button,
.row-actions a {
  border: 1px solid #d5deeb;
  border-radius: 6px;
  padding: 8px 10px;
  color: #1d4ed8;
  background: #fff;
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
}

.row-actions .danger {
  color: #d92d20;
}

.row-actions .warn {
  color: #b45309;
  border-color: #f3d19b;
  background: #fff8eb;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(320px, 1fr);
  gap: 24px;
  padding: 22px;
}

.settings-form {
  display: grid;
  align-content: start;
}

.preview-card {
  min-height: 300px;
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid #d5e0ee;
  border-radius: 8px;
  background: #f8fbff;
}

.preview-card.ink {
  background: #111827;
  color: #fff;
}

.preview-card.mint {
  background: #effcf7;
}

.preview-side {
  padding: 16px;
  background: rgba(37, 99, 235, 0.08);
}

.preview-side span {
  display: block;
  height: 42px;
  margin-bottom: 10px;
  border-radius: 6px;
  background: rgba(37, 99, 235, 0.18);
}

.preview-chat {
  padding: 18px;
}

.preview-chat header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 18px;
}

.preview-chat em {
  color: #12b76a;
  font-style: normal;
  font-weight: 900;
}

.bubble {
  max-width: 76%;
  margin: 12px 0;
  padding: 11px 13px;
  border-radius: 8px;
  background: #e8eef7;
}

.bubble.user {
  margin-left: auto;
  color: #fff;
  background: var(--accent, #2563eb);
}

.bubble.system {
  font-size: 13px;
  color: #475467;
  background: #f2f4f7;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.38);
}

.modal-card {
  width: min(520px, 100%);
  position: relative;
  padding: 24px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(15, 23, 42, 0.25);
}

.modal-card h2 {
  margin: 0 0 18px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: #f2f4f7;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 30;
  transform: translateX(-50%) translateY(18px);
  opacity: 0;
  pointer-events: none;
  border-radius: 999px;
  padding: 10px 18px;
  color: #fff;
  background: #101828;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .root-sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 12px;
  }

  .root-brand {
    min-width: 190px;
    margin: 0 10px 0 0;
    padding: 0;
  }

  .root-brand strong {
    font-size: 19px;
  }

  .nav-item {
    width: auto;
    min-width: max-content;
    border-radius: 8px;
    padding: 0 14px;
  }

  .nav-item.active,
  .nav-item:hover {
    box-shadow: inset 0 -3px 0 #1594df;
  }

  .metric-grid,
  .relation-board,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .root-topbar,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* Responsive polish for admin control center */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.table-wrap {
  -webkit-overflow-scrolling: touch;
}

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

  .relation-board,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  body {
    min-height: 100dvh;
  }

  .admin-login {
    min-height: 100dvh;
    padding: 16px;
    place-items: center;
  }

  .login-card {
    padding: 22px;
    border-radius: 8px;
    box-shadow: 0 18px 52px rgba(15, 23, 42, 0.12);
  }

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

  .login-card p {
    margin-bottom: 18px;
    font-size: 14px;
  }

  .admin-shell {
    min-height: 100dvh;
  }

  .root-sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    max-width: 100vw;
    border-right: 0;
    border-bottom: 1px solid #e6edf5;
    padding: 10px;
    gap: 6px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.06);
    scrollbar-width: none;
  }

  .root-sidebar::-webkit-scrollbar {
    display: none;
  }

  .root-brand {
    flex: 0 0 auto;
    min-width: 136px;
    max-width: 184px;
    min-height: 42px;
    display: flex;
    align-items: center;
    margin: 0 4px 0 0;
    padding: 0 4px;
  }

  .root-brand strong {
    font-size: 18px;
  }

  .nav-item {
    flex: 0 0 auto;
    min-height: 40px;
    min-width: auto;
    padding: 0 12px;
    border-radius: 7px;
    white-space: nowrap;
    font-size: 14px;
  }

  .root-main {
    padding: 14px 12px 22px;
  }

  .root-topbar {
    gap: 12px;
    margin-bottom: 16px;
  }

  .root-topbar h1 {
    font-size: 23px;
  }

  .top-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 92px;
    gap: 8px;
  }

  .ghost-link,
  .top-actions button,
  .ghost,
  .primary {
    min-height: 40px;
    padding: 9px 12px;
    text-align: center;
  }

  .metric-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .metric-grid article {
    padding: 14px;
  }

  .metric-grid strong {
    margin: 6px 0;
    font-size: 27px;
  }

  .relation-board,
  .settings-grid {
    padding: 16px;
    gap: 16px;
  }

  .relation-board p,
  .section-head p {
    font-size: 13px;
    line-height: 1.65;
  }

  .flow-line {
    align-items: stretch;
    gap: 8px;
  }

  .flow-line span {
    width: 100%;
    padding: 10px;
    font-size: 13px;
  }

  .flow-line i {
    display: none;
  }

  .section-head {
    gap: 10px;
  }

  .section-head .primary {
    width: 100%;
  }

  table {
    min-width: 980px;
  }

  th,
  td {
    padding: 12px 10px;
    font-size: 13px;
  }

  .row-actions {
    gap: 6px;
  }

  .row-actions button,
  .row-actions a {
    min-height: 32px;
    padding: 7px 9px;
  }

  .preview-card {
    min-height: 236px;
    grid-template-columns: 1fr;
  }

  .preview-side {
    display: none;
  }

  .preview-chat {
    padding: 14px;
  }

  .modal {
    align-items: end;
    justify-items: stretch;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    padding: 20px 16px 0;
  }

  .modal-card h2 {
    padding-right: 44px;
    font-size: 18px;
  }

  .two-col {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
    margin: 18px -16px 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: #fff;
    border-top: 1px solid #e6edf5;
  }

  .modal-actions button {
    flex: 1;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: auto;
    transform: translateY(18px);
    text-align: center;
  }

  .toast.show {
    transform: translateY(0);
  }
}

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

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