:root {
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #c8d0dc;
  --line-dark: #aeb8c6;
  --head: #f2f5f9;
  --head-2: #e8edf4;
  --text: #1f2937;
  --muted: #5f6b7a;
  --blue: #1f3f66;
  --blue-soft: #e8f0f8;
  --orange: #F28C28;
  --orange-hover: #E67E22;
  --orange-dark: #D96C00;
  --orange-soft: #FFF4E8;
  --orange-border: #F5CBA7;
  --green: #14804a;
  --state-orange: #b45309;
  --red: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 13px;
  line-height: 1.35;
}

button {
  font: inherit;
}

.topbar {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: #1f3f66;
  color: #fff;
  border-bottom: 1px solid #14304f;
}

.brand {
  font-size: 15px;
  font-weight: 700;
}

.meta {
  color: #d7e1ec;
  font-size: 12px;
}

.main-nav {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0 8px;
  background: #dfe5ee;
  border-bottom: 1px solid var(--line-dark);
}

.nav-item {
  height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid transparent;
  background: transparent;
  color: #26384d;
  cursor: pointer;
  text-decoration: none;
}

.nav-item:hover,
.nav-item.active {
  background: #fff;
  border-color: var(--line-dark);
  color: var(--blue);
}

.workspace {
  height: calc(100vh - 76px);
  padding: 8px;
  overflow: hidden;
}

.docs-workspace {
  overflow: hidden;
}

.docs-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 6px;
}

.docs-sidebar,
.docs-reader {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
}

.docs-sidebar {
  display: grid;
  grid-template-rows: 36px minmax(0, 1fr);
}

.docs-sidebar-head,
.docs-reader-head {
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
}

.docs-sidebar-head span {
  color: var(--muted);
  font-size: 12px;
}

.docs-list {
  overflow: auto;
  padding: 6px;
}

.doc-item {
  width: 100%;
  min-height: 42px;
  display: grid;
  grid-template-rows: auto auto;
  gap: 2px;
  margin-bottom: 5px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.doc-item:hover,
.doc-item.active {
  border-color: var(--orange-border);
  background: var(--orange-soft);
}

.doc-item span {
  font-weight: 700;
}

.doc-item em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.docs-reader {
  display: grid;
  grid-template-rows: 36px minmax(0, 1fr);
  overflow: hidden;
  min-height: 0;
}

.docs-reader-head h1 {
  margin: 0;
  font-size: 14px;
}

.markdown-body {
  overflow: auto;
  padding: 12px 14px 24px;
  background: #fff;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3 {
  margin: 16px 0 8px;
  color: var(--blue);
}

.markdown-body h1 {
  margin-top: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 20px;
}

.markdown-body h2 {
  font-size: 16px;
}

.markdown-body h3 {
  font-size: 14px;
}

.markdown-body p,
.markdown-body li {
  line-height: 1.65;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 14px;
}

.markdown-body th,
.markdown-body td {
  min-height: 32px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--head);
}

.markdown-body code {
  padding: 1px 4px;
  background: var(--head);
  border: 1px solid var(--line);
}

.markdown-body pre {
  padding: 10px;
  overflow: auto;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.markdown-body pre code {
  padding: 0;
  border: 0;
  background: transparent;
}

.error-line {
  border-color: #f0b4ad;
  background: #fff4f2;
  color: var(--red);
}

.module {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(245px, 1.15fr) minmax(220px, 0.85fr);
  gap: 6px;
}

.page-head {
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.page-head h1 {
  margin: 0;
  font-size: 14px;
}

.hint {
  color: var(--muted);
  font-size: 12px;
}

.master,
.detail,
.simple-panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
}

.toolbar {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
}

.toolbar .spacer {
  flex: 1;
}

.tool-btn,
.row-btn,
.tab-btn {
  height: 26px;
  border: 1px solid var(--line-dark);
  background: #fff;
  color: #26384d;
  border-radius: 2px;
  cursor: pointer;
}

.tool-btn {
  padding: 0 9px;
}

.tool-btn.primary {
  background: var(--orange);
  border-color: var(--orange-dark);
  color: #fff;
}

.tool-btn.primary:hover:not(:disabled) {
  background: var(--orange-hover);
  border-color: var(--orange-dark);
  color: #fff;
}

.tool-btn:hover:not(:disabled),
.row-btn:hover,
.tab-btn:hover,
.tab-btn.active {
  background: var(--orange-soft);
  border-color: var(--orange-border);
  color: var(--orange-dark);
}

.tool-btn:disabled {
  color: #a0a8b3;
  background: #f6f7f9;
  cursor: not-allowed;
}

.row-btn {
  min-width: 42px;
  padding: 0 7px;
}

.table-wrap {
  height: calc(100% - 40px);
  overflow: auto;
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  height: 36px;
  padding: 0 8px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--head-2);
  font-weight: 700;
  color: #334155;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f8fbff;
}

