:root {
  --ctrl-h: 32px;
  --ctrl-pad-x: 10px;
  --ctrl-radius: 6px;
  --ctrl-border: 1px solid rgba(255, 255, 255, 0.15);
  --ctrl-bg: rgba(0, 0, 0, 0.25);
  --ctrl-fg: #e2e8f0;
  --ctrl-placeholder: #64748b;
  --ctrl-label: #94a3b8;
  --ctrl-fs: 0.8125rem;
  --ctrl-label-fs: 0.75rem;
  --page-bg: #0f172a;
  --card-bg: #1e293b;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: clip;
}

body {
  background: var(--page-bg);
  color: var(--ctrl-fg);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.container {
  position: relative;
  max-width: min(1400px, 100%);
  margin: 0 auto;
  padding: 28px 24px 48px;
  overflow-x: clip;
}

.user-bar {
  position: absolute;
  top: 28px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 2;
}

.user-bar-name {
  color: #e2e8f0;
  font-size: var(--ctrl-fs);
}

header h1 {
  color: #f8fafc;
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  max-width: 360px;
}

.field label {
  color: var(--ctrl-label);
  font-size: var(--ctrl-label-fs);
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="email"],
input[type="number"],
input[type="date"],
select,
textarea {
  height: var(--ctrl-h);
  padding: 0 var(--ctrl-pad-x);
  border: var(--ctrl-border);
  border-radius: var(--ctrl-radius);
  background: var(--ctrl-bg);
  color: var(--ctrl-fg);
  font-size: var(--ctrl-fs);
}

select {
  min-width: 160px;
}

textarea {
  height: auto;
  min-height: 72px;
  padding: 6px var(--ctrl-pad-x);
}

input::placeholder {
  color: var(--ctrl-placeholder);
}

input:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.55);
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18);
}

.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--ctrl-h);
  padding: 0 var(--ctrl-pad-x);
  border-radius: var(--ctrl-radius);
  font-size: var(--ctrl-fs);
  cursor: pointer;
  border: var(--ctrl-border);
}

.btn-primary {
  background: #3273f6;
  border-color: #3273f6;
  color: #f8fafc;
}

.btn-secondary {
  background: var(--ctrl-bg);
  color: var(--ctrl-fg);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 16px;
  align-items: start;
}

.form-grid > .field {
  margin-bottom: 0;
  max-width: none;
}

.form-grid + .form-actions,
.choice-panel > .form-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.form-error {
  min-height: 1.25rem;
  margin: 0 0 12px;
  color: #fca5a5;
  font-size: var(--ctrl-fs);
}

.field-hint {
  margin: 0;
  color: var(--ctrl-placeholder);
  font-size: 12px;
  line-height: 1.4;
}

.field-error {
  min-height: 1.1rem;
  margin: 0;
  color: #fca5a5;
  font-size: 12px;
  line-height: 1.4;
}

input[aria-invalid="true"] {
  border-color: #f87171;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.portal-card {
  background: var(--card-bg);
  border: var(--ctrl-border);
  border-radius: 8px;
  padding: 16px;
}

.portal-card h2 {
  margin: 0 0 8px;
  color: #f8fafc;
  font-size: 1.125rem;
}

.portal-status {
  margin: 0;
  color: var(--ctrl-label);
  font-size: var(--ctrl-fs);
}

.portal-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
}

.portal-card-link:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18);
}

.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 0 16px;
  color: var(--ctrl-label);
  font-size: var(--ctrl-fs);
}

.breadcrumb a {
  color: #7dd3fc;
}

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  margin: 16px 0;
}

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

table.data th,
table.data td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: var(--ctrl-border);
  font-size: var(--ctrl-fs);
  vertical-align: top;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  margin: 0 0 16px;
}

.toolbar > .field {
  margin-bottom: 0;
}

.status-ok {
  color: #86efac;
  font-size: var(--ctrl-fs);
}

.panel {
  background: var(--card-bg);
  border: var(--ctrl-border);
  border-radius: 8px;
  padding: 16px;
  margin: 0 0 16px;
}

.cap-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin: 8px 0 0;
}

.choice-title {
  margin: 0;
  color: var(--ctrl-fg);
  font-size: var(--ctrl-fs);
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px 16px;
  margin: 8px 0 0;
}

.feishu-filter {
  width: 100%;
  margin: 8px 0 0;
}

.feishu-candidate-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 0;
}

.feishu-candidate {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  margin: 0;
  padding: 8px 10px;
  border: var(--ctrl-border);
  border-radius: var(--ctrl-radius);
  background: rgba(0, 0, 0, 0.15);
}

.feishu-candidate-body {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 16px;
  min-width: 0;
}

.feishu-candidate-name {
  flex: 0 0 6em;
  color: var(--ctrl-fg);
  font-size: var(--ctrl-fs);
  white-space: nowrap;
}

