:root {
  --green: #2B8C5E;
  --green-light: #E8F5EE;
  --green-hover: #237A4F;
  --mauve: #8B5C8E;
  --mauve-light: #F3EBF4;
  --mauve-hover: #7A4D7D;
  --white: #FFFFFF;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --red: #DC2626;
  --red-light: #FEF2F2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

/* Header */
header {
  background: #283048;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1rem;
  box-shadow: var(--shadow);
  position: relative;
}

header .logo {
  height: 44px;
  width: auto;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--white);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
}

.header-user {
  position: absolute;
  right: 2rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  color: rgba(255, 255, 255, 0.6);
  font-size: 0.75rem;
}

.logout-form {
  margin: 0;
}

.btn-logout {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.btn-logout:hover {
  color: white;
  border-color: rgba(255, 255, 255, 0.6);
}

/* Main layout */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Search form */
.search-form {
  background: var(--white);
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.search-form h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.025em;
}

.form-group input[type="text"],
.form-group select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.875rem;
  color: var(--gray-900);
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input[type="text"]:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(43, 140, 94, 0.15);
}

.form-group input[type="text"]::placeholder {
  color: var(--gray-300);
}

/* Tag multi-select */
.tag-select {
  position: relative;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: var(--white);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.tag-select:focus-within {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(43, 140, 94, 0.15);
}

.tag-select-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.5rem;
  min-height: 38px;
}

.tag-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: var(--green-light);
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.tag-remove {
  background: none;
  border: none;
  color: var(--green);
  cursor: pointer;
  font-size: 0.875rem;
  line-height: 1;
  padding: 0;
  margin-left: 0.1rem;
  opacity: 0.7;
}

.tag-remove:hover {
  opacity: 1;
  color: var(--green-hover);
}

.tag-input {
  flex: 1;
  min-width: 100px;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  padding: 0.15rem 0.25rem !important;
  font-size: 0.8125rem;
  background: transparent;
}

.tag-input:focus {
  border: none !important;
  box-shadow: none !important;
}

.state-dropdown {
  position: absolute;
  top: 100%;
  left: -1px;
  right: -1px;
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: var(--shadow-lg);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}

.state-option {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.8125rem;
  color: var(--gray-700);
  transition: background 0.1s;
}

.state-option:hover {
  background: var(--green-light);
  color: var(--green);
}

/* Action row */
.action-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--gray-200);
}

.btn-primary {
  background: var(--green);
  color: white;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  min-width: 140px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-primary:hover:not(:disabled) {
  background: var(--green-hover);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  background: var(--green);
}

.btn-searching {
  background: rgb(204, 46, 139);
  color: white;
  border: none;
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  min-width: 140px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.btn-searching:hover {
  background: rgb(224, 56, 159);
}

.spinner {
  animation: spin 0.8s linear infinite;
}

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

.btn-secondary {
  background: var(--white);
  color: var(--mauve);
  border: 1px solid var(--mauve);
  padding: 0.6rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}

.btn-secondary:hover {
  background: var(--mauve);
  color: white;
}

.result-count {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-left: auto;
}

/* Results section */
.results-section {
  background: var(--white);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.results-section .placeholder {
  padding: 3rem;
  text-align: center;
  color: var(--gray-500);
  font-size: 0.875rem;
}

.results-section .error {
  padding: 1rem;
  text-align: center;
  color: var(--red);
  background: var(--red-light);
}

.results-table-wrapper {
  overflow: auto;
  height: calc((100vh - 280px) / 2);
  min-height: 200px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.results-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

.results-table th {
  background: var(--green-light);
  color: var(--green);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.025em;
  font-size: 0.75rem;
  padding: 0.75rem;
  text-align: left;
  border-bottom: 2px solid var(--green);
  white-space: nowrap;
}

.results-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--gray-100);
  white-space: nowrap;
  vertical-align: middle;
}

.results-table tbody tr:nth-child(even) {
  background: var(--gray-100);
}

.results-table tbody tr:hover {
  background: var(--green-light);
}

/* Expired row styling */
.results-table tbody tr.expired-row {
  background: var(--red-light);
}

.results-table tbody tr.expired-row:hover {
  background: #FEE2E2;
}

td.expired {
  color: var(--red);
  font-weight: 600;
}

td.inactive {
  color: var(--red);
  font-weight: 600;
}

/* DEA number masking */
.dea-cell {
  white-space: nowrap;
}

.dea-cell .btn-reveal {
  margin-left: 0.5rem;
}

/* Toggle switch */
.toggle-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding-top: 0.25rem;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gray-300);
  border-radius: 22px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--green);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