tbody tr.selected {
  background: #dceafe;
}

.status {
  display: inline-block;
  min-width: 56px;
  height: 20px;
  line-height: 18px;
  padding: 0 6px;
  border: 1px solid #b8c4d2;
  background: #f5f7fa;
  text-align: center;
  border-radius: 2px;
}

.status.flow {
  color: var(--blue);
  border-color: #8fb1d4;
  background: #edf5ff;
}

.status.done {
  color: var(--green);
  border-color: #91c9aa;
  background: #eef9f2;
}

.status.warn {
  color: var(--state-orange);
  border-color: #e2bb76;
  background: #fff8e8;
}

.status.closed {
  color: var(--red);
  border-color: #e0a2a0;
  background: #fff1f1;
}

.detail {
  overflow: hidden;
}

.tabbar {
  height: 34px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  padding: 0 6px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
}

.tab-btn {
  height: 28px;
  padding: 0 10px;
  border-bottom-color: var(--line);
}

.tab-btn.active {
  background: #fff;
  border-bottom-color: #fff;
}

.detail-body {
  height: calc(100% - 34px);
  padding: 8px;
  overflow: auto;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.field {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  min-height: 32px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.field label {
  padding: 7px 8px;
  background: var(--head);
  color: var(--muted);
  border-right: 1px solid var(--line);
}

.field span {
  padding: 7px 8px;
  background: #fff;
}

.field.wide {
  grid-column: span 2;
}

.field.full {
  grid-column: 1 / -1;
}

.opportunity-info-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  gap: 8px;
}

.info-card-table,
.info-long-table {
  border: 1px solid var(--line);
  background: #fff;
}

.info-long-table {
  grid-column: 1 / -1;
}

.info-row {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  min-height: 32px;
  border-bottom: 1px solid var(--line);
}

.info-row:last-child {
  border-bottom: 0;
}

.info-row span {
  padding: 7px 8px;
  background: var(--head);
  color: var(--muted);
  border-right: 1px solid var(--line);
}

.info-row strong {
  padding: 7px 8px;
  font-weight: 400;
  color: var(--text);
  white-space: normal;
  word-break: break-word;
}

.info-long-table .info-row {
  grid-template-columns: 150px minmax(0, 1fr);
}

.edit-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 6px;
}

.edit-grid.one-col {
  grid-template-columns: 1fr;
}

.edit-field {
  display: grid;
  grid-template-columns: 108px minmax(0, 1fr);
  min-height: 32px;
  border: 1px solid var(--line);
  background: #fff;
}

.edit-field span {
  padding: 7px 8px;
  background: var(--head);
  color: var(--muted);
  border-right: 1px solid var(--line);
}

.edit-field input,
.edit-field textarea,
.edit-field select {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 5px 7px;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  background: #fff;
}

.edit-field textarea {
  min-height: 62px;
  resize: vertical;
}

.compact-form-grid {
  gap: 8px;
}

.radio-edit-field {
  grid-template-columns: 128px minmax(0, 1fr);
}

.textarea-box {
  position: relative;
  min-width: 0;
}

.textarea-box textarea {
  padding-right: 58px;
}

.textarea-box em {
  position: absolute;
  right: 8px;
  bottom: 6px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.edit-field.wide {
  grid-column: span 2;
}

.edit-field.full {
  grid-column: 1 / -1;
}

.form-section-title {
  height: 28px;
  display: flex;
  align-items: center;
  margin-top: 8px;
  font-weight: 700;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(31, 41, 55, 0.35);
}

.page-overlay {
  align-items: stretch;
}

.mock-page,
.modal {
  background: #fff;
  border: 1px solid var(--line-dark);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
}

.mock-page {
  width: min(1180px, 100%);
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr) 42px;
}

.modal {
  width: min(640px, 100%);
}

.mock-page-head,
.modal-head {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
}

.mock-page-head h2,
.modal-head h2 {
  margin: 0;
  font-size: 14px;
}

.mock-page-head span,
.modal-head span {
  color: var(--muted);
  font-size: 12px;
}

.mock-page-body,
.modal-body {
  padding: 10px;
  overflow: auto;
}

.opportunity-register-page {
  width: min(1240px, 100%);
}

.register-body {
  display: grid;
  gap: 10px;
  background: #f5f7fa;
}

.register-section {
  border: 1px solid var(--line);
  background: #fff;
}

.register-section h3 {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
  color: var(--text);
  font-size: 13px;
}

