/* 主题变量集中维护，让两套配色覆盖导航、表单与操作状态。 */
:root,
html[data-theme="blue"] {
  --brand: #416cf1;
  --brand-strong: #3156ce;
  --brand-soft: #eef3ff;
  --sidebar: #152647;
  --sidebar-deep: #0f1e39;
  --bg: #f5f7fb;
  --ink: #24334b;
  --muted: #64748b;
  --border: #e6ebf2;
}

html[data-theme="tcm"] {
  --brand: #087f8c;
  --brand-strong: #086875;
  --brand-soft: #e8f5f5;
  --sidebar: #123b43;
  --sidebar-deep: #0b2c33;
  --bg: #f3f8f8;
}

[x-cloak] {
  display: none !important;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0.01em;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

button {
  transition:
    background-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 4px;
}

input:not([type="checkbox"]),
select,
textarea {
  min-height: 40px;
  border-color: #dce3ed;
  background-color: #fff;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease;
}

input:not([type="checkbox"]):focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-soft);
}

/* 统一下拉框：去掉系统默认箭头，改用轻量自定义样式。 */
.app-select {
  appearance: none;
  -webkit-appearance: none;
  min-width: 8.5rem;
  border: 1px solid #dce3ed;
  border-radius: 0.5rem;
  background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7b92'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='1.8' d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
  padding: 0.55rem 2.4rem 0.55rem 0.85rem;
  color: var(--ink);
  font-size: 0.875rem;
  line-height: 1.35;
  box-shadow: 0 1px 2px #1b335108;
  cursor: pointer;
}

.app-select:hover {
  border-color: #c5d0de;
}

.app-select:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.app-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  background-color: #f8fafc;
}

input::placeholder,
textarea::placeholder {
  color: #8491a4;
}

textarea {
  resize: vertical;
}

input[type="checkbox"] {
  accent-color: var(--brand);
}

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

.text-brand-600 {
  color: var(--brand-strong);
}

.bg-brand-50 {
  background-color: var(--brand-soft);
}

.border-line {
  border-color: var(--border);
}

.brand-mark {
  background: var(--brand);
  box-shadow: 0 6px 16px #00000012;
}

.btn-brand {
  min-height: 42px;
  background: var(--brand);
  box-shadow: 0 4px 10px color-mix(in srgb, var(--brand) 18%, transparent);
}

.btn-brand:hover:not(:disabled) {
  background: var(--brand-strong);
  box-shadow: 0 5px 14px color-mix(in srgb, var(--brand) 26%, transparent);
}

.btn-brand:disabled {
  opacity: 0.5;
}

