/* RESET AND NORMALIZE */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  line-height: 1.6;
  color: #34495e;
  background-color: #ecf0f1;
  text-align: center; /* center align overall rendering */
}

/* GLOBAL STYLES */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

header {
  background-color: #2c3e50;
  color: #ecf0f1;
  padding: 1rem 0;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: center; /* center nav links */
  flex-wrap: wrap;
}

nav li {
  margin: 0 1rem;
}

nav a {
  color: #ecf0f1;
  text-decoration: none;
  font-weight: 500;
}

/* Header brand link (no inline styles) */
.brand-link {
  color: inherit;
  text-decoration: none;
}
.brand-link:hover { text-decoration: underline; }

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  left: 1rem;
  top: 1rem;
  width: auto;
  height: auto;
  background: #fff;
  color: #000;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  z-index: 1000;
}

nav a:hover {
  color: #3498db;
}

main {
  min-height: calc(100vh - 200px);
  padding: 2rem 0;
  max-width: 1100px;         /* center main content */
  margin: 0 auto;            /* center horizontally */
}

footer {
  background-color: #2c3e50;
  color: #ecf0f1;
  text-align: center;
  padding: 1rem 0;
  margin-top: auto;
}

/* TYPOGRAPHY */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #2c3e50;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }

p {
  margin-bottom: 1rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
}

input, select, button {
  font-family: inherit;
  font-size: 1rem;
}

/* LAYOUT */
.flex {
  display: flex;
}

.flex-column {
  flex-direction: column;
}

.flex-wrap {
  flex-wrap: wrap;
}

.justify-center {
  justify-content: center;
}

.align-center {
  align-items: center;
}

.space-between {
  justify-content: space-between;
}

.grid {
  display: grid;
  gap: 1rem;
}

/* COMPONENTS */
form {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  max-width: 500px;
  margin: 0 auto 2rem;
}

input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #bdc3c7;
  border-radius: 4px;
  margin-bottom: 1rem;
}

input:focus, select:focus {
  outline: none;
  border-color: #3498db;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

button {
  background-color: #1f5aa6; /* AA contrast with white text */
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: background-color 0.3s;
}

button:hover {
  background-color: #174984;
}

button.primary {
  background-color: #1e7e34;
}

button.primary:hover {
  background-color: #176a2b;
}

button.danger {
  background-color: #a93226;
}

button.danger:hover {
  background-color: #922b21;
}

#searchResults, #userList {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-top: 2rem;
}

.result-item, .list-item {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,0.1);
  border-left: 4px solid #1f5aa6; /* darker for better contrast */
}

/* Remove bullets from favorites list and ensure clean alignment */
#favoritesList {
  list-style: none;
  padding-left: 0;
  margin-left: 0;
}
.list-item {
  list-style: none; /* prevent default marker on li */
}

.result-item h3 a {
  color: #1f5aa6;
  text-decoration: none;
}

.result-item h3 a:hover {
  color: #174984;
}

/* Ensure links inside favorites have accessible color */
.list-item a {
  color: #1f5aa6;
}
.list-item a:hover { color: #174984; }

.add-btn, .remove-btn {
  margin-top: 1rem;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.hidden {
  display: none;
}

/* Utility spacing */
.ml-2 { margin-left: 0.5rem; }

.error {
  color: #e74c3c;
  background: #fdf2f2;
  padding: 1rem;
  border-radius: 4px;
  margin: 1rem 0;
  border: 1px solid #f5c6cb;
}

.success {
  color: #27ae60;
  background: #f0fff4;
  padding: 1rem;
  border-radius: 4px;
  margin: 1rem 0;
  border: 1px solid #c3e6cb;
}

/* Inline search message container */
#searchMessage {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 4px;
}

#searchMessage.error {
  color: #721c24;           /* dark red text for contrast */
  background: #f8d7da;      /* light red background */
  border: 1px solid #f5c6cb;
}

#searchMessage.success {
  color: #155724;           /* dark green text for contrast */
  background: #d4edda;      /* light green background */
  border: 1px solid #c3e6cb;
}

/* RESPONSIVE DESIGN */
@media (min-width: 768px) {
  .container {
    padding: 0 2rem;
  }
  
  form {
    padding: 3rem;
  }
  
  #searchResults, #userList {
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  }
  
  nav ul {
    justify-content: flex-start;
  }
  
  nav li:first-child {
    margin-left: 0;
  }
  
  .space-between {
    align-items: center;
  }
  
  main {
    padding: 3rem 0;
  }
}

/* ACCESSIBILITY */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

:focus-visible {
  outline: 2px solid #3498db;
  outline-offset: 2px;
}

/* High contrast/forced colors mode support */
@media (forced-colors: active) {
  * { forced-color-adjust: none; }
  body { background: Canvas; color: CanvasText; }
  button { border: 1px solid CanvasText; }
}