.feishu-candidate-id,
.feishu-candidate-groups,
.feishu-candidate-state {
  color: var(--ctrl-label);
  font-size: var(--ctrl-label-fs);
  line-height: 1.4;
  white-space: nowrap;
}

.feishu-candidate-id {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cap-list label,
.choice-grid label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--ctrl-fs);
  color: var(--ctrl-fg);
}

.cap-list input[type="checkbox"],
.choice-grid input[type="checkbox"] {
  width: 12px;
  height: 12px;
  accent-color: #3273f6;
}

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

.btn-ghost {
  background: transparent;
  color: var(--ctrl-fg);
}

.muted {
  color: var(--ctrl-label);
  font-size: var(--ctrl-fs);
}

.panel h2 {
  color: #e2e8f0;
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 12px;
}

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

.panel-head h2 {
  margin: 0;
}

.orders-table tfoot td {
  font-weight: 600;
  border-top: var(--ctrl-border);
}

.summary-facts {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 28px;
  margin-top: 12px;
  overflow-x: auto;
}

.summary-facts .summary-meta,
.summary-facts .metric-grid {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 28px;
  margin-top: 0;
}

.summary-facts .metric {
  min-width: 0;
}

#lines-toolbar .btn-secondary.is-active {
  background: #3273f6;
  border-color: #3273f6;
  color: #f8fafc;
}

table.data.order-detail input.line-actual {
  width: 120px;
  text-align: right;
}

.summary-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.summary-id-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.summary-id {
  margin: 0;
  color: #f8fafc;
  font-size: 1.125rem;
  font-weight: 600;
}

#order-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
}

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

.detail-title {
  margin: 0;
  color: #e2e8f0;
  font-size: 1rem;
  font-weight: 600;
}

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

.mode-chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  border: var(--ctrl-border);
  background: transparent;
  color: var(--ctrl-fg);
  font-size: var(--ctrl-label-fs);
  line-height: 1;
  cursor: pointer;
}

.mode-chip.is-active {
  background: #3273f6;
  border-color: #3273f6;
  color: #f8fafc;
}

.share-record {
  margin: 0 0 12px;
}

.share-record > summary {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.share-record > summary::-webkit-details-marker {
  display: none;
}

.share-fold {
  width: 16px;
  height: 16px;
  margin-top: 3px;
  flex: none;
  color: #cbd5e1;
  transition: transform 0.15s ease;
}

.share-record[open] > summary .share-fold {
  transform: rotate(90deg);
}

.share-mark {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex: none;
  color: #94a3b8;
}

.share-summary-body {
  flex: 1;
  min-width: 0;
}

.share-summary-body p {
  margin: 0 0 4px;
}

.share-summary .form-actions {
  margin-top: 0;
  flex: none;
}

.share-detail {
  margin-top: 8px;
}

.summary-card,
#order-lines,
#order-attachments {
  max-width: 100%;
  min-width: 0;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: var(--ctrl-border);
  font-size: var(--ctrl-label-fs);
  line-height: 1;
}

.status-chip-draft {
  background: rgba(56, 189, 248, 0.16);
  color: #7dd3fc;
}

.status-chip-confirmed {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}

.status-chip-voided {
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

.status-chip-unknown {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
}

.summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin-top: 12px;
}

.summary-meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.summary-meta-item .muted {
  font-size: var(--ctrl-label-fs);
}

.summary-facts .summary-meta-item .meta-value {
  margin: 4px 0 0;
  color: var(--ctrl-fg);
  font-size: 24px;
  line-height: 1.25;
}

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

.metric-grid-single {
  grid-template-columns: minmax(0, 1fr);
}

.metric-label {
  color: var(--ctrl-label);
  font-size: var(--ctrl-label-fs);
}

.metric-value {
  margin: 4px 0 0;
  color: var(--ctrl-fg);
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Segoe UI", monospace;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.metric-value-emphasis {
  font-weight: 700;
  color: #f8fafc;
}

.metric-hint {
  margin: 6px 0 0;
  color: #fbbf24;
  font-size: var(--ctrl-label-fs);
}

.metric-unallocated .metric-value {
  color: #fbbf24;
}

.void-reason {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.detail-head {
  margin-bottom: 8px;
}

.detail-head h2 {
  margin-bottom: 4px;
}

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

table.data.order-detail th,
table.data.order-detail td {
  height: 40px;
  vertical-align: middle;
}

table.data.order-detail th.num,
table.data.order-detail td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Segoe UI", monospace;
}

table.data.order-detail th.party,
table.data.order-detail td.party {
  text-align: left;
  overflow-wrap: anywhere;
  white-space: normal;
}

table.data.order-detail td.note {
  overflow-wrap: anywhere;
  white-space: normal;
}

