:root {
  color-scheme: light;
  --bg: #edf3f7;
  --panel: #ffffff;
  --panel-soft: #f7fafc;
  --line: #d5e1ea;
  --text: #172331;
  --muted: #667789;
  --brand: #157a8c;
  --brand-dark: #0f5f6e;
  --brand-soft: #eaf7f8;
  --good: #2f7d32;
  --warn: #9a5b00;
  --shadow: 0 10px 28px rgba(25, 53, 72, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

.app-shell {
  min-height: 100vh;
  padding: 18px 20px 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
}

.topbar p,
.section-title span,
label,
pre,
.audit-strip span {
  color: var(--muted);
  font-size: 12px;
}

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

button,
.section-title a,
.button-link {
  height: 36px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  padding: 0 13px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

button:hover,
.section-title a:hover,
.button-link:hover {
  border-color: var(--brand);
}

button.primary:hover {
  background: var(--brand-dark);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 0.88fr) minmax(360px, 0.82fr) minmax(560px, 1.35fr);
  gap: 16px;
  margin-top: 16px;
}

.workspace.report-focus {
  grid-template-columns: minmax(760px, 1fr);
}

.workspace.report-focus .form-panel,
.workspace.report-focus .kdocs-panel {
  display: none;
}

.workspace.report-focus .preview-panel {
  min-height: calc(100vh - 250px);
}

.workspace.report-focus iframe {
  min-height: calc(100vh - 350px);
}

.auto-panel {
  margin-top: 14px;
}

.shop-dashboard-panel {
  margin-top: 14px;
}

.shop-dashboard-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.shop-dashboard-list {
  overflow: auto;
}

.shop-dashboard-list table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.shop-dashboard-list th,
.shop-dashboard-list td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

.shop-dashboard-list td {
  color: var(--text);
}

.shop-dashboard-list strong,
.shop-dashboard-list span {
  display: block;
}

.shop-dashboard-list td span {
  color: var(--muted);
  margin-top: 4px;
}

.status-badge {
  display: inline-flex !important;
  width: fit-content;
  min-height: 22px;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  font-weight: 700;
}

.status-badge.ready {
  color: var(--good);
  background: #e8f4ea;
}

.status-badge.pending {
  color: var(--warn);
  background: #fff4df;
}

.status-badge.blocked {
  color: #b23a48;
  background: #fde8ec;
}

.compact-button {
  height: 28px;
  padding: 0 10px;
}

.auto-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.utility-hidden,
.auto-panel .auto-controls {
  display: none !important;
}

.compact-title {
  margin-bottom: 10px;
}

.data-status-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.data-status-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid #d9e7ef;
  border-radius: 9px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fbfd 100%);
}

.data-status-card span {
  color: #5f7184;
  font-size: 12px;
  font-weight: 700;
}

.data-status-card strong {
  color: #162638;
  font-size: 14px;
  text-align: right;
}

.check-row {
  display: inline-flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
}

.check-row input {
  width: 16px;
  height: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  min-width: 0;
  box-shadow: var(--shadow);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 36px;
}

.status-text {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark) !important;
  padding: 0 9px;
  font-weight: 700;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.style-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.style-switch select {
  height: 34px;
  min-width: 112px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 0 8px;
}

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

.field-grid.compact {
  margin-bottom: 14px;
}

.advanced-box {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  margin-top: 2px;
}

.advanced-box summary {
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 10px;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
}

input:focus,
select:focus {
  border-color: var(--brand);
  outline: 2px solid rgba(31, 122, 140, 0.14);
}

.audit-strip {
  display: none;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.audit-strip div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}

.audit-strip strong {
  display: block;
  font-size: 12px;
  margin-bottom: 3px;
}

pre {
  min-height: 104px;
  max-height: 220px;
  overflow: auto;
  padding: 10px;
  background: #f5f8fb;
  border: 1px solid var(--line);
  border-radius: 7px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.realtime-box {
  margin-top: 14px;
}

.debug-box {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-soft);
  overflow: hidden;
}

.debug-box summary {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.debug-box summary::marker {
  color: var(--brand);
}

.debug-box summary em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
}

.debug-box pre {
  margin: 0 12px 12px;
}

.compact-title {
  margin-bottom: 8px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 120px);
}

