:root {
  color-scheme: light;
  --td-brand-color: #0052d9;
  --td-brand-color-hover: #366ef4;
  --td-brand-color-active: #003cab;
  --td-brand-color-light: #ecf2fe;
  --td-success-color: #2ba471;
  --td-success-color-light: #e8f8f2;
  --td-warning-color: #e37318;
  --td-warning-color-light: #fff3e7;
  --td-error-color: #d54941;
  --td-error-color-light: #fff0ed;
  --td-text-color-primary: rgba(0, 0, 0, .9);
  --td-text-color-secondary: rgba(0, 0, 0, .6);
  --td-text-color-placeholder: rgba(0, 0, 0, .4);
  --td-text-color-disabled: rgba(0, 0, 0, .26);
  --td-bg-color-page: #f3f5f8;
  --td-bg-color-container: #fff;
  --td-bg-color-secondarycontainer: #f3f3f3;
  --td-component-border: #dcdcdc;
  --td-component-stroke: #e7e7e7;
  --td-radius-small: 3px;
  --td-radius-default: 6px;
  --td-radius-medium: 9px;
  --td-shadow-1: 0 1px 3px rgba(0, 0, 0, .08);
  --sidebar-width: 248px;
  --header-height: 64px;
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--td-bg-color-page); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--td-text-color-primary);
  background: var(--td-bg-color-page);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--td-brand-color); text-decoration: none; }
a, button, input, textarea, select { transition: border-color .16s, background-color .16s, color .16s, box-shadow .16s, transform .16s; }

/* SaaS shell */
.saas-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--td-bg-color-container);
  border-right: 1px solid var(--td-component-stroke);
}
.sidebar-brand {
  height: var(--header-height);
  flex: 0 0 var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  color: var(--td-text-color-primary);
  border-bottom: 1px solid var(--td-component-stroke);
}
.brand-mark {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  color: #fff;
  background: linear-gradient(145deg, #006eff, #0046b8);
  border-radius: 9px;
  box-shadow: 0 5px 14px rgba(0, 82, 217, .25);
  font-size: 19px;
  font-weight: 800;
}
.brand-copy { display: grid; line-height: 1.25; }
.brand-copy strong { font-size: 18px; letter-spacing: .03em; }
.brand-copy small { margin-top: 2px; color: var(--td-text-color-secondary); font-size: 11px; }
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 18px;
  scrollbar-width: thin;
}
.nav-section + .nav-section { margin-top: 17px; }
.nav-section-title {
  display: block;
  margin: 0 10px 5px;
  color: var(--td-text-color-placeholder);
  font-size: 12px;
  line-height: 28px;
}
.nav-item {
  position: relative;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 2px 0;
  padding: 8px 12px;
  color: var(--td-text-color-secondary);
  border-radius: var(--td-radius-default);
  font-weight: 500;
}
.nav-item:hover { color: var(--td-text-color-primary); background: var(--td-bg-color-secondarycontainer); }
.nav-item.active {
  color: var(--td-brand-color);
  background: var(--td-brand-color-light);
  font-weight: 600;
}
.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--td-brand-color);
}
.nav-icon {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}
.nav-icon svg { width: 18px; height: 18px; fill: currentColor; }
.sidebar-footer {
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 13px 14px;
  border-top: 1px solid var(--td-component-stroke);
}
.admin-profile { min-width: 0; display: flex; align-items: center; gap: 10px; flex: 1; }
.admin-profile > span:last-child { min-width: 0; display: grid; line-height: 1.35; }
.admin-profile strong, .admin-profile small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-profile strong { font-size: 13px; }
.admin-profile small { color: var(--td-text-color-secondary); font-size: 11px; }
.avatar {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: var(--td-brand-color);
  background: var(--td-brand-color-light);
  font-weight: 700;
}
.sidebar-footer form { margin: 0; }
.sidebar-logout {
  padding: 6px 8px;
  color: var(--td-text-color-secondary);
  background: transparent;
  border: 0;
  font-size: 12px;
  cursor: pointer;
}
.sidebar-logout:hover { color: var(--td-error-color); background: var(--td-error-color-light); }

