:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --purple: #7c3aed;
  --purple-light: #f5f3ff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --bg-page: #f8fafc;
  --card-bg: #ffffff;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

/* ─── LOGIN VIEW ─── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #eff6ff 0%, #f8fafc 70%);
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 42px 34px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 10px 25px -5px rgba(79, 70, 229, 0.08), 0 0 0 1px rgba(226, 232, 240, 0.8);
  animation: slideUp .5s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-icon {
  width: 68px;
  height: 68px;
  margin: 0 auto 20px;
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
  border: 1px solid #c7d2fe;
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  box-shadow: 0 8px 16px -4px rgba(79, 70, 229, 0.18);
}

.login-icon svg {
  width: 32px;
  height: 32px;
}

.login-brand {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -.02em;
}

.login-card .desc {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 26px;
}

.form-field {
  text-align: left;
  margin-bottom: 16px;
}

.form-field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 6px;
  letter-spacing: .02em;
}

.form-field .hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  padding: 11px 14px;
  font-size: 13.5px;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
  color: var(--text-main);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3.5px rgba(79, 70, 229, 0.12);
}

/* ─── BUTTONS ─── */
.btn {
  padding: 11px 18px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  color: #fff;
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4338ca 0%, #3730a3 100%);
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(79, 70, 229, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  background: #94a3b8;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.btn-success {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #a7f3d0;
}

.btn-success:hover {
  background: #d1fae5;
  color: #047857;
}

.btn-outline {
  background: #fff;
  border: 1.5px solid var(--border);
  color: #475569;
}

.btn-outline:hover {
  border-color: #cbd5e1;
  background: #f8fafc;
  color: var(--text-main);
}

.btn-ghost {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 7px 10px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-ghost:hover {
  color: var(--danger);
  background: var(--danger-light);
}

.btn-sm {
  padding: 7px 12px;
  font-size: 12px;
  border-radius: 8px;
  font-weight: 600;
}

/* ─── ICON BUTTONS FOR ACTION COLUMN (SYMBOLS ONLY) ─── */
.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .18s ease;
  color: #475569;
  flex-shrink: 0;
}

.btn-icon:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.08);
}

.btn-icon:active {
  transform: translateY(0);
}

.btn-icon svg {
  width: 15px;
  height: 15px;
}

.btn-icon-indigo {
  color: var(--primary);
  background: var(--primary-light);
  border-color: #c7d2fe;
}

.btn-icon-indigo:hover {
  background: #e0e7ff;
  border-color: var(--primary);
  color: #3730a3;
}

.btn-icon-emerald {
  color: var(--success);
  background: var(--success-light);
  border-color: #a7f3d0;
}

.btn-icon-emerald:hover {
  background: #d1fae5;
  border-color: var(--success);
  color: #047857;
}

.btn-icon-amber {
  color: var(--warning);
  background: var(--warning-light);
  border-color: #fde68a;
}

.btn-icon-amber:hover {
  background: #fef3c7;
  border-color: var(--warning);
  color: #b45309;
}

.btn-icon-rose {
  color: var(--danger);
  background: var(--danger-light);
  border-color: #fecaca;
}

.btn-icon-rose:hover {
  background: #fee2e2;
  border-color: var(--danger);
  color: #b91c1c;
}

/* Compact form link button */
.btn-table-form {
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: 7px;
  background: #fff;
  border: 1.2px solid #cbd5e1;
  color: var(--text-main);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  transition: all .15s ease;
  white-space: nowrap;
}

.btn-table-form:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ─── DASHBOARD ─── */
.dashboard {
  display: none;
  min-height: 100vh;
  background: var(--bg-page);
}

.topbar {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5 0%, #06b6d4 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.25);
}

.brand-badge svg {
  width: 20px;
  height: 20px;
}

.brand-text h1 {
  font-size: 16.5px;
  font-weight: 800;
  letter-spacing: -.02em;
}

