/* ============================================================
   TeamComm Admin — Replit-inspired neutral UI
   Base: 360 px | Desktop breakpoint: 768 px
   ============================================================ */

/* === VARIABLES === */
:root {
    --primary:      #0066cc;
    --primary-dark: #0052a3;
    --on-primary:   #ffffff;
    --bg:           #f4f4f5;
    --surface:      #ffffff;
    --line:         #e4e4e7;
    --ink:          #18181b;
    --muted:        #71717a;
    --danger:       #dc2626;
    --ok:           #16a34a;
    --warning:      #d97706;
    --radius:       6px;
    --sidebar-bg:   #18181b;
    --sidebar-hover:#27272a;
    --sidebar-active:#3f3f46;
    --sidebar-text: rgba(255,255,255,.85);
    --sidebar-w:    224px;
    --topbar-h:     52px;
    --tabbar-h:     56px;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; background: #f0f0f1; padding: 1px 5px; border-radius: 3px; }

/* === MOBILE TOPBAR === */
.topbar {
    display: flex;
    align-items: center;
    background: var(--sidebar-bg);
    color: #fff;
    height: var(--topbar-h);
    padding: 0 4px 0 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar .brand { font-size: 16px; font-weight: 700; flex: 1; letter-spacing: .01em; color: #fff; }
.topbar .more-btn {
    background: none; border: none;
    color: #fff;
    width: 44px; height: 44px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
}
.topbar .more-btn:hover { background: rgba(255,255,255,.1); }

/* === SIDEBAR (desktop only, hidden on mobile) === */
.sidebar { display: none; }

/* === APP SHELL === */
.app-shell { display: block; }

main.with-chrome {
    padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom, 0px));
}
main.bare {
    display: flex; flex-direction: column; min-height: 100vh;
    background: var(--sidebar-bg);
}

/* === BOTTOM TAB BAR (mobile) === */
.tab-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--line);
    box-shadow: 0 -1px 4px rgba(0,0,0,.06);
    z-index: 100;
}
.tab-bar a, .tab-bar .tab-more {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--muted);
    font-size: 10px;
    font-weight: 500;
    gap: 3px;
    text-decoration: none;
    padding: 4px 0;
    border: none; background: none; cursor: pointer;
    transition: color .15s;
}
.tab-bar a.active, .tab-bar .tab-more.active { color: var(--primary); }
.tab-bar a svg, .tab-bar .tab-more svg { width: 22px; height: 22px; fill: currentColor; }

/* === UNREAD BADGE === */
.nav-icon-wrap {
    position: relative;
    display: inline-flex;
}
.unread-badge {
    position: absolute;
    top: -5px; right: -7px;
    min-width: 16px; height: 16px;
    background: var(--primary-light);
    color: #fff;
    font-size: 10px; font-weight: 700; line-height: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 4px;
    pointer-events: none;
}
.sidebar .nav-icon-wrap .unread-badge {
    top: -4px; right: -6px;
    background: var(--primary-light);
}

/* === SLIDE-UP DRAWER (mobile "More") === */
.drawer-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.45); z-index: 150;
}
.drawer-overlay.open { display: block; }

