* {
  box-sizing: border-box;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  background: #0b0d12;
  color: #f5f6fa;
  min-height: 100vh;
}

header {
  display: flex;
  justify-content: space-between;
  padding: 2rem clamp(1rem, 5vw, 4rem);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: radial-gradient(circle at top, rgba(101, 182, 255, 0.2), transparent);
  flex-wrap: wrap;
  gap: 1.5rem;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-end;
}

.logout-btn {
  background: rgba(244, 67, 54, 0.2);
  color: #ff7b72;
  border: 1px solid rgba(244, 67, 54, 0.3);
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
}

.logout-btn:hover {
  background: rgba(244, 67, 54, 0.3);
  border-color: rgba(244, 67, 54, 0.5);
  transform: translateY(-1px);
}

h1 {
  margin: 0 0 0.4rem;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
}

p {
  margin: 0;
  color: rgba(255, 255, 255, 0.7);
}

.status-badges {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.9rem;
}

.badge.success {
  background: rgba(76, 175, 80, 0.2);
  color: #6df28a;
}

.badge.warning {
  background: rgba(255, 193, 7, 0.2);
  color: #ffd666;
}

.badge.danger {
  background: rgba(244, 67, 54, 0.2);
  color: #ff7b72;
}

main {
  padding: 2rem clamp(1rem, 5vw, 4rem);
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.card {
  background: rgba(20, 22, 32, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 16px;
  padding: 1.5rem;
  backdrop-filter: blur(10px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
}

.card h2 {
  margin-top: 0;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

label {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  gap: 0.35rem;
  color: rgba(255, 255, 255, 0.75);
}

input,
select,
button {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.65rem 0.75rem;
  background: rgba(13, 15, 24, 0.9);
  color: #f5f6fa;
  font-size: 0.95rem;
}

button {
  width: fit-content;
  cursor: pointer;
  border: none;
  background: linear-gradient(120deg, #8ea5ff, #7cd4ff);
  color: #0b0d12;
  font-weight: 600;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 15px rgba(140, 200, 255, 0.2);
}

.form-message {
  margin-left: 1rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.65);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.table-wrapper {
  margin-top: 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.05);
  overflow-x: auto;
}

.table-wrapper.compact {
  margin-top: 0.5rem;
  overflow-x: visible;
}

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

th,
td {
  text-align: left;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

thead th {
  background: rgba(0, 0, 0, 0.2);
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
}

tbody tr {
  cursor: pointer;
}

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

.muted {
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
}

.pill {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: capitalize;
}

.pill.active {
  background: rgba(76, 175, 80, 0.2);
  color: #6df28a;
}

.pill.expired {
  background: rgba(255, 193, 7, 0.2);
  color: #ffd666;
}

.pill.revoked {
  background: rgba(244, 67, 54, 0.2);
  color: #ff7b72;
}

.actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.actions button {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transition: background 0.15s ease;
}

.actions button:hover {
  background: rgba(255, 255, 255, 0.15);
}

#searchInput {
  width: 250px;
}

.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.stats-header button {
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 0.45rem 0.9rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.kpi-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.kpi-card span {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.65);
}

.kpi-card strong {
  font-size: 1.4rem;
}

.stats-block h3 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.stats-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.stats-block-header h3 {
  margin: 0;
}

.stats-filter {
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  min-width: 120px;
  max-width: 160px;
}

.stats-table {
  min-width: auto;
  width: 100%;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.5rem;
}

.pagination button {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

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

.pagination span {
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.machine-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.edit-name-btn {
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  background: rgba(101, 182, 255, 0.2);
  color: #a8d4ff;
  border: 1px solid rgba(101, 182, 255, 0.3);
}

.edit-name-btn:hover {
  background: rgba(101, 182, 255, 0.3);
}

.stats-table th,
.stats-table td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-table tbody tr:last-child td {
  border-bottom: none;
}

.detail-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
  z-index: 20;
}

.hidden {
  display: none;
}

.detail-modal.hidden {
  display: none;
}

.detail-card {
  width: min(900px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  background: #0f1119;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 2rem;
  position: relative;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
}

.detail-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  font-size: 1.8rem;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
}

.detail-heading {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.detail-grid {
  margin: 1.5rem 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.25rem;
}

.detail-grid span {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.5);
}

.detail-grid strong {
  display: block;
  margin-top: 0.35rem;
  font-size: 1rem;
}

.limit-form {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 1.5rem;
}

.limit-form label {
  flex: 1;
}

.detail-section {
  margin-top: 1.5rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.activations-list,
.activity-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  overflow: hidden;
}

.activations-list li,
.activity-list li {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.activations-list li:last-child,
.activity-list li:last-child {
  border-bottom: none;
}

.activation-meta,
.activity-meta {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.7);
}

.activation-meta span,
.activity-meta span,
.activity-meta small {
  margin-top: 0.2rem;
}

.activity-meta small {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.78rem;
}

.activations-list button {
  background: rgba(255, 87, 87, 0.2);
  border: 1px solid rgba(255, 87, 87, 0.4);
  color: #ffb3b3;
  padding: 0.35rem 0.6rem;
}

.activity-list .badge {
  align-self: flex-start;
}

.stats-filter-bar {
  display: flex;
  gap: 1rem;
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stats-filter-bar label {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.stats-filter-bar .stats-filter {
  min-width: 180px;
}

.customer-cell {
  cursor: pointer;
  color: #7cd4ff;
  transition: color 0.15s ease;
}

.customer-cell:hover {
  color: #a8e4ff;
  text-decoration: underline;
}

.header-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.admin-btn {
  background: rgba(101, 182, 255, 0.2);
  color: #a8d4ff;
  border: 1px solid rgba(101, 182, 255, 0.3);
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
}

.admin-btn:hover {
  background: rgba(101, 182, 255, 0.3);
  border-color: rgba(101, 182, 255, 0.5);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #141620;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header h2 {
  margin: 0;
}

.close-btn {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

.close-btn:hover {
  color: #fff;
}

.modal-body {
  padding: 1.5rem;
}

.create-user-form {
  margin-bottom: 2rem;
  padding-bottom: 2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.create-user-form h3,
.users-list h3 {
  margin-top: 0;
  margin-bottom: 1rem;
}

.users-list table {
  width: 100%;
}

@media (max-width: 700px) {
  header {
    flex-direction: column;
  }

  .table-header {
    flex-direction: column;
  }

  #searchInput {
    width: 100%;
  }
}

.modal-wide {
  max-width: 1100px;
}

.templates-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 1.5rem;
  min-height: 400px;
}

.templates-sidebar {
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  padding-right: 1.5rem;
}

.templates-sidebar h3 {
  margin-top: 0;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.7);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.templates-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.templates-list li {
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.templates-list li:hover {
  background: rgba(255, 255, 255, 0.05);
}

.templates-list li.active {
  background: rgba(101, 182, 255, 0.2);
  color: #a8d4ff;
}

.templates-list li.disabled {
  color: rgba(255, 255, 255, 0.4);
}

.templates-list .template-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6df28a;
}

.templates-list .template-status.off {
  background: rgba(255, 255, 255, 0.3);
}

.template-editor {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.template-form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.template-editor textarea {
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 200px;
  background: rgba(13, 15, 24, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 0.75rem;
  color: #f5f6fa;
}

.label-with-hint {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.label-with-hint small {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
}

.template-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.button-group {
  display: flex;
  gap: 0.5rem;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
  background: rgba(244, 67, 54, 0.2);
  color: #ff7b72;
  border: 1px solid rgba(244, 67, 54, 0.3);
}

.btn-danger:hover {
  background: rgba(244, 67, 54, 0.3);
}

.template-preview {
  margin-top: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.02);
}

.template-preview h4 {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.6);
}

.template-preview iframe {
  width: 100%;
  height: 250px;
  border: none;
  background: #fff;
  border-radius: 6px;
}

.email-logs-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.email-logs-section h3 {
  margin-top: 0;
  margin-bottom: 1rem;
}

@media (max-width: 800px) {
  .templates-layout {
    grid-template-columns: 1fr;
  }
  
  .templates-sidebar {
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-right: 0;
    padding-bottom: 1rem;
  }
  
  .template-form-row {
    grid-template-columns: 1fr;
  }
}