.brand-text .tag {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

/* ─── STAT CARDS ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px solid transparent;
  transition: transform .2s ease, box-shadow .2s ease;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px -2px rgba(0, 0, 0, 0.06);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg {
  width: 24px;
  height: 24px;
}

.stat-info .stat-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.stat-info .stat-num {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1;
}

.stat-blue {
  background: linear-gradient(135deg, #f0f7ff 0%, #e0effe 100%);
  border-color: #bae0fd;
}

.stat-blue .stat-icon {
  background: #0284c7;
  color: #fff;
  box-shadow: 0 4px 10px rgba(2, 132, 199, 0.25);
}

.stat-blue .stat-label {
  color: #0369a1;
}

.stat-blue .stat-num {
  color: #0c4a6e;
}

.stat-emerald {
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
  border-color: #bbf7d0;
}

.stat-emerald .stat-icon {
  background: #16a34a;
  color: #fff;
  box-shadow: 0 4px 10px rgba(22, 163, 74, 0.25);
}

.stat-emerald .stat-label {
  color: #15803d;
}

.stat-emerald .stat-num {
  color: #14532d;
}

.stat-amber {
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border-color: #fde68a;
}

.stat-amber .stat-icon {
  background: #d97706;
  color: #fff;
  box-shadow: 0 4px 10px rgba(217, 119, 6, 0.25);
}

.stat-amber .stat-label {
  color: #b45309;
}

.stat-amber .stat-num {
  color: #78350f;
}

.stat-purple {
  background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
  border-color: #e9d5ff;
}

.stat-purple .stat-icon {
  background: #9333ea;
  color: #fff;
  box-shadow: 0 4px 10px rgba(147, 51, 234, 0.25);
}

.stat-purple .stat-label {
  color: #7e22ce;
}

.stat-purple .stat-num {
  color: #581c87;
}

/* ─── SECTION CARDS ─── */
.section {
  background: #fff;
  border-radius: 18px;
  padding: 24px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02), 0 4px 16px -2px rgba(15, 23, 42, 0.03);
  margin-bottom: 24px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.section-title {
  font-size: 15.5px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -.01em;
}

.title-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.title-badge svg {
  width: 16px;
  height: 16px;
}

/* ─── FORM GRID ─── */
.form-grid-6 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.col-span-2 {
  grid-column: span 2;
}

.col-span-3 {
  grid-column: span 3;
}

.token-input-group {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.token-input-group input {
  font-family: monospace;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.token-input-group .btn-rnd {
  padding: 0 14px;
  border: 1.5px solid var(--border);
  background: #fff;
  border-radius: 10px;
  color: var(--primary);
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
}

.token-input-group .btn-rnd:hover {
  background: var(--primary-light);
  border-color: #c7d2fe;
}

.create-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.create-note {
  font-size: 12px;
  color: var(--text-muted);
}

/* Token Created Banner */
.token-banner {
  display: none;
  margin-top: 18px;
  padding: 18px 22px;
  border-radius: 14px;
  background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
  border: 1.5px solid #a7f3d0;
  animation: fadeIn .3s;
}

.token-banner-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}

.token-banner-info h4 {
  font-size: 13.5px;
  font-weight: 700;
  color: #065f46;
  margin-bottom: 2px;
}

.token-banner-info p {
  font-size: 12px;
  color: #047857;
}

.token-banner-code {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: .2em;
  color: #065f46;
  font-family: monospace;
  background: #fff;
  padding: 6px 14px;
  border-radius: 10px;
  border: 1px solid #86efac;
}

/* ─── TABLE & FILTERS ─── */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.filter-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-btn {
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .18s ease;
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-btn:hover {
  border-color: #cbd5e1;
  color: var(--text-main);
}

.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25);
}

.filter-btn .pill-count {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10.5px;
}

.filter-btn.active .pill-count {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

.search-box {
  position: relative;
  width: 220px;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  font-size: 12.5px;
  font-family: inherit;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: #fff;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.search-box svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: #94a3b8;
  pointer-events: none;
}

/* TABLE STYLES */
.table-container {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

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

th {
  background: #f8fafc;
  color: #475569;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1.5px solid var(--border);
  user-select: none;
  white-space: nowrap;
}

th.sortable {
  cursor: pointer;
  transition: background .15s;
}

th.sortable:hover {
  background: #f1f5f9;
  color: var(--primary);
}

th .sort-icon {
  display: inline-block;
  margin-left: 3px;
  font-size: 9.5px;
  color: #94a3b8;
  vertical-align: middle;
}

th.sorted-asc .sort-icon,
th.sorted-desc .sort-icon {
  color: var(--primary);
  font-weight: bold;
}

td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

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

tr:hover td {
  background: #fafbfd;
}

.cell-code {
  font-family: monospace;
  font-weight: 800;
  font-size: 13.5px;
  letter-spacing: .06em;
  color: #1e1b4b;
}

.cell-subject {
  font-weight: 700;
  color: var(--text-main);
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* BADGES */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.status-active {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid #a7f3d0;
}

.status-active .status-dot {
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.status-expired {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.status-expired .status-dot {
  background: #f59e0b;
}

.status-used {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #cbd5e1;
}

.status-used .status-dot {
  background: #94a3b8;
}

.status-revoked {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.status-revoked .status-dot {
  background: #ef4444;
}

.status-blue {
  background: #f0f9ff;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

.status-blue .status-dot {
  background: #0284c7;
}

.action-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #fff;
  padding: 12px 20px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  transition: transform .3s cubic-bezier(0.16, 1, 0.3, 1), opacity .3s;
  transform: translateY(100px);
  opacity: 0;
  pointer-events: none;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .2s;
}

.modal-box {
  background: #fff;
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2);
  animation: slideUp .25s ease;
  text-align: left;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon svg {
  width: 22px;
  height: 22px;
}

.modal-title {
  font-size: 16px;
  font-weight: 800;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 18px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 22px;
}

.empty-wrap {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

.empty-wrap svg {
  width: 40px;
  height: 40px;
  color: #cbd5e1;
  margin-bottom: 10px;
}

/* Checkbox toggle styled */
.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-main);
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* RESPONSIVE */
@media(max-width:900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-grid-6 {
    grid-template-columns: 1fr;
  }

  .col-span-2,
  .col-span-3 {
    grid-column: span 1;
  }
}

@media(max-width:640px) {
  .main {
    padding: 12px 10px 32px;
  }

  .stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 14px;
  }

  .stat-card {
    padding: 6px 7px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
  }

  .stat-icon {
    width: 26px;
    height: 26px;
    border-radius: 7px;
    flex-shrink: 0;
  }

  .stat-icon svg {
    width: 13px;
    height: 13px;
  }

  .stat-info {
    min-width: 0;
    overflow: hidden;
  }

  .stat-info .stat-label {
    font-size: 7.5px;
    font-weight: 700;
    margin-bottom: 1px;
    letter-spacing: .01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-info .stat-num {
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
  }

  .topbar {
    padding: 12px 16px;
  }

  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box {
    width: 100%;
  }

  .filter-pills {
    overflow-x: auto;
    padding-bottom: 4px;
  }
}
