/* Design Tokens & Variables - Light Theme (Default) */
:root {
  --primary: #10B981; /* Bright Green (Emerald) */
  --primary-hover: #059669;
  --primary-glow: rgba(16, 185, 129, 0.25);
  --primary-light: rgba(16, 185, 129, 0.1);
  
  --bg-main: #F8FAFC; /* Light Slate Gray */
  --bg-card: #FFFFFF; /* Pure White */
  --bg-modal: #FFFFFF;
  --border-color: rgba(15, 23, 42, 0.08); /* Subtle Dark Border */
  --border-focus: rgba(255, 193, 7, 0.6);
  
  /* Search Input (Light Mode - Bright Soft Sky Blue) */
  --search-bg: #E0F2FE;
  --search-border: #93C5FD;
  --search-text: #0F172A;
  
  --text-main: #0F172A; /* Dark Slate 900 */
  --text-muted: #475569; /* Slate 600 */
  --text-dark: #94A3B8; /* Slate 400 */
  
  --success: #10B981; /* Emerald 500 */
  --error: #EF4444; /* Red 500 */
  
  --font-family-title: 'Outfit', 'Sarabun', sans-serif;
  --font-family-body: 'Inter', 'Sarabun', sans-serif;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  
  --shadow-card: 0 4px 20px rgba(15, 23, 42, 0.05);
  --shadow-glow: 0 0 20px rgba(255, 193, 7, 0.25);
  
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  
  --bg-radial: radial-gradient(circle at 10% 20%, rgba(255, 193, 7, 0.04) 0%, transparent 40%),
               radial-gradient(circle at 90% 80%, rgba(16, 185, 129, 0.02) 0%, transparent 45%);
}

/* Dark Theme Overrides */
:root.dark-theme {
  --bg-main: #2C2C2E; /* Premium Charcoal Gray (Apple style, not too dark) */
  --bg-card: #3A3A3C; /* Balanced lighter gray card */
  --bg-modal: #3A3A3C; /* Matching gray modal */
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: rgba(255, 193, 7, 0.5);
  
  /* Search Input (Dark Mode) */
  --search-bg: rgba(255, 255, 255, 0.06);
  --search-border: rgba(255, 255, 255, 0.12);
  --search-text: #F1F5F9;
  
  --text-main: #F1F5F9; 
  --text-muted: #D1D5DB; /* Lighter gray for readability */
  --text-dark: #9CA3AF; 
  
  --shadow-card: 0 8px 25px rgba(0, 0, 0, 0.2);
  --shadow-glow: 0 0 20px rgba(255, 193, 7, 0.15);
  
  --bg-radial: radial-gradient(circle at 10% 20%, rgba(255, 193, 7, 0.02) 0%, transparent 40%),
               radial-gradient(circle at 90% 80%, rgba(255, 255, 255, 0.01) 0%, transparent 45%);
}

/* Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-family-body);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  -webkit-font-smoothing: antialiased;
  background-image: var(--bg-radial);
  background-attachment: fixed;
}

/* App Container */
.app-container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

/* Header */
.app-header {
  text-align: center;
  margin-bottom: 48px;
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 12px;
}

.logo-icon-wrapper {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0) 100%);
  border: 1px solid var(--border-color);
  padding: 10px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.logo-icon-wrapper:hover {
  transform: translateY(-2px) scale(1.05);
  border-color: var(--primary);
  box-shadow: var(--shadow-glow);
}

.logo-corn {
  image-rendering: pixelated;
}