.workspace { min-height: 100vh; margin-left: var(--sidebar-width); }
.workspace-header {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 28px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--td-component-stroke);
  backdrop-filter: blur(12px);
}
.breadcrumb { min-width: 0; display: flex; align-items: center; gap: 9px; color: var(--td-text-color-placeholder); }
.breadcrumb a { color: var(--td-text-color-secondary); }
.breadcrumb a:hover { color: var(--td-brand-color); }
.breadcrumb strong { overflow: hidden; color: var(--td-text-color-primary); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.header-actions { display: flex; align-items: center; gap: 16px; color: var(--td-text-color-secondary); font-size: 12px; }
.environment-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  color: #187a52;
  background: var(--td-success-color-light);
  border-radius: 999px;
}
.environment-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--td-success-color); box-shadow: 0 0 0 3px rgba(43, 164, 113, .14); }
.workspace-content {
  width: min(100%, 1800px);
  min-height: calc(100vh - var(--header-height));
  padding: 28px 30px 70px;
  margin: 0;
}

/* Page titles and reusable containers */
h1 { margin: 0; color: var(--td-text-color-primary); font-size: 24px; line-height: 1.4; font-weight: 600; letter-spacing: -.01em; }
h1 + p, .page-heading p { max-width: 980px; margin: 7px 0 0; }
h2 { margin: 0; font-size: 17px; line-height: 1.5; font-weight: 600; }
h3 { font-size: 15px; }
p { color: var(--td-text-color-secondary); line-height: 1.75; }
small, .muted { color: var(--td-text-color-secondary); }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.panel, .login-card, .item-card {
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-component-stroke);
  border-radius: var(--td-radius-medium);
  box-shadow: var(--td-shadow-1);
}
.panel { margin-top: 20px; padding: 22px 24px; overflow-x: auto; }
.panel > h2:first-child { margin-bottom: 16px; }
.item-card { padding: 20px; }