.drawer-panel {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-radius: 12px 12px 0 0;
    padding: 0 0 env(safe-area-inset-bottom, 8px);
    z-index: 200;
    transform: translateY(100%);
    transition: transform .22s ease;
    max-height: 70vh; overflow-y: auto;
}
.drawer-panel.open { transform: translateY(0); }
.drawer-handle {
    width: 32px; height: 4px; background: var(--line);
    border-radius: 2px; margin: 10px auto 4px; display: block;
}
.drawer-panel a {
    display: flex; align-items: center; gap: 12px;
    padding: 13px 20px; color: var(--ink); font-size: 14px;
    border-bottom: 1px solid var(--bg); text-decoration: none;
    transition: background .1s;
}
.drawer-panel a:hover { background: var(--bg); }
.drawer-panel a.active { color: var(--primary); font-weight: 600; }
.drawer-panel a svg { width: 18px; height: 18px; fill: currentColor; color: var(--muted); flex-shrink: 0; }
.drawer-panel a.active svg { color: var(--primary); }
.drawer-user {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 20px; color: var(--muted); font-size: 13px;
    border-bottom: 1px solid var(--line);
}
.drawer-sign-out { padding: 10px 16px; }
.drawer-sign-out form button {
    width: 100%; padding: 10px 16px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: none; cursor: pointer; font-size: 14px;
    color: var(--danger); text-align: center;
    transition: background .1s;
}
.drawer-sign-out form button:hover { background: #fef2f2; }

/* ============================================================
   DESKTOP (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {
    .topbar  { display: none; }
    .tab-bar { display: none; }
    .drawer-overlay, .drawer-panel { display: none !important; }

    .app-shell {
        display: grid;
        grid-template-columns: var(--sidebar-w) 1fr;
        min-height: 100vh;
    }

    .sidebar {
        display: flex; flex-direction: column;
        background: var(--sidebar-bg);
        position: sticky; top: 0; height: 100vh;
        overflow-y: auto;
    }
    .sidebar .sb-brand {
        font-size: 15px; font-weight: 700;
        color: #fff;
        padding: 18px 16px 14px;
        letter-spacing: .02em;
        border-bottom: 1px solid rgba(255,255,255,.08);
        flex-shrink: 0;
    }
    .sidebar nav {
        flex: 1; display: flex; flex-direction: column;
        padding: 8px 8px 0; gap: 1px;
    }
    .sidebar nav a {
        display: flex; align-items: center; gap: 10px;
        color: var(--sidebar-text);
        padding: 9px 10px;
        border-radius: var(--radius);
        font-size: 13px; font-weight: 500;
        text-decoration: none;
        min-height: 38px;
        transition: background .1s, color .1s;
    }
    .sidebar nav a svg { width: 16px; height: 16px; fill: currentColor; flex-shrink: 0; opacity: .7; }
    .sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
    .sidebar nav a:hover svg { opacity: 1; }
    .sidebar nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
    .sidebar nav a.active svg { opacity: 1; }
    .sidebar .sb-divider { height: 1px; background: rgba(255,255,255,.1); margin: 6px 8px; }
    .sidebar .sb-footer {
        padding: 10px 8px 16px;
        border-top: 1px solid rgba(255,255,255,.1);
        flex-shrink: 0;
    }
    .sidebar .sb-user {
        color: rgba(255,255,255,.45); font-size: 11px;
        padding: 4px 10px 8px;
        white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    }
    .sidebar .sb-footer button {
        width: 100%; padding: 8px 10px;
        border: 1px solid rgba(255,255,255,.15);
        border-radius: var(--radius);
        background: none; color: var(--sidebar-text);
        cursor: pointer; font-size: 13px; text-align: left;
        transition: background .1s;
    }
    .sidebar .sb-footer button:hover { background: var(--sidebar-hover); }

    main.with-chrome {
        padding: 28px 36px 48px;
    }
}

/* === TYPOGRAPHY === */
h1 { font-size: 18px; font-weight: 700; margin: 0 0 16px; color: var(--ink); }
h2 { font-size: 13px; font-weight: 600; margin: 24px 0 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
small { font-size: 12px; }
@media (min-width: 768px) {
    h1 { font-size: 20px; }
}

/* === CARDS === */
.card, details.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 12px 0;
}
details > summary { cursor: pointer; padding: 4px 0; font-weight: 600; font-size: 14px; color: var(--ink); list-style: none; }
details > summary::marker, details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: '+ '; color: var(--primary); }
details[open] > summary { margin-bottom: 14px; }
details[open] > summary::before { content: '− '; }

