:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --line: #d9e0e7;
  --line-strong: #b8c4d0;
  --text: #111827;
  --muted: #637083;
  --blue: #1d4ed8;
  --blue-soft: #dbeafe;
  --green: #047857;
  --green-soft: #dff7ec;
  --amber: #b45309;
  --amber-soft: #fff3d7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --violet: #6d28d9;
  --violet-soft: #ede9fe;
  --shadow: 0 16px 40px rgba(17, 24, 39, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100%;
}

body.auth-required .app-shell,
body.auth-required .detail-drawer,
body.auth-required .drawer-mask,
body.auth-required .image-viewer {
  display: none;
  opacity: 0 !important;
  pointer-events: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
  padding: 24px;
  pointer-events: auto;
}

.login-screen.hidden {
  display: none;
  pointer-events: none;
}

.login-panel {
  width: min(420px, 100%);
  border: 1px solid rgba(217, 224, 231, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  padding: 26px;
}

.login-panel h1 {
  margin-bottom: 22px;
}

.login-panel label + label {
  margin-top: 12px;
}

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

button {
  min-height: 38px;
  border: 1px solid #162033;
  border-radius: 8px;
  background: #162033;
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.button-busy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-busy::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

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

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.12;
}

h2 {
  margin-bottom: 4px;
  font-size: 19px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

.app-shell {
  width: min(1480px, calc(100% - 28px));
  margin: 12px auto 36px;
}

.topbar,
.panel,
.metric-card,
.detail-drawer {
  border: 1px solid rgba(217, 224, 231, 0.96);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-radius: 8px;
  padding: 16px 18px;
}

.top-actions,
.form-actions,
.button-row,
.mini-head,
.section-head,
.search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.eyebrow {
  margin-bottom: 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

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

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.metric-card {
  min-height: 92px;
  border-radius: 8px;
  padding: 14px;
}

.metric-card span {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  font-size: 29px;
  line-height: 1;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.panel {
  border-radius: 8px;
  padding: 16px;
}

.main-panel {
  min-height: 720px;
}

.section-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

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

.stack-form.form-busy {
  opacity: 0.55;
  pointer-events: none;
}

label span {
  display: block;
  margin-bottom: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

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

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

.form-actions {
  justify-content: flex-end;
}

.requirement-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.requirement-box .mini-head {
  margin-bottom: 8px;
}

.requirement-box h3 {
  margin: 0;
}

.ghost-button {
  background: #fff;
  color: var(--text);
  border-color: var(--line-strong);
}

.warn-button {
  background: var(--amber);
  border-color: var(--amber);
}

.success-button {
  background: var(--green);
  border-color: var(--green);
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  white-space: nowrap;
}

.status-pill span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.calm {
  border-color: #b8e2d0;
  background: var(--green-soft);
  color: var(--green);
}

.status-pill.warn {
  border-color: #efd09d;
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.bad {
  border-color: #f4b7b7;
  background: var(--red-soft);
  color: var(--red);
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin: -2px -2px 16px;
  padding-bottom: 10px;
}

.tab-button {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.tab-button.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
}

.hidden {
  display: none !important;
}

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 74px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  margin-bottom: 10px;
}

.loading-state strong {
  font-size: 13px;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 3px solid #dbeafe;
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.compact-select {
  max-width: 180px;
}

.project-boards {
  display: grid;
  gap: 12px;
}

.project-board {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  overflow: hidden;
}

.project-board-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.project-board-header h3 {
  margin: 0;
  font-size: 16px;
}

.board-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stat-chip,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.stat-chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
}

.issue-list,
.board-list {
  display: grid;
  gap: 8px;
}

.board-list {
  padding: 10px;
}

.board-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px 10px;
  color: var(--muted);
  font-size: 12px;
}

.board-pagination div {
  display: flex;
  gap: 6px;
}

.issue-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 12px;
  cursor: pointer;
}

.issue-card:hover {
  border-color: var(--blue);
  box-shadow: 0 8px 22px rgba(29, 78, 216, 0.1);
}

.issue-card-top,
.issue-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.issue-card-title {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
  word-break: break-word;
}

.issue-card-content {
  margin: 0;
  color: var(--muted);
  display: -webkit-box;
  line-height: 1.45;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.issue-card-meta {
  color: var(--muted);
  flex-wrap: wrap;
  font-size: 12px;
}

.tag.status-reported {
  background: var(--blue-soft);
  color: var(--blue);
}

.tag.status-processing {
  background: var(--amber-soft);
  color: var(--amber);
}

.tag.status-completed {
  background: var(--green-soft);
  color: var(--green);
}

.search-bar {
  align-items: stretch;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 150px 88px;
  margin-bottom: 10px;
}

.image-preview,
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.paste-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 58px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  outline: none;
}

.paste-zone:focus,
.paste-zone.active {
  border-color: var(--blue);
  background: var(--blue-soft);
  color: var(--blue);
}

.image-thumb {
  position: relative;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft);
}

.image-thumb img,
.image-grid .image-view-button {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.image-grid-item {
  position: relative;
  min-height: 92px;
}

.image-grid .image-view-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: inherit;
  min-height: 92px;
  overflow: hidden;
  padding: 0;
}

.image-delete-button {
  position: absolute;
  top: 5px;
  right: 5px;
  min-height: 26px;
  border: 1px solid rgba(15, 23, 42, 0.5);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.82);
  color: #fff;
  font-size: 12px;
  line-height: 1;
  padding: 0 7px;
}

.image-delete-button:hover {
  background: var(--red);
}

.image-thumb button {
  position: absolute;
  top: 5px;
  right: 5px;
  min-height: 26px;
  width: 26px;
  border-radius: 50%;
  border-color: rgba(15, 23, 42, 0.5);
  background: rgba(15, 23, 42, 0.82);
  padding: 0;
  line-height: 1;
}

.image-thumb span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden;
  background: rgba(15, 23, 42, 0.76);
  color: #fff;
  padding: 5px 7px;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.image-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-viewer {
  position: fixed;
  inset: 5vh 5vw;
  z-index: 36;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #0f172a;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.42);
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.image-viewer.open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.image-viewer img {
  max-width: calc(100% - 112px);
  max-height: calc(100% - 96px);
  object-fit: contain;
}

.viewer-close,
.viewer-nav {
  position: absolute;
  border-color: rgba(255, 255, 255, 0.28);
  background: rgba(15, 23, 42, 0.76);
  color: #fff;
}

.viewer-close {
  top: 14px;
  right: 14px;
  min-height: 34px;
  width: 34px;
  padding: 0;
}

.viewer-nav {
  top: 50%;
  width: 44px;
  min-height: 58px;
  padding: 0;
  transform: translateY(-50%);
  font-size: 30px;
}

.viewer-prev {
  left: 16px;
}

.viewer-next {
  right: 16px;
}

.viewer-caption {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  padding: 10px 12px;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(760px, calc(100vw - 24px));
  height: 100vh;
  border-radius: 8px 0 0 8px;
  padding: 16px;
  overflow: auto;
  transform: translateX(104%);
  transition: transform 0.18s ease;
}

.detail-drawer.open {
  transform: translateX(0);
}

.direct-detail-mode {
  background: var(--bg);
}

.direct-detail-mode .app-shell,
.direct-detail-mode .drawer-mask {
  display: none;
}

.direct-detail-mode .detail-drawer {
  left: 50%;
  right: auto;
  width: min(960px, 100vw);
  min-height: 100vh;
  border-radius: 0;
  transform: translateX(-50%);
}

.direct-detail-mode .detail-drawer.open {
  transform: translateX(-50%);
}

.drawer-mask {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: rgba(15, 23, 42, 0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.drawer-mask.open {
  opacity: 1;
  pointer-events: auto;
}

#imageViewerMask {
  z-index: 35;
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.button-row {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.sync-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.sync-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.sync-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.sync-grid strong {
  display: block;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.history-section {
  margin-top: 16px;
}

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

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px;
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.history-item pre {
  margin: 8px 0 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}

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

.config-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 12px;
}

.config-section label + label {
  margin-top: 10px;
}

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

.mini-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

.mini-head h3 {
  margin: 0;
}

.table-scroll {
  overflow-x: auto;
}

.config-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 560px;
}

.project-config-table {
  min-width: 1240px;
}

.feishu-config-table {
  min-width: 1320px;
}

.feishu-app-config-table,
.status-config-table {
  min-width: 760px;
}

.config-table th,
.config-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  text-align: left;
  vertical-align: middle;
}

.config-table th {
  color: var(--muted);
  font-size: 12px;
}

.config-table input,
.config-table select {
  min-width: 120px;
}

.danger-link {
  border-color: transparent;
  background: transparent;
  color: var(--red);
  padding: 0 4px;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  padding: 22px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 40;
  transform: translateX(-50%) translateY(20px);
  min-width: 220px;
  max-width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #111827;
  color: #fff;
  padding: 12px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1180px) {
  .workspace-grid,
  .config-grid {
    grid-template-columns: 1fr;
  }

  .search-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 18px, 1480px);
  }

  .topbar,
  .section-head,
  .issue-card-top,
  .issue-card-meta,
  .board-pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .metric-grid,
  .form-grid,
  .form-grid.two,
  .sync-grid,
  .search-bar {
    grid-template-columns: 1fr;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-button {
    white-space: nowrap;
  }
}
