/* ============================================================================
   contacts.css — Phase R5a — Contacts pane (orange identity).

   Orange is the warm sun-rise next to red Twin. Contacts are the people in
   the user's circle — warmer than the catalog Settings, calmer than the
   active Call. Liquid-glass cards. Avatar at corner narrates saves.

   All selectors live under .page-contacts.contacts-stage[data-color="orange"]
   with .c-* prefixes so we never collide with the existing .contact-* and
   .contacts-* legacy CSS in app.css. The legacy classes still apply to the
   existing #tpl-contact-detail-only ringtone + chat-log surfaces, which we
   reuse inside the new full-screen card via YStage.

   Layout adapts via container queries: 1-col stacks on phones, side-by-side
   compose + list on tablets, full topbar on desktops.
   ========================================================================= */

.page-contacts.contacts-stage {
    --c-color-0:  #ffb56c;   /* primary orange */
    --c-color-1:  #ff9d3d;   /* deeper sunset */
    --c-color-2:  #ffe2c2;   /* highlight */
    --c-color-3:  rgba(255, 157, 61, 0.16);
    --c-color-4:  rgba(255, 157, 61, 0.32);
    --c-glass:    rgba(28, 18, 10, 0.58);
    --c-glass-2:  rgba(40, 24, 12, 0.72);
    --c-border:   rgba(255, 181, 108, 0.22);
    --c-border-strong: rgba(255, 181, 108, 0.42);
    --c-fg:       #fef4e8;
    --c-fg-2:     #d8c5ad;
    --c-fg-3:     #998875;
    --c-shadow:   0 18px 42px rgba(255, 110, 30, 0.18);

    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px clamp(14px, 4vw, 28px);
    container-type: inline-size;
    color: var(--c-fg);
    min-height: 100%;
    background:
        radial-gradient(ellipse at 80% -10%, var(--c-color-3), transparent 55%),
        radial-gradient(ellipse at -10% 110%, rgba(255, 110, 30, 0.10), transparent 55%);
}

/* ── Topbar ─────────────────────────────────────────────────────── */