iframe {
  flex: 1;
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.dashboard-shell {
  display: grid;
  gap: 14px;
}

.dashboard-topbar .actions {
  align-items: end;
}

.toolbar-field {
  width: 150px;
}

.toolbar-field input,
.actions select {
  margin-top: 5px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.kpi-card {
  min-height: 110px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
}

.kpi-card span,
.kpi-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.kpi-card strong {
  font-size: 24px;
  line-height: 1.1;
}

.good-text {
  color: var(--good) !important;
}

.warn-text {
  color: var(--warn) !important;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(420px, 1.15fr) minmax(280px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.detail-panel {
  grid-column: 1 / -1;
}

.ranking-list,
.alert-list {
  display: grid;
  gap: 8px;
}

.rank-row {
  position: relative;
  width: 100%;
  min-height: 46px;
  height: auto;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 8px;
  overflow: hidden;
  text-align: left;
}

.rank-row > span {
  position: relative;
  z-index: 1;
}

.rank-row i {
  position: absolute;
  inset: auto auto 0 0;
  height: 4px;
  background: var(--brand);
  opacity: 0.8;
}

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

.rank-name {
  min-width: 0;
  font-weight: 600;
}

.rank-value {
  color: var(--brand-dark);
  font-weight: 700;
}

.trend-chart {
  height: 300px;
  display: grid;
  grid-template-columns: repeat(14, minmax(22px, 1fr));
  gap: 8px;
  align-items: end;
  padding-top: 8px;
}

.trend-bar {
  height: 100%;
  display: grid;
  grid-template-rows: 18px 1fr 28px;
  gap: 5px;
  align-items: end;
  justify-items: center;
  min-width: 0;
}

.trend-bar span,
.trend-bar strong {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.trend-bar i {
  width: 100%;
  max-width: 24px;
  min-height: 8px;
  background: linear-gradient(180deg, #1f7a8c, #7aa95c);
  border-radius: 5px 5px 2px 2px;
}

.alert-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 6px;
}

.alert-item.high {
  border-left-color: #b23a48;
}

.alert-item.medium {
  border-left-color: var(--warn);
}

.alert-item.low {
  border-left-color: var(--brand);
}

.alert-item span,
.alert-item em,
.empty-state {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.shop-table {
  overflow: auto;
}

.shop-table table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1060px;
}

.shop-table th,
.shop-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 12px;
}

.shop-table th:first-child,
.shop-table td:first-child {
  text-align: left;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--brand-dark);
  background: #eef8f7;
  font-size: 12px;
  white-space: nowrap;
}

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

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

  .trend-panel,
  .detail-panel {
    grid-column: 1 / -1;
  }

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

@media (max-width: 640px) {
  .topbar,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

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

  .trend-chart {
    gap: 5px;
    overflow-x: auto;
  }

  .trend-bar {
    min-width: 34px;
  }
}

/* Workbench visual iteration. Keeps the existing DOM and actions intact. */
body {
  background:
    linear-gradient(180deg, #eaf2f7 0%, #f4f7fa 38%, #edf3f7 100%);
}

.app-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(21, 122, 140, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(21, 122, 140, 0.04) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.72), transparent 48%);
}

.topbar,
.panel {
  position: relative;
}

.topbar {
  min-height: 74px;
  border-color: #cfdde7;
}

.topbar h1 {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar h1::before {
  content: "";
  width: 11px;
  height: 28px;
  border-radius: 4px;
  background: linear-gradient(180deg, #14966f, #2f80ed);
  box-shadow: 10px 8px 0 #e44848, 20px 2px 0 #f1b641;
}

.topbar p {
  margin-top: 5px;
}

.actions button,
.actions .button-link,
.preview-actions button,
.preview-actions a {
  font-weight: 700;
}

.actions button:not(.primary),
.preview-actions button,
.preview-actions a {
  background: #f8fbfd;
}

.actions .primary,
button.primary {
  box-shadow: 0 8px 18px rgba(21, 122, 140, 0.18);
}

.auto-panel {
  padding: 14px 18px;
}

.auto-panel .section-title {
  margin-bottom: 8px;
}

.auto-controls {
  padding-top: 2px;
}

.workspace > .panel,
.workspace > form.panel {
  padding: 18px;
}

.form-panel,
.kdocs-panel {
  border-top: 4px solid #2f80ed;
}

.kdocs-panel {
  border-top-color: #15945e;
}

.preview-panel {
  border-top: 4px solid #157a8c;
}

.form-panel .section-title,
.kdocs-panel .section-title,
.preview-panel .section-title {
  padding-bottom: 12px;
  border-bottom: 1px solid #e3ebf1;
}

.field-grid {
  gap: 12px;
}

label {
  color: #5e6f82;
  font-weight: 650;
}

input,
select {
  border-color: #cfdde8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85);
}

input:hover,
select:hover {
  border-color: #aebfcd;
}

.config-box {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid #d9e5ee;
  border-radius: 9px;
  background: #f8fbfd;
}

.config-box summary,
.advanced-box summary {
  color: #253449;
  font-weight: 800;
}

.inline-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

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

.preview-panel {
  background:
    linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
}

.preview-actions {
  gap: 10px;
}

.style-switch {
  padding: 6px 8px;
  border: 1px solid #dbe6ef;
  border-radius: 9px;
  background: #f8fbfd;
}

.style-switch select {
  min-width: 142px;
  border-color: transparent;
  background: #ffffff;
}

iframe {
  background: #edf3f7;
  box-shadow: inset 0 0 0 1px rgba(207, 221, 232, 0.75);
}

.shop-dashboard-panel {
  border-top: 4px solid #6b7c93;
}

.shop-dashboard-list table {
  border: 1px solid #dce7ef;
  border-radius: 9px;
  overflow: hidden;
}

.shop-dashboard-list th {
  background: #f4f8fb;
  color: #405066;
  font-weight: 800;
}

.status-badge {
  min-height: 24px;
}

@media (max-width: 1440px) {
  .workspace {
    grid-template-columns: minmax(320px, 0.95fr) minmax(320px, 0.9fr) minmax(480px, 1.2fr);
  }

  .workspace.report-focus {
    grid-template-columns: minmax(0, 1fr);
  }
}
