:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --success: #107c10;
  --danger: #d13438;
  --warning: #ffb900;
  --gray-50: #fafafa;
  --gray-100: #f5f5f5;
  --gray-200: #e5e5e5;
  --gray-300: #d4d4d4;
  --gray-400: #a3a3a3;
  --gray-500: #737373;
  --gray-600: #525252;
  --gray-700: #404040;
  --gray-800: #262626;
  --gray-900: #171717;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--gray-900);
  background: var(--gray-100);
}

/* Loading */
.loading-overlay {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; background: white; z-index: 1000;
}
.spinner {
  width: 40px; height: 40px; border: 3px solid var(--gray-200);
  border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Login */
.login-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}
.login-card {
  background: white; padding: 3rem; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); text-align: center; max-width: 400px;
}
.login-card h1 { margin-bottom: 0.5rem; color: var(--gray-800); }
.login-card p { margin-bottom: 1.5rem; color: var(--gray-500); }

/* App */
.app-container { min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.5rem; background: white; border-bottom: 1px solid var(--gray-200);
}
.header-left h1 { font-size: 1.25rem; font-weight: 600; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }
.user-name { font-size: 0.875rem; color: var(--gray-600); }

/* Messages */
.error-banner, .success-banner {
  padding: 0.75rem 1.5rem; display: flex; align-items: center; justify-content: space-between;
}
.error-banner { background: #fef2f2; color: var(--danger); border-bottom: 1px solid #fecaca; }
.success-banner { background: #f0fdf4; color: var(--success); border-bottom: 1px solid #bbf7d0; }

/* Tabs */
.tabs {
  display: flex; gap: 0; background: white; border-bottom: 1px solid var(--gray-200); padding: 0 1.5rem;
}
.tabs button {
  padding: 0.75rem 1.25rem; border: none; background: none; font-size: 0.875rem;
  color: var(--gray-500); cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 500; }
.tabs button:hover { color: var(--gray-700); }

/* Main Content */
.main-content { flex: 1; padding: 1.5rem; max-width: 1000px; margin: 0 auto; width: 100%; }
.tab-content { display: flex; flex-direction: column; gap: 1rem; }
.tab-description { color: var(--gray-500); margin-bottom: 0.5rem; }
.tab-description code { background: var(--gray-200); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.8rem; }

/* Toolbar */
.toolbar { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 200px; }
.toolbar-actions { display: flex; gap: 0.5rem; }

/* Forms */
.form-card {
  background: white; padding: 1.25rem; border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--gray-200);
}
.form-card h3 { margin-bottom: 0.75rem; font-size: 1rem; }
.form-group { display: flex; flex-direction: column; gap: 0.25rem; }
.form-group label { font-size: 0.8rem; font-weight: 500; color: var(--gray-600); }
.form-row { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; }
.form-row .form-group { flex: 1; }
.form-input {
  padding: 0.5rem 0.75rem; border: 1px solid var(--gray-300); border-radius: 6px;
  font-size: 0.875rem; outline: none; font-family: inherit;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(0,120,212,0.15); }
textarea.form-input { resize: vertical; }
.form-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.75rem; }

/* Tables */
.contact-table, .keys-table {
  background: white; border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--gray-200); overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 0.6rem 0.75rem; font-size: 0.75rem; font-weight: 600;
  text-transform: uppercase; color: var(--gray-500); background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--gray-100); font-size: 0.875rem; }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--gray-50); }
.mono { font-family: 'SF Mono', Monaco, Consolas, monospace; font-size: 0.8rem; }
.notes-cell { color: var(--gray-500); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions-cell { white-space: nowrap; }
tr.revoked { opacity: 0.5; }
.contact-count { font-size: 0.8rem; color: var(--gray-400); text-align: right; }

/* Badges */
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 9999px;
  font-size: 0.7rem; font-weight: 500;
}
.badge-active { background: #dcfce7; color: var(--success); }
.badge-revoked { background: #fee2e2; color: var(--danger); }

/* API Key Alert */
.key-alert {
  background: #fffbeb; border: 1px solid #fbbf24; border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.key-alert strong { display: block; margin-bottom: 0.5rem; }
.key-display { display: flex; align-items: center; gap: 0.5rem; }
.key-display code {
  flex: 1; padding: 0.5rem; background: white; border: 1px solid var(--gray-200);
  border-radius: 4px; font-size: 0.8rem; word-break: break-all;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border: 1px solid transparent; border-radius: 6px;
  font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: all 0.15s;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--gray-600); border-color: var(--gray-300); }
.btn-ghost:hover:not(:disabled) { background: var(--gray-100); }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.75rem; }
.btn-large { padding: 0.75rem 2rem; font-size: 1rem; }
.btn-close {
  background: none; border: none; font-size: 1.25rem; cursor: pointer; color: inherit; padding: 0;
}

/* Empty state */
.empty-state { padding: 2rem; text-align: center; color: var(--gray-400); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex;
  align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: white; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 90%; max-width: 550px; max-height: 90vh; overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 1rem; }
.modal-body { padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding: 1rem 1.25rem; border-top: 1px solid var(--gray-200);
}
.import-result {
  padding: 0.75rem; background: #f0fdf4; border-radius: 6px; font-size: 0.875rem;
}
