:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --danger-dark: #b91d1d;
  --warning-bg: #fffbeb;
  --warning-border: #f59e0b;
  --success: #16a34a;
  --border: #d1d5db;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --radius: 0.5rem;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

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

.logo {
  font-size: 1.5rem;
}

.brand h1 {
  font-size: 1.25rem;
  margin: 0;
  font-weight: 600;
}

.container {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}

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

.card h2 {
  font-size: 1.125rem;
  margin: 0 0 1rem 0;
}

.card h3 {
  font-size: 1rem;
  margin: 0 0 0.5rem 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.field label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text);
}

.field input {
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
}

.field input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

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

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

.btn-secondary {
  background: var(--text-muted);
  color: #fff;
}

.btn-secondary:hover {
  background: #4b5563;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

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

.btn-small {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  background: #e5e7eb;
  color: var(--text);
}

.btn-small:hover {
  background: #d1d5db;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 1rem;
}

.inline-form .field {
  margin: 0;
  flex: 1 1 180px;
}

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

.section-header h2 {
  margin: 0;
}

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  font-weight: 600;
  background: #f9fafb;
}

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

.data-table code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

.empty-row td {
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-active {
  background: #d1fae5;
  color: #065f46;
}

.badge-revoked {
  background: #fee2e2;
  color: #991b1b;
}

.card-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}

.key-plain {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  background: #fff;
  border: 1px dashed var(--warning-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.key-plain code {
  flex: 1 1 auto;
  font-size: 1rem;
  word-break: break-all;
}

.messaggi {
  margin-bottom: 1rem;
}

.messaggio {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  font-size: 0.95rem;
}

.messaggio.errore {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.messaggio.successo {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.messaggio.info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.hidden {
  display: none !important;
}

.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}

@media (max-width: 600px) {
  .brand h1 {
    font-size: 1rem;
  }

  .inline-form {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-form .field {
    width: 100%;
  }

  .btn {
    width: 100%;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
}
