:root {
  --page: #f4f7f6;
  --ink: #141918;
  --muted: #65726f;
  --line: #dfe7e4;
  --primary: #0f766e;
  --primary-dark: #06433e;
  --soft: #eef8f5;
  --white: #ffffff;
  --danger: #b45309;
  --shadow: 0 18px 55px rgba(20, 34, 31, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(235, 247, 243, 0.95), rgba(250, 252, 251, 0.92)),
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.18), transparent 24rem);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button,
a.button,
a.round-action {
  min-height: 44px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.hidden {
  display: none !important;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.login-card {
  display: grid;
  width: min(430px, 100%);
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-card h1 {
  font-size: 2rem;
}

.login-card p {
  color: var(--muted);
  line-height: 1.5;
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.login-message {
  min-height: 24px;
  font-size: 0.92rem;
}

.app-shell {
  width: min(1160px, 100%);
  margin: 0 auto;
  padding: 14px 12px 24px;
}

.app-header {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 14px;
}

.app-header h1 {
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  font-weight: 900;
  letter-spacing: 0;
}

.app-header p:not(.eyebrow) {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.session-bar {
  display: flex;
  max-width: 590px;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  color: #38504b;
  font-size: 0.85rem;
}

.session-bar span,
.session-bar button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  padding: 8px 10px;
}

.session-bar button {
  min-height: 34px;
  color: var(--primary-dark);
  font-weight: 800;
  cursor: pointer;
}

#connectionStatus {
  color: var(--primary-dark);
  font-weight: 900;
}

#connectionStatus.offline {
  color: var(--danger);
}

#syncButton:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.contacts-panel,
.detail-panel,
.form-panel {
  border: 1px solid rgba(255, 255, 255, 0.82);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.contacts-panel {
  position: relative;
  overflow: hidden;
  padding: 20px 18px 12px;
}

.directory-toolbar {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  gap: 8px;
  border: 1px solid rgba(221, 226, 224, 0.92);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 24px rgba(20, 34, 31, 0.14);
  padding: 7px;
}

.toolbar-button {
  display: grid;
  width: 44px;
  height: 44px;
  min-height: 44px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #101614;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  background: #f1f5f4;
  outline: none;
}

.panel-title {
  min-height: 70px;
  padding: 10px 120px 14px 4px;
}

.panel-title h2,
.detail-panel h2,
.form-title h2 {
  font-size: 1.45rem;
}

.panel-title p,
.form-title p {
  margin-top: 5px;
  color: var(--muted);
}

.search-wrap {
  margin: 0 0 12px;
}

.field {
  display: block;
}

.field span {
  display: block;
  margin-bottom: 8px;
  color: #344640;
  font-size: 0.92rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cfe7e1;
  border-radius: 18px;
  background: var(--white);
  color: var(--ink);
  outline: none;
  padding: 14px 16px;
}

input:focus,
textarea:focus {
  border-color: #14b8a6;
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.2);
}

textarea {
  min-height: 260px;
  line-height: 1.65;
  resize: vertical;
}

.contacts-list {
  max-height: calc(100vh - 180px);
  overflow: auto;
  padding: 0 2px 10px;
}

.letter-row {
  padding: 14px 6px 6px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 900;
}

.contact-result-name {
  color: #0f766e;
  font-size: 0.98rem;
  letter-spacing: 0;
  text-transform: none;
}

.contact-item {
  display: flex;
  width: 100%;
  gap: 12px 16px;
  align-items: flex-start;
  flex-wrap: wrap;
  border: 0;
  border-bottom: 1px solid #e5ece9;
  background: transparent;
  color: var(--ink);
  padding: 12px 4px;
  text-align: left;
  cursor: pointer;
}

.contact-main {
  min-width: 0;
  flex: 1 1 180px;
  padding-top: 5px;
}

.contact-item:hover,
.contact-item.selected {
  background: #f5faf8;
}

.avatar {
  display: grid;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 999px;
  background: var(--avatar-bg, #8dd3c7);
  color: white;
  font-size: 1.35rem;
  font-weight: 800;
  overflow: hidden;
}

.avatar.large {
  width: 74px;
  height: 74px;
  font-size: 2rem;
}

.avatar-button {
  display: block;
  border: 0;
  border-radius: 999px;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.avatar-button:focus-visible {
  outline: 3px solid #2dd4bf;
  outline-offset: 4px;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.contact-name {
  display: block;
  overflow: hidden;
  color: #101614;
  font-size: 1.06rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-subtitle {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.92rem;
}

.reference-match {
  display: block;
  flex: 0 1 220px;
  margin-left: auto;
  max-width: 100%;
  border: 1px solid #99f6e4;
  border-radius: 14px;
  background: #ecfeff;
  color: #0f766e;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.35;
  padding: 7px 9px;
}

.reference-label {
  display: block;
  margin-bottom: 2px;
  color: #155e75;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.reference-match mark {
  border-radius: 6px;
  background: #facc15;
  color: #111827;
  padding: 0 3px;
}

.pending-badge {
  margin-left: auto;
  border-radius: 999px;
  background: #fef3c7;
  color: #92400e;
  padding: 5px 8px;
  font-size: 0.75rem;
  font-weight: 800;
}

.detail-panel,
.form-panel {
  padding: 20px;
}

.detail-empty {
  display: grid;
  min-height: 420px;
  place-content: center;
  text-align: center;
}

.detail-empty p {
  max-width: 330px;
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.55;
}

.detail-heading {
  display: flex;
  gap: 16px;
  align-items: center;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.detail-heading p {
  margin-top: 5px;
  color: var(--muted);
}

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(8, 18, 16, 0.72);
  padding: 18px;
}

.photo-card {
  width: min(420px, 100%);
  border: 1px solid rgba(153, 246, 228, 0.45);
  border-radius: 24px;
  background: white;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.32);
  padding: 16px;
  text-align: center;
}

.photo-card-image {
  display: grid;
  width: 100%;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border-radius: 20px;
  background: #effaf7;
}

.photo-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-card-image .avatar {
  width: 150px;
  height: 150px;
  font-size: 4rem;
}

.photo-card h2 {
  margin-top: 14px;
  font-size: 1.35rem;
}

.photo-close {
  display: block;
  margin-left: auto;
  margin-bottom: 10px;
  border: 1px solid #d6e4e0;
  border-radius: 999px;
  background: white;
  color: var(--primary-dark);
  font-weight: 900;
  padding: 9px 14px;
  cursor: pointer;
}

.detail-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.round-action,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  padding: 12px 16px;
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}

.round-action.whatsapp,
.button.whatsapp {
  background: #16a34a;
  color: white;
}

.round-action.phone,
.button.dark {
  background: #111827;
  color: white;
}

.primary {
  background: var(--primary);
  color: var(--white);
}

.secondary {
  border: 1px solid #afd9d1;
  background: white;
  color: var(--primary-dark);
}

.danger {
  border: 1px solid #fed7aa;
  background: #fff7ed;
  color: #9a3412;
}

.reference-card {
  border: 1px solid #dbe8e4;
  border-radius: 18px;
  background: #f8fbfa;
  padding: 16px;
}

.reference-card h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.reference-card p {
  color: #33423f;
  line-height: 1.65;
  white-space: pre-wrap;
}

.detail-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}

.form-title,
.actions {
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.form-title {
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.close-button {
  border: 1px solid #d6e4e0;
  border-radius: 999px;
  background: white;
  color: var(--primary-dark);
  font-weight: 800;
  padding: 10px 14px;
  cursor: pointer;
}

form {
  display: grid;
  gap: 16px;
  padding-top: 18px;
}

.photo-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  border: 1px solid #dbe8e4;
  border-radius: 18px;
  background: #f8fbfa;
  padding: 14px;
}

.photo-preview {
  width: 72px;
  height: 72px;
  font-size: 1.8rem;
}

.photo-picker input {
  padding: 11px 12px;
}

.two-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.actions {
  flex-wrap: wrap;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.quick-actions,
.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.empty-state {
  border: 1px dashed #b9d8d1;
  border-radius: 18px;
  background: #f7fbfa;
  padding: 18px;
  color: var(--muted);
  line-height: 1.55;
}

@media (max-width: 880px) {
  .app-shell {
    width: min(620px, 100%);
  }

  .app-header,
  .workspace,
  .two-columns {
    display: block;
  }

  .session-bar {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .contacts-panel,
  .detail-panel,
  .form-panel {
    margin-bottom: 14px;
  }

  .contacts-list {
    max-height: none;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 10px 8px 22px;
  }

  .login-card,
  .contacts-panel,
  .detail-panel,
  .form-panel {
    border-radius: 22px;
  }

  .app-header h1 {
    font-size: 1.65rem;
  }

  .session-bar span:nth-child(3),
  .session-bar span:nth-child(4) {
    display: none;
  }

  .panel-title {
    padding-right: 116px;
  }

  .reference-match {
    flex: 1 0 calc(100% - 68px);
    margin-left: 68px;
  }

  .contact-main {
    flex-basis: calc(100% - 68px);
  }

  .detail-actions,
  .actions,
  .quick-actions,
  .save-actions,
  .button {
    width: 100%;
  }

  .photo-field {
    grid-template-columns: auto minmax(0, 1fr);
  }

  #removePhotoButton {
    grid-column: 1 / -1;
  }

  .detail-footer {
    justify-content: stretch;
  }
}
