:root {
  --bg: #0f1419;
  --panel: #171d25;
  --border: #2a3441;
  --text: #e8eef6;
  --muted: #93a0b0;
  --accent: #3d9cf0;
  --ok: #2f9e6b;
  --danger: #d45454;
  --warn: #c9953a;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2740 0%, var(--bg) 45%);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }

.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: #121820;
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar nav a {
  color: var(--muted);
  padding: 10px 12px;
  border-radius: 8px;
}
.sidebar nav a.active,
.sidebar nav a:hover {
  background: #1d2734;
  color: var(--text);
}
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }
.content { flex: 1; }
.topbar { padding: 22px 28px 0; }
.topbar h1 { margin: 0; font-size: 1.4rem; }
.page { padding: 20px 28px 40px; }

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card, .panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card-label { color: var(--muted); font-size: .85rem; }
.card-value { font-size: 1.8rem; font-weight: 700; margin-top: 6px; }
.grid-2 {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.settings-grid {
  grid-template-columns: minmax(320px, 1fr) minmax(320px, 1fr);
}
.settings-2fa {
  margin-bottom: 16px;
}
.settings-hint {
  font-size: .85rem;
  line-height: 1.35;
  margin: 0;
}
.totp-setup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
}
.totp-qr {
  margin: 0;
  text-align: center;
}
.totp-qr img {
  display: block;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
.form-row-tight {
  display: grid;
  gap: 10px;
}
.form { display: grid; gap: 10px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 10px;
}
.licenses-layout,
.ips-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.ips-list { min-width: 0; }
.ips-table { min-width: 720px; }
.ips-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.ips-toolbar h2 { margin: 0; }
.ips-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.ips-filters select { min-width: 160px; }
.ips-max-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.ips-max-form input[type="number"] { width: 72px; }
.text-danger { color: #e35d6a; }
.licenses-form { position: relative; z-index: 2; }
.licenses-list { min-width: 0; }
.licenses-table { min-width: 720px; }
.help-panel h2 { margin-top: 0; }
.help-steps {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  display: grid;
  gap: 6px;
}
.help-steps strong { color: var(--text); }
.key-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  max-width: 360px;
}
.actions-bar form { margin: 0; }
.inline-renew {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.inline-renew input[type="number"],
.inline-renew input[name="ip_address"] {
  width: 72px;
  padding: 6px 8px;
}
.btn-xs {
  padding: 6px 8px;
  font-size: .78rem;
  font-weight: 600;
}
.badge.active, .badge-cdd {
  background: color-mix(in srgb, var(--accent) 40%, black);
}
.badge.suspended { background: color-mix(in srgb, var(--warn) 35%, black); }
label { display: grid; gap: 6px; font-size: .9rem; color: var(--muted); }
input, select, textarea, button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f151d;
  color: var(--text);
  padding: 10px 12px;
}
button {
  background: var(--accent);
  border: none;
  color: #041018;
  font-weight: 700;
  cursor: pointer;
}
.btn-secondary { background: #2a3648; color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.inline { display: inline-flex; gap: 6px; align-items: center; }
.tight input { width: 120px; padding: 6px 8px; }
.actions { display: flex; flex-direction: column; gap: 6px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: .92rem; }
th { color: var(--muted); font-weight: 600; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  background: #243041;
  font-size: .78rem;
}
.badge.ok { background: color-mix(in srgb, var(--ok) 35%, black); }
.badge.online { background: color-mix(in srgb, var(--ok) 45%, black); }
.badge.offline { background: #2a3340; color: var(--muted); }
.badge.invalid_key, .badge.revoked, .badge.ip_denied, .badge.expired { background: color-mix(in srgb, var(--danger) 35%, black); }
.logs-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}
.logs-filters label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.logs-filters input, .logs-filters select { min-width: 120px; }
.check-inline { flex-direction: row !important; align-items: center; gap: 6px !important; }
.alert {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  background: #243041;
}
.alert.ok { background: color-mix(in srgb, var(--ok) 25%, black); }
.alert.error, .alert.danger { background: color-mix(in srgb, var(--danger) 25%, black); }

.logs-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.logs-live {
  display: flex;
  align-items: center;
  gap: 8px;
}
.live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(47, 158, 107, .6);
  animation: live-pulse 1.6s ease-out infinite;
}
.live-dot.paused {
  background: var(--warn);
  animation: none;
}
.live-dot.offline {
  background: var(--danger);
  animation: none;
}
@keyframes live-pulse {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 107, .55); }
  70% { box-shadow: 0 0 0 8px rgba(47, 158, 107, 0); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 107, 0); }
}
.logs-toolbar-actions { display: flex; gap: 8px; }
tr.log-flash td {
  animation: log-flash .9s ease;
}
@keyframes log-flash {
  from { background: color-mix(in srgb, var(--accent) 28%, transparent); }
  to { background: transparent; }
}

.stack { display: grid; gap: 16px; }
label.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text);
  white-space: normal;
  line-height: 1.35;
}
label.check input {
  width: auto;
  margin-top: 3px;
  flex: 0 0 auto;
}
label.check span {
  min-width: 0;
  overflow-wrap: anywhere;
}
.code-sample {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: 8px;
  background: #0b1118;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .78rem;
  overflow: auto;
  white-space: pre-wrap;
}

.processor-grid { align-items: start; }
.processor-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.processor-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.button-link {
  display: inline-block;
  background: var(--accent);
  color: #041018 !important;
  font-weight: 700;
  padding: 10px 12px;
  border-radius: 8px;
}
.badge.done, .badge.ready { background: color-mix(in srgb, var(--ok) 35%, black); }
.badge.processing, .badge.scanning, .badge.uploaded { background: color-mix(in srgb, var(--warn) 35%, black); }
.badge.error { background: color-mix(in srgb, var(--danger) 35%, black); }

