:root {
  color-scheme: light;
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-soft: #eef3ed;
  --ink: #22251f;
  --muted: #697164;
  --line: #dfe5da;
  --primary: #24705a;
  --primary-strong: #155444;
  --accent: #b46a33;
  --warning: #b78a00;
  --danger: #b94d46;
  --success: #27834f;
  --info: #386a8d;
  --shadow: 0 18px 44px rgba(45, 54, 38, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: linear-gradient(140deg, #eef3ed 0%, #f8f5ee 52%, #e8f1f6 100%);
}

.login-screen.is-visible {
  display: grid;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  color: var(--ink);
  margin-bottom: 4px;
}

.login-hint {
  margin: 0;
  font-size: 13px;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: #26342e;
  color: #f7faf4;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #d8f0df;
  color: #163a2f;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
  font-size: 18px;
}

.brand-subtitle {
  color: #becdc2;
  font-size: 12px;
  margin-top: 2px;
}

.nav-list {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 11px 12px;
  color: #dfe9e0;
  background: transparent;
  text-align: left;
}

.nav-item:hover,
.nav-item.is-active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.13);
  color: #ffffff;
}

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: #bde3ca;
  font-weight: 700;
}

.sidebar-note {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.07);
}

.note-label {
  font-size: 12px;
  color: #bde3ca;
  font-weight: 700;
}

.sidebar-note p {
  margin: 8px 0 0;
  color: #d6e0d6;
  font-size: 13px;
  line-height: 1.55;
}

.main-area {
  min-width: 0;
  padding: 24px 28px 40px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  margin-bottom: 5px;
}

h3 {
  font-size: 16px;
  margin-bottom: 0;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

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

.user-pill {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
}

.btn.primary {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

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

.btn.secondary {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

.btn.ghost {
  color: var(--primary-strong);
  background: transparent;
  border-color: var(--line);
}

.small-action {
  min-height: 32px;
  padding: 0 10px;
}

.icon-btn {
  width: 36px;
  padding: 0;
  border-color: var(--line);
  background: var(--surface);
  font-size: 24px;
  line-height: 1;
}

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

select[multiple],
.multi-select {
  min-height: 112px;
  padding: 8px;
}

select[multiple] option {
  padding: 6px 8px;
}

textarea {
  resize: vertical;
}

.view {
  display: none;
}

.view.is-visible {
  display: block;
}

.section-header,
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.section-header {
  margin-bottom: 16px;
}

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

.metric-card,
.panel,
.table-wrap,
.status-strip {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.75);
}

.metric-card {
  padding: 16px;
}

.roas-folder-grid {
  grid-template-columns: 1fr;
}

.roas-folder-grid .metric-value {
  font-size: 18px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  margin-top: 8px;
  font-size: 27px;
  line-height: 1.15;
  font-weight: 800;
}

.metric-detail {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.dashboard-grid,
.history-grid,
.management-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 14px;
}

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

.panel {
  padding: 16px;
}

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

.project-list,
.history-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.project-row,
.history-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcf8;
}

.project-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.row-title {
  font-weight: 800;
  margin-bottom: 4px;
}

.row-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.tag,
.source-tag,
.status-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.tag {
  background: var(--surface-soft);
  color: #3f5146;
}

.source-tag {
  background: #eef6fa;
  color: var(--info);
  border-color: #d1e4ef;
}

.status-tag {
  background: #f5efe4;
  color: var(--accent);
  border-color: #ead8bd;
}

.status-tag.done {
  background: #e8f5eb;
  color: var(--success);
  border-color: #cae6d0;
}

.status-tag.pending {
  background: #eef6fa;
  color: var(--info);
  border-color: #c6dfeb;
}

.status-tag.warning {
  background: #fff4d8;
  color: #9b6a12;
  border-color: #ead28f;
}

.status-tag.muted {
  background: var(--surface-soft);
  color: var(--muted);
  border-color: var(--line);
}

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

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

.project-picker-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-grid > .project-picker-field {
  grid-column: 1 / -1;
}

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

.hidden {
  display: none !important;
}

.multi-filter {
  position: relative;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.multi-trigger {
  width: 100%;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  text-align: left;
}

.multi-filter.is-open .multi-trigger {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 112, 90, 0.14);
}

.multi-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 12px;
}

