:root {
  --bg: #f5f7f5;
  --surface: #ffffff;
  --ink: #202124;
  --muted: #77716c;
  --line: #dfe5df;
  --primary: #e64f3d;
  --primary-strong: #c83d2d;
  --accent: #177866;
  --accent-strong: #123f37;
  --soft: #eef3ef;
  --cream: #f9fbf7;
  --warn: #9c3d2f;
  --shadow: 0 18px 45px rgba(46, 32, 22, .08);
  --soft-shadow: 0 12px 30px rgba(46, 32, 22, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    linear-gradient(180deg, #fbfcfa 0%, var(--bg) 42%, #eef3ef 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  cursor: pointer;
}

.shell, .admin-shell {
  width: min(1440px, calc(100% - 40px));
  margin: 0 auto;
  padding: 22px 0 42px;
}

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

h1, h2, h3, p { margin: 0; }

h1 {
  font-size: 26px;
  line-height: 1.25;
}

h2 {
  font-size: 20px;
  line-height: 1.35;
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  margin-bottom: 6px;
}

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

.pill {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  color: var(--accent);
  font-weight: 700;
  box-shadow: var(--soft-shadow);
}

.ghost-link, .text-btn {
  display: inline-flex;
  align-items: center;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
}

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

.primary, .secondary {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 700;
  transition: transform .16s ease, box-shadow .16s ease, background .16s ease;
}

.primary {
  background: linear-gradient(135deg, var(--primary), #f17856);
  color: white;
  box-shadow: 0 12px 22px rgba(230, 79, 61, .2);
}

.primary:hover {
  background: linear-gradient(135deg, var(--primary-strong), #e95f45);
  transform: translateY(-1px);
}

.secondary {
  background: var(--accent-strong);
  color: white;
}

.hidden { display: none !important; }

.auth-grid {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 0;
  align-items: center;
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
}

body:has(#authView:not(.hidden)) #mainTopbar {
  display: none;
}

body:has(#authView:not(.hidden)) .shell {
  width: min(1180px, calc(100% - 40px));
  padding-top: 28px;
}

.category-panel, .generator-panel, .result-panel, .admin-panel, .admin-login .auth-panel, .student-sidebar, .account-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.intro-panel {
  grid-column: 1 / -1;
  grid-row: 1;
  min-height: 620px;
  padding: 0;
  display: block;
  overflow: hidden;
}

.intro-copy {
  position: relative;
  z-index: 1;
}

.intro-panel h2 {
  max-width: 620px;
  font-size: 38px;
  line-height: 1.18;
}

.intro-panel p {
  max-width: 590px;
  color: var(--muted);
  line-height: 1.8;
  margin-top: 14px;
}

.hero-visual {
  position: relative;
  min-height: 620px;
  height: 100%;
  border-radius: 0;
  overflow: hidden;
  border: 0;
  background: var(--surface);
}

.hero-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,.16) 0%, rgba(255,255,255,.08) 48%, rgba(255,255,255,.66) 72%, rgba(255,255,255,.9) 100%);
  pointer-events: none;
}

.hero-visual img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 620px;
  object-fit: cover;
  transform: scaleX(-1);
}

.flow-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  max-width: 780px;
}

.auth-benefits {
  grid-column: 1 / -1;
  max-width: none;
}

.flow-list span {
  padding: 12px;
  border-radius: 8px;
  background: var(--soft);
  font-weight: 700;
  text-align: center;
}

.auth-panel {
  grid-column: 2;
  grid-row: 1;
  z-index: 2;
  margin-right: 28px;
  padding: 24px;
  align-self: center;
  background: rgba(255, 255, 255, .82);
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  box-shadow: 0 20px 50px rgba(39, 35, 29, .14);
  backdrop-filter: blur(18px);
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--soft);
  border-radius: 8px;
  margin-bottom: 18px;
}

.tab, .nav-btn {
  border: 0;
  background: transparent;
  min-height: 36px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
}

.tab.active, .nav-btn.active {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
}

.form-stack, .settings-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

textarea {
  min-height: 118px;
  resize: vertical;
  line-height: 1.6;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 124, 112, .12);
}

.workspace {
  display: grid;
  grid-template-columns: 290px minmax(360px, 1fr) minmax(360px, .9fr);
  gap: 16px;
  align-items: start;
}