/* === LOGIN === */
.login-hero {
    background: var(--sidebar-bg);
    color: #fff;
    text-align: center;
    padding: 48px 24px 72px;
    flex-shrink: 0;
}
.login-logo {
    display: inline-flex; align-items: center; justify-content: center;
    width: 64px; height: 64px;
    background: rgba(255,255,255,.1);
    border-radius: 12px;
    margin-bottom: 16px;
    color: #fff;
}
.login-hero h1 { font-size: 22px; margin: 0 0 4px; color: #fff; text-transform: none; letter-spacing: 0; }
.login-hero p { margin: 0; opacity: .6; font-size: 13px; }
.login-body {
    flex: 1; display: flex; align-items: flex-start;
    justify-content: center; padding: 0 16px 48px;
}
.login-card {
    background: var(--surface);
    border-radius: 10px;
    padding: 28px 24px 24px;
    width: 100%; max-width: 380px;
    margin-top: -36px;
    box-shadow: 0 4px 24px rgba(0,0,0,.14);
    border: 1px solid var(--line);
}
.login-card h2 {
    margin-top: 0; margin-bottom: 20px;
    font-size: 16px; font-weight: 700;
    color: var(--ink);
    text-transform: none; letter-spacing: 0;
}

/* === FORMS === */
label { display: block; margin: 14px 0; font-size: 13px; font-weight: 500; color: var(--ink); }
label.label--inline { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label > .hint, label > span.hint {
    display: block; color: var(--muted);
    font-size: 12px; font-weight: 400; margin-top: 4px;
}
input[type=text], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=email],
input[type=datetime-local],
textarea, select {
    display: block; width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: #fff; color: var(--ink);
    font: inherit; font-size: 14px;
    min-height: 38px;
    transition: border-color .12s, box-shadow .12s;
}
textarea { min-height: 80px; resize: vertical; }
select[multiple] { min-height: 140px; }
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,102,204,.15);
}