.toggle-label {
  font-size: 0.8125rem;
  color: var(--gray-700);
}

.dea-masked {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  letter-spacing: 0.05em;
  color: var(--gray-500);
}

.dea-revealed {
  font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
  letter-spacing: 0.05em;
  color: var(--gray-900);
  font-weight: 500;
}

.btn-reveal {
  background: none;
  border: none;
  color: var(--mauve);
  cursor: pointer;
  font-size: 0.6875rem;
  text-decoration: underline;
  padding: 0;
  white-space: nowrap;
}

.btn-reveal:hover {
  color: var(--mauve-hover);
}

/* Physician match badge */
.physician-cell {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.physician-badge {
  display: inline-block;
  background: var(--green);
  color: white;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  width: fit-content;
}

/* Network status badge colors */
.badge-in { background: var(--green); }
.badge-bx { background: #111827; }
.badge-bi { background: #4B5563; }
.badge-bn { background: #9CA3AF; }
.badge-bu { background: #7F1D1D; }
.badge-na { background: #CA8A04; }
.badge-no { background: #6EE7B7; color: #065F46; }

.physician-detail {
  font-size: 0.6875rem;
  color: var(--gray-500);
  white-space: nowrap;
}

/* Limit select in action row */
.action-row .form-group {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.action-row .form-group label {
  text-transform: none;
  font-size: 0.875rem;
  white-space: nowrap;
}

.action-row select {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.875rem;
}

/* Slow search warning */
.slow-warning {
  font-size: 0.8125rem;
  color: var(--mauve);
  font-style: italic;
  animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Infinite scroll sentinel */
.loading-more,
.end-of-results {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 1rem;
  color: var(--gray-500);
  font-size: 0.8125rem;
}

.end-of-results {
  color: var(--gray-300);
  font-style: italic;
}

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-50);
}

.login-card {
  background: var(--white);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  text-align: center;
  max-width: 380px;
  width: 100%;
}

.login-logo {
  height: 48px;
  margin-bottom: 1.5rem;
}

.login-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--gray-500);
  font-size: 0.875rem;
  margin-bottom: 1.5rem;
}

.login-error {
  background: var(--red-light);
  color: var(--red);
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.8125rem;
  margin-bottom: 1rem;
}

.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
  padding: 0.7rem 1.5rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  width: 100%;
  justify-content: center;
}

.btn-google:hover {
  border-color: var(--gray-500);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Responsive */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-group.full-width {
    grid-column: 1;
  }

  header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }

  header h1 {
    font-size: 1rem;
    position: static;
    transform: none;
    white-space: normal;
    flex: 1 1 auto;
    text-align: center;
  }

  main {
    padding: 0.75rem;
  }

  .search-form {
    padding: 1rem;
  }

  .action-row {
    flex-direction: column;
    align-items: stretch;
  }

  .action-row .form-group {
    justify-content: space-between;
  }

  .btn-primary,
  .btn-secondary,
  .btn-searching {
    width: 100%;
    text-align: center;
    justify-content: center;
  }

  .result-count {
    margin-left: 0;
    text-align: center;
  }

  .slow-warning {
    text-align: center;
  }

  .results-table-wrapper {
    height: calc(100vh - 200px);
  }

  .tag-select-inner {
    min-height: 34px;
  }

  .header-user {
    position: static;
    width: 100%;
    justify-content: center;
  }

  .user-email {
    display: inline;
    font-size: 0.7rem;
  }

  .login-card {
    margin: 1rem;
  }

  .state-dropdown {
    max-height: 150px;
  }
}
