* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    -webkit-text-size-adjust: 100%;
}

/* iOS Safari: allow body to fill visible viewport (address bar / dynamic height) */
html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #f5f5f5;
    color: #333;
    /* Use stable initial height so iOS keyboard opening doesn't expand the layout (100dvh can grow when keyboard opens) */
    height: var(--initial-viewport-height, 100vh);
    min-height: var(--initial-viewport-height, 100vh);
    min-height: -webkit-fill-available;
    overflow: hidden;
}

.app-container {
    display: flex;
    /* Match body: stable height so chat doesn't get bigger when text box is focused on iOS */
    height: var(--initial-viewport-height, 100vh);
    width: 100%;
    max-width: 100vw;
    position: relative;
    overflow: hidden;
    background: white;
    --drawer-width: min(380px, 92vw);
    transition: padding-left 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

body:has(.app-header-strip) .app-container {
    height: calc(var(--initial-viewport-height, 100vh) - 48px);
}

/* When keyboard is open (iOS/Android): pin layout to visual viewport so chat doesn't overlap header and proportions stay correct */
body.keyboard-open {
    height: var(--visual-viewport-height, 100vh) !important;
    min-height: 0 !important;
    overflow: hidden !important;
}
/* Pin app header to top of visible area (avoid overlap with browser chrome on iOS) */
body.keyboard-open .app-header-strip {
    position: fixed !important;
    top: var(--visual-viewport-offset-top, 0) !important;
    left: 0 !important;
    right: 0 !important;
    z-index: 100 !important;
}
body.keyboard-open .app-container {
    position: fixed !important;
    top: calc(var(--visual-viewport-offset-top, 0) + 48px) !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(var(--visual-viewport-height, 100vh) - 48px) !important;
    min-height: 0 !important;
}
body.keyboard-open:has(.app-header-strip) .app-container {
    position: fixed !important;
    top: calc(var(--visual-viewport-offset-top, 0) + 48px) !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(var(--visual-viewport-height, 100vh) - 48px) !important;
    min-height: 0 !important;
}

.drawer-overlay {
    position: absolute;
    inset: 0;
    background: rgba(17, 24, 39, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 20;
}

.app-container.drawer-open .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
}

.sidebar.drawer {
    width: var(--drawer-width);
    background: white;
    border-right: 1px solid #e5e5e5;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    inset: 0 auto 0 0;
    transform: translateX(calc(-1 * var(--drawer-width)));
    transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 30;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.12);
}

.app-container.drawer-open .sidebar.drawer {
    transform: translateX(0);
}

.drawer-close {
    display: none;
}

@media (min-width: 960px) {
    .drawer-overlay {
        display: none;
    }

    .app-container.drawer-open {
        padding-left: var(--drawer-width);
    }

    .sidebar.drawer {
        box-shadow: none;
    }
}

@media (max-width: 959px) {
    .drawer-close {
        display: inline-flex;
    }
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-top-controls {
    padding: 20px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.supplier-select-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    letter-spacing: 0.2px;
}

.supplier-select {
    width: 220px;
    max-width: 58vw;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 12px;
    font-family: inherit;
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.supplier-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Ensure supplier dropdown wins against any global select styling */
#supplierSelect {
    padding: 12px 14px !important;
    border: 1px solid #e2e8f0 !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    font-family: inherit !important;
    background: white !important;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#supplierSelect:focus {
    outline: none;
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1) !important;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
    color: #1a1a1a;
}

.badge {
    background: #2563eb;
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-button:hover {
    background: #f3f4f6;
}

.sort-indicator {
    padding: 12px 20px;
    font-size: 12px;
    color: #6b7280;
    border-bottom: 1px solid #e5e5e5;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    padding: 16px 20px;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    transition: background 0.2s;
    position: relative;
}

.conversation-item:hover {
    background: #f9fafb;
}

.conversation-item.active {
    background: #eff6ff;
    border-left: 3px solid #2563eb;
}

.conversation-item-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #6b7280;
    flex-shrink: 0;
}

.avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conversation-meta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.conversation-name {
    font-weight: 500;
    font-size: 14px;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-time {
    font-size: 12px;
    color: #6b7280;
    white-space: nowrap;
}

.conversation-item.has-unread .conversation-name {
    font-weight: 700;
}

.conversation-item.has-unread .conversation-preview {
    color: #1f2937;
    font-weight: 600;
}

.unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 7px;
    border-radius: 999px;
    background: #2563eb;
    border: 1px solid #2563eb;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    text-align: center;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.conversation-section-label {
    padding: 10px 20px;
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    background: #f3f4f6;
    text-align: center;
    border-top: 1px solid #f3f4f6;
    border-bottom: 1px solid #f3f4f6;
}

