﻿:root {
  --bg-a: #eef4fb;
  --bg-b: #dce8f7;
  --panel-bg: rgba(255, 255, 255, 0.92);
  --line: #d8e3ef;
  --text: #1e2f42;
  --muted: #5f748a;
  --brand: #1c6de5;
  --brand-strong: #0f56bd;
  --danger: #ba2c2c;
  --danger-soft: #ffeaea;
  --ok: #1a915e;
  --warn: #d17f14;
  --shadow: 0 10px 28px rgba(25, 58, 100, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  color: var(--text);
  font-family: "Segoe UI Variable", "Trebuchet MS", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(145deg, var(--bg-a), var(--bg-b));
  overflow: hidden;
}

.bg-decor {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 8% 15%, rgba(28, 109, 229, 0.16), transparent 28%),
    radial-gradient(circle at 92% 80%, rgba(16, 120, 99, 0.14), transparent 25%);
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1600px;
  margin: 0 auto;
  padding: 8px;
  height: 100vh;
}

.topbar {
  position: sticky;
  top: 10px;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  box-shadow: var(--shadow);
}

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

.topbar-group.right {
  justify-content: flex-end;
}

.meta-pill {
  border: 1px solid var(--line);
  background: #f2f7ff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  color: var(--muted);
}

.btn {
  appearance: none;
  border: 1px solid #b7c8dc;
  background: #ffffff;
  color: var(--text);
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #9cb4cc;
  box-shadow: 0 4px 12px rgba(17, 55, 102, 0.1);
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  border-color: transparent;
  color: #fff;
}

.btn-secondary {
  background: #eef5ff;
  border-color: #c3d8f3;
}

.btn-outline-danger {
  background: #fff;
  border-color: #e4b8b8;
  color: #9f2424;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
}

.status-bar {
  min-height: 18px;
  margin: 4px 2px 0;
  border-radius: 8px;
  font-size: 12px;
  line-height: 18px;
  padding: 0 8px;
  color: var(--muted);
}

.status-bar.is-ok {
  color: var(--ok);
}

.status-bar.is-warn {
  color: var(--warn);
}

.status-bar.is-error {
  color: var(--danger);
}

.workspace-grid {
  margin-top: 6px;
  display: grid;
  width: 100%;
  grid-template-columns: minmax(200px, 0.65fr) minmax(560px, 1.55fr) minmax(200px, 0.6fr);
  grid-template-rows: minmax(0, 1fr) minmax(170px, 30vh);
  grid-template-areas:
    "products editor calc"
    "bundles bundles bundles";
  gap: 8px;
  height: calc(100vh - 108px);
  min-height: 0;
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 8px;
  min-height: 0;
  overflow: hidden;
}

.panel-products {
  grid-area: products;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-editor {
  grid-area: editor;
}

.panel-calc {
  grid-area: calc;
}

.panel-bundles {
  grid-area: bundles;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

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

.panel-header h2 {
  margin: 0;
  font-size: 16px;
}

.panel-header-calc {
  flex-wrap: wrap;
  align-items: flex-start;
}

.panel-header-calc h2 {
  flex: 0 0 100%;
  white-space: nowrap;
}

.panel-header.split {
  align-items: flex-start;
  flex-wrap: wrap;
}

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

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

.field {
  margin-bottom: 6px;
}

.field label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--muted);
}

.field input,
.field textarea {
  width: 100%;
  border: 1px solid #bfd1e6;
  border-radius: 10px;
  padding: 7px 8px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: #7ea7da;
  box-shadow: 0 0 0 2px rgba(63, 131, 221, 0.15);
}

.product-list {
  max-height: none;
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}

.product-item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid #d8e3ef;
  border-radius: 10px;
  background: #fbfdff;
  padding: 8px;
}

.thumb {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid #d5e2ef;
  object-fit: cover;
  background: #f2f6fb;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  transform-origin: center;
  position: relative;
  z-index: 1;
}

.thumb:hover {
  transform: scale(1.85);
  z-index: 10;
  box-shadow: 0 10px 20px rgba(20, 50, 92, 0.25);
}

.thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7d8fa4;
  font-size: 12px;
}

.product-main {
  min-width: 0;
}