.logo-text {
  font-family: 'Press Start 2P', monospace;
  font-size: 1.6rem;
  font-weight: normal;
  letter-spacing: -1px;
  background: linear-gradient(135deg, #FF9100 0%, #FF3D00 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-top: 4px;
}

.app-subtitle {
  font-family: var(--font-family-title);
  color: var(--text-muted);
  font-size: 1.05rem;
  font-weight: 400;
}

.app-info-banner {
  display: inline-block;
  margin-top: 14px;
  padding: 6px 16px;
  background-color: rgba(255, 193, 7, 0.08);
  border: 1px solid rgba(255, 193, 7, 0.15);
  border-radius: 50px;
  color: #D97706; /* Darker warm amber for readability in light mode */
  font-size: 0.88rem;
  font-weight: 500;
  font-family: var(--font-family-title);
}

:root.dark-theme .app-info-banner {
  color: var(--primary);
  background-color: rgba(255, 193, 7, 0.05);
  border-color: rgba(255, 193, 7, 0.12);
}

/* Search and Controls Section */
.search-section {
  display: flex;
  gap: 16px;
  margin-bottom: 32px;
  align-items: center;
}

.search-box-wrapper {
  position: relative;
  flex-grow: 1;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 20px;
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  pointer-events: none;
  transition: var(--transition);
}

#search-input {
  width: 100%;
  padding: 16px 20px 16px 56px;
  background-color: var(--search-bg);
  border: 1px solid var(--search-border);
  border-radius: var(--radius-md);
  color: var(--search-text);
  font-family: var(--font-family-body);
  font-size: 1.05rem;
  font-weight: 400;
  outline: none;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: var(--transition);
}

#search-input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

#search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--primary-glow);
  background-color: var(--bg-card);
  color: var(--text-main);
}

#search-input:focus ~ .search-icon {
  color: var(--primary);
}

.clear-btn {
  position: absolute;
  right: 18px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  transition: var(--transition);
}

.clear-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.clear-btn svg {
  width: 16px;
  height: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 24px;
  border-radius: var(--radius-md);
  font-family: var(--font-family-title);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-card);
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

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

.btn-secondary {
  background-color: rgba(15, 23, 42, 0.05);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

:root.dark-theme .btn-secondary {
  background-color: rgba(255, 255, 255, 0.05);
}

.btn-secondary:hover {
  background-color: rgba(15, 23, 42, 0.08);
  border-color: var(--text-muted);
}

:root.dark-theme .btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.btn-icon-only {
  width: 50px;
  height: 50px;
  padding: 0;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

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

.btn-icon {
  width: 18px;
  height: 18px;
}

/* Results Section Header */
.results-header {
  margin-bottom: 20px;
}

.results-count {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Directory Grid */
.directory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
  width: 100%;
}

/* Contact Card */
.contact-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  transition: var(--transition);
}

.contact-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 193, 7, 0.4);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

:root.dark-theme .contact-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.contact-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-name {
  font-family: var(--font-family-title);
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.2px;
}

.contact-nick {
  font-family: var(--font-family-body);
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: -2px;
}

.contact-nick-value {
  color: var(--text-main);
  font-weight: 600;
}

.contact-pos-badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 4px 10px;
  background-color: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 400;
}

:root.dark-theme .contact-pos-badge {
  background-color: rgba(255, 255, 255, 0.04);
}

.contact-pos-empty {
  font-size: 0.85rem;
  color: var(--text-dark);
  font-style: italic;
}

/* Phone Display & Copy/Call Actions Layout */
.contact-phone-display {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-family-title);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-main);
  padding: 8px 12px;
  background-color: rgba(15, 23, 42, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  margin-top: 8px;
}

:root.dark-theme .contact-phone-display {
  background-color: rgba(255, 255, 255, 0.02);
}

.contact-phone-display svg {
  width: 16px;
  height: 16px;
  color: var(--primary);
  flex-shrink: 0;
}

.contact-card-actions {
  display: flex;
  gap: 8px;
  border-top: 1px solid var(--border-color);
  padding-top: 16px;
  margin-top: auto; /* Push buttons to the very bottom */
}

.contact-card-actions .btn {
  padding: 10px 14px;
  font-size: 0.9rem;
  border-radius: var(--radius-sm);
  flex: 1;
}