.dropzone {
  position: relative;
  border: 2px dashed #4a5d75;
  border-radius: 14px;
  background: #101822;
  min-height: 280px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease, transform .15s ease;
  margin-bottom: 10px;
  outline: none;
  overflow: hidden;
}
.dropzone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 3;
  font-size: 0;
}
.dropzone:hover {
  border-color: #6f879f;
  background: #132033;
}
.dropzone.dragover {
  border-style: solid;
  border-color: #2f9e6b !important;
  background: #1b3d2d !important;
  box-shadow: 0 0 0 4px rgba(47, 158, 107, .4), inset 0 0 50px rgba(47, 158, 107, .25);
  transform: scale(1.02);
}
.dropzone.dragover strong { color: #9af0c8; }
.dropzone.dragover #dropzone-hint { color: #8fddb8; }
.dropzone.has-file {
  border-style: solid;
  border-color: #2f9e6b;
  background: #163528;
  box-shadow: 0 0 0 2px rgba(47, 158, 107, .3);
}
.dropzone.has-file strong { color: #9af0c8; }
.dropzone-inner {
  display: grid;
  gap: 8px;
  text-align: center;
  padding: 22px 18px;
  pointer-events: none;
  z-index: 1;
  position: relative;
}
.dropzone-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 4px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  color: #9eb0c3;
  background: #1a2432;
  border: 1px solid #2a3648;
}
.dropzone.dragover .dropzone-icon,
.dropzone.has-file .dropzone-icon {
  color: #0d281c;
  background: #2f9e6b;
  border-color: #3cbc80;
}
.dropzone-file {
  margin-top: 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: .85rem;
  word-break: break-all;
}
#upload-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.hidden { display: none !important; }

.upload-progress {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}
.upload-progress-bar,
.overlay-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #243041;
  overflow: hidden;
}
.upload-progress-bar span,
.overlay-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2f7cc8, #3d9cf0);
  transition: width .15s ease;
}
.upload-progress-text {
  color: var(--muted);
  font-size: .9rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 16, .72);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 9999;
  padding: 20px;
}
.loading-card {
  width: min(420px, 100%);
  background: #171d25;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 22px;
  text-align: center;
  display: grid;
  gap: 10px;
}
.loading-card h3 { margin: 0; }
.loading-spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto 6px;
  border-radius: 50%;
  border: 3px solid #2a3648;
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
body.loading-lock { overflow: hidden; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}
.auth-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  display: grid;
  gap: 12px;
}
.auth-card h1 { margin: 0; font-size: 1.3rem; }
.auth-card form { display: grid; gap: 12px; }

.fm {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}
.fm-tree {
  max-height: calc(100vh - 120px);
  overflow: auto;
  padding: 10px 8px;
}
.fm-tree-title {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 4px 8px 10px;
}
.fm-tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--text);
  font-size: .86rem;
  white-space: nowrap;
}
.fm-tree-item:hover, .fm-tree-item.active { background: #094771; color: #fff; }
.fm-right { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.fm-path { padding: 10px 14px; }
.fm-path-bar {
  margin: 4px 0 8px;
  padding: 6px 8px;
  background: #0d1218;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: .85rem;
  overflow-x: auto;
  white-space: nowrap;
}
.fm-table-wrap { padding: 0; overflow: auto; max-height: 420px; }
.fm-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.fm-table th {
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: #151c24;
  position: sticky;
  top: 0;
}
.fm-table td { padding: 5px 10px; border-bottom: 1px solid #1a222c; }
.fm-table td:nth-child(2), .fm-table th:nth-child(2) { text-align: right; width: 90px; white-space: nowrap; }
.fm-table td:nth-child(3) { width: 150px; color: var(--muted); }
.fm-table td:nth-child(4) { width: 140px; color: var(--muted); white-space: nowrap; }
.fm-table tr:hover td { background: #094771; color: #fff; }
.fm-table tr:hover td, .fm-table tr:hover a, .fm-table tr.active td, .fm-table tr.active a { color: #fff; }
.fm-table tr.active td { background: #0078d4; }
.fm-table td a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.fm-icon { width: 18px; height: 18px; flex-shrink: 0; }
.editor-layout {
  display: grid;
  grid-template-columns: minmax(280px, 400px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.editor-side { max-height: calc(100vh - 120px); overflow: auto; }
.editor-crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0 0 12px;
  font-size: .88rem;
}
.editor-crumbs a { color: var(--muted); }
.editor-crumbs a:hover { color: var(--text); }
.editor-crumbs .here { color: var(--text); font-weight: 600; }
.editor-list { display: flex; flex-direction: column; gap: 2px; }
.editor-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  font-size: .9rem;
}
.editor-item:hover, .editor-item.active { background: #1d2734; }
.editor-item .tag {
  color: var(--muted);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  min-width: 52px;
}
.editor-toolbar { display: flex; gap: 12px; align-items: baseline; margin-bottom: 10px; flex-wrap: wrap; }
.editor-code {
  width: 100%;
  min-height: 480px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 13px;
  line-height: 1.45;
  background: #0d1218;
  color: #e8eef6;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
}
.editor-actions { margin: 10px 0; display: flex; gap: 8px; flex-wrap: wrap; }
.editor-main .inline { display: inline-block; margin-right: 8px; }
@media (max-width: 980px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; }
  .cards, .grid-2, .licenses-layout, .ips-layout, .settings-grid, .totp-setup, .editor-layout, .fm { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