.product-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 2px;
}

.product-meta {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-stock-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}

.stock-quick-input,
.stock-inline-input,
.sold-sets-input {
  width: 78px;
  border: 1px solid #bfd1e6;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 12px;
  color: var(--text);
  background: #fff;
}

.stock-quick-input:focus,
.stock-inline-input:focus,
.sold-sets-input:focus {
  outline: none;
  border-color: #7ea7da;
  box-shadow: 0 0 0 2px rgba(63, 131, 221, 0.15);
}

.stock-meta {
  color: #365472;
}

.stock-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.stock-sub {
  font-size: 12px;
  color: #496581;
}

.empty-block {
  border: 1px dashed #c4d5e9;
  color: #5f748a;
  border-radius: 10px;
  padding: 10px;
  background: #f7fbff;
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #d8e3ef;
  border-radius: 10px;
  background: #fff;
  margin-bottom: 6px;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.items-table th,
.items-table td {
  border-bottom: 1px solid #e4edf6;
  padding: 8px;
  font-size: 13px;
  text-align: left;
  vertical-align: middle;
}

.items-table th {
  color: #4e657d;
  background: #f2f7ff;
}

.items-table .qty-input {
  width: 90px;
}

.items-table .empty-row {
  text-align: center;
  color: var(--muted);
  padding: 16px;
}

.items-table .sum-row td {
  background: #f7fbff;
  font-weight: 700;
}

.items-table .thumb {
  width: 40px;
  height: 40px;
}

.items-table tr.missing {
  background: #fff7f7;
}

.calc-inputs {
  margin-bottom: 6px;
}

.calc-output-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.calc-output-grid.secondary {
  margin-top: 8px;
}

.kv {
  border: 1px solid #d8e3ef;
  border-radius: 10px;
  padding: 8px;
  background: #fbfdff;
}

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

.kv strong {
  font-size: 15px;
}

.warning-box {
  display: none;
  margin-top: 6px;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid #f2cb95;
  background: #fff6ea;
  color: #9a610e;
}

.warning-box.show {
  display: block;
}

.warning-box.danger {
  border-color: #efb2b2;
  background: var(--danger-soft);
  color: #9b1f1f;
}

.bundle-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  flex: 1 1 auto;
  gap: 8px;
  margin-bottom: 8px;
  overflow: auto;
  min-height: 0;
}

.bundle-card {
  border: 1px solid #d4e2f0;
  background: #fcfeff;
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.bundle-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(28, 69, 121, 0.1);
}

.bundle-card.active {
  border-color: #5b92d8;
  box-shadow: inset 0 0 0 1px #5b92d8;
}

.bundle-card.loss {
  border-color: #e0a9a9;
  background: #fff7f7;
}

.bundle-card.stock-deficit {
  border-color: #df9a9a;
}

.bundle-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}

.bundle-inline-edit {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: #3f5874;
  font-size: 12px;
}

.bundle-info {
  font-size: 12px;
  color: #516a84;
  margin: 3px 0;
  line-height: 1.35;
  word-break: break-word;
}

.bundle-info.muted {
  color: #9a2f2f;
}

.summary-grid {
  border-top: 1px dashed #c9d8e8;
  padding-top: 6px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.summary-item {
  border: 1px solid #d8e3ef;
  border-radius: 10px;
  padding: 8px;
  background: #f9fcff;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 3px;
}

.summary-item strong {
  font-size: 16px;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 1220px) {
  .workspace-grid {
    grid-template-columns: 290px 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "products editor"
      "calc calc"
      "bundles bundles";
    height: auto;
  }

  .product-list {
    max-height: 340px;
  }
}

@media (max-width: 840px) {
  body {
    overflow: auto;
  }

  .app-shell {
    padding: 8px;
    height: auto;
  }

  .topbar {
    position: static;
  }

  .workspace-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "products"
      "editor"
      "calc"
      "bundles";
    height: auto;
  }

  .topbar-group.right {
    justify-content: flex-start;
  }

  .btn {
    padding: 8px 10px;
  }

  .calc-output-grid {
    grid-template-columns: 1fr;
  }

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

  .product-list {
    max-height: 280px;
    height: auto;
  }
}