.action-btn-call {
  background-color: var(--primary);
  color: #ffffff !important;
}

.action-btn-call:hover {
  background-color: var(--primary-hover);
  box-shadow: var(--shadow-glow);
}

.action-btn-copy {
  background-color: rgba(15, 23, 42, 0.04);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

:root.dark-theme .action-btn-copy {
  background-color: rgba(255, 255, 255, 0.04);
}

.action-btn-copy:hover {
  background-color: rgba(15, 23, 42, 0.08);
  border-color: var(--text-muted);
}

:root.dark-theme .action-btn-copy:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.phone-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 1.1rem;
  transition: var(--transition);
}

.phone-link:hover {
  color: var(--primary-hover);
  text-shadow: 0 0 10px rgba(255, 193, 7, 0.3);
}

.phone-icon {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Loading Spinner */
.loading-spinner-wrapper {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  gap: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 193, 7, 0.1);
  border-radius: 50%;
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}

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

/* Empty State / No Results */
.no-results-state {
  text-align: center;
  padding: 80px 24px;
  background-color: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  max-width: 600px;
  margin: 40px auto;
}

.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--text-dark);
  margin-bottom: 16px;
}

.no-results-state h3 {
  font-family: var(--font-family-title);
  font-size: 1.35rem;
  margin-bottom: 8px;
}

.no-results-state p {
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Modals & Dialog overlays */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(7, 10, 20, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background-color: var(--bg-modal);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  max-width: 500px;
  width: 100%;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  transform: translateY(20px);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

.modal-overlay.open .modal-card {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
}

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

.modal-icon {
  width: 24px;
  height: 24px;
  color: var(--primary);
}

#modal-title {
  font-family: var(--font-family-title);
  font-size: 1.35rem;
  font-weight: 600;
}

.close-modal-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.close-modal-btn:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

.close-modal-btn svg {
  width: 20px;
  height: 20px;
}

.modal-form {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-family: var(--font-family-title);
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group label .required {
  color: var(--error);
  margin-left: 2px;
}

.form-group input {
  padding: 12px 16px;
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-family-body);
  font-size: 1rem;
  outline: none;
  transition: var(--transition);
}

.form-group input:focus {
  border-color: var(--border-focus);
  background-color: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.error-message {
  color: var(--error);
  font-size: 0.85rem;
  font-weight: 500;
  display: none;
}

.form-group.has-error input {
  border-color: var(--error);
}

.form-group.has-error .error-message {
  display: block;
}

.submit-status {
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
}

.submit-status.success {
  background-color: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.submit-status.error {
  background-color: rgba(239, 68, 68, 0.1);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 20px);
  background-color: #1E293B;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  padding: 14px 28px;
  border-radius: 50px;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  border-left: 3px solid var(--primary);
}

.toast-content {
  color: var(--text-main);
  font-family: var(--font-family-title);
  font-weight: 500;
  font-size: 0.95rem;
}

/* Footer Section */
.app-footer {
  text-align: center;
  padding: 40px 0 0 0;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.app-footer p {
  color: var(--text-dark);
  font-size: 0.85rem;
}

/* Responsive Breakpoints */
@media (max-width: 768px) {
  .app-container {
    padding: 24px 16px;
  }
  
  .app-header {
    margin-bottom: 32px;
  }
  
  .logo-text {
    font-size: 1.8rem;
  }
  
  .search-section {
    flex-direction: column;
    gap: 12px;
    align-items: stretch;
  }
  
  .search-actions {
    width: 100%;
    display: flex;
    gap: 12px;
  }
  
  #add-contact-trigger {
    flex-grow: 1;
    padding: 14px;
  }
  
  #search-input {
    padding: 14px 20px 14px 48px;
    font-size: 0.95rem;
  }
  
  .search-icon {
    left: 16px;
  }
  
  .directory-grid {
    grid-template-columns: 1fr;
  }
  
  .modal-card {
    border-radius: var(--radius-md);
  }
}
