:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f9fbff;
  --line: #dde4ef;
  --text: #152033;
  --muted: #667085;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --green: #0f9f6e;
  --amber: #b7791f;
  --red: #d92d20;
  --shadow: 0 10px 28px rgba(21, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Manrope", "Noto Sans TC", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

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

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 20px;
  padding: 20px;
  border-right: 1px solid var(--line);
  background: #101828;
  color: #f8fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: #98a2b3;
  font-size: 0.78rem;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.side-nav a {
  padding: 11px 12px;
  border-radius: 8px;
  color: #d0d5dd;
  font-weight: 700;
}

.side-nav a.active,
.side-nav a:hover {
  background: #1d2939;
  color: #ffffff;
}

.side-status {
  align-self: end;
  display: grid;
  gap: 10px;
}

.side-status div {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.side-status span {
  display: block;
  margin-bottom: 4px;
  color: #98a2b3;
  font-size: 0.78rem;
}

.main {
  min-width: 0;
  padding: 22px;
}

.page-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.page-bar h1 {
  margin: 0;
  font-size: 1.45rem;
}

.page-bar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.bar-actions,
.inline-actions,
.form-actions,
.pagination-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.panel {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 1rem;
}

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

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.kpi-card,
.stat-card,
.info-card,
.project-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.kpi-card {
  padding: 16px;
}

.kpi-card span,
.stat-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.kpi-card strong {
  font-size: 1.6rem;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 18px;
}

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

.form-grid.single {
  grid-template-columns: 1fr;
}

.wide,
.filter-actions,
.form-actions {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: #344054;
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 11px;
  border: 1px solid #cfd8e6;
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
}

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

.primary-btn,
.secondary-btn,
.warning-btn,
.danger-btn,
.ghost-btn,
.primary-link,
.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-btn,
.primary-link {
  color: white;
  background: var(--primary);
}

.primary-btn:hover,
.primary-link:hover {
  background: var(--primary-strong);
}

.secondary-btn {
  color: #0f5132;
  background: #dcfce7;
  border-color: #bbf7d0;
}

.warning-btn {
  color: #7c2d12;
  background: #ffedd5;
  border-color: #fed7aa;
}

.warning-btn:hover {
  background: #fed7aa;
}

.danger-btn {
  color: #7f1d1d;
  background: #fee2e2;
  border-color: #fecaca;
}

.danger-btn:hover {
  background: #fecaca;
}

.ghost-btn,
.mini-btn {
  color: var(--text);
  background: #ffffff;
  border-color: var(--line);
}

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

.project-card {
  width: 100%;
  padding: 12px;
  text-align: left;
}

.project-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.project-card strong {
  display: block;
  margin-bottom: 4px;
}

.project-card p {
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.5;
}

.project-card-meta,
.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #eef4ff;
  color: #175cd3;
  font-size: 0.76rem;
  font-weight: 800;
}

.badge.running {
  background: #fff7ed;
  color: var(--amber);
}

.badge.failed {
  background: #fef3f2;
  color: var(--red);
}

.badge.completed {
  background: #ecfdf3;
  color: var(--green);
}

.detail-empty,
.empty-cell {
  padding: 28px 12px;
  color: var(--muted);
  text-align: center;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.detail-head h2 {
  margin: 0 0 6px;
}

.detail-meta {
  color: var(--muted);
  line-height: 1.6;
}

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

.stat-card {
  padding: 13px;
}

.stat-card strong {
  font-size: 1.15rem;
}

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

.tag {
  padding: 5px 8px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #344054;
  font-size: 0.78rem;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
}

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

.data-table th,
.data-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.data-table tr:hover td {
  background: var(--surface-soft);
}

.keyword-score {
  font-weight: 800;
  color: var(--primary);
}

.cell-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.8rem;
}

.pagination-bar {
  justify-content: flex-end;
  margin-top: 14px;
}

.log-stream {
  display: grid;
  gap: 10px;
  max-height: 620px;
  overflow: auto;
}

.log-item {
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  background: #ffffff;
}

.log-item.success {
  border-left-color: var(--green);
}

.log-item.warning {
  border-left-color: var(--amber);
}

.log-item.error {
  border-left-color: var(--red);
}

.log-meta {
  display: flex;
  gap: 9px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.log-message {
  line-height: 1.55;
}

.log-context,
.strategy-block {
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  background: #101828;
  color: #f8fafc;
  font-size: 0.8rem;
  line-height: 1.55;
}

.strategy-block {
  max-height: 360px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.toggle input {
  width: auto;
}

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

.info-card {
  padding: 13px;
}

.info-card strong {
  display: block;
  margin-bottom: 6px;
}

.info-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(29, 78, 216, 0.16), transparent 34%),
    radial-gradient(circle at 80% 10%, rgba(22, 163, 74, 0.16), transparent 30%),
    #f6f8fb;
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 24px;
}

.login-card h1 {
  margin: 0 0 8px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.table-input {
  min-width: 150px;
  min-height: 34px;
  margin-right: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.mini-danger {
  min-height: 34px;
  padding: 0 10px;
}

.toast-wrap {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  display: grid;
  gap: 10px;
}

.toast {
  min-width: 230px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #ffffff;
  background: #344054;
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--green);
}

.toast.error {
  background: var(--red);
}

.toast.info {
  background: var(--primary);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .side-status {
    align-self: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-column,
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .page-bar,
  .detail-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .two-column,
  .kpi-grid,
  .form-grid,
  .filter-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }
}
