@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500&family=Space+Grotesk:wght@400;500;600&display=swap');

:root {
    --bg: #f6f3ea;
    --bg-alt: #eaf1ff;
    --panel: rgba(255, 255, 255, 0.88);
    --ink: #1f2933;
    --muted: #5f6b78;
    --accent: #155eef;
    --accent-strong: #0b4ab8;
    --warm: #f97316;
    --border: rgba(15, 23, 42, 0.10);
    --shadow: 0 18px 45px rgba(15, 23, 42, 0.10);
    --radius: 18px;
    --font-sans: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font-sans);
    color: var(--ink);
    background: radial-gradient(circle at top left, #fff8ef 0%, #f6f3ea 45%, #eaf1ff 100%);
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 12% 18%, rgba(21, 94, 239, 0.12), transparent 45%),
        radial-gradient(circle at 85% 12%, rgba(249, 115, 22, 0.12), transparent 40%),
        linear-gradient(135deg, rgba(21, 94, 239, 0.08), rgba(249, 115, 22, 0.06));
    z-index: -1;
}

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: clamp(16px, 4vw, 40px);
}

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 18px 28px;
    margin-bottom: 26px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.brand-badge {
    padding: 10px 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: 0.08em;
    box-shadow: 0 12px 25px rgba(21, 94, 239, 0.28);
}

.brand-text h1 {
    margin: 0;
    font-size: clamp(24px, 3.4vw, 36px);
    letter-spacing: -0.01em;
}

.subtitle {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.sub-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-strong);
    text-decoration: none;
}

.sub-link::after {
    content: '→';
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.sub-link:hover {
    text-decoration: underline;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.btn {
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.9);
    color: var(--ink);
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
}

.btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    box-shadow: none;
}

