/* Realty Connect - shared styles */
:root {
    --primary: #0e7a6d;
    --primary-dark: #0a5f55;
    --green: #128C7E;
    --accent: #25D366;
    --bg: #f0f2f5;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --text: #1f2933;
    --muted: #5f6b76;
    --border: #e1e5ea;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --warn: #b45309;
    --warn-bg: #fff4e0;
    --info: #0b5ea8;
    --info-bg: #e7f1fb;
    --success-bg: #e3f6ea;
    --out-bubble: #d9fdd3;
    --in-bubble: #ffffff;
    --chat-bg: #efeae2;
    --tick-read: #34b7f1;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --sidebar-w: 240px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75em; }
a { color: var(--primary); }
img { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(18, 140, 126, .55); outline-offset: 2px; }
.skip-link {
    position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff;
    padding: 8px 12px; z-index: 1000; border-radius: 0 0 6px 0;
}
.skip-link:focus { left: 0; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
    background: #0b2e2a; color: #d6e6e3;
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: #07352f; font-weight: 800;
}
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; flex-direction: column; gap: 2px; padding: 6px 10px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px;
    color: #d6e6e3; text-decoration: none; font-weight: 500;
}
.nav-link:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav-link.active { background: rgba(37, 211, 102, .18); color: #fff; }
.nav-link.active .nav-icon { color: var(--accent); }
.nav-label { flex: 1; }
.nav-badge {
    min-width: 20px; padding: 0 6px; height: 20px; line-height: 20px; border-radius: 10px;
    background: var(--accent); color: #05352c; font-size: .75rem; font-weight: 700; text-align: center;
}
.nav-link:focus-visible { outline-color: #fff; }
.sidebar-foot { padding: 14px 18px; font-size: .85rem; border-top: 1px solid rgba(255, 255, 255, .1); }
.sidebar-foot .muted { color: #9bb8b3; }
.nav-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 40; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
    display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: var(--surface);
    border-bottom: 1px solid var(--border); flex: 0 0 auto; min-height: 56px;
}
.topbar-title { font-weight: 700; font-size: 1.05rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 10px; }
.topbar-name { font-weight: 500; }
.nav-toggle { display: none; }
.avatar {
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
    width: 34px; height: 34px; border-radius: 50%; background: #d3ede9; color: var(--primary-dark); font-weight: 700;
}
.content { flex: 1; min-height: 0; overflow: auto; padding: 24px; }
.content:focus { outline: none; }
.main-chat { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.main-chat > .alert { margin: 10px 16px 0; }
.main-chat > #chat-app, .main-chat > #team-app { flex: 1; min-height: 0; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
    border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.2rem;
}
.icon-btn:hover { background: rgba(0, 0, 0, .06); color: var(--text); }

/* ---------- Components ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-header h1 { margin: 0; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-title { margin: 0 0 12px; font-size: 1.05rem; font-weight: 700; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; color: var(--primary-dark); }
.stat-label { color: var(--muted); font-size: .88rem; margin-top: 4px; }

.table-wrap { overflow-x: auto; border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { background: var(--surface-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
.table tbody tr:hover { background: #fafbfc; }
.table tbody tr:last-child td { border-bottom: 0; }
.card > .table-wrap { margin: 0 -18px -18px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 16px; border: 1px solid transparent; border-radius: 8px; cursor: pointer;
    font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none;
    background: var(--surface-2); color: var(--text); border-color: var(--border);
    transition: background .15s, border-color .15s;
}
.btn:hover { background: #e9ecf0; }
.btn:disabled, .btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #a31f1f; }
.btn-success { background: #1b8a3b; color: #fff; border-color: #1b8a3b; }
.btn-success:hover { background: #146c2d; }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: rgba(14, 122, 109, .08); }
.btn-sm { padding: 5px 10px; font-size: .85rem; border-radius: 6px; }
.btn-block { width: 100%; }

.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600;
    background: #e6e9ed; color: #384250; white-space: nowrap;
}
.badge-green { background: #d8f3e1; color: #0d5d27; }
.badge-red { background: #fbdcdc; color: #8f1d1d; }
.badge-orange { background: #ffe8c7; color: #8a4b04; }
.badge-gray { background: #e6e9ed; color: #384250; }
.badge-blue { background: #d9eafb; color: #0b4a85; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; }
.form-row { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-grid .form-row { margin-bottom: 0; }
.form-row label { font-weight: 600; font-size: .9rem; }
.input {
    width: 100%; padding: 9px 12px; font: inherit; color: var(--text); background: #fff;
    border: 1px solid #c5ccd4; border-radius: 8px;
}
.input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(18, 140, 126, .2); }
textarea.input { resize: vertical; min-height: 80px; }
select.input { appearance: auto; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: #0d5d27; border-color: #b9e5c6; }
.alert-error { background: var(--danger-bg); color: #8f1d1d; border-color: #f4bcb7; }
.alert-info { background: var(--info-bg); color: #0b4a85; border-color: #b7d5f1; }
.muted { color: var(--muted); }
.text-right { text-align: right; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab {
    padding: 9px 14px; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer;
    font: inherit; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 1.05rem; margin-bottom: 4px; }
.dot-online, .dot-offline { display: inline-block; width: 9px; height: 9px; border-radius: 50%; vertical-align: middle; }
.dot-online { background: var(--accent); box-shadow: 0 0 0 2px rgba(37, 211, 102, .25); }
.dot-offline { background: #b6bec7; }
.pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; background: #101820; color: #e6edf3; padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-word; }

/* ---------- Auth ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #0b2e2a 0%, #128C7E 100%); }
.auth-box { width: 100%; max-width: 400px; background: var(--surface); border-radius: 14px; padding: 28px; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand .brand-mark { width: 48px; height: 48px; font-size: 1.4rem; border-radius: 12px; margin-bottom: 8px; }
.auth-brand h1 { margin: 0 0 2px; }
.auth-brand p { margin: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
    padding: 11px 14px; border-radius: 8px; background: #263238; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .25);
    animation: toast-in .2s ease-out; word-break: break-word;
}
.toast-error { background: #a31f1f; }
.toast-success { background: #146c2d; }
.toast-warn { background: #8a4b04; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Chat (chat.js + team.js) ---------- */
.chat-layout { display: flex; height: 100%; min-height: 0; background: var(--surface); }
.chat-list-pane { width: 340px; flex: 0 0 340px; display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.chat-list-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.chat-list-head .tabs { margin: 0; }
.chat-list-head .tab { padding: 6px 10px; font-size: .88rem; }
.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-section { padding: 10px 14px 4px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); list-style: none; }
.chat-item {
    display: flex; gap: 10px; width: 100%; padding: 11px 14px; text-align: left; border: 0; background: transparent; cursor: pointer;
    font: inherit; color: inherit; border-bottom: 1px solid #f0f2f4; align-items: flex-start;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.active { background: #e4f4f1; }
.chat-item .avatar { margin-top: 2px; position: relative; }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.chat-item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: .75rem; color: var(--muted); white-space: nowrap; }
.chat-item-bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.chat-item-preview { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-meta { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-badge {
    flex: 0 0 auto; min-width: 20px; height: 20px; line-height: 20px; padding: 0 6px; border-radius: 10px;
    background: var(--accent); color: #05352c; font-size: .75rem; font-weight: 700; text-align: center;
}
.chat-item .dot-online, .chat-item .dot-offline { position: absolute; right: -1px; bottom: -1px; border: 2px solid #fff; width: 13px; height: 13px; }
.chat-item.active .dot-online, .chat-item.active .dot-offline { border-color: #e4f4f1; }

.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); min-height: 0; }
.chat-placeholder { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
.chat-placeholder strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 4px; }
.chat-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.chat-back { display: none; }
.chat-head-text { min-width: 0; flex: 1; }
.chat-head-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head-sub { font-size: .82rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-warn { padding: 8px 14px; background: var(--warn-bg); color: #7a4306; font-size: .88rem; border-bottom: 1px solid #f3d9a8; flex: 0 0 auto; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px 6%; display: flex; flex-direction: column; gap: 4px; min-height: 0; overscroll-behavior: contain; }
.chat-older { align-self: center; margin-bottom: 8px; }
.chat-loading, .chat-nomsg { align-self: center; color: var(--muted); font-size: .9rem; padding: 12px; }

.msg { max-width: min(75%, 560px); padding: 6px 10px 4px; border-radius: 10px; box-shadow: 0 1px 1px rgba(0, 0, 0, .12); word-break: break-word; position: relative; }
.msg-in { align-self: flex-start; background: var(--in-bubble); border-top-left-radius: 2px; }
.msg-out { align-self: flex-end; background: var(--out-bubble); border-top-right-radius: 2px; }
.msg-held { background: var(--warn-bg); }
.msg-rejected, .msg-failed { background: var(--danger-bg); }
.msg-sender { font-size: .78rem; font-weight: 700; color: var(--primary-dark); margin-bottom: 1px; }
.msg-body { white-space: pre-wrap; margin: 0; }
.msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; font-size: .7rem; color: var(--muted); margin-top: 2px; }
.msg-status { font-weight: 700; letter-spacing: -1px; }
.msg-status.read { color: var(--tick-read); }
.msg-note { font-size: .8rem; margin-top: 3px; color: #7a4306; }
.msg-note.err { color: var(--danger); }
.msg-image { display: block; margin: 2px 0 4px; }
.msg-image img { display: block; max-width: 100%; max-height: 300px; border-radius: 6px; background: #ddd; }
.file-chip {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 2px 0 4px; background: rgba(0, 0, 0, .05);
    border-radius: 8px; text-decoration: none; color: inherit;
}
.file-chip:hover { background: rgba(0, 0, 0, .09); }
.file-chip-icon { font-size: 1.3rem; }
.file-chip-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.file-chip-size { font-size: .75rem; color: var(--muted); }
.file-chip-text { min-width: 0; display: flex; flex-direction: column; }

.composer { flex: 0 0 auto; background: #f0f2f5; border-top: 1px solid var(--border); padding: 8px 12px; }
.composer-file { display: flex; align-items: center; gap: 8px; padding: 6px 10px; margin-bottom: 6px; background: #fff; border: 1px solid var(--border); border-radius: 8px; font-size: .88rem; }
.composer-file span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer-row .input { border-radius: 20px; resize: none; min-height: 40px; max-height: 140px; padding: 9px 14px; overflow-y: auto; line-height: 1.4; }
.composer-row .btn { border-radius: 20px; height: 40px; }
.composer-readonly { padding: 12px; text-align: center; color: var(--muted); background: #f0f2f5; border-top: 1px solid var(--border); font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; width: 260px; }
    body.nav-open .sidebar { transform: none; box-shadow: 0 0 30px rgba(0, 0, 0, .35); }
    .nav-toggle { display: inline-flex; }
    .topbar { padding: 8px 12px; }
    .topbar-name { display: none; }
    .content { padding: 16px; }
    .chat-list-pane { width: 280px; flex-basis: 280px; }
    .chat-messages { padding: 12px 3%; }
}
@media (max-width: 760px) {
    .chat-list-pane { width: 100%; flex: 1 1 100%; border-right: 0; }
    .chat-pane { display: none; width: 100%; }
    .chat-layout.has-chat .chat-list-pane { display: none; }
    .chat-layout.has-chat .chat-pane { display: flex; }
    .chat-back { display: inline-flex; }
    .msg { max-width: 88%; }
    .page-header { margin-bottom: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
