:root {
  --bg: #f5f6f2;
  --panel: #ffffff;
  --panel-alt: #f9faf7;
  --ink: #17201a;
  --muted: #667069;
  --line: #d9dfd7;
  --line-strong: #b9c3b6;
  --accent: #245f63;
  --accent-ink: #ffffff;
  --blue: #315f91;
  --green: #2f6f4e;
  --amber: #9b6618;
  --red: #a34242;
  --violet: #67508d;
  --shadow: 0 18px 45px rgba(31, 44, 34, 0.1);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 20px 16px;
  color: #f6f9f7;
  background: #17201a;
  border-right: 1px solid #0f1511;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: #245f63;
  border-radius: 8px;
  font-weight: 800;
}

.brand-block h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.15;
  letter-spacing: 0;
}

.brand-block p {
  margin: 3px 0 0;
  color: rgba(246, 249, 247, 0.68);
  font-size: 12px;
}

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

.nav-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  color: rgba(246, 249, 247, 0.76);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  text-align: left;
}

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

.nav-icon {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  color: #d5e0d7;
  font-size: 15px;
}

.sidebar-footer {
  width: 100%;
  margin-top: auto;
  padding: 14px 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: rgba(246, 249, 247, 0.72);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  text-align: left;
}

.sidebar-footer:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.24);
}

.sidebar-footer strong {
  display: block;
  margin-top: 5px;
  color: #ffffff;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.sidebar-footer em {
  display: block;
  margin-top: 8px;
  color: rgba(246, 249, 247, 0.58);
  font-style: normal;
}

.workspace {
  min-width: 0;
  padding: 20px 24px 32px;
}

.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 0 0 18px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

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

.cloud-status {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.cloud-status.online {
  color: var(--green);
  background: #edf6ee;
  border-color: #c7dccb;
}

.cloud-status.configured {
  color: var(--blue);
  background: #edf3fb;
  border-color: #c8d7ea;
}

.cloud-status.error {
  color: var(--red);
  background: #fff0ef;
  border-color: #e6b8b3;
}

.hidden {
  display: none !important;
}

.view-root {
  padding-top: 18px;
}

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

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.toolbar.compact {
  padding: 10px 12px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.content-grid.wide-side {
  grid-template-columns: minmax(0, 1fr) 430px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.panel-body {
  padding: 16px;
}

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

.metric {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
  line-height: 1;
}

.metric b {
  display: inline-block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  background: var(--panel-alt);
  font-weight: 700;
  white-space: nowrap;
}

td {
  line-height: 1.45;
}

tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;
  font-size: 12px;
}

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

.tight {
  white-space: nowrap;
}

.form-grid {
  display: grid;
  gap: 12px;
}

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

.form-field {
  display: grid;
  gap: 6px;
}

.form-field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

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

textarea {
  min-height: 76px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 95, 99, 0.14);
}

.checkbox-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.checkbox-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
}

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

.soft-rule {
  margin: 18px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.primary-button,
.ghost-button,
.danger-button,
.small-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.primary-button {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}

.primary-button:hover {
  background: #1c4e52;
}

.ghost-button {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line-strong);
}

.ghost-button:hover {
  border-color: var(--accent);
}

.danger-button {
  color: #ffffff;
  background: var(--red);
  border-color: var(--red);
}

.small-button {
  min-height: 30px;
  padding: 5px 9px;
  color: var(--accent);
  background: #eef6f4;
  border-color: #c7dbd6;
  font-size: 12px;
}

.file-button {
  position: relative;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 12px;
  white-space: nowrap;
}

.status-active,
.status-available,
.status-released,
.status-finished,
.status-approved,
.status-revision {
  color: var(--green);
  background: #edf6ee;
  border-color: #c7dccb;
}

.status-draft,
.status-qc,
.status-prototype {
  color: var(--amber);
  background: #fff7e9;
  border-color: #ead2a6;
}

.status-hold,
.status-scrapped,
.status-new_part {
  color: var(--red);
  background: #fff0ef;
  border-color: #e6b8b3;
}

.status-built,
.status-issued,
.status-borrowed {
  color: var(--blue);
  background: #edf3fb;
  border-color: #c8d7ea;
}

.status-superseded,
.status-closed {
  color: var(--violet);
  background: #f3eef9;
  border-color: #d4c7e4;
}

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

.list-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: 0;
}

.list-row strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

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

.list-row b {
  white-space: nowrap;
}

.allocation-table table {
  min-width: 680px;
}

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

