:root {
  --bg: #eef3f4;
  --surface: #ffffff;
  --surface-soft: #f7faf9;
  --text: #172326;
  --muted: #647174;
  --line: #d9e2e1;
  --primary: #1f6f78;
  --primary-strong: #155860;
  --accent: #c9862d;
  --success: #26835f;
  --warning: #b7791f;
  --danger: #bd3b3b;
  --shadow: 0 18px 48px rgba(24, 43, 46, .14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 1160px);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--surface-soft);
  box-shadow: var(--shadow);
  position: relative;
  padding-bottom: 86px;
}

.app-header {
  min-height: 96px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 4vw, 36px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

.role-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px clamp(16px, 4vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.role-btn,
.nav-btn,
.ghost-btn,
.primary-btn,
.secondary-btn,
.danger-btn {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 800;
}

.role-btn.is-active,
.nav-btn.is-active,
.primary-btn {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

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

.ghost-btn,
.secondary-btn {
  color: var(--primary);
}

.danger-btn {
  border-color: #efc1c1;
  color: var(--danger);
}

.view-stack {
  padding: 18px clamp(14px, 4vw, 36px);
}

.view {
  display: none;
}

.view.is-active {
  display: grid;
  gap: 16px;
}

.status-band {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
}

.status-band strong,
.kpi-card strong {
  display: block;
  margin-top: 4px;
  font-size: 22px;
}

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

.hint {
  margin: 12px 0 0;
  line-height: 1.6;
  font-size: 14px;
}

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

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

.kpi-card {
  padding: 16px;
}

.kpi-card span {
  color: var(--muted);
  font-size: 13px;
}

.panel {
  padding: 16px;
}

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

.panel-head h2 {
  margin-bottom: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #e8f3f4;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.pill.danger {
  background: #ffeded;
  color: var(--danger);
}

.bar-list,
.risk-list,
.lead-list,
.report-list {
  display: grid;
  gap: 10px;
}

.forecast-row {
  display: grid;
  grid-template-columns: 82px 1fr 86px;
  gap: 12px;
  align-items: center;
}

.bar-track {
  height: 20px;
  border-radius: 999px;
  background: #edf2f2;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  min-width: 2px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--primary), #4e9d83);
}

.risk-item,
.lead-card,
.report-card {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.risk-item.high {
  border-left: 5px solid var(--danger);
}

.risk-item.medium {
  border-left: 5px solid var(--warning);
}

.lead-card {
  cursor: pointer;
}

.lead-topline,
.lead-meta,
.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.lead-topline strong {
  font-size: 17px;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 6px;
  background: #f0f4f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.tag.success {
  background: #e8f6ef;
  color: var(--success);
}

.tag.warning {
  background: #fff5df;
  color: var(--warning);
}

.tag.danger {
  background: #ffeded;
  color: var(--danger);
}

.progress-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 10px;
}

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

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

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

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

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

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

#aiPrompt,
.ai-output {
  width: 100%;
  min-height: 168px;
}

.ai-output {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfdfd;
  line-height: 1.7;
  white-space: pre-wrap;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 1160px);
  height: 72px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
  z-index: 20;
}

.nav-btn {
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.nav-btn.is-active {
  background: #e8f3f4;
  color: var(--primary);
  border-bottom: 4px solid var(--primary);
}

dialog {
  width: min(720px, calc(100vw - 24px));
  border: 0;
  border-radius: 12px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(13, 31, 34, .44);
}

.dialog-card {
  padding: 18px;
}

.close-btn {
  float: right;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.detail-grid {
  clear: both;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  padding-top: 12px;
}

.detail-cell {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.detail-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.hidden-file {
  display: none;
}

@media (max-width: 760px) {
  .app-shell {
    box-shadow: none;
  }

  .app-header {
    min-height: 84px;
  }

  .status-band,
  .kpi-grid,
  .form-grid,
  .toolbar,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .forecast-row {
    grid-template-columns: 68px 1fr 74px;
  }

  .role-strip {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 420px) {
  .view-stack {
    padding-inline: 12px;
  }

  .app-header {
    padding-inline: 14px;
  }

  .ghost-btn {
    min-width: 64px;
  }
}
