:root {
  --bg: #f6f8fb;
  --panel: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #d8dee9;
  --brand: #2563eb;
  --brand-deep: #1d4ed8;
  --mint: #0f766e;
  --mint-soft: #d9f7f2;
  --amber: #b45309;
  --amber-soft: #fff3d6;
  --rose: #be123c;
  --rose-soft: #ffe4ec;
  --violet: #6d28d9;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Inter", "Helvetica Neue", Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

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

.section-rail {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 16px;
  background: #111827;
  color: #f9fafb;
}

.brand-block {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 4px 4px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #2dd4bf;
  color: #073b3a;
  font-weight: 800;
}

.brand-block h1 {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 700;
}

.brand-block p {
  margin: 3px 0 0;
  color: #a7b0c2;
  font-size: 12px;
}

.section-buttons {
  display: grid;
  gap: 10px;
}

.section-btn.layui-btn {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  justify-items: start;
  width: 100%;
  height: 44px;
  margin: 0;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #dbe4f0;
  background: rgba(255, 255, 255, 0.06);
  line-height: 44px;
  text-align: left;
}

.section-btn.layui-btn:hover,
.section-btn.layui-btn.active {
  border-color: rgba(45, 212, 191, 0.65);
  color: #ffffff;
  background: rgba(45, 212, 191, 0.16);
}

.section-btn .layui-icon {
  font-size: 18px;
}

.workspace {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 24px;
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.workspace-header h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.2;
  font-weight: 800;
}

.panel-host {
  min-height: 0;
  flex: 1;
}

.section-panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 16px;
  height: calc(100vh - 104px);
}

.section-panel[hidden] {
  display: none;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(260px, 36%) minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
}

.area {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.area-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.area-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
}

.area-count {
  min-width: 32px;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--mint);
  background: var(--mint-soft);
  font-size: 12px;
  font-weight: 800;
  line-height: 24px;
  text-align: center;
}

.candidate-list,
.generated-list {
  display: grid;
  align-content: start;
  gap: 10px;
  height: calc(100% - 56px);
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.candidate-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 10px;
  align-items: start;
  width: 100%;
  height: auto;
  min-height: 58px;
  padding: 12px;
  border: 1px solid #dfe5ef;
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

.candidate-card:hover,
.candidate-card:focus {
  border-color: #93c5fd;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.12);
  outline: none;
}

.candidate-copy {
  display: block;
  min-width: 0;
}

.candidate-title {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

.candidate-card-long .candidate-title {
  font-size: 13px;
  line-height: 1.42;
}

.candidate-card-xlong {
  padding: 11px 12px;
}

.candidate-card-xlong .candidate-title {
  font-size: 12px;
  line-height: 1.48;
}

.candidate-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  white-space: normal;
  overflow-wrap: anywhere;
}

.candidate-card .layui-icon {
  color: var(--brand);
  font-size: 18px;
  justify-self: end;
  margin-top: 2px;
}

.generated-card {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid #dfe5ef;
  border-radius: 8px;
  background: #ffffff;
}

.generated-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.generated-meta strong {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

.generated-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #ffffff;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--brand);
  border-color: #bfdbfe;
  background: #eff6ff;
}

.remove-generated:hover {
  color: var(--rose);
  border-color: #fecdd3;
  background: var(--rose-soft);
}

.sentence-shell {
  min-height: 54px;
  padding: 11px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  color: #172554;
  background: #eff6ff;
  line-height: 2.2;
  cursor: pointer;
}

.sentence-text {
  white-space: pre-wrap;
}

.term-bubble {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0 2px;
  padding: 2px 9px;
  border: 1px solid #99f6e4;
  border-radius: 999px;
  color: #115e59;
  background: var(--mint-soft);
  font-weight: 800;
  line-height: 1.4;
  cursor: pointer;
}

.term-bubble:hover {
  border-color: #2dd4bf;
  background: #ccfbf1;
}

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.06);
}

.copy-textarea {
  position: fixed;
  left: -9999px;
  top: -9999px;
}

.empty-state,
.loading-state,
.error-state {
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  color: var(--muted);
  background: #f8fafc;
  font-size: 14px;
}

.error-state {
  color: var(--rose);
  background: var(--rose-soft);
  border-color: #fecdd3;
}

.choice-wrap {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.choice-btn {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #dbe4ef;
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
  text-align: left;
  cursor: pointer;
}

.choice-btn:hover,
.choice-btn.active {
  border-color: #93c5fd;
  background: #eff6ff;
}

.choice-id {
  display: block;
  margin-bottom: 4px;
  color: var(--brand-deep);
  font-size: 12px;
  font-weight: 800;
}

.choice-preview {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.rule-editor {
  display: grid;
  gap: 16px;
  max-height: calc(92vh - 64px);
  overflow: auto;
  padding: 18px;
  background: #f8fafc;
}

.editor-current {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: #1e40af;
  background: #eff6ff;
  font-size: 13px;
}

.editor-field {
  display: grid;
  gap: 8px;
}

.editor-field label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.editor-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.editor-inline-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.editor-list {
  display: grid;
  gap: 10px;
}

.editor-row {
  display: grid;
  gap: 10px;
  align-items: start;
}

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

.term-row {
  grid-template-columns: minmax(120px, 180px) minmax(0, 1fr) 32px;
}

.rule-editor .layui-input,
.rule-editor .layui-textarea {
  border-color: #d8dee9;
  border-radius: 8px;
  background: #ffffff;
}

.rule-editor .layui-textarea {
  min-height: 62px;
  resize: vertical;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

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

  .section-rail {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 14px;
  }

  .brand-block {
    grid-template-columns: 38px minmax(0, 1fr);
    padding-bottom: 12px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

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

  .workspace {
    padding: 16px;
  }

  .section-panel {
    height: auto;
    min-height: calc(100vh - 184px);
  }

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

  .candidate-list,
  .generated-list {
    max-height: 48vh;
  }

  .term-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .section-buttons {
    grid-template-columns: 1fr;
  }

  .workspace-header h2 {
    font-size: 22px;
  }

  .area-header {
    min-height: 50px;
    padding: 12px;
  }

  .candidate-list,
  .generated-list {
    padding: 10px;
  }

  .bottom-bar {
    justify-content: stretch;
  }

  .bottom-bar .layui-btn {
    width: 100%;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .editor-actions {
    width: 100%;
    justify-content: stretch;
  }

  .header-actions .layui-btn,
  .editor-actions .layui-btn {
    flex: 1;
  }

  .editor-field-head {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-inline-actions {
    justify-content: stretch;
  }

  .pattern-row {
    grid-template-columns: 1fr;
  }
}