.secondary-button {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  background: white;
  color: #53647d;
  font-size: 12px;
  font-weight: 500;
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

/* 登录页使用轻量矢量插画，避免外部图片加载影响首屏。 */
.login-layout {
  display: grid;
  min-height: 100dvh;
  grid-template-columns: 1fr 1fr;
  background: white;
}

.login-story {
  position: relative;
  display: flex;
  min-height: 100dvh;
  flex-direction: column;
  overflow: hidden;
  padding: 40px 48px;
  background:
    radial-gradient(ellipse at 70% 85%, #2b5480 0, transparent 55%),
    var(--sidebar);
  color: white;
}

.login-story-content {
  width: 100%;
  max-width: 500px;
  margin: auto;
  padding: 65px 0 20px;
}

.login-eyebrow {
  margin-bottom: 22px;
  color: #91acd1;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.19em;
}

.login-story h2 {
  font-size: clamp(30px, 3.2vw, 46px);
  font-weight: 650;
  line-height: 1.55;
  letter-spacing: 0.04em;
}

.login-story-content > p {
  margin-top: 22px;
  color: #b7c7de;
  font-size: 13px;
  line-height: 2;
}

.login-visual {
  position: relative;
  height: 280px;
  margin-top: 32px;
}

.visual-orbit {
  position: absolute;
  inset: 12px 10px 0;
  border: 1px solid #ffffff13;
  border-radius: 50%;
  transform: rotate(-18deg);
}

.bike-illustration {
  position: absolute;
  inset: 38px 0 0;
  width: 90%;
  color: #d9e5f5;
  filter: drop-shadow(0 16px 18px #050e2029);
}

.visual-message {
  position: absolute;
  top: 0;
  right: -5px;
  width: 198px;
  border: 1px solid #ffffff29;
  border-radius: 12px;
  padding: 15px 18px;
  background: #ffffff0d;
  backdrop-filter: blur(12px);
  color: #d2deee;
  font-size: 11px;
}

.message-dot,
.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: #18a27f;
  vertical-align: middle;
}

.message-dot {
  background: #80d7c9;
}

.visual-message-line {
  display: block;
  width: 75%;
  height: 4px;
  margin: 12px 0;
  border-radius: 3px;
  background: #ffffff26;
}

.visual-message b {
  color: #91e0d2;
  font-size: 11px;
  font-weight: 500;
}

.login-story-footer {
  display: flex;
  gap: 24px;
  padding-top: 22px;
  color: #9fb3cd;
  font-size: 11px;
}

.login-form-area {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.login-card > .mb-6 {
  margin-bottom: 36px;
}

.login-card > .mb-6 > .brand-mark {
  display: none;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.login-card input {
  min-height: 48px;
  background: #f9fafc;
}

.login-card .btn-brand {
  min-height: 48px;
  margin-top: 22px;
}

/* 关键词与回复保留阅读宽度；手机端由表格容器横向滚动，避免汉字被逐字挤开。 */
.keyword-table td:first-child {
  min-width: 180px;
  width: 24%;
}

.keyword-table td:nth-child(3) {
  min-width: 260px;
  width: 40%;
}

/* 桌面导航常驻，窄屏通过 Alpine 控制抽屉，保持相同的业务入口。 */
.app-header {
  height: 56px;
  background: #fff;
}

.app-brand {
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-deep));
  border-right: 1px solid #ffffff12;
}

.app-brand .brand-mark {
  border: 1px solid #ffffff20;
  background: #ffffff12;
  box-shadow: none;
}

.app-sidebar {
  position: sticky;
  top: 56px;
  z-index: 30;
  height: calc(100dvh - 56px);
  width: 244px;
  padding-top: 6px;
  background: linear-gradient(180deg, var(--sidebar), var(--sidebar-deep));
  color: #f6f8fc;
}

.app-sidebar .text-muted,
.app-sidebar > .text-slate-400 {
  color: #93a6c4;
}

.app-sidebar nav {
  margin-top: 16px;
}

.nav-item {
  position: relative;
  min-height: 46px;
  margin-bottom: 6px;
  color: #b5c2d8;
  font-size: 13px;
  font-weight: 500;
}

.nav-item:hover {
  background: #ffffff0a;
  color: white;
}

.nav-item.nav-active {
  background: var(--brand);
  color: white;
  box-shadow: 0 5px 14px #00000012;
}

.nav-active::after {
  position: absolute;
  right: 14px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: white;
  content: "";
}

.sidebar-note {
  border: 1px solid #ffffff13;
  background: #ffffff06;
}

.sidebar-note p,
.sidebar-footer {
  color: #9daec9;
}

.user-menu-trigger svg {
  transition: transform 160ms ease;
}

.user-menu-panel {
  box-shadow: 0 12px 32px rgba(21, 39, 71, 0.12);
}

.workspace-main {
  /* 内容区占满侧栏右侧宽度，不再限制 max-width */
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  padding: 20px 28px 32px;
}

.settings-page {
  width: 100%;
}

.workspace-main h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.workspace-main h1 + p {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.5;
}

.workspace-main section > .mb-3:first-child,
.workspace-main section > .mb-5:first-child {
  margin-bottom: 12px;
}

.workspace-main section > .bg-white,
.stats-grid > div {
  border-radius: 12px;
  box-shadow: 0 3px 12px #1b335103;
}

.stats-grid > div {
  padding: 12px 14px;
}

.stat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.stat-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
}

.stat-icon svg {
  width: 14px;
  height: 14px;
}

.stat-enabled {
  background: #eaf7f2;
  color: #168465;
}

.stat-words {
  background: #f1edfc;
  color: #8360bf;
}

.stat-priority {
  background: #fff4e6;
  color: #b47b25;
}

.stat-value {
  margin-top: 4px;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.2;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-caption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}

.count-badge {
  display: inline-block;
  min-width: 23px;
  margin-left: 6px;
  border-radius: 5px;
  padding: 2px 6px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 11px;
  text-align: center;
}

.table-toolbar {
  padding: 0;
}

.table-toolbar select {
  min-width: 124px;
}

.overflow-x-auto {
  border: 1px solid var(--border);
  border-radius: 9px;
}

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

thead {
  background: #f8fafd;
  color: #6b7b92;
}

th {
  height: 46px;
  white-space: nowrap;
}

tbody tr {
  transition: background-color 160ms ease;
}

tbody tr:hover {
  background: #fafbfe;
}

tbody td {
  padding-top: 20px !important;
  padding-bottom: 20px !important;
  font-size: 12px;
  line-height: 1.8;
}

.pill {
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  border: 1px solid color-mix(in srgb, var(--brand) 12%, transparent);
  border-radius: 5px;
  padding: 2px 8px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.keyword-reply {
  display: -webkit-box;
  min-width: 180px;
  overflow: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.9;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.switch-on {
  background: var(--brand);
}

button[role="switch"]::before {
  position: absolute;
  inset: -10px -2px;
  content: "";
}

.empty-symbol {
  display: grid;
  width: 50px;
  height: 50px;
  margin: 10px auto 14px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f6f8fc;
  color: var(--brand);
  font-size: 30px;
}

.record-status {
  display: inline-flex;
  background: #f1f3f7;
  color: #5c6d84;
}

.record-status-submitted {
  background: #eaf7f1;
  color: #168465;
}

.record-status-pending,
.record-status-sending {
  background: #eef3ff;
  color: #3156ce;
}

.record-status-uncertain,
.record-status-expired {
  background: #fff3e4;
  color: #9c6418;
}

.reply-test-page > .bg-white {
  padding: 28px;
}

.reply-test-page [aria-live] {
  min-height: 160px;
  margin-top: 26px;
  padding: 24px;
  border-style: dashed;
  background: #f8fafd;
  line-height: 1.9;
}

.settings-page form {
  padding: 26px;
}

.settings-page form > label:first-child {
  border-bottom: 1px solid var(--border);
  padding-bottom: 22px;
}

.settings-page form > .flex:last-child {
  border-top: 1px solid var(--border);
  padding-top: 22px;
}

.dialog-open {
  overflow: hidden;
}

[role="dialog"] {
  background: #101d35a6;
  backdrop-filter: blur(4px);
}

[role="dialog"] > div {
  box-shadow: 0 24px 80px #0f172a33;
}

.toast-success {
  border-left: 4px solid #65d9ae;
}

.toast-error {
  border-left: 4px solid #fb7185;
}

.boot-screen {
  display: flex;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 2px solid #dce4f3;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: ebike-spin 0.8s linear infinite;
}

.loading-indicator {
  position: fixed;
  top: 84px;
  right: 24px;
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  background: white;
  color: var(--muted);
  box-shadow: 0 4px 20px #1526470a;
  font-size: 12px;
}

.mobile-menu-button {
  min-width: 40px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  color: var(--ink);
}

@keyframes ebike-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .workspace-main {
    padding-right: 22px;
    padding-left: 22px;
  }

  .stats-grid > div {
    padding: 15px;
  }

  .login-story {
    padding: 32px;
  }
}

@media (max-width: 767px) {
  .login-layout {
    display: block;
    background: var(--bg);
  }

  .login-story {
    min-height: auto;
    padding: 26px 24px;
  }

  .login-story-content {
    padding: 32px 0 12px;
  }

  .login-story h2 {
    font-size: 28px;
  }

  .login-story-content > p,
  .login-visual,
  .login-eyebrow,
  .login-story-footer {
    display: none;
  }

  .login-form-area {
    padding: 24px 16px;
  }

  .login-card {
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px 24px;
  }

  .app-sidebar {
    position: fixed;
    display: flex;
    flex-direction: column;
    top: 52px;
    left: 0;
    height: calc(100dvh - 52px);
    transform: translateX(-100%);
    visibility: hidden;
    transition:
      transform 200ms ease,
      visibility 200ms;
  }

  .app-sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .app-header {
    height: 52px;
  }

  .app-brand {
    display: none;
  }

  .mobile-menu-button {
    display: inline-flex;
  }

  .workspace-main {
    padding: 22px 16px 32px;
  }

  .workspace-main h1 {
    font-size: 23px;
  }

  .workspace-main h1 + p {
    max-width: 32em;
  }

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

  .stat-icon {
    width: 24px;
    height: 24px;
    border-radius: 6px;
  }

  .stat-caption {
    font-size: 10px;
  }

  table {
    min-width: 720px;
  }

  .table-toolbar input {
    max-width: none;
  }

  .table-toolbar select {
    width: 100%;
  }

  .reply-test-page > .bg-white,
  .settings-page form {
    padding: 18px;
  }

  .loading-indicator {
    top: 72px;
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