.rule-item {
  padding: 12px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.rule-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.rule-item strong {
  display: block;
  margin-top: 6px;
  font-size: 13px;
}

.label-preview {
  max-width: 420px;
  padding: 18px;
  background: #ffffff;
  border: 2px solid #111811;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.label-preview h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.label-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid #d8d8d8;
}

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

.label-line strong {
  text-align: right;
  word-break: break-word;
}

.payload-box {
  margin-top: 14px;
  padding: 12px;
  color: #111811;
  background: #f1f3ef;
  border: 1px dashed #888f88;
  border-radius: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 10;
  display: none;
  max-width: 360px;
  padding: 12px 14px;
  color: #ffffff;
  background: #17201a;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

.toast.show {
  display: block;
}

.help-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  padding: 22px;
}

.help-modal.open {
  display: grid;
  place-items: center;
}

.help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 21, 17, 0.62);
  border: 0;
  border-radius: 0;
}

.help-dialog {
  position: relative;
  width: min(1080px, 100%);
  max-height: calc(100vh - 44px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(15, 21, 17, 0.28);
  overflow: hidden;
}

.cloud-dialog {
  width: min(920px, 100%);
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-alt);
}

.help-header h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  border-color: var(--accent);
}

.help-content {
  overflow: auto;
  padding: 20px;
}

.help-content section {
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.help-content section:first-child {
  padding-top: 0;
}

.help-content section:last-child {
  border-bottom: 0;
}

.help-content h3 {
  margin: 0 0 12px;
  font-size: 17px;
  line-height: 1.25;
}

.help-content h4 {
  margin: 0 0 8px;
  font-size: 14px;
}

.help-content p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.help-content code {
  padding: 1px 5px;
  color: #123b3f;
  background: #edf6f4;
  border: 1px solid #c7dbd6;
  border-radius: 4px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", ui-monospace, monospace;
  font-size: 12px;
}

.help-lead > p {
  max-width: 800px;
}

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

.concept-grid > div,
.help-table > div,
.help-columns > div,
.decision-list > div {
  padding: 13px;
  background: var(--panel-alt);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.concept-grid span {
  display: inline-flex;
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.concept-grid strong,
.help-table strong,
.decision-list strong {
  display: block;
  margin-bottom: 5px;
  font-size: 14px;
}

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

.rule-note {
  display: grid;
  gap: 8px;
  padding: 14px;
  background: #fbfcfa;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.step-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.step-list li {
  padding-left: 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.step-list strong {
  color: var(--ink);
}

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

.decision-list .primary-button,
.decision-list .ghost-button {
  margin-top: 12px;
}

.cloud-warning {
  margin-top: 10px !important;
  color: var(--amber) !important;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 18px;
  background: #f5f6f2;
}

.auth-gate.open {
  display: grid;
}

.auth-card {
  width: min(430px, 100%);
  padding: 22px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-brand {
  padding: 0 0 16px;
  margin-bottom: 18px;
  color: var(--ink);
  border-bottom-color: var(--line);
}

.auth-brand p {
  color: var(--muted);
}

.auth-card h2 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.auth-copy,
.auth-note,
.auth-error {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.auth-copy {
  margin: 0 0 16px;
}

.auth-note {
  margin: 0;
}

.auth-error {
  display: none;
  margin: 0;
  padding: 9px 10px;
  color: var(--red);
  background: #fff0ef;
  border: 1px solid #e6b8b3;
  border-radius: 8px;
}

.auth-error.show {
  display: block;
}

body.auth-required .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

body.modal-open {
  overflow: hidden;
}

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

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

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .brand-block {
    padding-bottom: 12px;
  }

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

  .nav-item {
    justify-content: center;
  }

  .sidebar-footer {
    margin-top: 0;
  }

  .content-grid,
  .content-grid.wide-side {
    grid-template-columns: 1fr;
  }

  .metric-grid,
  .rule-strip,
  .concept-grid,
  .help-table,
  .help-columns,
  .decision-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px 12px 24px;
  }

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

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > * {
    flex: 1 1 auto;
  }

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

  .metric-grid,
  .rule-strip,
  .concept-grid,
  .help-table,
  .help-columns,
  .decision-list,
  .form-row {
    grid-template-columns: 1fr;
  }

  .help-modal {
    padding: 8px;
  }

  .help-dialog {
    max-height: calc(100vh - 16px);
  }

  .help-header,
  .help-content {
    padding: 14px;
  }

  .help-header h2 {
    font-size: 18px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-group {
    width: 100%;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .sidebar,
  .topbar,
  .toolbar,
  .panel:not(.print-panel),
  .toast {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .workspace {
    padding: 0;
  }

  .label-preview {
    box-shadow: none;
  }
}