.register-section h3 span {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--orange-border);
  background: var(--orange-soft);
  color: var(--orange-dark);
  font-weight: 700;
}

.register-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 8px;
  padding: 10px;
}

.register-field {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr);
  min-height: 32px;
  border: 1px solid var(--line);
  background: #fff;
}

.register-field.wide {
  grid-column: span 2;
}

.register-field.full,
.register-note {
  grid-column: 1 / -1;
}

.register-field > span {
  padding: 7px 8px;
  background: var(--head);
  color: var(--muted);
  border-right: 1px solid var(--line);
}

.register-field b {
  margin-left: 2px;
  color: #c92a2a;
}

.register-field input,
.register-field select,
.register-field textarea {
  width: 100%;
  min-width: 0;
  height: 30px;
  padding: 5px 7px;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  background: #fff;
}

.register-field textarea {
  min-height: 68px;
  resize: vertical;
}

.radio-line,
.check-line,
.money-line,
.customer-select-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 7px;
}

.radio-line label,
.check-line label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.radio-line input,
.check-line input {
  width: auto;
  height: auto;
  padding: 0;
}

.multi-field {
  grid-template-columns: 104px minmax(0, 1fr);
}

.check-line {
  flex-wrap: wrap;
  min-height: 30px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.money-line,
.customer-select-line {
  padding: 0;
  gap: 0;
}

.money-line input,
.customer-select-line input {
  flex: 1;
}

.money-line select {
  width: 58px;
  border-left: 1px solid var(--line);
}

.mini-btn {
  height: 30px;
  padding: 0 10px;
  border: 0;
  border-left: 1px solid var(--orange-border);
  background: var(--orange-soft);
  color: var(--orange-dark);
  cursor: pointer;
  font: inherit;
  white-space: nowrap;
}

.mini-btn:hover {
  background: #ffe8d0;
}

.register-note {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid #d3dfec;
  background: #f8fbff;
  color: #31445c;
}

.customer-picker {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 30;
  transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 40px));
}

.customer-list {
  display: grid;
  gap: 6px;
}

.customer-list button {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}

.customer-list button:hover {
  border-color: var(--orange-border);
  background: var(--orange-soft);
}

.customer-list span {
  color: var(--muted);
}

.mock-page-footer,
.modal-footer {
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  padding: 0 10px;
  background: var(--head);
  border-top: 1px solid var(--line);
}

.sub-title {
  height: 28px;
  display: flex;
  align-items: center;
  margin: 0 0 6px;
  font-size: 13px;
  font-weight: 700;
}

.note-line {
  min-height: 30px;
  padding: 7px 8px;
  border: 1px solid #d3dfec;
  background: #f8fbff;
  color: #31445c;
}

.compact-table {
  min-width: 760px;
}

.compact-table th,
.compact-table td {
  height: 32px;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 6px;
}

.summary-cell {
  border: 1px solid var(--line);
  background: #fff;
}

.summary-cell h3 {
  height: 30px;
  margin: 0;
  padding: 7px 8px;
  background: var(--head);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.summary-cell strong {
  display: block;
  padding: 10px 8px 2px;
  font-size: 20px;
}

.summary-cell span {
  display: block;
  padding: 0 8px 10px;
  color: var(--muted);
}

.simple-panel {
  height: 100%;
  padding: 8px;
  overflow: auto;
}

.customer-layout {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 6px;
}

/* ---- Login page ---- */
.login-page {
  background: var(--bg);
}

.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100vh - 42px);
}

.login-card {
  width: min(380px, calc(100% - 32px));
  padding: 28px 24px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.10);
}

.login-card h1 {
  margin: 0 0 20px;
  font-size: 18px;
  color: var(--blue);
  text-align: center;
}

.login-field {
  margin-bottom: 14px;
}

.login-field label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
}

.login-field input {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  font: inherit;
  outline: 0;
}

.login-field input:focus {
  border-color: var(--orange-border);
}

.login-error {
  min-height: 20px;
  margin-bottom: 8px;
  color: var(--red);
  font-size: 12px;
}

.login-btn {
  width: 100%;
  height: 34px;
  font-size: 14px;
}

/* ---- Logout button in topbar ---- */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logout-btn {
  height: 26px;
  padding: 0 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 2px;
  background: rgba(255,255,255,0.1);
  color: #d7e1ec;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.logout-btn:hover {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

@media (max-width: 900px) {
  .meta {
    display: none;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 76px);
    overflow: visible;
  }

  .module {
    height: auto;
    grid-template-rows: auto minmax(260px, auto) minmax(260px, auto);
  }

  .master,
  .detail {
    min-height: 260px;
  }

  .detail-grid,
  .edit-grid,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .field.wide,
  .edit-field.wide {
    grid-column: auto;
  }
}
