:root {
  color-scheme: light;
  --page: #f4f6f4;
  --surface: #ffffff;
  --surface-muted: #f8faf8;
  --text: #17211b;
  --muted: #66736b;
  --border: #d8ded9;
  --border-strong: #b8c2bb;
  --accent: #176b45;
  --accent-hover: #125738;
  --info: #315f89;
  --warning: #9b5d12;
  --danger: #a23a35;
  --danger-hover: #842e2a;
  --focus: #2d70a3;
  --radius: 6px;
  --shadow: 0 10px 30px rgba(24, 39, 30, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  background: var(--page);
}

body {
  margin: 0;
  min-width: 0;
  color: var(--text);
  background: var(--page);
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
.table-frame:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.shell {
  width: min(1400px, calc(100% - 48px));
  margin: 0 auto;
}

.app-header {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-block {
  display: flex;
  align-items: baseline;
  gap: 14px;
  min-width: 0;
}

.product-name {
  margin: 0;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

.header-actions,
.primary-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.connection {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  white-space: nowrap;
}

.connection-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  border-radius: 50%;
  background: var(--warning);
}

.connection.is-online .connection-dot {
  background: var(--accent);
}

.connection.is-error .connection-dot {
  background: var(--danger);
}

.main-content {
  padding: 24px 0 40px;
}

.summary-strip {
  min-height: 82px;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.summary-item {
  min-width: 0;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-right: 1px solid var(--border);
}

.summary-item:last-child {
  border-right: 0;
}

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

.summary-item strong {
  font-size: 24px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}

.workspace {
  margin-top: 24px;
}

.section-heading {
  min-height: 48px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.section-heading p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.toolbar {
  margin: 12px 0;
  display: grid;
  grid-template-columns: minmax(220px, 420px) 160px 150px;
  gap: 8px;
}

.search-field,
.filter-field {
  min-width: 0;
}

input,
select {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}

input::placeholder {
  color: #879189;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--accent);
}

.selection-bar {
  min-height: 52px;
  margin-bottom: 12px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #b9d2c2;
  border-radius: var(--radius);
  background: #eef7f1;
}

.selection-bar[hidden] {
  display: none;
}

.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.selection-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.selection-actions select {
  width: 180px;
}

.button,
.icon-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-weight: 600;
}

.button {
  padding: 0 14px;
  white-space: nowrap;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.button-primary {
  color: #ffffff;
  background: var(--accent);
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.button-secondary {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface);
}

.button-secondary:hover:not(:disabled) {
  background: var(--surface-muted);
}

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

.button-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

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

.icon-button:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.table-frame {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  min-width: 1390px;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 600;
}

th.checkbox-column { width: 46px; }
th:nth-child(2) { width: 232px; }
th:nth-child(3) { width: 84px; }
th:nth-child(4) { width: 84px; }
th:nth-child(5) { width: 140px; }
th:nth-child(6) { width: 76px; }
th:nth-child(7) { width: 150px; }
th:nth-child(8) { width: 174px; }
th:nth-child(9) { width: 120px; }
th:nth-child(10) { width: 116px; }
th.actions-column { width: 168px; }

.checkbox-column {
  padding-left: 13px;
  padding-right: 8px;
  text-align: center;
}

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

tbody tr:hover td {
  background: #fbfcfb;
}

.code-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

code,
.machine-code {
  font-family: Consolas, "Cascadia Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.code-cell code {
  color: #123b2a;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.code-cell .text-button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.text-button {
  padding: 2px 4px;
  color: var(--info);
  border: 0;
  border-radius: 3px;
  background: transparent;
  font-size: 12px;
}

.text-button:hover {
  background: #edf4f8;
}

.text-button.danger {
  color: var(--danger);
}

.status-badge,
.edition-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.status-available { color: var(--accent); background: #eef7f1; border-color: #bad7c5; }
.status-bound { color: var(--info); background: #edf4f8; border-color: #bdcfdd; }
.status-expired { color: var(--warning); background: #faf3e9; border-color: #ddc6a3; }
.status-revoked { color: var(--danger); background: #fbefee; border-color: #dfbbb8; }
.status-pending_deletion { color: var(--info); background: #edf4f8; border-color: #bdcfdd; }
.edition-standard { color: #58665d; background: #f2f4f2; border-color: #cbd2cd; }
.edition-enhanced { color: #7a4b0c; background: #fff5df; border-color: #dec38d; }

.points-value {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.cell-primary,
.cell-secondary {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-secondary {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 28px;
}

.table-message {
  height: 180px;
  color: var(--muted);
  text-align: center;
}

.mobile-license-list {
  display: none;
}

dialog {
  width: min(520px, calc(100% - 32px));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 32px);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(18, 27, 21, 0.42);
}

.dialog-header,
.dialog-footer {
  min-height: 58px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
}

.dialog-header {
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.dialog-body {
  padding: 20px 16px;
}

.dialog-body code {
  display: block;
  margin-top: 12px;
  padding: 10px;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.dialog-footer {
  justify-content: flex-end;
  gap: 8px;
  border-top: 1px solid var(--border);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-grid.one-column {
  grid-template-columns: 1fr;
}

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

.form-grid .full-width {
  grid-column: 1 / -1;
}

.points-control {
  min-height: 38px;
  display: grid;
  grid-template-columns: 18px auto minmax(92px, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 400;
}

.points-control #create-points {
  min-width: 0;
}

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

.model-config-dialog {
  width: min(920px, calc(100% - 32px));
  overflow: hidden;
}

.model-config-dialog .dialog-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.model-config-layout {
  min-height: 450px;
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
}

.model-config-list-pane {
  min-width: 0;
  padding: 16px;
  overflow: auto;
  border-right: 1px solid var(--border);
  background: var(--surface-muted);
}

.model-config-list-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.model-config-list-heading h3 {
  margin: 0;
  font-size: 14px;
}

.model-config-list {
  margin-top: 12px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.model-config-item {
  min-width: 0;
  padding: 11px 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.model-config-item strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-config-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.model-config-form {
  min-width: 0;
  padding: 20px;
  display: grid;
  align-content: start;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.model-config-form label {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.model-config-form label:nth-of-type(n + 3),
.model-config-form .dialog-hint,
.model-config-form-actions {
  grid-column: 1 / -1;
}

.model-config-form .dialog-hint {
  margin: 0;
}

.model-config-form-actions {
  min-height: 0;
  padding: 16px 0 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(420px, calc(100% - 40px));
  padding: 10px 14px;
  color: #ffffff;
  border-radius: var(--radius);
  background: #24342a;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

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

.toast.is-error {
  background: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .summary-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .summary-item:nth-child(3) {
    border-right: 0;
  }

  .summary-item:nth-child(n + 4) {
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1400px);
  }

  .header-inner {
    min-height: 96px;
    align-items: flex-start;
    padding: 14px 0;
    gap: 12px;
  }

  .brand-block {
    display: block;
  }

  .product-name {
    margin-bottom: 3px;
  }

  .header-actions {
    align-items: flex-end;
    flex-direction: column;
  }

  .connection {
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .main-content {
    padding-top: 16px;
  }

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

  .summary-item,
  .summary-item:nth-child(3) {
    border-right: 1px solid var(--border);
  }

  .summary-item:nth-child(even) {
    border-right: 0;
  }

  .summary-item:nth-child(n + 3) {
    border-top: 1px solid var(--border);
  }

  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-actions {
    display: grid;
    grid-template-columns: 64px 84px minmax(0, 1fr);
  }

  .primary-actions .button {
    min-width: 0;
    padding: 0 10px;
  }

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

  .selection-bar {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .selection-actions {
    width: 100%;
    margin-left: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 70px;
  }

  .selection-actions select {
    width: 100%;
  }

  .selection-actions #clear-selection {
    grid-column: 1 / -1;
  }

  .table-frame {
    display: none;
  }

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

  .mobile-license-item {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

  .mobile-item-header {
    display: grid;
    gap: 10px;
  }

  .mobile-identity,
  .mobile-badges {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
  }

  .mobile-identity code {
    min-width: 0;
    overflow: hidden;
    color: #123b2a;
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-badges {
    padding-left: 26px;
  }

  .mobile-details {
    margin: 12px 0 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-top: 1px solid var(--border);
  }

  .mobile-details div {
    min-width: 0;
    padding: 9px 8px 7px 0;
    border-bottom: 1px solid var(--border);
  }

  .mobile-details div:nth-child(even) {
    padding-left: 8px;
    border-left: 1px solid var(--border);
  }

  .mobile-details dt {
    color: var(--muted);
    font-size: 11px;
  }

  .mobile-details dd {
    margin: 2px 0 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-item-footer {
    padding-top: 8px;
  }

  .mobile-item-footer .row-actions {
    justify-content: flex-end;
  }

  .mobile-empty {
    min-height: 160px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
  }

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

  .form-grid .full-width {
    grid-column: auto;
  }

  .model-config-dialog {
    width: calc(100% - 16px);
    overflow: auto;
  }

  .model-config-layout {
    min-height: 0;
    grid-template-columns: 1fr;
  }

  .model-config-list-pane {
    max-height: 220px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .model-config-form {
    padding: 16px;
    grid-template-columns: 1fr;
  }

  .model-config-form label:nth-of-type(n + 3),
  .model-config-form .dialog-hint,
  .model-config-form-actions {
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
}
