*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e6ed;
  --text: #1a1d23;
  --text-secondary: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);
}

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.page {
  display: none;
}
.page.active {
  display: block;
}

/* ---- Login ---- */
#login-page {
  display: none;
  place-items: center;
  min-height: 100vh;
  padding: 1rem;
}
#login-page.active {
  display: grid;
}

.login-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.login-header {
  text-align: center;
  margin-bottom: 1.5rem;
}
.login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.login-header p {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ---- Fields ---- */
.field {
  margin-bottom: 1rem;
}
.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--text-secondary);
}
.field input,
.field select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s;
  background: var(--surface);
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover {
  background: var(--danger-hover);
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover {
  background: var(--bg);
}
.btn-block {
  width: 100%;
}
.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* ---- Topbar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  box-shadow: var(--shadow);
}
.topbar h2 {
  font-size: 1.125rem;
  font-weight: 700;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.topbar-right span {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* ---- Tabs ---- */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
}
.tab {
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.15s;
}
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab:hover {
  color: var(--text);
}

.tab-content {
  display: none;
  padding: 1.5rem;
}
.tab-content.active {
  display: block;
}

/* ---- Section headers ---- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

/* ---- Form card ---- */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}
.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ---- Search bar ---- */
.search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-bar input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  transition: border-color 0.15s;
}
.search-bar input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.search-bar select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
  min-width: 150px;
}

.btn-warning {
  background: var(--warning);
  color: #fff;
}
.btn-warning:hover {
  background: #d97706;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
thead th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td {
  border-bottom: none;
}
tbody tr:hover {
  background: #f9fafb;
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-active {
  background: #dcfce7;
  color: #166534;
}
.badge-inactive {
  background: #fee2e2;
  color: #991b1b;
}
.badge-pending {
  background: #fef3c7;
  color: #92400e;
}
.badge-revoked {
  background: #fecaca;
  color: #991b1b;
}
.badge-expired {
  background: #e5e7eb;
  color: #374151;
}

/* ---- Action cells ---- */
.action-cell {
  display: flex;
  gap: 0.375rem;
  flex-wrap: wrap;
}
.hint-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  font-style: italic;
}
.form-card h4 {
  font-size: 0.9375rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  margin-top: 0.5rem;
}
.page-info {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.page-btns {
  display: flex;
  gap: 0.25rem;
}
.page-btns .btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---- Date display ---- */
.date-primary {
  display: block;
  font-size: 0.8125rem;
}
.date-ago {
  display: block;
  font-size: 0.6875rem;
  color: var(--text-secondary);
}
.text-muted {
  font-size: 0.75rem;
  color: var(--text-secondary);
}
.num-col {
  color: var(--text-secondary);
  font-size: 0.75rem;
  width: 2rem;
  text-align: center;
}

/* ---- Utility ---- */
.hidden {
  display: none !important;
}
.error-text {
  color: var(--danger);
  font-size: 0.8125rem;
  margin-top: 0.5rem;
}
.empty-msg {
  text-align: center;
  padding: 2rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}
.key-text {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.75rem;
  word-break: break-all;
}

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: #1e293b;
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.8125rem;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  transition: opacity 0.3s, transform 0.3s;
  opacity: 1;
  transform: translateY(0);
}
.toast.hidden {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}
.toast.toast-error {
  background: var(--danger);
}
.toast.toast-success {
  background: var(--success);
}
