:root {
  --bg: #0f1419;
  --panel: #171d25;
  --panel-2: #1f2732;
  --border: #2a3441;
  --text: #e8edf4;
  --muted: #8b98a8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #1a2330 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.view {
  min-height: 100vh;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  margin: 10vh auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}

.brand.compact {
  margin-bottom: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(135deg, #2563eb, #7c3aed);
}

.brand h1,
.brand span {
  margin: 0;
  font-size: 1.25rem;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(59, 130, 246, 0.35);
  border-color: var(--primary);
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.92rem;
}

.btn:hover {
  border-color: #405066;
}

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.35);
}

.error {
  color: #fca5a5;
  font-size: 0.88rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 20, 25, 0.85);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: calc(100vh - 73px);
}

.sidebar {
  padding: 20px 12px;
  border-right: 1px solid var(--border);
  background: rgba(23, 29, 37, 0.65);
}

.nav {
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav.active,
.nav:hover {
  background: var(--panel-2);
  color: var(--text);
  border-color: var(--border);
}

.content {
  padding: 24px;
}

.tab {
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.stat-card .label {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat-card .value {
  font-size: 1.8rem;
  font-weight: 700;
  margin-top: 8px;
}

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

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

.license-stats-panel,
.license-machine-stats-panel {
  margin-bottom: 16px;
}

.licenses-tab {
  display: flex;
  flex-direction: column;
}

.license-stats-compact {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-bottom: 14px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(23, 29, 37, 0.75);
}

.license-stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.88rem;
}

.license-stat-item em {
  font-style: normal;
  color: var(--muted);
}

.license-stat-item strong {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.licenses-tab .toolbar {
  margin-bottom: 12px;
  flex-shrink: 0;
}

.license-groups-wrap {
  overflow: auto;
  max-height: calc(100vh - 240px);
  margin-bottom: 12px;
}

.license-machine-group {
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.license-machine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.license-machine-header::-webkit-details-marker {
  display: none;
}

.license-machine-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.license-copy-btn {
  padding: 4px 10px;
  font-size: 0.75rem;
}

.license-days-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.license-days-field select {
  flex: 0 0 auto;
  min-width: 96px;
}

.license-days-field input[type='number'] {
  flex: 1 1 auto;
  min-width: 0;
}

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

.license-code-cell .mono {
  min-width: 0;
}

.price-cell {
  min-width: 110px;
}

.price-view,
.price-editor {
  display: flex;
  align-items: center;
  gap: 6px;
}

.price-editor.hidden,
.price-view.hidden {
  display: none;
}

.price-text.price-saved-flash {
  color: #86efac;
  transition: color 0.2s ease;
}

.price-input {
  width: 88px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.88rem;
}

.field-hint {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.extend-mode-fieldset {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.extend-mode-fieldset legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
}

.extend-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--text);
  font-size: 0.88rem;
}

.extend-mode-option:last-child {
  margin-bottom: 0;
}

.extend-mode-option input {
  width: auto;
  margin-top: 3px;
}

.license-machine-code {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
}

.license-machine-code::before {
  content: '▸';
  color: var(--muted);
  transition: transform 0.15s ease;
}

.license-machine-group[open] .license-machine-code::before {
  transform: rotate(90deg);
}

.license-machine-meta {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 0.82rem;
}

.license-machine-body {
  border-top: 1px solid var(--border);
}

.license-machine-body .table-wrap {
  border: none;
  border-radius: 0;
}

.license-machine-body table {
  min-width: 820px;
}

.license-machine-body th,
.license-machine-body td {
  padding: 10px 12px;
}

.licenses-tab .pager {
  margin-top: 0;
  flex-shrink: 0;
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar input,
.toolbar select {
  width: auto;
  min-width: 220px;
}

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

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.88rem;
}

th {
  background: var(--panel-2);
  color: var(--muted);
  position: sticky;
  top: 0;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.badge.active {
  background: rgba(34, 197, 94, 0.15);
  color: #86efac;
}

.badge.expired {
  background: rgba(245, 158, 11, 0.15);
  color: #fcd34d;
}

.badge.revoked {
  background: rgba(239, 68, 68, 0.15);
  color: #fca5a5;
}

.badge.inactive {
  background: rgba(148, 163, 184, 0.12);
  color: #94a3b8;
}

.badge.anomaly.high {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
}

.badge.anomaly.warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.anomaly-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 120px;
}

.anomaly-hint {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.row-anomaly--high td {
  background: rgba(239, 68, 68, 0.06);
}

.row-anomaly--warn td {
  background: rgba(245, 158, 11, 0.05);
}

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

.row-actions .btn {
  padding: 6px 10px;
  font-size: 0.78rem;
}

.nickname-cell {
  min-width: 140px;
}

.nickname-view,
.nickname-editor {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nickname-editor.hidden,
.nickname-view.hidden {
  display: none;
}

.nickname-text {
  min-width: 0;
}

.nickname-input {
  flex: 1;
  min-width: 80px;
  max-width: 160px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 0.9rem;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--panel-2);
  color: var(--text);
}

.icon-btn.primary:hover {
  color: var(--success);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.note-cell {
  max-width: 220px;
}

.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  color: var(--muted);
}

.form-panel {
  max-width: 760px;
}

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

.span-2 {
  grid-column: span 2;
}

.result-box {
  margin-top: 16px;
  padding: 14px;
  border-radius: 10px;
  background: #0b1220;
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.audit-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.audit-item {
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.86rem;
}

.audit-item time {
  color: var(--muted);
  margin-right: 10px;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.dialog-body {
  padding: 20px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

#detail-content {
  max-height: 50vh;
  overflow: auto;
  background: #0b1220;
  padding: 12px;
  border-radius: 10px;
}

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

.events-detail-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 16px;
}

.events-detail-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
}

.event-day-group {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.event-day-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.event-day-header::-webkit-details-marker {
  display: none;
}

.event-day-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.98rem;
  font-weight: 600;
}

.event-day-title::before {
  content: '▸';
  color: var(--muted);
  transition: transform 0.15s ease;
}

.event-day-group[open] .event-day-title::before {
  transform: rotate(90deg);
}

.event-day-body {
  border-top: 1px solid var(--border);
}

.event-day-body .table-wrap {
  border: none;
  border-radius: 0;
}

.event-day-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.event-day-group--anomaly {
  border-color: rgba(245, 158, 11, 0.35);
}

.events-anomaly-panel {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid rgba(245, 158, 11, 0.28);
  background: rgba(245, 158, 11, 0.08);
}

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

.events-anomaly-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.events-anomaly-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(15, 20, 25, 0.35);
  border: 1px solid var(--border);
}

.events-anomaly-item--high {
  border-color: rgba(239, 68, 68, 0.28);
  background: rgba(239, 68, 68, 0.08);
}

.events-anomaly-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.events-anomaly-copy strong {
  font-size: 0.88rem;
}

.events-anomaly-copy span {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.event-row-anomaly--high td {
  background: rgba(239, 68, 68, 0.08);
}

.event-row-anomaly--warn td {
  background: rgba(245, 158, 11, 0.06);
}

.event-name-cell {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.event-anomaly-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 600;
  white-space: nowrap;
}

.event-anomaly-tag--high {
  background: rgba(239, 68, 68, 0.18);
  color: #fecaca;
}

.event-anomaly-tag--warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.empty-hint {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

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

  .sidebar {
    display: flex;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    width: auto;
    white-space: nowrap;
  }

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

  .span-2 {
    grid-column: span 1;
  }
}