.contacts-stage .c-topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 14px 16px;
    border: 1px solid var(--c-border);
    border-radius: 18px;
    background: var(--c-glass);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    box-shadow: var(--c-shadow);
}
.contacts-stage .c-title { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.contacts-stage .c-sub   { margin: 4px 0 0; font-size: 12.5px; color: var(--c-fg-2); line-height: 1.45; }
.contacts-stage .c-topbar-right {
    display: flex; align-items: center; gap: 10px;
}
.contacts-stage .c-avatar-host {
    width: 56px; height: 56px;
    flex: 0 0 56px;
    position: relative;
}
.contacts-stage .c-stats {
    font-size: 11.5px;
    color: var(--c-fg-2);
    white-space: nowrap;
}

/* ── Action bar (Add button + search) ───────────────────────────── */

.contacts-stage .c-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.contacts-stage .c-search {
    flex: 1 1 auto;
    appearance: none;
    background: var(--c-glass-2);
    border: 1px solid var(--c-border);
    color: var(--c-fg);
    border-radius: 999px;
    padding: 9px 14px;
    font: inherit; font-size: 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.contacts-stage .c-search::placeholder { color: var(--c-fg-3); }
.contacts-stage .c-search:focus {
    border-color: var(--c-color-1);
    box-shadow: 0 0 0 3px var(--c-color-3);
}
.contacts-stage .c-add-btn {
    appearance: none;
    border: 1px solid var(--c-border-strong);
    background: linear-gradient(180deg, var(--c-color-0), var(--c-color-1));
    color: #2a1404;
    border-radius: 999px;
    padding: 9px 16px;
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(255, 110, 30, 0.32);
    transition: transform .12s ease, box-shadow .15s ease;
}
.contacts-stage .c-add-btn:hover  { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(255,110,30,.4); }
.contacts-stage .c-add-btn:active { transform: translateY(0); }

/* ── Add-by-address inline form ─────────────────────────────────── */

.contacts-stage .c-add-form {
    display: flex; flex-direction: column; gap: 10px;
    padding: 14px 16px;
    border: 1px solid var(--c-border);
    border-radius: 18px;
    background: var(--c-glass);
}
.contacts-stage .c-add-form input {
    appearance: none;
    background: rgba(0,0,0,.32);
    border: 1px solid var(--c-border);
    color: var(--c-fg);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit; font-size: 14px;
    outline: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.contacts-stage .c-add-form input:focus {
    border-color: var(--c-color-1);
    box-shadow: 0 0 0 3px var(--c-color-3);
}
.contacts-stage .c-add-form .c-row {
    display: flex; gap: 8px; flex-wrap: wrap;
}
.contacts-stage .c-add-form .c-row > * { flex: 1 1 auto; }

/* ── Empty state ────────────────────────────────────────────────── */

.contacts-stage .c-empty {
    display: flex; flex-direction: column; align-items: center;
    text-align: center; gap: 12px;
    padding: 40px 18px;
    border: 1px dashed var(--c-border);
    border-radius: 22px;
    background: var(--c-glass);
    color: var(--c-fg-2);
}
.contacts-stage .c-empty-glyph {
    width: 72px; height: 72px;
    border-radius: 50%;
    border: 1px solid var(--c-border-strong);
    display: grid; place-items: center;
    font-size: 32px; color: var(--c-color-0);
    background: radial-gradient(circle at 40% 35%, var(--c-color-3), transparent 65%);
}
.contacts-stage .c-empty p { margin: 0; max-width: 420px; line-height: 1.5; font-size: 14px; }

/* ── Contact list ───────────────────────────────────────────────── */

.contacts-stage .c-list {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
@container (min-width: 720px) {
    .contacts-stage .c-list { grid-template-columns: 1fr 1fr; }
}
@container (min-width: 1080px) {
    .contacts-stage .c-list { grid-template-columns: 1fr 1fr 1fr; }
}

.contacts-stage .c-row {
    appearance: none;
    display: grid;
    grid-template-columns: 48px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid var(--c-border);
    border-radius: 16px;
    background: var(--c-glass);
    color: var(--c-fg);
    text-align: left;
    cursor: pointer;
    font: inherit;
    transition: transform .12s ease, border-color .15s ease, background .15s ease;
}
.contacts-stage .c-row:hover {
    transform: translateY(-1px);
    border-color: var(--c-border-strong);
    background: var(--c-glass-2);
}
.contacts-stage .c-row:active { transform: translateY(0); }

.contacts-stage .c-row-orb {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 19px; font-weight: 700;
    color: #2a1404;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.32);
    overflow: hidden;
}
.contacts-stage .c-row-info {
    display: flex; flex-direction: column; min-width: 0; gap: 2px;
}
.contacts-stage .c-row-name {
    font-size: 14.5px; font-weight: 600; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contacts-stage .c-row-addr {
    font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 11px; color: var(--c-fg-3);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.contacts-stage .c-row-when {
    font-size: 11px; color: var(--c-fg-3); white-space: nowrap; text-align: right;
    line-height: 1.3;
}
.contacts-stage .c-row-when small { display: block; opacity: .7; font-size: 10px; }

/* ── Full-screen contact detail (presented via YStage) ──────────── */

.c-detail-stage {
    display: flex;
    flex-direction: column;
    height: 100%;
    color: #fef4e8;
    position: relative;
    background:
        radial-gradient(ellipse at 50% -10%, rgba(255, 157, 61, 0.18), transparent 55%),
        linear-gradient(180deg, rgba(28, 18, 10, 0.96), rgba(14, 9, 5, 0.98));
}
/* Custom backdrop layer (R5c). Painted as a separate element via ::before
   so we can control opacity without dimming the rest of the stage. */
.c-detail-stage[data-has-bg="true"]::before {
    content: '';
    position: absolute; inset: 0;
    z-index: 0;
    background-image: var(--cd-bg-image);
    background-size: cover;
    background-position: center;
    opacity: 0.32;
    pointer-events: none;
}
.c-detail-stage > * { position: relative; z-index: 1; }
.c-detail-stage .c-detail-topbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255, 181, 108, 0.18);
    background: rgba(28, 18, 10, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.c-detail-stage .c-back {
    appearance: none;
    border: 1px solid rgba(255, 181, 108, 0.25);
    background: rgba(0,0,0,.3);
    color: #fef4e8;
    width: 38px; height: 38px;
    border-radius: 50%;
    font-size: 18px; cursor: pointer;
    display: grid; place-items: center;
    transition: background .15s ease, border-color .15s ease;
}
.c-detail-stage .c-back:hover { background: rgba(255,157,61,.18); border-color: rgba(255,181,108,.5); }

.c-detail-stage .c-detail-title { margin: 0; font-size: 17px; font-weight: 600; }
.c-detail-stage .c-detail-addr {
    font-family: var(--mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 11px; color: #d8c5ad; opacity: .8; margin-top: 2px;
}

.c-detail-stage .c-detail-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px clamp(14px, 4vw, 28px) 32px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
@container (min-width: 880px) {
    .c-detail-stage .c-detail-body { grid-template-columns: 320px 1fr; align-items: start; }
}

.c-detail-stage .c-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 22px 18px;
    border: 1px solid rgba(255, 181, 108, 0.22);
    border-radius: 22px;
    background: rgba(28, 18, 10, 0.55);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
}
.c-detail-stage .c-hero-orb-wrap {
    position: relative;
    width: 160px; height: 160px;
}
.c-detail-stage .c-hero-orb {
    width: 160px; height: 160px;
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 64px; font-weight: 700; color: #2a1404;
    background-size: cover;
    background-position: center;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5),
                inset 0 0 0 4px rgba(255, 255, 255, 0.06);
    overflow: hidden;
}
.c-detail-stage .c-hero-orb-edit {
    position: absolute;
    right: -2px; bottom: -2px;
    width: 44px; height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(28, 18, 10, 0.95);
    background: linear-gradient(180deg, #ffb56c, #ff9d3d);
    color: #2a1404;
    font-size: 18px; cursor: pointer;
    display: grid; place-items: center;
    box-shadow: 0 4px 14px rgba(255, 110, 30, 0.4);
    transition: transform .12s ease, box-shadow .15s ease;
    appearance: none;
}
.c-detail-stage .c-hero-orb-edit:hover  { transform: scale(1.06); box-shadow: 0 8px 20px rgba(255, 110, 30, 0.5); }
.c-detail-stage .c-hero-orb-edit:active { transform: scale(0.98); }
.c-detail-stage .c-hero-name {
    margin: 0; font-size: 22px; font-weight: 600; text-align: center;
}
.c-detail-stage .c-hero-actions {
    display: flex; gap: 8px; flex-wrap: wrap; justify-content: center;
}

.c-detail-stage .c-fields {
    display: flex; flex-direction: column; gap: 14px;
}
.c-detail-stage .c-card {
    padding: 16px 18px;
    border: 1px solid rgba(255, 181, 108, 0.18);
    border-radius: 18px;
    background: rgba(28, 18, 10, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.c-detail-stage .c-card h3 {
    margin: 0 0 8px; font-size: 13px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.06em; color: #ffb56c;
}
.c-detail-stage .c-card p.c-help {
    margin: 4px 0 0; font-size: 11.5px; color: #998875; line-height: 1.45;
}

.c-detail-stage .c-input,
.c-detail-stage .c-textarea {
    width: 100%;
    appearance: none;
    background: rgba(0,0,0,.36);
    border: 1px solid rgba(255, 181, 108, 0.25);
    color: #fef4e8;
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit; font-size: 14px;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.c-detail-stage .c-textarea { resize: vertical; min-height: 76px; line-height: 1.45; }
.c-detail-stage .c-input:focus,
.c-detail-stage .c-textarea:focus {
    border-color: #ff9d3d;
    box-shadow: 0 0 0 3px rgba(255, 157, 61, 0.18);
}

.c-detail-stage .c-action {
    appearance: none;
    border: 1px solid rgba(255, 181, 108, 0.32);
    background: rgba(0,0,0,.4);
    color: #fef4e8;
    border-radius: 999px;
    padding: 9px 16px;
    font: inherit; font-weight: 500; font-size: 13px;
    cursor: pointer;
    display: inline-flex; gap: 6px; align-items: center;
    transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.c-detail-stage .c-action:hover  { background: rgba(255,157,61,.18); border-color: rgba(255,181,108,.5); transform: translateY(-1px); }
.c-detail-stage .c-action:active { transform: translateY(0); }
.c-detail-stage .c-action.primary {
    background: linear-gradient(180deg, #ffb56c, #ff9d3d);
    color: #2a1404;
    font-weight: 600;
    border-color: rgba(255, 181, 108, 0.6);
}
.c-detail-stage .c-action.danger {
    background: rgba(120, 30, 20, 0.5);
    border-color: rgba(255, 110, 90, 0.4);
    color: #ffd1c8;
}
.c-detail-stage .c-action.danger:hover { background: rgba(160, 40, 28, 0.6); }

.c-detail-stage .c-saved-flash {
    font-size: 11.5px; color: #ffb56c; opacity: 0; transition: opacity .2s ease;
    margin-left: 8px;
}
.c-detail-stage .c-saved-flash[data-on="true"] { opacity: 1; }

/* The legacy ringtone + chat-log markup we keep working inside this stage. */
.c-detail-stage .contact-ringtone-status { color: #d8c5ad; }
.c-detail-stage .contact-chat-msg {
    padding: 6px 8px;
    border: 1px solid rgba(255, 181, 108, 0.14);
    border-radius: 8px;
    margin-bottom: 6px;
    background: rgba(0,0,0,.25);
    font-size: 12.5px;
}
.c-detail-stage .contact-chat-msg.me   { border-color: rgba(255, 181, 108, 0.32); }
.c-detail-stage .contact-chat-msg small { color: #998875; }

@media (prefers-reduced-motion: reduce) {
    .contacts-stage .c-row,
    .c-detail-stage .c-action,
    .contacts-stage .c-add-btn { transition: none; }
}