/* Dashboard and statistic cards */
.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.stats article {
  position: relative;
  min-height: 112px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
  overflow: hidden;
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-component-stroke);
  border-radius: var(--td-radius-medium);
  box-shadow: var(--td-shadow-1);
}
.stats article::after {
  content: "";
  position: absolute;
  top: -26px;
  right: -18px;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: var(--td-brand-color-light);
}
.stats strong { position: relative; z-index: 1; display: block; color: var(--td-text-color-primary); font-size: 29px; line-height: 1.25; font-weight: 600; }
.stats span { position: relative; z-index: 1; margin-top: 7px; color: var(--td-text-color-secondary); }
.lyric-engine-stats { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
.lyric-engine-stats strong { overflow-wrap: anywhere; font-size: 23px; }
.module-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 16px;
  margin-top: 24px;
}
.module-card {
  position: relative;
  min-height: 150px;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  padding: 21px;
  overflow: hidden;
  color: var(--td-text-color-primary);
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-component-stroke);
  border-radius: var(--td-radius-medium);
  box-shadow: var(--td-shadow-1);
}
.module-card::after {
  content: "→";
  position: absolute;
  top: 18px;
  right: 20px;
  color: var(--td-text-color-placeholder);
  font-size: 19px;
}
.module-card:hover { border-color: #85adf8; box-shadow: 0 7px 18px rgba(0, 82, 217, .1); transform: translateY(-2px); }
.module-card > span { color: var(--td-brand-color); font-size: 13px; font-weight: 600; }
.module-card > strong { padding-right: 30px; font-size: 22px; line-height: 1.35; font-weight: 600; }
.module-card > small { align-self: end; color: var(--td-text-color-secondary); }

/* Forms and buttons */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 18px 20px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: var(--td-text-color-primary); font-size: 13px; font-weight: 500; }
input, textarea, select {
  width: 100%;
  min-height: 36px;
  padding: 7px 11px;
  color: var(--td-text-color-primary);
  background: var(--td-bg-color-container);
  border: 1px solid var(--td-component-border);
  border-radius: var(--td-radius-small);
  outline: none;
  font: inherit;
  font-weight: 400;
}
input::placeholder, textarea::placeholder { color: var(--td-text-color-placeholder); }
input:hover, textarea:hover, select:hover { border-color: #a6a6a6; }
input:focus, textarea:focus, select:focus { border-color: var(--td-brand-color); box-shadow: 0 0 0 2px rgba(0, 82, 217, .12); }
input:disabled { color: var(--td-text-color-disabled); background: var(--td-bg-color-secondarycontainer); cursor: not-allowed; }
textarea { min-height: 88px; resize: vertical; }
button, .button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 16px;
  color: #fff;
  background: var(--td-brand-color);
  border: 1px solid var(--td-brand-color);
  border-radius: var(--td-radius-small);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
}
button:hover, .button:hover { color: #fff; background: var(--td-brand-color-hover); border-color: var(--td-brand-color-hover); }
button:active, .button:active { background: var(--td-brand-color-active); transform: translateY(1px); }
button.danger { background: var(--td-error-color); border-color: var(--td-error-color); }
button.danger:hover { background: #b93630; border-color: #b93630; }
button.quiet {
  color: var(--td-text-color-primary);
  background: var(--td-bg-color-container);
  border-color: var(--td-component-border);
}
button.quiet:hover { color: var(--td-brand-color); background: var(--td-brand-color-light); border-color: #85adf8; }
.button-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 13px;
  color: var(--td-brand-color);
  background: var(--td-bg-color-container);
  border: 1px solid #85adf8;
  border-radius: var(--td-radius-small);
  font-weight: 500;
  white-space: nowrap;
}
.button-link:hover {
  color: var(--td-brand-color-hover);
  background: var(--td-brand-color-light);
}
.check-row { display: flex; align-items: center; gap: 9px; font-weight: 400; }
.check-row input { width: 16px; min-height: 16px; accent-color: var(--td-brand-color); }
.inline-form { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.inline-form label { min-width: 92px; }
.inline-form input { min-width: 100px; flex: 1; }
.actions-stack { min-width: 220px; display: grid; gap: 9px; }

/* Tables, detail lists and status */
table { width: 100%; min-width: 760px; border-spacing: 0; border-collapse: separate; }
th, td { padding: 13px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--td-component-stroke); }
th {
  color: var(--td-text-color-secondary);
  background: #f7f8fa;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 600;
  white-space: nowrap;
}
th:first-child { border-radius: 5px 0 0 0; }
th:last-child { border-radius: 0 5px 0 0; }
tbody tr:hover td { background: #f8faff; }
tbody tr:last-child td { border-bottom: 0; }
code { color: #0052a8; font-family: "Cascadia Mono", Consolas, monospace; }
.hash { display: inline-block; max-width: 340px; overflow-wrap: anywhere; font-size: 11px; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  color: var(--td-text-color-secondary);
  background: var(--td-bg-color-secondarycontainer);
  border: 1px solid var(--td-component-stroke);
  border-radius: var(--td-radius-small);
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}
.badge.published { color: #187a52; background: var(--td-success-color-light); border-color: #b5e6d4; }
.badge.danger { color: #a9322c; background: var(--td-error-color-light); border-color: #f3c3be; }
.routes { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 0; margin: 0; border-top: 1px solid var(--td-component-stroke); }
.routes dt, .routes dd { min-height: 44px; margin: 0; padding: 10px 12px; border-bottom: 1px solid var(--td-component-stroke); }
.routes dt { color: var(--td-text-color-secondary); background: #f7f8fa; }
.routes dd { overflow-wrap: anywhere; color: var(--td-text-color-primary); }
.routes dd code, .routes dd:has(code) { color: var(--td-brand-color); }
.cards { display: grid; gap: 14px; }
.item-title, .actions { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.item-title h3 { margin: 0; }
.item-title p { margin: 4px 0; }
.item-card pre, pre { max-height: 260px; overflow: auto; padding: 14px; color: #d8e6ff; background: #1e2738; border-radius: var(--td-radius-default); white-space: pre-wrap; }
.device-license-row { display: flex; justify-content: space-between; gap: 24px; margin-top: 17px; padding-top: 17px; border-top: 1px solid var(--td-component-stroke); }

/* Feedback */
.notice {
  position: relative;
  margin: 0 0 18px;
  padding: 11px 14px 11px 40px;
  color: var(--td-text-color-secondary);
  background: #f2f3ff;
  border: 1px solid #d9e1ff;
  border-radius: var(--td-radius-default);
}
.notice::before { content: "i"; position: absolute; top: 11px; left: 14px; width: 18px; height: 18px; display: grid; place-items: center; color: #fff; background: var(--td-brand-color); border-radius: 50%; font: 700 11px/1 serif; }
.notice:empty { display: none; }
.notice.success { color: #187a52; background: var(--td-success-color-light); border-color: #b5e6d4; }
.notice.success::before { content: "✓"; background: var(--td-success-color); }
.notice.error { color: #a9322c; background: var(--td-error-color-light); border-color: #f3c3be; }
.notice.error::before { content: "!"; background: var(--td-error-color); }
.notice.warning { color: #9a4c0e; background: var(--td-warning-color-light); border-color: #f3d4b7; }
.notice.warning::before { content: "!"; background: var(--td-warning-color); }

/* Login */
.login-app { background: #eef3fb; }
.login-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr auto; }
.login-brand { display: flex; align-items: center; gap: 12px; width: max-content; margin: 28px 36px; color: var(--td-text-color-primary); }
.login-brand > span:last-child { display: grid; line-height: 1.25; }
.login-brand strong { font-size: 18px; }
.login-brand small { color: var(--td-text-color-secondary); font-size: 11px; }
.login-content { width: 100%; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(420px, 100%); padding: 34px 36px; box-shadow: 0 15px 45px rgba(39, 72, 128, .12); }
.login-card h1 { font-size: 25px; }
.login-card form { display: grid; gap: 17px; margin-top: 24px; }
.login-card button { width: 100%; margin-top: 3px; }
.login-footer { padding: 22px; color: var(--td-text-color-placeholder); text-align: center; font-size: 12px; }

@media (max-width: 1180px) {
  .module-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .stats, .lyric-engine-stats { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
}

@media (max-width: 820px) {
  :root { --sidebar-width: 100%; }
  .sidebar { position: relative; inset: auto; width: 100%; max-height: none; }
  .sidebar-brand { height: 58px; flex-basis: 58px; }
  .sidebar-nav { display: flex; gap: 12px; padding: 10px 12px 14px; overflow-x: auto; }
  .nav-section { min-width: 188px; }
  .nav-section + .nav-section { margin-top: 0; }
  .sidebar-footer { display: none; }
  .workspace { margin-left: 0; }
  .workspace-header { position: relative; height: 56px; padding: 0 16px; }
  .workspace-content { padding: 20px 14px 50px; }
  .header-date { display: none; }
  .form-grid, .module-grid, .stats, .lyric-engine-stats { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: auto; }
  .page-heading, .device-license-row { flex-direction: column; }
  .actions-stack { width: 100%; min-width: 0; }
  .routes { grid-template-columns: 110px minmax(0, 1fr); }
}

@media (max-width: 520px) {
  .environment-pill { display: none; }
  .login-brand { margin: 20px; }
  .login-card { padding: 28px 22px; }
  .panel { padding: 18px 16px; }
  .inline-form { align-items: stretch; flex-direction: column; }
}