.student-dashboard {
  display: grid;
  grid-template-columns: 228px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.student-sidebar {
  padding: 14px;
  position: sticky;
  top: 16px;
  min-height: calc(100vh - 88px);
  background:
    linear-gradient(180deg, #143d35 0%, #19372f 48%, #2d3029 100%);
  border-color: rgba(255, 255, 255, .14);
  color: #fff;
  box-shadow: 0 18px 45px rgba(30, 34, 28, .13);
}

.student-card {
  padding: 10px 8px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, .15);
}

.student-card h2 {
  margin-bottom: 4px;
  color: #fff;
  font-size: 22px;
}

.student-sidebar .eyebrow {
  color: #a9e6d9;
}

.student-sidebar .muted {
  color: rgba(255, 255, 255, .68);
}

.credit-number {
  display: block;
  margin-top: 14px;
  padding: 14px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, .11);
  color: #fff2e9;
  font-size: 28px;
  line-height: 1;
}

.student-nav {
  display: grid;
  gap: 7px;
  padding: 16px 0;
}

.student-nav-btn {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, .72);
  font-weight: 700;
  text-align: left;
  padding: 0 12px;
}

.student-nav-btn.active {
  background: #fbfcfa;
  border-color: rgba(255, 255, 255, .8);
  color: var(--accent-strong);
  box-shadow: 0 10px 22px rgba(0, 0, 0, .12);
}

.side-stats {
  display: grid;
  gap: 4px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .15);
  color: rgba(255, 255, 255, .66);
  font-size: 12px;
}

.side-stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 30px;
  padding: 0 3px;
}

.side-stats strong {
  color: #fff;
  font-size: 13px;
}

.student-main {
  display: grid;
  gap: 12px;
}