.btn.compact {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn.primary {
    border: none;
    background: linear-gradient(135deg, var(--warm), #ea580c);
    color: #fff;
}

.btn.ghost {
    background: transparent;
}

.layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    grid-template-areas:
        "compose messages"
        "contacts messages";
    gap: 24px;
    align-items: start;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.compose-panel {
    grid-area: compose;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.contacts-panel {
    grid-area: contacts;
    padding: 12px;
}

.mobile-account-panel {
    display: none;
}

.messages-panel {
    grid-area: messages;
}

.contacts-header {
    align-items: center;
    margin-bottom: 0;
}

.contacts-toggle {
    min-width: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 4px;
    border: 0;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.contacts-toggle:disabled {
    cursor: default;
}

.contacts-toggle-icon {
    display: inline-block;
    font-size: 1rem;
    transition: transform 0.15s ease;
}

.contacts-toggle[aria-expanded="true"] .contacts-toggle-icon {
    transform: rotate(180deg);
}

.contact-list {
    display: grid;
    gap: 10px;
    max-height: min(42vh, 430px);
    overflow-y: auto;
    padding-right: 4px;
    margin-top: 10px;
}

.contact-list[hidden] {
    display: none;
}

.contact-card {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.72);
    overflow: hidden;
}

.contact-select {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    padding: 10px 12px;
    color: var(--ink);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.contact-main {
    display: flex;
    align-items: center;
}

.contact-main .contact-select {
    flex: 1;
}

.contact-edit {
    margin-right: 8px;
    padding: 6px 8px;
    border: 0;
    color: var(--accent-strong);
    background: transparent;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.contact-select span:last-child {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.contact-select strong,
.contact-select small {
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-select small {
    color: var(--muted);
}

.contact-color {
    width: 14px;
    height: 14px;
    flex: 0 0 14px;
    border-radius: 50%;
    background: var(--contact-color, #64748b);
    border: 1px solid rgba(15, 23, 42, 0.18);
}

.profile-avatar {
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 5px;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: transparent;
}

.profile-avatar[hidden] {
    display: none;
}

.contact-preference-form {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: end;
    gap: 8px;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
}

.contact-preference-form[hidden] {
    display: none;
}

.contact-preference-form label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 0.78rem;
}

.contact-note-field {
    min-width: 0;
}

.contact-preference-form input[type="color"] {
    width: 48px;
    height: 32px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.contact-preference-form textarea,
.bulk-form textarea {
    width: 100%;
    resize: vertical;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 9px 10px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

.contact-preference-form textarea {
    min-height: 36px;
    height: 36px;
    resize: none;
}

.contact-form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 36px;
}

.contact-save-status {
    color: var(--muted);
    font-size: 0.78rem;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(21, 94, 239, 0.12);
    color: var(--accent-strong);
    font-size: 0.9rem;
}

.user-profile-strip {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.user-profile-strip .user-chip {
    flex: 1 1 130px;
}

.compose label {
    display: block;
    margin-top: 10px;
    font-weight: 500;
}

.compose input[type="text"],
.compose input[type="file"],
.compose textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 1rem;
    font-family: var(--font-sans);
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.compose input[type="text"]:focus-visible,
.compose input[type="file"]:focus-visible,
.compose textarea:focus-visible {
    outline: none;
    border-color: rgba(21, 94, 239, 0.6);
    box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.15);
}

.compose textarea {
    min-height: 140px;
    resize: vertical;
}

.field-hint {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.field-hint.error {
    color: #b93815;
}

.form-actions {
    margin-top: 12px;
    display: flex;
    justify-content: flex-end;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.panel-meta {
    color: var(--muted);
    font-size: 0.85rem;
}

.panel-meta-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.live-pill {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(21, 94, 239, 0.12);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.auth-layout {
    grid-template-columns: minmax(0, 1fr);
}

.auth-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-forms {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.auth-form h2 {
    margin: 0 0 4px;
    font-size: 1.05rem;
}

.auth-form label {
    font-weight: 500;
}

.auth-form input[type="text"],
.auth-form input[type="password"],
.auth-form input[type="number"] {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 1rem;
    font-family: var(--font-sans);
    background: #fff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-form input[type="text"]:focus-visible,
.auth-form input[type="password"]:focus-visible,
.auth-form input[type="number"]:focus-visible {
    outline: none;
    border-color: rgba(21, 94, 239, 0.6);
    box-shadow: 0 0 0 3px rgba(21, 94, 239, 0.15);
}

.cf-turnstile {
    min-height: 65px;
}

.auth-honeypot {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.auth-actions {
    display: flex;
    gap: 10px;
}

.notice {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.notice.hidden {
    display: none;
}

.notice.success {
    color: #0b4ab8;
    background: rgba(21, 94, 239, 0.12);
    border-color: rgba(21, 94, 239, 0.2);
}

.notice.error {
    color: #b93815;
    background: rgba(249, 115, 22, 0.12);
    border-color: rgba(249, 115, 22, 0.2);
}

.blog-content {
    font-size: 1rem;
    line-height: 1.65;
    color: var(--ink);
}

.blog-content p {
    margin: 0 0 16px;
}

.blog-content p:last-child {
    margin-bottom: 0;
}

.blog-content hr {
    border: none;
    height: 1px;
    background: linear-gradient(90deg, rgba(21, 94, 239, 0.2), rgba(15, 23, 42, 0.08));
    margin: 18px 0 22px;
}

.blog-section-title {
    margin: 28px 0 12px;
    font-size: 1.1rem;
}

.post-card {
    padding: 14px;
    border-radius: 14px;
    border: 1px dashed var(--border);
    background: rgba(255, 255, 255, 0.65);
    color: var(--muted);
}

.admin-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 20px;
}

.admin-page {
    max-width: 1600px;
}

.admin-grid > .panel {
    min-width: 0;
}

.admin-fold > summary {
    cursor: pointer;
    font-size: 1.18rem;
    font-weight: 700;
    line-height: 1.5;
}

.admin-fold > summary:focus-visible {
    outline: 3px solid rgba(21, 94, 239, 0.35);
    outline-offset: 4px;
}

.admin-fold > summary .tag {
    float: right;
    margin-left: 10px;
}

.admin-fold[open] > summary {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.admin-grid > .panel > .blog-section-title:first-child {
    margin-top: 0;
}

.admin-jump-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.admin-jump-links a {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--accent-strong);
    background: rgba(255, 255, 255, 0.72);
    font-size: 0.84rem;
    font-weight: 600;
    text-decoration: none;
}

.admin-jump-links a:hover {
    text-decoration: underline;
}

.admin-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.tag-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.tag {
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(21, 94, 239, 0.12);
    color: var(--accent-strong);
    font-size: 0.8rem;
    font-weight: 600;
}

.admin-form {
    margin-bottom: 14px;
}

.admin-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    align-items: center;
}

.admin-form input[type="text"],
.admin-form input[type="search"],
.admin-form input[type="password"],
.admin-form input[type="date"],
.admin-form input[type="datetime-local"],
.admin-form select,
.admin-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    background: #fff;
}

.message-filter-row {
    grid-template-columns: minmax(180px, 1.4fr) minmax(120px, 0.8fr) repeat(3, minmax(150px, 1fr)) auto auto;
}

.admin-export-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
}

.admin-export-users {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 6px;
    max-height: 280px;
    padding: 10px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.74);
}

.admin-export-user {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.admin-export-user:hover {
    background: rgba(21, 94, 239, 0.08);
}

.admin-export-user[hidden] {
    display: none;
}

.admin-export-dates {
    margin-top: 14px;
    max-width: 520px;
}

.table-wrap {
    overflow-x: auto;
}

.admin-scroll-table {
    max-height: min(58vh, 620px);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.74);
    scrollbar-gutter: stable;
}

.message-scroll-table {
    max-height: min(68vh, 760px);
}

.admin-scroll-table:focus-visible {
    outline: 3px solid rgba(21, 94, 239, 0.25);
    outline-offset: 2px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-observability-table {
    min-width: 1080px;
}

.admin-table th,
.admin-table td {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    text-align: left;
}

.admin-scroll-table .admin-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f7f9fc;
    box-shadow: 0 1px 0 var(--border);
}

.admin-table tbody tr:nth-child(even) {
    background: rgba(240, 244, 250, 0.45);
}

.admin-table tbody tr:hover {
    background: rgba(21, 94, 239, 0.055);
}

.admin-table input[type="text"],
.admin-table input[type="password"],
.admin-table textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 8px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

.admin-table textarea {
    min-width: 220px;
    resize: vertical;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.admin-section-header {
    align-items: flex-start;
}

.admin-section-header h2 {
    margin-bottom: 4px;
}

.panel-result-count {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 0.82rem;
}

.observability-filter-row {
    grid-template-columns: minmax(260px, 1fr) minmax(150px, auto) auto auto;
}

.audit-filter-row {
    grid-template-columns: minmax(260px, 1fr) repeat(2, minmax(145px, auto)) auto auto;
}

.admin-time-stack,
.trace-cell {
    display: grid;
    gap: 4px;
}

.admin-time-stack small,
.trace-cell small {
    color: var(--muted);
    font-size: 0.72rem;
}

.admin-agent,
.log-message,
.trace-cell code,
.admin-table code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.admin-agent {
    max-width: 280px;
    color: var(--muted);
    font-size: 0.8rem;
}

.admin-nowrap {
    white-space: nowrap;
}

.status-tag {
    white-space: nowrap;
}

.status-success,
.status-http-2 {
    color: #08663f;
    background: rgba(16, 185, 129, 0.13);
}

.status-failure,
.status-http-4,
.status-http-5 {
    color: #a12d18;
    background: rgba(239, 68, 68, 0.12);
}

.status-blocked,
.status-http-3 {
    color: #95500a;
    background: rgba(245, 158, 11, 0.15);
}

.status-info,
.status-muted,
.status-http-0,
.status-http-1 {
    color: var(--muted);
    background: rgba(100, 116, 139, 0.13);
}

.admin-thumb-link {
    display: inline-flex;
    border-radius: 10px;
    border: 1px solid var(--border);
    overflow: hidden;
    background: #fff;
}

.admin-thumb {
    width: 96px;
    height: 72px;
    display: block;
    object-fit: cover;
}

.chatbox {
    height: clamp(320px, 55vh, 560px);
    overflow-y: auto;
    padding-right: 6px;
    scroll-behavior: smooth;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.msg {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: min(78%, 520px);
}

.msg.incoming {
    align-self: flex-start;
}

.msg.outgoing {
    align-self: flex-end;
    text-align: right;
}

.meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--muted);
}

.msg.outgoing .meta {
    justify-content: flex-end;
}

.direction {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(21, 94, 239, 0.12);
    color: var(--accent-strong);
    font-size: 0.75rem;
    font-family: var(--font-mono);
}

.route {
    font-weight: 500;
}

.bubble {
    padding: 8px 14px 10px;
    border-radius: 16px;
    background: #fff;
    border: 1px solid var(--border);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.08);
    line-height: 1.4;
}

.message-text,
.image-caption {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: normal;
}

.chat-image {
    display: block;
    max-width: 100%;
    max-height: 360px;
    border-radius: 12px;
    object-fit: contain;
}

.image-caption {
    margin-top: 8px;
}

.msg.outgoing .bubble {
    border: none;
    color: #fff;
    background: linear-gradient(135deg, var(--accent), #3478f6);
}

.msg.has-contact-color .bubble {
    border-inline-start: 4px solid var(--contact-color);
}

.msg.has-contact-color .route::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-inline-end: 5px;
    border-radius: 50%;
    background: var(--contact-color);
}

.bulk-dialog {
    width: min(560px, calc(100vw - 32px));
    max-height: min(720px, calc(100vh - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--ink);
    background: #fff;
}

.bulk-dialog::backdrop {
    background: rgba(15, 23, 42, 0.52);
}

.bulk-form {
    padding: 18px;
}

.bulk-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.bulk-dialog-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.dialog-close {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    color: var(--ink);
    background: transparent;
    font-size: 1.4rem;
    cursor: pointer;
}

.bulk-contact-list {
    display: grid;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
}

.bulk-contact-option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.bulk-contact-option input {
    accent-color: var(--accent);
}

.bulk-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
}

.split-actions {
    justify-content: space-between;
}

#bulkRecipientsSummary {
    color: var(--muted);
    overflow-wrap: anywhere;
}

.bulk-form textarea,
.bulk-form input[type="file"] {
    width: 100%;
    margin-top: 6px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    color: var(--ink);
    background: #fff;
    font: inherit;
}

.profile-editor-dialog {
    width: min(680px, calc(100vw - 24px));
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 16px;
    color: var(--ink);
    background: #fff;
}

.profile-editor-dialog::backdrop {
    background: rgba(15, 23, 42, 0.55);
}

.profile-editor-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.profile-editor-canvas {
    display: block;
    width: min(100%, 560px);
    height: auto;
    margin: 14px auto;
    border: 1px solid var(--border);
    background-color: #eef1f5;
    background-image:
        linear-gradient(45deg, #d8dde5 25%, transparent 25%),
        linear-gradient(-45deg, #d8dde5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #d8dde5 75%),
        linear-gradient(-45deg, transparent 75%, #d8dde5 75%);
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-size: 16px 16px;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    touch-action: none;
    cursor: crosshair;
}

.profile-tool-row,
.profile-editor-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-tool-row .active {
    border-color: var(--accent);
    background: rgba(21, 94, 239, 0.12);
}

.profile-control-row {
    display: grid;
    grid-template-columns: minmax(130px, auto) minmax(180px, 1fr);
    align-items: center;
    gap: 12px;
    margin-top: 12px;
}

.profile-color-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(44px, 1fr));
    gap: 6px;
    margin-top: 6px;
}

.profile-color-grid button {
    min-height: 44px;
    border: 1px solid rgba(15, 23, 42, 0.24);
    border-radius: 7px;
    background: var(--profile-color);
    cursor: pointer;
}

.profile-color-grid button.active {
    outline: 3px solid var(--accent);
    outline-offset: 1px;
}

.profile-custom-color,
.profile-fill-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    margin-top: 10px;
}

.profile-custom-color input {
    width: 88px;
    height: 44px;
}

.profile-editor-actions {
    justify-content: flex-end;
    margin-top: 14px;
}

.feature-list {
    display: grid;
    gap: 10px;
    margin: 12px 0 20px;
    padding-left: 22px;
}

.feature-list li::marker {
    color: var(--warm);
}

.device-list,
.official-account-list {
    display: grid;
    gap: 14px;
}

.device-card,
.official-account-card {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.74);
}

.device-card h3,
.official-account-card h2 {
    margin: 0 0 10px;
    font-size: 1.05rem;
}

.official-account-card {
    display: block;
}

.official-account-card p {
    margin: 0 0 12px;
    color: var(--muted);
}

.device-card-main {
    min-width: 0;
}

.device-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(125px, 1fr));
    gap: 12px;
    margin: 0;
}

.device-meta div {
    min-width: 0;
}

.device-meta dt {
    color: var(--muted);
    font-size: 0.76rem;
}

.device-meta dd {
    margin: 3px 0 0;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    overflow-wrap: anywhere;
}

.device-revoke-form {
    flex: 0 0 auto;
}

.check-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 0.88rem;
}

.check-label input {
    accent-color: var(--accent);
}

.broadcast-row {
    grid-template-columns: minmax(180px, 0.65fr) minmax(260px, 1.8fr) auto;
}

.reservation-row {
    grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1.3fr) auto auto;
}

.empty-state {
    color: var(--muted);
    font-size: 0.95rem;
    margin: 0;
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
        grid-template-areas:
            "compose"
            "contacts"
            "messages";
    }

    .messages-panel {
        order: 3;
    }

    .compose-panel {
        order: 1;
    }

    .contacts-panel {
        order: 2;
    }

    .chatbox {
        height: clamp(260px, 45vh, 480px);
    }
}

@media (max-width: 640px) {
    .profile-control-row {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .profile-color-grid {
        grid-template-columns: repeat(4, minmax(44px, 1fr));
    }

    .panel {
        padding: 14px;
    }

    .controls {
        width: 100%;
        justify-content: flex-start;
    }

    .contact-preference-form {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .contact-form-actions {
        grid-column: 1 / -1;
        justify-content: flex-end;
    }

    .msg {
        max-width: 100%;
    }

    .chatbox {
        height: 50vh;
    }

    .message-filter-row {
        grid-template-columns: 1fr;
    }

    .observability-filter-row,
    .audit-filter-row {
        grid-template-columns: 1fr;
    }

    .admin-section-header {
        align-items: stretch;
        flex-direction: column;
    }

    .admin-scroll-table,
    .message-scroll-table {
        max-height: 62vh;
    }

    .device-card {
        flex-direction: column;
    }

    .device-meta {
        grid-template-columns: 1fr;
    }

    .device-revoke-form,
    .device-revoke-form .btn {
        width: 100%;
    }

    .broadcast-row,
    .reservation-row {
        grid-template-columns: 1fr;
    }

    body.chat-authenticated {
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    .chat-authenticated .page {
        width: 100%;
        height: 100dvh;
        max-width: none;
        padding: 8px max(8px, env(safe-area-inset-right)) max(2px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
        display: flex;
        flex-direction: column;
    }

    .chat-authenticated .topbar {
        flex: 0 0 auto;
        gap: 7px;
        margin-bottom: 8px;
    }

    .chat-authenticated .brand {
        width: 100%;
        gap: 9px;
    }

    .chat-authenticated .brand-badge {
        padding: 7px 9px;
        border-radius: 10px;
        box-shadow: none;
        font-size: 0.78rem;
    }

    .chat-authenticated .brand-text {
        min-width: 0;
        flex: 1;
        line-height: 1.1;
    }

    .chat-authenticated .brand-text h1 {
        font-size: 1.05rem;
    }

    .chat-authenticated .subtitle {
        display: none;
    }

    .chat-authenticated .sub-link {
        margin: 3px 8px 0 0;
        font-size: 0.68rem;
    }

    .chat-authenticated .controls {
        width: 100%;
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 6px;
        padding: 1px 0 3px;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: none;
    }

    .chat-authenticated .controls::-webkit-scrollbar {
        display: none;
    }

    .chat-authenticated .controls .btn {
        flex: 0 0 auto;
        padding: 6px 10px;
        box-shadow: none;
        white-space: nowrap;
        font-size: 0.76rem;
    }

    .chat-authenticated .layout {
        flex: 1 1 auto;
        min-height: 0;
        display: grid;
        grid-template-columns: minmax(0, 1.45fr) minmax(112px, 0.75fr);
        grid-template-rows: auto minmax(180px, 1fr) auto;
        grid-template-areas:
            "contacts account"
            "messages messages"
            "compose compose";
        gap: 0 6px;
        align-items: stretch;
        overflow: hidden;
    }

    .chat-authenticated .panel {
        border-radius: 14px;
        box-shadow: 0 8px 22px rgba(15, 23, 42, 0.09);
    }

    .chat-authenticated .contacts-panel {
        order: 1;
        min-width: 0;
        padding: 2px 6px;
    }

    .chat-authenticated .contacts-header {
        gap: 4px;
    }

    .chat-authenticated .contacts-toggle {
        min-width: 0;
        min-height: 28px;
        padding: 2px 1px;
        font-size: 0.69rem;
    }

    .chat-authenticated #contactsTitle {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-authenticated #bulkOpen {
        min-height: 28px;
        padding: 3px 5px;
        white-space: nowrap;
        font-size: 0.62rem;
    }

    .chat-authenticated .mobile-account-panel {
        grid-area: account;
        order: 1;
        min-width: 0;
        display: flex;
        align-items: stretch;
        padding: 2px 5px;
    }

    .chat-authenticated .mobile-account-open {
        width: 100%;
        min-width: 0;
        padding: 0;
        border: 0;
        display: grid;
        grid-template-columns: 24px minmax(0, 1fr);
        gap: 5px;
        align-items: center;
        color: inherit;
        background: transparent;
        font: inherit;
        text-align: left;
        cursor: pointer;
    }

    .chat-authenticated .mobile-account-open .profile-avatar {
        width: 24px;
        height: 24px;
    }

    .chat-authenticated .mobile-account-copy {
        min-width: 0;
        display: flex;
        flex-direction: column;
        line-height: 1.1;
    }

    .chat-authenticated .mobile-account-copy span,
    .chat-authenticated .mobile-account-copy strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-authenticated .mobile-account-copy span {
        color: var(--muted);
        font-size: 0.57rem;
    }

    .chat-authenticated .mobile-account-copy strong {
        margin-top: 1px;
        font-size: 0.68rem;
    }

    .chat-authenticated .layout.contacts-open {
        grid-template-areas:
            "contacts contacts"
            "messages messages"
            "compose compose";
    }

    .chat-authenticated .layout.contacts-open .mobile-account-panel {
        display: none;
    }

    .chat-authenticated .contact-list {
        max-height: min(28dvh, 220px);
        margin-top: 4px;
    }

    .chat-authenticated .messages-panel {
        order: 2;
        min-height: 0;
        display: flex;
        flex-direction: column;
        padding: 8px 10px 3px;
    }

    .chat-authenticated .messages-panel .panel-header {
        flex: 0 0 auto;
        margin-bottom: 7px;
    }

    .chat-authenticated .chatbox {
        flex: 1 1 auto;
        height: auto;
        min-height: 0;
        padding-right: 2px;
        overscroll-behavior: contain;
    }

    .chat-authenticated .messages {
        gap: 10px;
    }

    .chat-authenticated .msg {
        max-width: 88%;
        gap: 4px;
    }

    .chat-authenticated .messages .profile-avatar {
        width: 32px;
        height: 32px;
        flex-basis: 32px;
    }

    .chat-authenticated .meta {
        gap: 5px;
        font-size: 0.68rem;
    }

    .chat-authenticated .bubble {
        padding: 8px 11px;
        border-radius: 14px;
        box-shadow: 0 5px 12px rgba(15, 23, 42, 0.07);
    }

    .chat-authenticated .compose-panel {
        order: 3;
        max-height: 42dvh;
        gap: 0;
        padding: 5px 8px 2px;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .chat-authenticated .compose-panel > .user-profile-strip {
        display: none;
    }

    .chat-authenticated .compose {
        position: relative;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "recipient-label recipient-label"
            "recipient recipient"
            "message send"
            "file file";
        gap: 4px 7px;
    }

    .chat-authenticated .compose.has-image-hint {
        grid-template-areas:
            "recipient-label recipient-label"
            "recipient recipient"
            "message send"
            "file file"
            "hint hint";
    }

    .chat-authenticated .compose label {
        margin: 0;
    }

    .chat-authenticated .compose label[for="recipient"] {
        grid-area: recipient-label;
        color: var(--muted);
        font-size: 0.7rem;
    }

    .chat-authenticated .compose label[for="message"],
    .chat-authenticated .compose label[for="image"] {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    .chat-authenticated #recipient {
        grid-area: recipient;
        min-height: 36px;
        padding: 7px 10px;
        font-size: 0.9rem;
    }

    .chat-authenticated #message {
        grid-area: message;
        min-height: 50px;
        max-height: 88px;
        padding: 8px 10px;
        resize: none;
        font-size: 0.95rem;
    }

    .chat-authenticated #image {
        grid-area: file;
        min-height: 34px;
        padding: 4px 6px;
        font-size: 0.72rem;
    }

    .chat-authenticated #image::file-selector-button {
        margin-right: 7px;
        padding: 5px 8px;
        border: 1px solid var(--border);
        border-radius: 999px;
        color: var(--ink);
        background: rgba(255, 255, 255, 0.9);
        font: inherit;
    }

    .chat-authenticated #imageHint {
        grid-area: hint;
        margin: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 0.68rem;
    }

    .chat-authenticated #imageHint:empty {
        display: none;
    }

    .chat-authenticated .form-actions {
        grid-area: send;
        align-self: stretch;
        margin: 0;
    }

    .chat-authenticated .form-actions .btn {
        height: 100%;
        min-width: 68px;
        padding: 8px 12px;
        box-shadow: none;
    }
}