.conversation-section-empty {
    padding: 12px 20px;
    text-align: center;
    font-size: 12px;
    color: #9ca3af;
    border-bottom: 1px solid #f3f4f6;
}

.conversation-preview {
    font-size: 13px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
}

.conversation-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #6b7280;
    padding: 4px 8px;
    background: #f3f4f6;
    border-radius: 4px;
}

.conversation-tag-icon {
    width: 14px;
    height: 14px;
}

.main-panel {
    flex: 1;
    min-width: 0; /* Allow shrinking so content fits viewport on mobile */
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    /* Reserve space at bottom so input area is never cut off by system UI (e.g. home bar) */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.conversation-header {
    padding: 20px 24px;
    border-bottom: 1px solid #e5e5e5;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.conversation-title-with-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.drawer-toggle {
    color: #111827;
    border: 1px solid #e5e5e5;
    background: white;
}

.drawer-toggle .drawer-toggle-icon {
    transition: transform 180ms ease;
}

.app-container.drawer-open .drawer-toggle .drawer-toggle-icon {
    transform: rotate(180deg);
}

.drawer-toggle:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.conversation-title-section {
    min-width: 0;
}

.conversation-title-section h2,
.conversation-title-section p {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-title-section h2 {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 4px;
}

.conversation-load-more-wrap {
    padding: 8px 14px 16px 14px;
}

.load-more-conversations {
    width: 100%;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.load-more-conversations:hover:not(:disabled) {
    background: #e5f1ff;
    border-color: #bfdbfe;
    color: #1d4ed8;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.load-more-conversations:disabled {
    opacity: 0.6;
    cursor: default;
    box-shadow: none;
}

.conversation-title-section p {
    font-size: 13px;
    color: #6b7280;
}

.messages-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px;
    background: #efeae2;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6b7280;
    font-size: 14px;
}

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

.message-date-header {
    text-align: center;
    padding: 12px 0;
    margin: 16px 0 8px 0;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
}

.message-date-header::before,
.message-date-header::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: #e5e5e5;
}

.message-date-header::before {
    left: 0;
}

.message-date-header::after {
    right: 0;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 70%;
}

.message.inbound {
    align-self: flex-start;
}

.message.outbound {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 12px;
    color: #6b7280;
    flex-shrink: 0;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-reply-quote {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 420px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(17, 24, 39, 0.04);
    border-left: 3px solid rgba(37, 99, 235, 0.7);
    cursor: pointer;
    user-select: none;
}

.message-reply-quote:hover {
    background: rgba(17, 24, 39, 0.06);
}

.message-reply-quote-label {
    font-size: 11px;
    font-weight: 700;
    color: #2563eb;
    letter-spacing: 0.2px;
}

.message-reply-quote-body {
    font-size: 12px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.message-highlight .message-bubble {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.message-reactions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.message.outbound .message-reactions {
    justify-content: flex-end;
    align-self: flex-end;
}

.message-reaction-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 20px;
    padding: 0 8px;
    border-radius: 999px;
    background: rgba(17, 24, 39, 0.06);
    border: 1px solid rgba(17, 24, 39, 0.08);
    color: #111827;
    font-size: 14px;
    line-height: 1;
}

.message-sender {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 4px;
}

.message.outbound .message-sender {
    text-align: right;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    white-space: pre-wrap; /* preserve \n + multiple spaces exactly as sent */
    font-size: 14px;
    line-height: 1.5;
}

.message.inbound .message-bubble {
    background: white;
    border: 1px solid #e5e5e5;
    border-bottom-left-radius: 4px;
    color: #1a1a1a;
}

.message.outbound .message-bubble {
    background: #dcf8c6;
    border: 1px solid #b7e4a8;
    border-bottom-right-radius: 4px;
    color: #1a1a1a;
}

.message-bubble.template-bubble {
    padding: 0;
    overflow: hidden;
}

.template-card {
    display: flex;
    flex-direction: column;
    max-width: 520px;
}

.template-meta {
    padding: 10px 12px 6px 12px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.3px;
    color: rgba(17, 24, 39, 0.55);
    text-transform: uppercase;
}

.template-header {
    padding: 0 12px 6px 12px;
    font-size: 14px;
    font-weight: 800;
    color: #111827;
    white-space: pre-wrap;
}

.template-body {
    padding: 0 12px 10px 12px;
    font-size: 14px;
    color: #111827;
    white-space: pre-wrap;
}

.template-footer {
    padding: 0 12px 10px 12px;
    font-size: 12px;
    color: rgba(17, 24, 39, 0.6);
    white-space: pre-wrap;
}

.template-buttons {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(17, 24, 39, 0.1);
}

.template-btn {
    padding: 10px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: #2563eb;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.65);
}

.template-btn + .template-btn {
    border-top: 1px solid rgba(17, 24, 39, 0.08);
}

.template-btn:hover {
    background: rgba(255, 255, 255, 0.8);
}

.template-btn.template-btn-disabled {
    color: rgba(17, 24, 39, 0.45);
    cursor: not-allowed;
}

.message-bubble.interactive-bubble {
    padding: 0;
    overflow: hidden;
}

.message-bubble.media-bubble {
    padding: 6px 10px;
    border-radius: 18px;
    background: transparent;
    border: none;
}

.message-media-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: min(320px, 70vw);
}

.message-media-meta {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    flex-direction: column;
    gap: 2px;
}

.message-media-file-name {
    font-size: 13px;
    color: #111827;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-media-file-type {
    font-size: 11px;
    color: #6b7280;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-media-icon-btn {
    border: none;
    background: none;
    color: #2563eb;
    padding: 4px;
    border-radius: 999px;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}

.message-media-icon-btn:hover {
    background: rgba(37, 99, 235, 0.08);
}

.message-media-image,
.message-media-video {
    display: block;
    max-width: min(320px, 70vw);
    max-height: 360px;
    border-radius: 12px;
    background: #000;
    object-fit: cover;
}

.message-media-audio {
    max-width: min(320px, 70vw);
}

.message-media-file {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    font-size: 13px;
    color: #2563eb;
    text-decoration: none;
}

.message-media-file-title {
    font-size: 13px;
    font-weight: 600;
    color: #2563eb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: min(320px, 70vw);
}

.message-media-file:hover {
    text-decoration: underline;
}

.interactive-card {
    display: flex;
    flex-direction: column;
    max-width: 320px;
    min-width: 240px;
}

.interactive-header {
    padding: 12px 14px 8px 14px;
    font-size: 15px;
    font-weight: 700;
    color: #111827;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-body {
    padding: 10px 14px 12px 14px;
    font-size: 14px;
    color: #374151;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.interactive-body br {
    display: block;
    content: "";
    margin-top: 4px;
}

.interactive-buttons {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-btn-row {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-btn-row:first-of-type {
    border-top-width: 1px;
}

.interactive-btn {
    display: block;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
    color: #2563eb;
    text-align: center;
}

.interactive-footer {
    padding: 8px 14px 12px 14px;
    font-size: 12px;
    color: rgba(55, 65, 81, 0.85);
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-list-btn {
    padding: 10px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-list-btn-inner {
    display: inline-block;
    font-size: 14px;
    font-weight: 600;
    color: #2563eb;
}

.interactive-list-section-title {
    padding: 8px 14px 4px 14px;
    font-size: 13px;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.interactive-list-row {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.interactive-list-row-title {
    font-size: 14px;
    font-weight: 500;
    color: #111827;
}

.interactive-list-row-desc {
    font-size: 12px;
    color: #6b7280;
}

.interactive-cta {
    padding: 10px 14px 12px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.interactive-cta-link {
    display: inline-block;
    font-size: 14px;
    font-weight: 600;
    color: #2563eb;
    text-decoration: none;
}

.interactive-cta-link:hover {
    text-decoration: underline;
}

.message-time {
    font-size: 11px;
    color: #9ca3af;
    padding: 0 4px;
    margin-top: 2px;
}

.message.outbound .message-time {
    text-align: right;
}

.message-status {
    display: inline-flex;
    margin-left: 4px;
}

.input-area {
    border-top: 1px solid #e5e5e5;
    background: white;
    flex-shrink: 0;
    min-width: 0; /* Allow shrinking so row fits viewport on mobile */
    overflow: hidden;
    /* Keep input and send button visible on all screen sizes; safe area for notched devices */
    padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    min-height: 140px;
}

.reply-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    border-bottom: 1px solid #e5e5e5;
    background: #f9fafb;
}

.reply-banner-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.reply-banner-label {
    font-size: 11px;
    font-weight: 800;
    color: #2563eb;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.reply-banner-preview {
    font-size: 13px;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

/* Single row: textarea + send button side by side (button never under input) */
.input-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-end;
    width: 100%;
    min-width: 0; /* Allow row to shrink inside input-area on mobile */
    max-width: 100%;
}

.input-tabs {
    display: flex;
    border-bottom: 1px solid #e5e5e5;
}

.tab-button {
    padding: 12px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-button:hover {
    color: #1a1a1a;
    background: #f9fafb;
}

.tab-button.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}

.input-container {
    flex: 1;
    min-width: 0;
    padding: 16px 12px 16px 20px;
}

#messageInput {
    width: 100%;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    min-height: 80px;
    margin-bottom: 0;
}

#messageInput:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.input-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.media-attach-row {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 8px;
    font-size: 12px;
    color: #6b7280;
    min-width: 0;
}

.media-upload-hint {
    margin-top: 6px;
    font-size: 11px;
    color: #64748b;
}

.media-file-label {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.media-file-clear-btn {
    border: none;
    background: none;
    color: #9ca3af;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
}

.media-file-clear-btn:hover {
    color: #4b5563;
}

.media-upload-status {
    display: none;
}

.media-upload-progress {
    --progress-accent: #2563eb;
    display: flex;
    align-items: center;
    flex: 0 0 92px;
    width: 92px;
    min-width: 92px;
    max-width: 92px;
    padding: 4px 6px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(239, 246, 255, 0.92));
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.05);
    overflow: hidden;
}

.media-upload-progress[data-tone="success"] {
    --progress-accent: #16a34a;
}

.media-upload-progress[data-tone="error"] {
    --progress-accent: #dc2626;
}

.media-upload-progress-value {
    font-size: 11px;
    font-weight: 800;
    color: #0f172a;
    white-space: nowrap;
}

.media-upload-progress-copy {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.media-upload-progress-head {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
}

.media-upload-progress-spinner {
    width: 10px;
    height: 10px;
    flex: 0 0 auto;
    border: 2px solid rgba(148, 163, 184, 0.35);
    border-top-color: var(--progress-accent);
    border-radius: 50%;
    animation: media-upload-progress-spin 0.9s linear infinite;
    display: none;
}

.media-upload-progress[data-busy="true"] .media-upload-progress-spinner {
    display: inline-flex;
}

.media-upload-progress-detail {
    display: none;
}

.media-upload-progress-bar {
    position: relative;
    height: 4px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(148, 163, 184, 0.18);
}

.media-upload-progress-bar span {
    display: block;
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--progress-accent), #60a5fa);
    transition: width 220ms ease;
}

@keyframes media-upload-progress-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.input-icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.input-icon-button:hover {
    background: #f3f4f6;
    color: #1a1a1a;
}

.send-button-container {
    flex-shrink: 0;
    padding: 0 20px 16px 0;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
}

.send-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s;
}

.send-button:hover {
    background: #1d4ed8;
}

.send-button:active {
    background: #1e40af;
}

/* Keep input area and Send button visible on small screens (e.g. phone, Galaxy Ultra, iPhone) */
/* On mobile: single row with textarea + icon-only send button on the right, never under */
@media (max-width: 768px) {
    .input-area {
        /* Ensure this area is never cut off; padding must apply and stay visible */
        padding: 10px 12px max(24px, env(safe-area-inset-bottom, 0px)) 12px;
        min-height: auto;
        /* Keep input visible on iOS: never collapse, stay above browser/safe area */
        min-height: 64px;
        flex-shrink: 0;
        z-index: 10;
        background: white;
    }

    /* Force row layout: textarea and button side by side, never stacked */
    .input-row {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        align-items: flex-end !important;
        width: 100%;
        gap: 8px;
    }

    .input-container {
        flex: 1 1 0%;
        min-width: 0;
        padding: 0;
        max-width: none;
    }

    #messageInput {
        min-height: 44px;
        max-height: 120px;
        min-width: 0; /* Allow textarea to shrink so button stays visible */
        margin-bottom: 0;
        padding: 10px 12px;
        border-radius: 20px;
        width: 100%;
        box-sizing: border-box;
    }

    .send-button-container {
        flex: 0 0 auto;
        padding: 0;
        margin: 0;
        align-self: flex-end;
    }

    /* Icon-only send button beside the input */
    .send-button {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        border-radius: 50%;
        font-size: 0;
    }

    .send-button svg {
        width: 20px;
        height: 20px;
    }

    .send-button span {
        display: none !important;
    }

    .media-upload-progress {
        flex: 0 0 88px;
        width: 88px;
        min-width: 88px;
        max-width: 88px;
        padding: 4px 6px;
    }
}

/* Prevent iOS Safari auto-zoom on focus (requires >= 16px) */
@supports (-webkit-touch-callout: none) {
    #messageInput {
      font-size: 16px !important;
    }
  }  

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}
