/* Carelink admin — warm earthy palette, mobile-first.
   Cream / sage-teal / coral. Lots of whitespace. Soft shadows. */

:root {
    /* Palette */
    --bg:        #FAF6F1;     /* cream */
    --bg-soft:   #F4ECDF;     /* slightly warmer cream */
    --card:      #FFFFFF;
    --border:    #EDE3D6;     /* warm border */
    --border-2:  #E0D4C0;
    --text:      #2D3F47;     /* deep slate */
    --text-dim:  #6E7B82;
    --text-soft: #94A0A6;

    --primary:        #4A8A7E;     /* sage-teal */
    --primary-dark:   #3A6E66;
    --primary-soft:   #DAEAE5;

    --accent:         #E8806B;     /* warm coral */
    --accent-dark:    #D45A3D;
    --accent-soft:    #FBE4DD;

    --amber:     #E8B547;
    --amber-soft:#FBEBC1;
    --success:   #5FA577;
    --success-soft:#D8EBDD;
    --danger:    #C95757;
    --danger-soft:#F4D8D8;

    /* Shape & shadow */
    --radius:      14px;
    --radius-sm:   10px;
    --radius-lg:   20px;
    --radius-pill: 999px;

    --shadow-card:  0 1px 2px rgba(45,63,71,0.04), 0 4px 14px rgba(45,63,71,0.05);
    --shadow-pop:   0 4px 14px rgba(45,63,71,0.08), 0 12px 32px rgba(45,63,71,0.10);

    --header-h:    60px;
    --sidebar-w:   300px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, "Inter", "Segoe UI", Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

* { -webkit-tap-highlight-color: transparent; }

.hidden { display: none !important; }

a { color: var(--primary-dark); }

/* ---------- Inputs / buttons ---------- */

input, textarea, select {
    font: inherit;
    color: var(--text);
    width: 100%;
    padding: 0.7rem 0.85rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { min-height: 6rem; resize: vertical; }

button {
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    padding: 0.7rem 1.1rem;
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    background: var(--card);
    color: var(--text);
    transition: transform 0.05s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
    min-height: 44px;     /* touch target */
}
button:active { transform: translateY(1px); }
button.primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    box-shadow: 0 1px 2px rgba(216,90,61,0.18), 0 4px 10px rgba(216,90,61,0.18);
}
button.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
button.secondary {
    background: var(--card);
    color: var(--primary-dark);
    border-color: var(--primary);
}
button.secondary:hover { background: var(--primary-soft); }
button.danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
button.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
button.ghost:hover { background: var(--bg-soft); color: var(--text); }
button.icon {
    width: 44px; height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text);
}
button.icon:hover { background: var(--bg-soft); }

.error    { color: var(--danger); margin: 0.4rem 0 0; }
.muted    { color: var(--text-dim); }
.row-flex { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.row-flex > * { flex: 1 1 auto; }
.row-flex > button { flex: 0 0 auto; }

/* ---------- Login ---------- */

#login {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background:
      radial-gradient(circle at 20% 20%, #FBE4DD 0%, transparent 45%),
      radial-gradient(circle at 80% 70%, #DAEAE5 0%, transparent 50%),
      var(--bg);
    padding: 1rem;
}
#login-form {
    width: 100%;
    max-width: 360px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    display: flex; flex-direction: column; gap: 0.9rem;
    box-shadow: var(--shadow-pop);
}
#login-form h1 {
    margin: 0 0 0.4rem;
    color: var(--primary-dark);
    font-size: 1.8rem;
    letter-spacing: -0.02em;
}

/* ---------- App shell ---------- */

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* Top bar — visible on all screens but acts as the only nav on mobile. */
.topbar {
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.8rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 30;
}
.topbar .brand {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--primary-dark);
    letter-spacing: -0.01em;
}
.topbar .brand .dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 0.5rem;
    vertical-align: middle;
}
.topbar .spacer { flex: 1; }
.topbar .right {
    display: flex; align-items: center; gap: 0.5rem;
}
.topbar .me-name {
    font-size: 0.9rem;
    color: var(--text-dim);
    max-width: 200px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Body row holds optional sidebar + main */
.body-row { display: flex; flex: 1; min-height: 0; }

/* Drawer / sidebar */
#sidebar {
    width: 100%;
    max-width: 320px;
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 1.2rem 1rem;
    display: flex; flex-direction: column; gap: 0.8rem;
    overflow-y: auto;

    position: fixed;
    top: var(--header-h);
    left: 0;
    height: calc(100vh - var(--header-h));
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 25;
    box-shadow: var(--shadow-pop);
}
#sidebar.open { transform: translateX(0); }

.scrim {
    position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(45,63,71,0.4);
    z-index: 20;
    opacity: 0; pointer-events: none;
    transition: opacity 0.22s;
}
.scrim.visible { opacity: 1; pointer-events: auto; }

#sidebar h3 {
    margin: 0.5rem 0 0.2rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-soft);
    font-weight: 700;
}

#residences { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 0.3rem; }
#residences li {
    padding: 0.7rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background 0.12s, border-color 0.12s;
}
#residences li:hover { background: var(--bg-soft); }
#residences li.active {
    background: var(--primary-soft);
    border-color: var(--primary);
}
#residences li .li-title { font-weight: 600; color: var(--text); }
#residences li .li-sub { font-size: 0.85rem; color: var(--text-dim); margin-top: 0.1rem; }

