:root {
  color-scheme: light;
  --ink: #172121;
  --muted: #647071;
  --line: #d8e1df;
  --panel: #ffffff;
  --canvas: #f4f7f5;
  --brand: #0b5a59;
  --brand-strong: #084745;
  --accent: #d95427;
  --soft: #e7f2ef;
  --shadow: 0 10px 26px rgba(27, 44, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 16px;
  color: #fff;
  background: var(--brand);
  box-shadow: var(--shadow);
}

.eyebrow,
h1 {
  margin: 0;
}

.eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(1.55rem, 8vw, 2.15rem);
  line-height: 1.05;
}

.counter {
  min-width: 76px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  text-align: right;
  background: rgba(255, 255, 255, 0.12);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-box {
  display: none;
  gap: 6px;
  align-items: end;
  text-align: right;
}

.user-box span {
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 800;
}

.user-box button {
  min-height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 900;
}

body:has(#appShell:not([hidden])) .user-box {
  display: grid;
}

.counter strong,
.counter span {
  display: block;
}

.counter strong {
  font-size: 1.15rem;
}

.counter span {
  font-size: 0.72rem;
}

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

.login-panel {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 22px 12px;
}

.login-form {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-form h2 {
  margin: 0;
  color: var(--brand);
  font-size: 1.35rem;
}

.login-form label {
  display: grid;
  gap: 5px;
}

.login-form label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

.form-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--accent);
  font-size: 0.9rem;
  font-weight: 800;
}

.search-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.search-box {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.search-box svg,
.chevron {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.search-box svg {
  color: var(--brand);
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.filters label {
  display: grid;
  gap: 5px;
}

.filters span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.filters select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.toolbar button,
.form-actions button,
.icon-button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  color: var(--brand);
  background: var(--soft);
  font-weight: 800;
}

.contact-list {
  display: grid;
  gap: 10px;
}

.contact-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(27, 44, 42, 0.05);
}

.card-main {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 22px;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 12px;
  border: 0;
  text-align: left;
  color: inherit;
  background: transparent;
}

.avatar {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
  font-weight: 900;
}

.identity {
  min-width: 0;
}

.name,
.meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name {
  font-size: 0.98rem;
}

.meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.chevron {
  color: var(--muted);
  transition: transform 160ms ease;
}

.contact-card.is-open .chevron {
  transform: rotate(90deg);
}

.quick-actions {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 12px 12px 64px;
}

.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  min-width: max-content;
  padding: 0 12px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 800;
}

.action.whatsapp {
  background: #207a55;
}

.action.edit-action {
  border: 0;
  color: var(--brand);
  background: var(--soft);
}

.details {
  padding: 0 12px 12px 64px;
}

.details dl {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px 0 0;
  border-top: 1px solid var(--line);
}

.details div {
  display: grid;
  gap: 2px;
}

.details dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 0.92rem;
}

.empty-state {
  margin: 28px 8px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.contact-dialog {
  width: min(720px, calc(100% - 18px));
  max-height: min(820px, calc(100% - 18px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 22px 70px rgba(23, 33, 33, 0.28);
}

.contact-dialog::backdrop {
  background: rgba(23, 33, 33, 0.48);
}

.contact-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.form-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -14px -14px 0;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.form-header h2 {
  margin: 2px 0 0;
  font-size: 1.25rem;
}

.form-header .eyebrow {
  color: var(--brand);
}

.icon-button {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.contact-form label {
  display: grid;
  gap: 5px;
}

.contact-form label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.contact-form input,
.contact-form select,
.contact-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
}

.contact-form textarea {
  resize: vertical;
}

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

.save-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.form-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 10px;
  margin: 0 -14px -14px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.form-actions button {
  min-height: 46px;
  font-weight: 900;
}

.primary-button {
  color: #fff !important;
  background: var(--brand) !important;
}

.danger-button {
  color: #fff !important;
  background: var(--accent) !important;
}

.danger-button[hidden] {
  display: none;
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 20px;
  }

  .search-panel {
    grid-template-columns: 1.35fr 1fr;
    align-items: end;
  }

  .contact-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 380px) {
  .filters {
    grid-template-columns: 1fr;
  }

  .quick-actions,
  .details {
    padding-left: 12px;
  }
}
