:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #21252e;
  --border: #2a2f3a;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-hover: #3d79ec;
  --success: #34d399;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  box-shadow: 0 0 12px rgba(79, 140, 255, 0.6);
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status--online .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status--online {
  color: var(--success);
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 32px 20px 64px;
}

.container--wide {
  max-width: 960px;
}

.card--narrow {
  max-width: 520px;
  margin-left: auto;
  margin-right: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

h1 {
  font-size: 22px;
  margin: 0 0 8px;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 20px;
}

.center {
  text-align: center;
}

.qr {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: #fff;
  border-radius: var(--radius);
  margin: 0 auto 20px;
  width: fit-content;
}

.qr svg {
  display: block;
}

.manual {
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--muted);
}

.manual summary {
  cursor: pointer;
  user-select: none;
}

.manual-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.manual-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.manual-body input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  background: var(--accent);
  color: #fff;
  width: 100%;
}

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

.btn:active {
  transform: scale(0.99);
}

.btn--ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--sm {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
}

.files-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  animation: slidein 0.25s ease;
}

.file-item.is-unread {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(79, 140, 255, 0.55);
}

.file-item.is-unread .file-name::after {
  content: "новый";
  display: inline-block;
  margin-left: 8px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--accent);
  background: rgba(79, 140, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  vertical-align: middle;
}

@keyframes slidein {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.file-icon {
  font-size: 26px;
  flex-shrink: 0;
}

.file-meta {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.empty {
  text-align: center;
  color: var(--muted);
  padding: 32px 0 8px;
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 8px auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 14px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-success {
  border-color: var(--success);
}

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

.hidden {
  display: none !important;
}

/* --- Topbar right group --- */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* --- Headings --- */
h2 {
  font-size: 18px;
  margin: 0 0 8px;
}

/* --- Forms --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 13px;
}

.field span {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-size: 12px;
}

.field input,
.input-inline {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.field input:focus,
.input-inline:focus {
  outline: none;
  border-color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 14px;
  margin-top: 12px;
}

.admin-link {
  display: inline-block;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.admin-link:hover {
  color: var(--accent);
}

/* --- Receiver: license bar --- */
.license-bar {
  margin-bottom: 14px;
  font-size: 13px;
}

/* --- Receiver top row: devices + pairing --- */
.receiver-top {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 860px) {
  .receiver-top {
    grid-template-columns: 1fr;
  }
}

.devices-panel {
  margin-bottom: 0;
}

/* --- Pairing card --- */
.pairing-card {
  margin-bottom: 0;
  height: 100%;
}

.pairing-desc {
  margin-bottom: 12px;
}

.pairing-grid {
  display: flex;
  gap: 20px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.pairing-info {
  flex: 1;
  min-width: 180px;
}

.code-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.pair-code {
  font-size: 38px;
  font-weight: 800;
  letter-spacing: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
  margin: 4px 0;
}

.small {
  font-size: 12px;
}

.device-count {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

/* --- Files panel --- */
.files-panel {
  margin-bottom: 16px;
}

.files-panel .file-item {
  flex-wrap: wrap;
}

.files-panel .file-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* --- Pagination --- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.pagination-info {
  font-size: 13px;
  color: var(--muted);
  margin-right: 4px;
}

.pagination .btn--page {
  width: auto;
  min-width: 36px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
}

.pagination .btn--page.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pagination .btn--page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- Admin --- */

.create-row {
  display: flex;
  gap: 10px;
}

.create-row .input-inline {
  flex: 1;
}

.table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

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

.admin-table th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.admin-table td.center {
  text-align: center;
}

.uuid {
  font-size: 12px;
  color: var(--text);
  background: var(--surface-2);
  padding: 3px 7px;
  border-radius: 6px;
  margin-right: 8px;
  word-break: break-all;
}

.btn--xs {
  width: auto;
  padding: 5px 10px;
  font-size: 12px;
}

.btn--danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
}

.btn--danger:hover {
  background: rgba(248, 113, 113, 0.12);
}

.receiver-panel .panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.receiver-panel .panel-header h2 {
  margin: 0;
}

.panel-badge {
  font-size: 12px;
  white-space: nowrap;
}

.files-hint {
  font-size: 13px;
  margin: -4px 0 12px;
}

.empty--compact {
  padding: 20px 0;
}

.empty--compact .empty-icon {
  display: none;
}

/* --- Device list --- */
.device-filter {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.device-filter:hover {
  border-color: var(--accent);
}

.device-filter.is-active {
  border-color: var(--accent);
  background: rgba(96, 165, 250, 0.08);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25);
}

.device-filter-icon {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}

.device-filter-body {
  flex: 1;
  min-width: 0;
}

.device-filter-name {
  font-weight: 600;
  font-size: 14px;
}

.device-filter-sub {
  font-size: 12px;
  margin-top: 2px;
  line-height: 1.35;
}

.device-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.device-item {
  display: flex;
  align-items: stretch;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.device-item.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.25);
}

.device-select {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.device-select:hover {
  background: rgba(255, 255, 255, 0.03);
}

.device-item.is-selected .device-select {
  background: rgba(96, 165, 250, 0.08);
}

.device-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 8px 8px 8px 0;
  flex-shrink: 0;
}

.device-actions .btn--xs {
  min-width: 34px;
  padding: 6px 8px;
}