/* Main */
#main {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    min-width: 0;
}
#welcome.empty {
    text-align: center;
    color: var(--text-dim);
    padding: 4rem 1rem;
    font-size: 1.05rem;
}
#welcome.empty::before {
    content: "🌿";
    display: block; font-size: 3rem; margin-bottom: 0.6rem;
}

#residence-view header {
    display: flex; align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    margin-bottom: 0.4rem;
}
#residence-view h2 {
    margin: 0;
    font-size: 1.6rem;
    letter-spacing: -0.02em;
    color: var(--text);
}
#rv-location {
    color: var(--text-dim); font-size: 0.95rem;
    flex: 1; min-width: 200px;
}

.presence {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-pill);
    background: var(--bg-soft);
    color: var(--text-dim);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.presence::before {
    content: "";
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-soft);
}
.presence.online { background: var(--success-soft); color: var(--success); }
.presence.online::before { background: var(--success); }

.pings-badge {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-pill);
    background: var(--amber-soft);
    color: #876B1F;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
}
.pings-badge::before {
    content: "📞";
}

/* Tabs — horizontal scroll on small screens */
.tabs {
    display: flex;
    gap: 0.2rem;
    border-bottom: 1.5px solid var(--border);
    margin: 1.2rem -0.2rem 1.4rem;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 1px; /* so the indicator doesn't clip */
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
    background: transparent;
    border: none;
    padding: 0.7rem 0.9rem;
    margin-bottom: -1.5px;
    border-bottom: 2.5px solid transparent;
    border-radius: 0;
    color: var(--text-dim);
    font-weight: 600;
    white-space: nowrap;
    min-height: auto;
    transition: color 0.15s, border-color 0.15s;
}
.tabs button:hover { color: var(--text); }
.tabs button.active {
    color: var(--primary-dark);
    border-bottom-color: var(--accent);
}

.tab-bodies > div { display: flex; flex-direction: column; gap: 1rem; }
.tab-bodies > div.hidden { display: none; }

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.1rem;
    box-shadow: var(--shadow-card);
}
.card h4 {
    margin: 0 0 0.8rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
    font-weight: 700;
}
.card form.list, .card .list { display: flex; flex-direction: column; gap: 0.6rem; }

/* List items inside a card */
.list { display: flex; flex-direction: column; gap: 0.6rem; }
.list-item {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
}
.list-item.done { opacity: 0.55; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; }
.list-item .li-sub { color: var(--text-dim); font-size: 0.88rem; margin-top: 0.15rem; }

/* Pair code display */
.pair-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.6rem;
    letter-spacing: 0.4rem;
    background: var(--accent-soft);
    color: var(--accent-dark);
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    display: inline-block;
    font-weight: 700;
}

/* Person tag pill */
.tag {
    display: inline-block;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: var(--radius-pill);
    padding: 0.1rem 0.55rem;
    font-size: 0.8rem;
    font-weight: 600;
    margin-left: 0.5rem;
    vertical-align: middle;
}

/* Recorder bar */
.recorder { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.rec-status { color: var(--accent-dark); font-weight: 600; }
.media-preview { margin-top: 0.6rem; }
.media-preview audio, .media-preview video { width: 100%; max-width: 360px; border-radius: var(--radius-sm); }
audio, video { max-width: 100%; }

/* ---------- Background gallery ---------- */

.bg-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.7rem;
}
.bg-tile {
    position: relative;
    aspect-ratio: 16 / 10;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 2.5px solid transparent;
    transition: transform 0.12s, border-color 0.15s, box-shadow 0.15s;
    background-size: cover;
    background-position: center;
    box-shadow: var(--shadow-card);
}
.bg-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-pop); }
.bg-tile.selected { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.bg-tile .label {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.55));
    color: #fff;
    padding: 0.55rem 0.7rem 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}
.bg-tile.none {
    background:
      repeating-linear-gradient(45deg,
        var(--bg-soft) 0 8px,
        var(--card) 8px 16px);
    color: var(--text-dim);
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
}

/* ---------- Desktop ---------- */

@media (min-width: 768px) {
    body { font-size: 15px; }

    /* Sidebar always visible, no drawer behavior */
    #sidebar {
        position: static;
        transform: none !important;
        height: auto;
        flex-shrink: 0;
        box-shadow: none;
        max-width: var(--sidebar-w);
        width: var(--sidebar-w);
    }
    .scrim { display: none; }
    #hamburger { display: none; }

    .topbar { padding: 0 1.4rem; }
    #main { padding: 1.6rem 2rem; }

    #residence-view h2 { font-size: 1.8rem; }
}

/* ---------- Helpers ---------- */

.field-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 600;
    margin-bottom: -0.2rem;
}

@media (max-width: 767px) {
    /* On mobile keep tabs density tight */
    .tabs { font-size: 0.95rem; margin-top: 0.8rem; margin-bottom: 1rem; }
    .card { padding: 0.95rem 0.95rem; }
    #residence-view h2 { font-size: 1.4rem; }
}