.multi-filter.is-open .multi-menu {
  display: grid;
  gap: 10px;
}

.multi-options {
  display: grid;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
}

.multi-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border-radius: 8px;
  color: var(--ink);
  padding: 4px 6px;
}

.multi-option:hover {
  background: var(--surface-soft);
}

.multi-option input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  padding: 0;
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.text-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  font-size: 12px;
}

.project-picker {
  min-height: 38px;
  max-height: 156px;
  overflow: auto;
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.compact-picker {
  max-height: 150px;
}

.project-check {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  color: var(--ink);
}

.project-check input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  margin: 2px 0 0;
  padding: 0;
}

.project-check strong,
.project-check span {
  display: block;
}

.project-check span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.wide-label {
  margin-top: 14px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

.dense-table table {
  min-width: 1900px;
}

.roas-table table {
  min-width: 1700px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f2f5ee;
  color: #4c5548;
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 13px;
}

tbody tr:hover {
  background: #fbfcf8;
}

.dense-table td,
.dense-table th {
  padding: 10px;
}

.number {
  font-variant-numeric: tabular-nums;
}

.delta {
  font-weight: 800;
}

.delta.up {
  color: var(--success);
}

.delta.down {
  color: var(--danger);
}

.risk-row {
  background: #fff8ec;
}

.risk-row:hover {
  background: #fff5df;
}

.summary-row {
  background: #eef3ed;
  font-weight: 800;
}

.summary-row:hover {
  background: #e5ede5;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 14px;
  overflow: hidden;
}

.pipeline-step {
  padding: 12px;
  border-right: 1px solid var(--line);
}

.pipeline-step:last-child {
  border-right: 0;
}

.pipeline-step strong {
  display: block;
  margin-bottom: 4px;
}

.pipeline-step span {
  color: var(--muted);
  font-size: 12px;
}

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

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

.management-grid {
  margin-bottom: 14px;
}

.plan-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}

.adjustment-flow {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.adjustment-flow > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.adjustment-flow strong,
.adjustment-flow span {
  display: block;
}

.adjustment-flow span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.adjustment-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.adjust-input {
  min-width: 108px;
}

.note-input {
  min-width: 220px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  grid-auto-flow: column;
  gap: 6px;
  margin-top: 8px;
  color: var(--text);
}

.inline-check input {
  width: 18px;
  height: 18px;
}

.review-decision {
  min-width: 150px;
  margin-bottom: 8px;
}

.review-note {
  margin-top: 8px;
  color: var(--accent);
  line-height: 1.5;
}

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

.current-config div {
  display: grid;
  gap: 4px;
}

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

.current-config strong {
  color: var(--ink);
  font-size: 16px;
}

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

.detail-grid > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px 12px;
}

.detail-grid span,
.detail-grid strong {
  display: block;
}

.detail-grid span {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.detail-grid strong {
  font-weight: 650;
  line-height: 1.45;
}

.execution-shot-panel {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.execution-shot-panel > span {
  color: var(--muted);
  font-size: 12px;
}

.shot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.shot-card {
  display: grid;
  gap: 8px;
}

.shot-preview,
.shot-placeholder {
  min-height: 180px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 650;
}

.shot-card strong {
  font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
}

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

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

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
}

dialog {
  width: min(820px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(21, 31, 25, 0.45);
}

.dialog-card {
  padding: 20px;
}

.dialog-header,
.dialog-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.dialog-actions {
  align-items: center;
  justify-content: flex-end;
  margin-top: 18px;
}

.pipeline-preview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.pipeline-preview div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcf8;
}

.pipeline-preview strong,
.pipeline-preview span {
  display: block;
}

.pipeline-preview span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 340px;
  background: #26342e;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

.empty-state {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.validation-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

@media (max-width: 1100px) {
  .metric-grid,
  .toolbar,
  .status-strip,
  .adjustment-flow {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

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

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

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

  .main-area {
    padding: 20px 14px 32px;
  }

  .topbar,
  .section-header {
    display: grid;
  }

  .topbar-actions,
  .inline-actions {
    width: 100%;
  }

  .topbar-actions > *,
  .inline-actions > * {
    flex: 1 1 180px;
  }

  .metric-grid,
  .toolbar,
  .form-grid,
  .pipeline-preview,
  .status-strip,
  .adjustment-flow,
  .adjustment-fields,
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