/* Buttons */
button {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 8px 16px;
    cursor: pointer; font: inherit; font-size: 13px; font-weight: 500;
    min-height: 34px; display: inline-flex; align-items: center;
    color: var(--ink);
    transition: background .1s, border-color .1s, color .1s;
}
button:hover { background: var(--bg); }
button.primary {
    background: var(--primary); color: var(--on-primary);
    border-color: var(--primary); font-weight: 600;
}
button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
button.danger-btn { color: var(--danger); border-color: #fca5a5; }
button.danger-btn:hover { background: #fef2f2; }
button.btn-danger {
    background: var(--danger); color: #fff;
    border-color: var(--danger); font-weight: 600;
}
button.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.btn-link-danger {
    color: var(--danger); font-weight: 500; cursor: pointer;
}
.button-link-outline {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border: 1px solid var(--line);
    border-radius: var(--radius); color: var(--ink);
    font-size: 13px; font-weight: 500; text-decoration: none;
    min-height: 34px; transition: background .1s, border-color .1s;
    white-space: nowrap; background: var(--surface);
}
.button-link-outline:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn-link-dm {
    color: var(--primary); font-weight: 500; font-size: 13px;
    text-decoration: none; display: inline-block; padding: 2px 0;
}
.btn-link-dm:hover { text-decoration: underline; }
.del-details > summary.btn-link-danger { list-style: none; }
.del-details > summary.btn-link-danger::marker,
.del-details > summary.btn-link-danger::-webkit-details-marker { display: none; }
.del-details > summary.btn-link-danger::before { display: none; }
.del-confirm-label {
    background: #fef2f2; border: 1px solid #fca5a5;
    border-radius: var(--radius); padding: 10px 12px;
    display: flex; align-items: flex-start; gap: 8px;
    font-size: 13px; width: 100%; font-weight: 400; cursor: pointer;
}
.del-confirm-label input[type=checkbox] { margin-top: 2px; flex-shrink: 0; }

form.inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
form.inline label { margin: 0; min-width: 140px; }
.inline-actions { display: inline-block; margin-right: 4px; }
.inline-actions button { padding: 5px 12px; font-size: 12px; min-height: 30px; }

fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin: 14px 0; }
fieldset legend { padding: 0 6px; color: var(--muted); font-size: 12px; font-weight: 500; }
fieldset label { display: inline-flex; align-items: center; gap: 6px; margin: 4px 12px 4px 0; font-weight: 400; }

/* === FLASH BANNERS === */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    background: #fefce8; border: 1px solid #fde047;
    padding: 10px 14px; border-radius: var(--radius); margin: 10px 0;
    font-size: 13px; line-height: 1.45;
}
.alert::before { content: 'ℹ'; font-style: normal; flex-shrink: 0; margin-top: 1px; color: #ca8a04; font-weight: 700; }
.alert.error { background: #fef2f2; border-color: #fca5a5; }
.alert.error::before { content: '✕'; color: var(--danger); }
.alert.ok, .alert.success { background: #f0fdf4; border-color: #86efac; }
.alert.ok::before, .alert.success::before { content: '✓'; color: var(--ok); }
.hint { color: var(--muted); font-size: 12px; }

/* === STAT GRID === */
.stat-grid {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 10px; margin-bottom: 24px;
}
.stat {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 16px;
    border-left: 3px solid var(--primary);
}
.stat .num { font-size: 22px; font-weight: 700; color: var(--ink); }
.stat .lbl { color: var(--muted); font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; margin-top: 3px; }
@media (min-width: 768px) {
    .stat-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; }
    .stat .num { font-size: 24px; }
}

/* === DATA TABLE ===
   Mobile: each row becomes a card with labelled cells.
   Desktop: normal table.
   Add data-label="Column name" to every <td>.
============================================================ */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data, table.table {
    width: 100%; border-collapse: collapse; margin-top: 10px;
}

@media (max-width: 767px) {
    table.data thead { display: none; }
    table.data, table.data tbody,
    table.data tr, table.data td { display: block; }
    table.data tbody { display: flex; flex-direction: column; gap: 10px; }
    table.data tr {
        background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius); overflow: hidden;
    }
    table.data td {
        display: flex; align-items: flex-start; gap: 8px;
        padding: 8px 14px; border-bottom: 1px solid var(--bg);
        font-size: 13px; word-break: break-word;
    }
    table.data td:last-child { border-bottom: none; }
    table.data td::before {
        content: attr(data-label);
        font-weight: 600; color: var(--muted);
        font-size: 10px; text-transform: uppercase;
        letter-spacing: .05em;
        min-width: 68px; padding-top: 2px; flex-shrink: 0;
    }
    table.data td[data-label=""]::before { display: none; min-width: 0; }
    table.data td:empty { display: none; }
    table.data td[data-label="Actions"] { flex-direction: column; align-items: flex-start; gap: 6px; }
    table.data td[data-label="Actions"]::before { display: none; }
}

@media (min-width: 768px) {
    table.data, table.table {
        background: var(--surface); border: 1px solid var(--line);
        border-radius: var(--radius); overflow: hidden;
    }
    table.data th, table.table th,
    table.data td, table.table td {
        text-align: left; padding: 9px 14px;
        border-bottom: 1px solid var(--line); vertical-align: middle;
        font-size: 13px;
    }
    table.data th, table.table th {
        background: #f4f4f5; font-weight: 600;
        font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
        color: var(--muted);
    }
    table.data tr:last-child td, table.table tr:last-child td { border-bottom: none; }
    table.data tbody tr:hover td, table.table tbody tr:hover td { background: #fafafa; }
}

/* === SORTABLE COLUMN HEADERS === */
th.sortable { white-space: nowrap; }
th.sortable a {
    color: inherit; text-decoration: none;
    display: inline-flex; align-items: center; gap: 4px;
}
th.sortable a:hover { color: var(--ink); text-decoration: none; }
th.sortable a::after {
    content: '↕';
    opacity: .30;
    font-size: 10px;
}
th.sort-asc a::after  { content: '↑'; opacity: .75; color: var(--primary); }
th.sort-desc a::after { content: '↓'; opacity: .75; color: var(--primary); }
th.sort-asc, th.sort-desc { color: var(--ink); }

/* Header-only sort bar above photo grid — no body rows, no bottom border */
table.photos-sort-bar { margin-bottom: 8px; }
table.photos-sort-bar thead tr th { border-bottom: none; }

.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11px; color: var(--muted); }

/* === PILLS === */
.pill {
    display: inline-block; padding: 2px 8px;
    border-radius: 20px; font-size: 11px; font-weight: 600;
    background: #f4f4f5; color: var(--muted);
    text-transform: uppercase; letter-spacing: .03em;
}
.pill.ok  { background: #dcfce7; color: #15803d; }
.pill.bad { background: #fee2e2; color: #b91c1c; }

/* === PHOTO GRID === */
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-tile {
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 8px;
}
.photo-tile img { width: 100%; aspect-ratio: 1/1; object-fit: cover; border-radius: 4px; display: block; }
.photo-tile .meta { font-size: 11px; margin-top: 6px; }
.photo-tile .meta .dim { color: var(--muted); }
@media (min-width: 768px) {
    .photo-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
}

/* === FILTER ROW === */
.filter-row {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
    background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 14px 16px; margin: 12px 0;
}
.filter-row label { margin: 0; flex: 1 1 140px; }
.filter-row button { align-self: flex-end; }

/* === LAYOUT HELPERS === */
.two-col { display: grid; grid-template-columns: 1fr; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 600px) { .row { grid-template-columns: 1fr 1fr; } }
@media (min-width: 768px) {
    .two-col { grid-template-columns: 1fr 1fr; }
    .row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* === STATUS CARD VARIANTS (backup_status) === */
.card--info  { border-left: 3px solid var(--primary);  margin-bottom: 20px; }
.card--ok    { border-left: 3px solid var(--ok);       margin-bottom: 20px; }
.card--error { border-left: 3px solid var(--danger);   margin-bottom: 20px; }

/* Anchor styled like a primary button */
a.btn-primary {
    display: inline-flex; align-items: center;
    padding: 8px 16px; border-radius: var(--radius);
    background: var(--primary); color: #fff;
    font-size: 13px; font-weight: 600; text-decoration: none;
    border: 1px solid var(--primary); min-height: 34px;
    transition: background .1s, border-color .1s;
}
a.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; }

/* Page-level action button row */
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }

/* Empty-state hint block inside a card */
.hint-empty { text-align: center; padding: 24px 0; }
/* Centered empty state for list/thread pages */
.hint-center { text-align: center; padding: 32px 0; }
/* Bottom margin on a hint paragraph */
.hint-mb { margin-bottom: 16px; }

/* Info card content spacing */
.card-body > p { margin: 0 0 8px; }
.card-body > p:last-child { margin-bottom: 0; }

/* === MISC === */
.big-num { font-size: 22px; font-weight: 700; margin: 8px 0 16px; }
.danger { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.btn-full { width: 100%; justify-content: center; }
.mt-8  { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.mb-6  { margin-bottom: 6px; }
.page-sub { font-size: 13px; font-weight: 400; color: var(--muted); text-transform: none; letter-spacing: 0; }
.locations-stub { text-align: center; padding: 40px 24px; }
.locations-stub__icon { width: 44px; height: 44px; fill: var(--muted); margin-bottom: 12px; display: block; margin-left: auto; margin-right: auto; }

/* Page header row with action button */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 8px; margin-bottom: 4px;
}
.page-header h1 { margin: 0; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* === CHAT — conversation list === */
.conv-list { display: flex; flex-direction: column; }
.conv-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; text-decoration: none; color: var(--ink);
    border-bottom: 1px solid var(--line);
    background: var(--surface); transition: background .1s;
}
.conv-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.conv-item:last-child  { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.conv-item:only-child  { border-radius: var(--radius); }
.conv-item:hover { background: var(--bg); text-decoration: none; }
.conv-avatar {
    width: 40px; height: 40px; border-radius: 50%;
    background: #dbeafe; color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; flex-shrink: 0;
}
.conv-avatar--dm { background: #ede9fe; color: #6d28d9; }
.conv-body { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 14px; display: block; }
.conv-item--unread .conv-name { font-weight: 700; color: var(--ink); }
.conv-item--unread .conv-preview { color: var(--ink); }
.conv-unread-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--primary); flex-shrink: 0;
    margin-left: 4px;
}
.conv-preview {
    display: block; font-size: 12px; color: var(--muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    margin-top: 2px;
}
.conv-preview--empty { font-style: italic; }
.conv-sender { font-weight: 500; }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0; }
.conv-time { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* === CHAT — thread header === */
.chat-thread-header {
    display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.chat-back-link {
    font-size: 20px; line-height: 1; color: var(--ink);
    text-decoration: none; padding: 4px 6px 4px 0;
    flex-shrink: 0; opacity: .5;
}
.chat-back-link:hover { text-decoration: none; opacity: 1; }
.chat-thread-title { margin: 0; flex: 1; font-size: 16px; }
.chat-group-link { font-size: 12px; flex-shrink: 0; }

/* === CHAT — thread layout === */
.chat-thread {
    display: flex; flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - 80px);
    min-height: 320px;
}
@media (min-width: 768px) {
    .chat-thread {
        height: calc(100dvh - 100px);
        min-height: 400px;
    }
}

/* === CHAT — messages area === */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 12px 10px; display: flex; flex-direction: column; gap: 4px;
}

/* === CHAT — bubbles === */
.bubble-row {
    display: flex; max-width: 100%;
}
.bubble-row--me   { justify-content: flex-end; }
.bubble-row--them { justify-content: flex-start; }

.bubble {
    max-width: 72%; padding: 8px 12px;
    border-radius: 12px; font-size: 13px; line-height: 1.45;
    position: relative;
}
.bubble--me {
    background: var(--primary); color: #fff;
    border-bottom-right-radius: 4px;
}
.bubble--them {
    background: var(--surface); color: var(--ink);
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.bubble__sender {
    display: block; font-size: 11px; font-weight: 700;
    color: var(--primary); margin-bottom: 3px;
}
.bubble--me .bubble__sender { color: rgba(255,255,255,.7); }
.bubble__body { margin: 0; word-break: break-word; white-space: pre-wrap; }
.bubble--me .bubble__body { color: #fff; }
.bubble__time {
    display: block; font-size: 10px; text-align: right;
    margin-top: 4px; opacity: .65;
}
.bubble__photo-link { display: block; margin: 4px 0; }
.bubble__photo {
    max-width: 200px; max-height: 200px;
    border-radius: 6px; display: block; object-fit: cover;
}

/* === CHAT — pinned banner === */
.pinned-banner {
    display: flex; align-items: center; gap: 10px;
    background: #eff6ff; border-bottom: 1px solid #bfdbfe;
    padding: 8px 14px; font-size: 13px;
}
.pinned-banner__icon { font-size: 14px; flex-shrink: 0; }
.pinned-banner__body { flex: 1; min-width: 0; cursor: pointer; }
.pinned-banner__label {
    display: block; font-weight: 600; font-size: 10px;
    color: var(--primary); text-transform: uppercase; letter-spacing: .5px;
    margin-bottom: 1px;
}
.pinned-banner__sender { color: var(--primary); font-weight: 500; margin-right: 4px; }
.pinned-banner__text {
    color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: block; max-width: 100%;
}
.pinned-banner__unpin { flex-shrink: 0; }
.pinned-banner__unpin-btn {
    background: none; border: none; cursor: pointer; font-size: 14px;
    color: var(--muted); padding: 4px 6px; border-radius: 4px; min-height: 0;
}
.pinned-banner__unpin-btn:hover { background: rgba(0,0,0,.06); color: var(--ink); }

/* Bubble pinned state */
.bubble--pinned { border-left: 2px solid var(--primary) !important; }

/* Pin button inside bubble footer */
.bubble__footer {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 8px; margin-top: 2px;
}
.bubble__pin-form { display: inline; }
.bubble__pin-btn {
    background: none; border: none; cursor: pointer; min-height: 0;
    font-size: 12px; padding: 0 2px; opacity: .35;
    transition: opacity .15s;
}
.bubble__pin-btn:hover { opacity: 1; }
.bubble__pinned-tag { font-size: 10px; color: var(--primary); font-weight: 500; }

/* === CHAT — input bar === */
.chat-input-bar {
    display: flex; align-items: flex-end; gap: 8px;
    padding: 8px 10px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.chat-input {
    flex: 1; resize: none; border: 1px solid var(--line);
    border-radius: 20px; padding: 9px 14px;
    font: inherit; font-size: 14px; line-height: 1.4;
    min-height: 38px; max-height: 120px;
    background: var(--bg);
    display: block; width: auto;
}
.chat-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(0,102,204,.12); }
.chat-send-btn {
    width: 38px; height: 38px; border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; min-height: 0; background: var(--primary);
    border-color: var(--primary);
}
.chat-send-btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.chat-send-btn svg { width: 18px; height: 18px; fill: #fff; }

/* Attach button */
.chat-attach-btn {
    width: 38px; height: 38px; border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; min-height: 0;
    background: transparent; border: none; cursor: pointer;
    color: var(--muted); transition: color .15s;
}
.chat-attach-btn:hover { color: var(--primary); }
.chat-attach-btn svg {
    width: 20px; height: 20px; fill: none;
    stroke: currentColor; stroke-width: 2;
    stroke-linecap: round; stroke-linejoin: round;
}

/* Hidden native file input */
.chat-file-input { display: none; }

/* Photo preview strip shown above the input row */
.chat-input-bar { flex-wrap: wrap; }
.chat-photo-preview {
    width: 100%; order: -1;
    display: flex; align-items: flex-start; gap: 8px;
    padding: 6px 4px 2px;
}
.chat-photo-preview img {
    max-height: 80px; max-width: 120px;
    border-radius: 6px; object-fit: cover;
    border: 1px solid var(--line);
}
.chat-photo-remove {
    background: var(--danger); color: #fff;
    border: none; border-radius: 50%;
    width: 22px; height: 22px; font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0; padding: 0;
    margin-top: 2px;
}

/* === LOCATIONS PAGE === */
.loc-grid { display: grid; gap: 14px; }
@media (min-width: 640px) { .loc-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .loc-grid { grid-template-columns: repeat(3, 1fr); } }
.loc-card { padding: 16px 18px; }
.loc-card__header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.loc-card__header strong { font-size: 14px; }
.loc-badge { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 20px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.loc-badge--live { background: #dcfce7; color: #15803d; }
.loc-badge--none { background: var(--bg); color: var(--muted); }
.loc-meta { display: grid; gap: 8px; margin: 0 0 12px; }
.loc-meta div { display: flex; flex-direction: column; gap: 2px; }
.loc-meta dt { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.loc-meta dd { margin: 0; font-size: 12px; font-variant-numeric: tabular-nums; }
.loc-actions { margin-bottom: 12px; }
.btn-maps { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); font-size: 12px; font-weight: 500; text-decoration: none; transition: background .1s, border-color .1s; min-height: 30px; background: var(--surface); }
.btn-maps:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); text-decoration: none; }
.loc-history { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 10px; }
.loc-history > summary { font-size: 12px; color: var(--muted); cursor: pointer; padding: 4px 0; list-style: none; }
.loc-history > summary::marker, .loc-history > summary::-webkit-details-marker { display: none; }
.loc-history > summary:hover { color: var(--ink); }
.loc-pings { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.loc-pings li { display: flex; align-items: baseline; gap: 8px; font-size: 11px; }
.loc-pings time { font-weight: 600; color: var(--ink); min-width: 36px; }
.loc-pings a { color: var(--primary); text-decoration: none; font-variant-numeric: tabular-nums; }
.loc-pings a:hover { text-decoration: underline; }

/* === Reaction chips === */
.bubble__reactions {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin-top: 6px; padding-top: 4px;
    border-top: 1px solid rgba(0,0,0,.06);
}
.reaction-chip {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 7px; border-radius: 20px;
    border: 1px solid rgba(0,0,0,.12);
    background: rgba(255,255,255,.7);
    font-size: 12px; line-height: 1.5; white-space: nowrap;
}
.reaction-chip--me {
    border-color: var(--primary); background: #dbeafe;
    color: var(--primary); font-weight: 600;
}

/* === @mention highlight === */
.mention { color: var(--primary); font-weight: 600; font-style: normal; }

/* === Script output box (backup_status) === */
.output-box {
    background: #18181b; color: #d4d4d4;
    padding: 16px 20px; border-radius: var(--radius);
    overflow-x: auto; overflow-y: auto;
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12px; line-height: 1.55;
    margin: 0 0 20px; max-height: 480px;
}

/* === Restore modal (backups) === */
.modal-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.5); z-index: 1000;
    align-items: center; justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal-box {
    background: var(--surface); border-radius: 10px;
    padding: 28px 28px 24px; max-width: 480px; width: 90%;
    box-shadow: 0 8px 40px rgba(0,0,0,.2);
    border: 1px solid var(--line);
}
.modal-box h2 { margin-top: 0; font-size: 16px; color: var(--danger); text-transform: none; letter-spacing: 0; }
.modal-box p { font-size: 13px; margin: 8px 0; }
.modal-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
