@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

:root {
  --black: #111111;
  --white: #FFFFFF;
  --gray-600: #6B7280;
  --gray-400: #9CA3AF;
  --gray-300: #D1D5DB;
  --gray-200: #E5E7EB;
  --off-white: #F5F5F0;
  --off-white-light: #FAFAF5;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #f59e0b;
  --radius-lg: 12px;
  --radius-md: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--off-white);
  color: var(--black);
  min-height: 100vh;
}

/* --- Navbar --- */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--black);
  text-decoration: none;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.nav-link {
  color: var(--gray-600);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}

/* --- Container --- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* --- Login --- */
.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-md);
  padding: 2.5rem 2rem;
}

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo h1 { font-size: 1.25rem; font-weight: 700; margin-top: 0.75rem; }
.login-logo p { font-size: 0.85rem; color: var(--gray-600); margin-top: 0.25rem; }

.login-error {
  display: none;
  padding: 0.6rem 0.75rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius-md);
  color: #991b1b;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.login-error.visible { display: block; }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.375rem; }

.form-input, .form-select {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--black);
  background: var(--white);
  transition: border-color 0.15s;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(17,17,17,0.08);
}

.form-hint { font-size: 0.8rem; color: var(--gray-400); margin-top: 0.25rem; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--black); color: var(--white); border-color: var(--black); }
.btn-primary:hover { background: #333; }
.btn-primary:disabled { background: var(--gray-400); border-color: var(--gray-400); cursor: not-allowed; }

.btn-secondary { background: var(--white); color: var(--black); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--off-white); }

.btn-danger { background: var(--white); color: var(--red); border-color: var(--gray-300); }
.btn-danger:hover { background: #fef2f2; border-color: var(--red); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; }

.btn .spinner {
  display: none;
  width: 16px; height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn.loading .spinner { display: inline-block; }
.btn.loading .btn-text { opacity: 0.7; }

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

/* --- Dashboard --- */
.dashboard-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title { font-size: 1.4rem; font-weight: 700; }
.page-subtitle { font-size: 0.9rem; color: var(--gray-600); margin-top: 0.25rem; }

/* --- Stats --- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  box-shadow: var(--shadow);
}

.stat-label { font-size: 0.8rem; color: var(--gray-600); display: block; }
.stat-value { font-size: 1.5rem; font-weight: 700; display: block; margin-top: 0.25rem; }

/* --- Table --- */
.table-wrapper {
  overflow-x: auto;
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow);
}

table { width: 100%; border-collapse: collapse; font-size: 0.825rem; }

th {
  background: var(--black);
  color: var(--white);
  padding: 0.65rem 0.5rem;
  text-align: left;
  white-space: nowrap;
  font-weight: 500;
  font-size: 0.8rem;
}

th:first-child { border-radius: var(--radius-lg) 0 0 0; }
th:last-child { border-radius: 0 var(--radius-lg) 0 0; }

td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--gray-200);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

tr:nth-child(even) td { background: var(--off-white-light); }
tr:hover td { background: var(--off-white); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-active { background: #dcfce7; color: #166534; }
.badge-inactive { background: #fef2f2; color: #991b1b; }
.badge-expired { background: #fef3c7; color: #92400e; }
.badge-bound { background: #e0e7ff; color: #3730a3; }
.badge-unbound { background: var(--gray-200); color: var(--gray-600); }

.actions-cell {
  display: flex;
  gap: 0.25rem;
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  margin: 1rem;
}

.modal-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

/* --- Key Display --- */
.key-display {
  background: var(--off-white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1rem;
  letter-spacing: 1px;
  text-align: center;
  word-break: break-all;
  user-select: all;
}

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 68px;
  right: 1rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.2s ease-out;
  max-width: 360px;
}

.toast.success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.toast.error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.toast.info { background: var(--off-white-light); border: 1px solid var(--gray-200); color: var(--black); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Dropdown --- */
.nav-dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  min-width: 200px;
  z-index: 100;
  padding: 4px;
}

.dropdown-menu.open {
  display: block;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: none;
  background: none;
  text-align: left;
  font-size: 0.85rem;
  color: #111;
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
}

.dropdown-item:hover {
  background: #F5F5F0;
}

/* --- Utilities --- */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }

@media (max-width: 768px) {
  .container { padding: 1rem; }
  .dashboard-header { flex-direction: column; }
  td, th { padding: 0.4rem; font-size: 0.75rem; }
}
