/* ---------- app shell ---------- */

body.app { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: .75rem;
  padding: calc(.75rem + env(safe-area-inset-top)) 1rem .75rem;
  background: var(--forest); color: #fff;
}
.topbar img { width: 30px; height: 30px; border-radius: 4px; }
.topbar h1 { margin: 0; font-size: 1.1rem; color: #fff; flex: 1; }
.topbar .btn-link { color: #9ee6b8; }

.view { max-width: 560px; margin: 0 auto; padding: 1rem; display: grid; gap: 1rem; }
.view > h2 { margin: .5rem 0 0; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around; max-width: 560px; margin: 0 auto;
  padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom));
  background: #fff; border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; max-width: 110px; display: grid; justify-items: center; gap: 2px;
  padding: .35rem 0; border-radius: 10px;
  color: var(--muted); font-size: .72rem; font-weight: 600; text-decoration: none;
}
.tabbar a[aria-current="page"] { color: var(--green-dark); background: #e9f7ee; }

/* ---------- login ---------- */

.login { min-height: 100vh; display: grid; align-content: center; gap: 1.25rem; max-width: 420px; margin: 0 auto; padding: 1.5rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom)); }
.login-logo { background: #fff; border-radius: var(--radius); padding: 1rem 1.25rem; box-shadow: var(--shadow); }
.login-logo img { display: block; width: 100%; height: auto; }
.code-input { font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- install banner ---------- */

.install { display: flex; gap: .9rem; align-items: center; background: var(--forest); color: #fff; border-radius: var(--radius); padding: 1rem; }
.install img { width: 44px; height: 44px; border-radius: 10px; flex: none; }
.install p { margin: 0; font-size: .9rem; }
.install strong { display: block; font-size: 1rem; }
.install .btn { flex: none; }
.install .share-glyph { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -.2em; }

/* ---------- my card ---------- */

.qr-panel { display: grid; justify-items: center; gap: .5rem; text-align: center; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.qr-panel button { background: none; border: 0; padding: 0; cursor: zoom-in; }
.qr-panel img { width: min(240px, 70vw); height: auto; display: block; }
.qr-panel .url { font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }

.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.tool {
  display: flex; align-items: center; gap: .6rem; min-height: 56px; padding: .65rem .8rem;
  background: #fff; border: 0; border-radius: 12px; box-shadow: var(--shadow);
  color: var(--forest); font: 600 .9rem/1.2 var(--font); text-align: left; text-decoration: none; cursor: pointer;
}
.tool .icon { color: var(--green); }

.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; align-content: center; gap: 1rem;
  padding: 1.5rem; background: #fff; text-align: center;
}
.overlay img.qr-big { width: min(88vw, 70vh); height: auto; }
.overlay h2 { font-size: 1.5rem; margin: 0; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgb(0 0 0 / 40%); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  background: var(--stone); border-radius: 20px 20px 0 0;
  padding: 1.25rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  display: grid; gap: 1rem;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; }

.sig-preview { background: #fff; border-radius: 10px; padding: 1rem; border: 1px solid var(--line); overflow-x: auto; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translateX(-50%);
  background: var(--forest); color: #fff; padding: .65rem 1.1rem; border-radius: 999px;
  font-weight: 600; font-size: .9rem; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ---------- profile editor ---------- */

.photo-edit { display: flex; align-items: center; gap: 1rem; }
.photo-edit .avatar { width: 84px; height: 84px; }
.theme-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.theme-picker label { display: grid; justify-items: center; gap: .3rem; font-size: .8rem; font-weight: 600; cursor: pointer; }
.theme-picker input { position: absolute; opacity: 0; pointer-events: none; }
.theme-picker .swatch { width: 100%; aspect-ratio: 1.586; border-radius: 8px; border: 2px solid var(--line); }
.theme-picker input:checked + .swatch { border-color: var(--green); box-shadow: 0 0 0 3px rgb(13 171 76 / 25%); }
.theme-picker input:focus-visible + .swatch { outline: 2px solid var(--forest); outline-offset: 2px; }
.swatch-classic { background: linear-gradient(90deg, #fff 62%, var(--green) 62%); }
.swatch-forest { background: linear-gradient(90deg, var(--forest) 62%, var(--green) 62%); }
.swatch-green { background: var(--green); }
.swatch-stone { background: linear-gradient(90deg, var(--stone) 62%, var(--sage) 62%); }

/* ---------- contacts ---------- */

.toolbar { display: flex; gap: .5rem; align-items: center; }
.toolbar input[type="search"] {
  flex: 1; min-width: 0; padding: .65rem .8rem; border: 1.5px solid var(--line); border-radius: 10px; font: inherit; background: #fff;
}
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; scrollbar-width: none; }
.chip {
  flex: none; padding: .35rem .8rem; border-radius: 999px; border: 1.5px solid var(--line);
  background: #fff; color: var(--forest); font: 600 .82rem/1.2 var(--font); cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--forest); border-color: var(--forest); color: #fff; }

.list { list-style: none; margin: 0; padding: 0; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .row { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; color: inherit; text-decoration: none; }
.list .grow { flex: 1; min-width: 0; }
.list .name { font-weight: 600; color: var(--forest); }
.list .sub { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--green); flex: none; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.avatar {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  display: grid; place-items: center; object-fit: cover;
  background: #dff3e6; color: var(--forest); font-weight: 700; font-size: .9rem;
}
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700; background: #e9f7ee; color: var(--green-dark); }
.badge-warn { background: #fff4dc; color: #8a5a00; }
.badge-muted { background: #eef0ef; color: var(--muted); }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.quick-actions .btn { flex-direction: column; gap: .2rem; font-size: .8rem; min-height: 64px; }
.quick-actions .icon { color: var(--green); }

.bulkbar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 11;
  display: flex; gap: .5rem; align-items: center; justify-content: space-between;
  max-width: 560px; margin: 0 auto; padding: .75rem 1rem; background: var(--forest); color: #fff;
  border-radius: 14px 14px 0 0;
}

/* ---------- insights & admin ---------- */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.stat { background: #fff; border-radius: 12px; box-shadow: var(--shadow); padding: .9rem 1rem; }
.stat .value { font-size: 1.8rem; font-weight: 700; color: var(--forest); line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat .label { font-size: .82rem; color: var(--muted); }
.stat .delta { font-size: .78rem; color: var(--green-dark); font-weight: 600; }

.segmented { display: flex; background: #e6ebe8; border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: none; padding: .55rem; border-radius: 10px; font: 600 .9rem var(--font); color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed="true"] { background: #fff; color: var(--forest); box-shadow: 0 1px 3px rgb(0 0 0 / 10%); }

@media (min-width: 720px) {
  .view { padding: 1.5rem; }
  .tool-grid { grid-template-columns: repeat(3, 1fr); }
  .stats { grid-template-columns: repeat(4, 1fr); }
}