.student-panel {
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.student-panel .workspace {
  grid-template-columns: minmax(420px, 1fr) minmax(330px, .78fr);
  gap: 16px;
}

.category-panel, .generator-panel, .result-panel {
  padding: 18px;
  box-shadow: var(--soft-shadow);
}

.category-panel {
  grid-column: 1 / -1;
  padding: 14px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(10px);
}

.category-panel .section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.category-panel .section-title h2 {
  font-size: 16px;
}

.compact-title .eyebrow {
  margin-bottom: 0;
}

.section-title {
  margin-bottom: 14px;
}

.category-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.category-card {
  flex: 0 0 220px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  transition: border-color .16s ease, box-shadow .16s ease, transform .16s ease;
}

.category-card.active {
  border-color: var(--primary);
  background: #fff4f1;
  box-shadow: 0 10px 24px rgba(230, 79, 61, .13);
  transform: translateY(-1px);
}

.category-card h3 {
  font-size: 15px;
  margin-bottom: 6px;
}

.category-card p {
  font-size: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.category-card p, .muted {
  color: var(--muted);
  line-height: 1.6;
}

.badge {
  display: inline-flex;
  margin-top: 10px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e8f2ef;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.generator-head {
  border-bottom: 1px solid var(--line);
  padding: 0 0 14px;
  margin-bottom: 16px;
}

.generator-head h2 {
  font-size: 24px;
}

.rule-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.rule-list span {
  padding: 6px 9px;
  border-radius: 6px;
  background: #eef7f4;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 15px;
}

.field-grid label:has(textarea) {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

#generateBtn {
  min-width: 160px;
}

.empty-state {
  min-height: 260px;
  border: 1px dashed #dacfc4;
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 18px;
  background: #fbfcfa;
}

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

.result-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.result-block h3 {
  font-size: 15px;
  margin-bottom: 10px;
  color: var(--accent-strong);
}

.title-options {
  display: grid;
  gap: 8px;
}

.copy-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 11px;
  border-radius: 6px;
  background: #f8f0e8;
}

.copy-row button, .small-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 6px 10px;
  white-space: nowrap;
  color: var(--accent-strong);
  font-weight: 700;
}

.danger-btn {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: #b42318;
  color: #fff;
  padding: 0 12px;
  font-weight: 700;
  text-align: center;
}

.content-box {
  white-space: pre-wrap;
  line-height: 1.75;
  font-size: 14px;
  color: #37322e;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag-list span {
  padding: 6px 9px;
  border-radius: 999px;
  background: #fff0eb;
  color: var(--primary-strong);
  font-weight: 700;
  font-size: 13px;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.image-plan {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(135deg, #fff, #f5faf6);
}

.image-plan strong {
  display: block;
  margin-bottom: 8px;
}

.image-plan p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.image-plan img {
  display: block;
  width: 100%;
  border-radius: 6px;
  margin-bottom: 8px;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: var(--soft);
}

.history-section {
  margin-top: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.account-grid {
  display: grid;
  grid-template-columns: minmax(0, .8fr) minmax(320px, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

.account-card {
  padding: 18px;
  box-shadow: var(--soft-shadow);
  background: rgba(255, 255, 255, .9);
}

.account-card h2 {
  font-size: 30px;
  color: var(--accent-strong);
}

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

.cost-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.cost-row strong {
  color: var(--primary);
  white-space: nowrap;
}

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

.history-item, .admin-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px;
  background: #fff;
  box-shadow: var(--soft-shadow);
}

.history-meta, .admin-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.admin-login {
  display: grid;
  place-items: center;
  min-height: 480px;
}

.admin-login .auth-panel {
  width: min(420px, 100%);
}

.admin-grid {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
}

.admin-nav {
  display: grid;
  align-content: start;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.nav-btn {
  text-align: left;
  padding: 0 12px;
}

.admin-panel {
  padding: 18px;
  min-height: 520px;
}

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: var(--soft);
}

.stat-card strong {
  display: block;
  font-size: 28px;
  margin-top: 8px;
}

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

.admin-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-edit-grid, .inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  align-items: end;
}

.admin-edit-grid label:nth-child(5),
.admin-edit-grid label:nth-child(6) {
  grid-column: span 2;
}

.admin-edit-grid label:has(textarea) {
  grid-column: span 2;
}

.admin-edit-grid textarea {
  min-height: 92px;
}

.copy-box {
  width: 100%;
  min-height: 130px;
  margin: 12px 0;
}

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

.record-actions select {
  width: auto;
  min-width: 120px;
  min-height: 36px;
  padding: 7px 10px;
}

.admin-table {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.admin-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

.admin-table th {
  background: var(--soft);
  color: var(--muted);
  font-weight: 700;
}

.admin-table tr:last-child td {
  border-bottom: 0;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(31, 36, 40, .28);
  z-index: 50;
  padding: 20px;
}

.modal-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

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

.agent-generate-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.settings-form {
  max-width: 720px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
}

@media (max-width: 1080px) {
  .student-dashboard {
    grid-template-columns: 1fr;
  }
  .student-sidebar {
    position: static;
    min-height: auto;
  }
  .student-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .student-nav-btn {
    text-align: center;
  }
  .student-panel .workspace {
    grid-template-columns: minmax(0, 1fr);
  }
  .workspace {
    grid-template-columns: 260px minmax(0, 1fr);
  }
  .result-panel {
    grid-column: auto;
  }
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .shell, .admin-shell {
    width: min(100% - 22px, 1440px);
    padding-top: 14px;
  }
  .topbar, .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }
  .auth-grid, .workspace, .admin-grid, .field-grid, .flow-list, .admin-edit-grid, .inline-form, .stats-grid, .student-panel .workspace, .account-grid, .agent-generate-grid {
    grid-template-columns: 1fr;
  }
  .auth-grid {
    min-height: auto;
    display: grid;
    grid-template-columns: 1fr;
  }
  .intro-panel {
    grid-column: 1;
    grid-row: 1;
    grid-template-columns: 1fr;
    min-height: auto;
    padding: 0;
  }
  .hero-visual,
  .hero-visual img {
    min-height: 560px;
  }
  .hero-visual::after {
    background: linear-gradient(180deg, rgba(255,255,255,.08) 0%, rgba(255,255,255,.62) 42%, rgba(255,255,255,.92) 100%);
  }
  .auth-panel {
    grid-column: 1;
    grid-row: 1;
    width: min(100% - 28px, 390px);
    margin: 220px auto 18px;
  }
  .student-nav {
    grid-template-columns: 1fr;
  }
  .student-sidebar {
    padding: 12px;
  }
  .student-card {
    padding-bottom: 12px;
  }
  .credit-number {
    font-size: 24px;
    padding: 12px;
  }
  .category-list {
    display: grid;
    overflow: visible;
  }
  .category-card {
    flex-basis: auto;
  }
  .category-panel,
  .generator-panel,
  .result-panel {
    padding: 14px;
  }
  .generator-head h2 {
    font-size: 21px;
  }
  .intro-panel h2 {
    font-size: 26px;
  }
  .admin-edit-grid label:nth-child(5),
  .admin-edit-grid label:nth-child(6) {
    grid-column: auto;
  }
  .image-grid {
    grid-template-columns: 1fr;
  }
}
