:root {
  color-scheme: dark;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 14px;
  --bg: #111315;
  --surface: #171a1d;
  --surface-strong: #1e2226;
  --border: #30363b;
  --text: #f3f5f6;
  --muted: #9ea7ad;
  --green: #35b779;
  --green-dark: #187a4d;
  --cyan: #2aaac5;
  --amber: #d7a324;
  --red: #df5f61;
  --focus: #78d4e8;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button,
input,
select,
summary {
  outline: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--focus);
}

input,
select {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #0d0f11;
  color: var(--text);
  padding: 8px 10px;
}

input::placeholder {
  color: #69737a;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 19, 21, 0.96);
  backdrop-filter: blur(10px);
}

.topbar-inner {
  width: min(1600px, calc(100% - 32px));
  min-height: 64px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-inline div {
  display: grid;
  gap: 2px;
}

.brand-inline strong {
  font-size: 15px;
}

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

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--green);
  color: #07130d;
  font-weight: 800;
  font-size: 24px;
}

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 18px;
}

.workspace {
  width: min(1600px, calc(100% - 32px));
  margin: 24px auto 48px;
}

.product-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border);
}

.product-tab {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
  background: var(--surface-strong);
  color: var(--muted);
  text-decoration: none;
}

.product-tab:hover,
.product-tab.is-active {
  background: #123323;
  color: #a5e8c5;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border-block: 1px solid var(--border);
  background: var(--surface);
}

.metrics > div {
  min-height: 84px;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  border-right: 1px solid var(--border);
}

.metrics > div:last-child {
  border-right: 0;
}

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

.metrics strong {
  font-size: 26px;
  line-height: 1;
}

.section-band {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 20px;
}

.section-heading {
  min-height: 42px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.section-heading h1,
.section-heading h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
}

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

.create-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) 100px minmax(220px, 1.2fr) 120px minmax(220px, 1fr) 100px;
  gap: 12px;
  align-items: end;
}

.create-grid label {
  min-width: 0;
  display: grid;
  gap: 7px;
}

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

.create-action {
  min-height: 38px;
}

.quick-expiry {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 7px 12px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  filter: brightness(1.1);
}

.button-primary {
  background: var(--green);
  color: #06120c;
  font-weight: 700;
}

.button-danger {
  background: #642b2d;
  border-color: #8c3d40;
}

.button-success {
  background: var(--green-dark);
  border-color: #299264;
}

.button-quiet,
.icon-button {
  background: var(--surface-strong);
  border-color: var(--border);
}

.button-full {
  width: 100%;
}

.license-section {
  padding-inline: 0;
}

.license-heading {
  padding-inline: 20px;
}

.table-tools {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 130px 110px;
  gap: 10px;
}

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

.license-table {
  width: 100%;
  min-width: 1500px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.column-code { width: 330px; }
.column-select { width: 48px; }
.column-status { width: 110px; }
.column-expiry { width: 300px; }
.column-remaining { width: 190px; }
.column-devices { width: 100px; }
.column-heartbeat { width: 170px; }
.column-note { width: 130px; }
.column-actions { width: 170px; }

.license-table thead {
  background: #14171a;
}

.license-table th,
.license-table td {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

.license-table th {
  background: #14171a;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.license-table tbody tr:hover {
  background: #1a1e21;
}

.actions-column {
  width: 170px;
}

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

.code-cell code {
  color: #d8f3e5;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

.code-cell + small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
}

.icon-button {
  min-width: 44px;
  height: 28px;
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
}

.status {
  display: inline-flex;
  min-width: 58px;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
}

.status-active {
  background: #123d2a;
  color: #77dbaa;
}

.status-expired {
  background: #473716;
  color: #e8bd53;
}

.status-pending {
  background: #163d4a;
  color: #7ed9ef;
}

.status-revoked {
  background: #4b2426;
  color: #f08b8d;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 7px;
}

.expiration-form input {
  width: 180px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.row-actions form {
  margin: 0;
}

.mode-line {
  margin-bottom: 6px;
}

.mode-badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 700;
}

.mode-manual {
  background: #29332d;
  color: #9fdab7;
}

.mode-consignment {
  background: #243a4a;
  color: #9ddcf0;
}

.bulk-toolbar,
.batch-result,
.export-band {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 20px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  background: #14171a;
}

.bulk-toolbar {
  justify-content: space-between;
}

.selection-summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.bulk-actions,
.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.batch-result {
  border-color: #2a6f4e;
  background: #123323;
}

.batch-result span,
.export-band span {
  color: var(--muted);
}

.export-band {
  justify-content: space-between;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 16px 20px 4px;
  color: var(--muted);
}

.pagination-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.note-cell {
  min-width: 130px;
  max-width: 240px;
  overflow-wrap: anywhere;
}

details {
  position: relative;
}

summary {
  cursor: pointer;
  color: #b8dfe7;
}

.device-list {
  position: absolute;
  z-index: 15;
  top: calc(100% + 8px);
  left: 0;
  width: 280px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #101315;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  padding: 8px;
}

.device-list > div {
  display: grid;
  gap: 3px;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.device-list > div:last-child {
  border-bottom: 0;
}

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

.alert {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 11px 14px;
}

.alert-success {
  border-color: #2a6f4e;
  background: #123323;
  color: #8ce0b6;
}

.alert-error {
  border-color: #7a3538;
  background: #3d1d1f;
  color: #f2a0a2;
}

.empty-state {
  height: 120px;
  color: var(--muted);
  text-align: center !important;
}

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

.text-success {
  color: var(--green);
}

.text-warning {
  color: var(--amber);
}

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

.text-cyan {
  color: var(--cyan);
}

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

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid #2a6f4e;
  border-radius: 5px;
  background: #123323;
  color: #a5e8c5;
  padding: 10px 14px;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #0f1113;
}

.login-shell {
  width: min(390px, calc(100% - 32px));
}

.login-panel {
  border-top: 3px solid var(--green);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  padding: 32px;
}

.login-panel .brand-mark {
  margin-bottom: 22px;
}

.login-panel h1 {
  margin: 0;
  font-size: 22px;
}

.login-panel > p {
  margin: 6px 0 24px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.login-form .button {
  margin-top: 10px;
}

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

  .metrics > div:nth-child(2) {
    border-right: 1px solid var(--border);
  }

  .metrics > div:nth-child(3) {
    border-right: 0;
  }

  .metrics > div:nth-child(-n + 3) {
    border-bottom: 1px solid var(--border);
  }

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

  .create-action {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .workspace,
  .topbar-inner {
    width: min(100% - 20px, 1600px);
  }

  .workspace {
    margin-top: 12px;
  }

  .metrics,
  .create-grid,
  .table-tools {
    grid-template-columns: 1fr;
  }

  .metrics > div {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metrics > div:last-child {
    border-bottom: 0;
  }

  .section-band {
    padding: 14px;
  }

  .license-section {
    padding-inline: 0;
  }

  .license-heading {
    padding-inline: 14px;
    align-items: stretch;
    flex-direction: column;
  }
}
