/* ==========================================================================
   Dynamic Web Phonebook Directory - Clean Flat Light Mode Stylesheet
   ========================================================================== */

:root {
  /* Clean Light Theme Color Palette */
  --bg-app: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-input: #FFFFFF;
  --bg-subtle: #F1F5F9;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;
  --text-inverse: #FFFFFF;

  --border-subtle: #E2E8F0;
  --border-card: #E2E8F0;
  --border-focus: #10B981;

  /* Brand Colors */
  --wa-green: #25D366;
  --wa-dark: #128C7E;
  --wa-hover: #1EBE5D;

  --danger: #EF4444;
  --danger-tint: #FEF2F2;

  --success: #10B981;
  --success-tint: #D1FAE5;
  --success-text: #065F46;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Font */
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Reset & Base Setup */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100vh;
  background-color: #F1F5F9;
  font-family: var(--font-main);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: clip;
}

body {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0;
}

@media (min-width: 481px) {
  body {
    padding: 20px 0;
    background-color: #E2E8F0;
  }
}

/* ==========================================================================
   Mobile-Only App Container
   ========================================================================== */
#app-container {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background-color: var(--bg-app);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: clip;
  border-left: 1px solid var(--border-subtle);
  border-right: 1px solid var(--border-subtle);
}

@media (min-width: 481px) {
  #app-container {
    min-height: calc(100vh - 40px);
    border-radius: 20px;
    border: 1px solid #CBD5E1;
    overflow: visible;
  }
}

/* ==========================================================================
   Header Section & Sticky Search
   ========================================================================== */
#header-section {
  display: contents;
}

/* Top bar (scrolls away naturally) */
.header-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  background: #FFFFFF;
  border-bottom: 1px solid #F1F5F9;
}

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

.header-icon-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #10B981, #059669);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-text-group {
  display: flex;
  flex-direction: column;
}

#app-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.25;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: #F8FAFC;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: #E2E8F0;
  color: var(--text-primary);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn.is-refreshing #refresh-icon {
  animation: spin 0.8s linear infinite;
}

/* ==========================================================================
   Sticky Search Container (Stays Fixed to Top When Scrolled)
   ========================================================================== */
#search-container {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 16px 12px;
  background: #FFFFFF;
  border-bottom: 1px solid var(--border-subtle);
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: #FFFFFF;
  border: 1.5px solid var(--border-subtle);
  border-radius: var(--radius-full);
  padding: 0 16px;
  transition: border-color 0.2s ease;
}

.search-input-wrapper:focus-within {
  border-color: #10B981;
  background: #FFFFFF;
}

#search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 10px;
}

#search-input {
  width: 100%;
  height: 44px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-primary);
  outline: none;
}

#search-input::placeholder {
  color: #94A3B8;
  font-weight: 400;
}

.clear-btn {
  background: #E2E8F0;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.clear-btn:hover {
  background: #CBD5E1;
  color: var(--text-primary);
}

/* ==========================================================================
   Stats Bar
   ========================================================================== */
#stats-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 8px;
}

.stats-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#contact-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-full);
  background: #E2E8F0;
  color: #334155;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ==========================================================================
   Status & Alerts Container
   ========================================================================== */
#status-container {
  padding: 0 16px;
}

.status-box {
  background: #FFFFFF;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 30px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 10px;
  margin-bottom: 20px;
}

/* Loading Spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #E2E8F0;
  border-top-color: #10B981;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

#loading-text {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Error State */
.error-state {
  border-color: #FECACA;
  background: #FEF2F2;
}

.error-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: #FEE2E2;
  color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

.alert-heading {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.alert-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  max-width: 260px;
}

.retry-btn {
  padding: 8px 18px;
  border-radius: var(--radius-full);
  background: #10B981;
  color: #FFFFFF;
  border: none;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s ease;
}

.retry-btn:hover {
  background: #059669;
}

/* Empty State */
.empty-state {
  background: #FFFFFF;
}

.empty-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: #F1F5F9;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}

/* ==========================================================================
   Contact Cards Grid (Mobile Cards List - Clean Flat Style)
   ========================================================================== */
#contact-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 0 16px 24px;
  flex-grow: 1;
}

/* Individual Card */
.contact-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  transition: border-color 0.2s ease;
}

.contact-card:hover {
  border-color: #CBD5E1;
}

/* Card Header */
.card-header-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: #EFF6FF;
  color: #2563EB;
  font-weight: 800;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid #DBEAFE;
}

.header-info {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-width: 0;
}

.contact-name-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

/* Card Body */
.card-body-wrapper {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-desc-text {
  font-size: 0.86rem;
  color: var(--text-secondary);
  line-height: 1.45;
  background: #F8FAFC;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid #F1F5F9;
}

.message-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #F0FDF4;
  border: 1px dashed #A7F3D0;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

.message-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #065F46;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 4px;
}

.contact-msg-snippet {
  font-size: 0.82rem;
  color: #047857;
  font-style: italic;
  line-height: 1.4;
  word-break: break-word;
}

/* Card Actions (Strictly WhatsApp and Salin Nomor) */
.card-actions-wrapper {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-top: 2px;
}

/* Action Buttons */
.btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  border: none;
  transition: background-color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn-action svg {
  flex-shrink: 0;
}

.btn-action:active {
  transform: scale(0.97);
}

/* WhatsApp Button */
.btn-whatsapp {
  background: #25D366;
  color: #FFFFFF;
}

.btn-whatsapp:hover {
  background: #1EBE5D;
}

/* Salin Nomor Button */
.btn-secondary {
  background: #F1F5F9;
  color: #1E293B;
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: #E2E8F0;
}

.btn-secondary.is-copied {
  background: #D1FAE5 !important;
  color: #065F46 !important;
  border-color: #A7F3D0 !important;
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */
.toast-notification {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #0F172A;
  color: #FFFFFF;
  padding: 9px 16px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
}

.toast-notification.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast-icon {
  color: #10B981;
  display: flex;
  align-items: center;
}

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