table.data.order-detail td.amount-emphasis {
  font-weight: 700;
  background: rgba(50, 115, 246, 0.12);
}

table.data.order-detail th.sticky-party,
table.data.order-detail td.sticky-party {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--card-bg);
}

table.data.order-detail thead th.sticky-party {
  z-index: 2;
}

table.data.order-detail .param-col {
  display: none;
}

table.data.order-detail.params-on .param-col {
  display: table-cell;
}

table.data.order-detail-all {
  min-width: 880px;
}

table.data.order-detail-all.params-on {
  min-width: 1280px;
}

table.data.order-detail-selected {
  min-width: 480px;
}

.attach-status {
  min-height: 1.25rem;
  margin: 0 0 8px;
}

.attach-empty {
  margin: 8px 0 0;
}

@media (max-width: 720px) {
  .user-bar {
    position: static;
    justify-content: flex-end;
    margin-bottom: 16px;
  }

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

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

  .summary-top {
    align-items: flex-start;
    flex-direction: column;
  }

  #order-actions {
    justify-content: flex-start;
    width: 100%;
  }
}

.gp-manage .product-bar {
  padding: 12px 16px;
}

.gp-manage .product-bar-row .field {
  margin-bottom: 0;
  max-width: 320px;
}

.gp-manage .product-bar select {
  width: 100%;
  min-width: 240px;
  max-width: 320px;
}

.gp-manage .form-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.gp-manage .form-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.gp-manage table.data.sub-lines,
.gp-manage table.data.gp-calc-table,
.gp-manage table.data.orders-table {
  min-width: 720px;
}

.gp-manage table.data.sub-lines th,
.gp-manage table.data.sub-lines td,
.gp-manage table.data.gp-calc-table th,
.gp-manage table.data.gp-calc-table td,
.gp-manage table.data.orders-table th,
.gp-manage table.data.orders-table td {
  height: 44px;
  vertical-align: middle;
}

.gp-manage table.data th.num,
.gp-manage table.data td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Segoe UI", monospace;
}

.gp-manage table.data th.party,
.gp-manage table.data td.party {
  text-align: left;
  overflow-wrap: anywhere;
  white-space: normal;
}

.gp-manage table.data td.num input,
.gp-manage table.data td.num select {
  text-align: right;
  width: 100%;
  max-width: 180px;
  margin-left: auto;
}

.gp-manage table.data.sub-lines .line-shares {
  width: 160px;
  max-width: 180px;
}

.gp-manage table.data.sub-lines .line-prio {
  width: 100px;
  max-width: 100px;
}

.gp-manage table.data.sub-lines .line-yield {
  width: 140px;
  max-width: 140px;
}

.gp-manage table.data td.amount-emphasis {
  font-weight: 700;
  background: rgba(50, 115, 246, 0.12);
}

.gp-manage table.data th.actions,
.gp-manage table.data td.actions {
  text-align: right;
  white-space: nowrap;
}

.gp-manage #calc-context:empty,
.gp-manage #calc-freshness:empty {
  display: none;
}

@media (max-width: 1100px) {
  .gp-manage .form-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 639px) {
  .gp-manage .product-bar-row .field,
  .gp-manage .product-bar select {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .gp-manage .form-grid-4 {
    grid-template-columns: 1fr;
  }

  .gp-manage .form-actions {
    justify-content: stretch;
  }

  .gp-manage .form-actions .btn-primary,
  .gp-manage .form-actions .btn-secondary {
    width: auto;
  }
}

.sheet-dialog {
  background: var(--card-bg);
  color: var(--ctrl-fg);
  color-scheme: dark;
  border: var(--ctrl-border);
  border-radius: 8px;
  padding: 16px 20px 20px;
  max-width: 920px;
  width: calc(100vw - 32px);
}

.sheet-dialog-wide {
  max-width: min(1280px, calc(100vw - 32px));
}

.sheet-dialog .muted {
  color: var(--ctrl-label);
}

.sheet-dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.dialog-bar h2,
.sheet-dialog h2 {
  margin: 0;
  color: #e2e8f0;
  font-size: 1.125rem;
  font-weight: 600;
}

.timeline-table {
  border-collapse: collapse;
}

.gp-manage table.data.timeline-table th,
.gp-manage table.data.timeline-table td {
  white-space: nowrap;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  vertical-align: middle;
}

.gp-manage table.data.timeline-table th {
  vertical-align: bottom;
  text-align: center;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ctrl-fg);
}

.timeline-table .share-up {
  color: #f87171;
}

.timeline-table .share-down {
  color: #4ade80;
}

.timeline-table .yield-cell {
  color: var(--ctrl-fg);
}

#environment-mark {
  position: sticky;
  top: 0;
  z-index: 20;
  margin: 0;
  padding: 10px 16px;
  background: #c2410c;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-align: center;
}
