/* ─── Brand tokens ────────────────────────────────────────────────────────────── */
:root {
    --brand:         #E04020;
    --brand-dark:    #C4321A;
    --brand-darker:  #A82A14;
    --brand-light:   #F26040;
    --brand-subtle:  rgba(224, 64, 32, 0.10);
    --brand-subtle2: rgba(224, 64, 32, 0.06);
}

/* ─── Reset & Base ───────────────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background-color: #F8FAFC;
    color: #111;
}

#app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ─── Dashboard Utilities ────────────────────────────────────────────────────── */
.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #0F172A;
    margin: 0 0 1.5rem;
}

.card {
    background: white;
    border-radius: 12px;
    padding: 1.25rem;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    border: 1px solid #E2E8F0;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-active   { background: #FEF0EC; color: #A82A14; }
.badge-inactive { background: #F1F5F9; color: #64748B; }
.badge-error    { background: #FEE2E2; color: #991B1B; }
.badge-inbound  { background: #DBEAFE; color: #1E40AF; }
.badge-outbound { background: #FEF3C7; color: #92400E; }
.badge-received  { background: #DBEAFE; color: #1E40AF; }
.badge-sent      { background: #F0FDF4; color: #166534; }
.badge-delivered { background: #DCFCE7; color: #166534; }
.badge-failed    { background: #FEE2E2; color: #991B1B; }
.badge-pending   { background: #FEF3C7; color: #92400E; }
.badge-processed { background: #DCFCE7; color: #166534; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1rem;
    border-radius: 8px;
    border: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn-primary {
    background: var(--brand);
    color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }

.btn-secondary {
    background: #F1F5F9;
    color: #374151;
    border: 1px solid #E2E8F0;
}
.btn-secondary:hover:not(:disabled) { background: #E2E8F0; }

.btn-danger {
    background: #FEE2E2;
    color: #991B1B;
}
.btn-danger:hover:not(:disabled) { background: #FECACA; }

.btn-ghost {
    background: transparent;
    color: #64748B;
}
.btn-ghost:hover:not(:disabled) { background: #F1F5F9; }

.table-container {
    overflow-x: auto;
    border-radius: 12px;
    border: 1px solid #E2E8F0;
    background: white;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

table.data-table th {
    background: #F8FAFC;
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    color: #64748B;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid #E2E8F0;
}

table.data-table td {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid #F1F5F9;
    color: #374151;
    vertical-align: middle;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover td { background: #FEF8F6; }

.empty-table {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    gap: 0.75rem;
    color: #94A3B8;
}

.empty-table-icon { font-size: 2.5rem; opacity: 0.5; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
}

.form-input, .form-select {
    padding: 0.6rem 0.875rem;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #111;
    background: white;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-input:focus, .form-select:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-subtle);
}

.form-hint {
    font-size: 0.78rem;
    color: #94A3B8;
}

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.alert {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: 0.875rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.alert-error   { background: #FEE2E2; color: #991B1B; border: 1px solid #FECACA; }
.alert-success { background: #DCFCE7; color: #166534; border: 1px solid #BBF7D0; }
.alert-info    { background: #DBEAFE; color: #1E40AF; border: 1px solid #BFDBFE; }

/* ─── Chat Container ─────────────────────────────────────────────────────────── */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background-color: #ECE5DD;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23C9BBAD' fill-opacity='0.3'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    position: relative;
}

/* ─── Chat Header ────────────────────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--brand);
    color: white;
    padding: 0.75rem 1rem;
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.25);
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--brand-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.chat-header-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chat-header-subtitle {
    font-size: 0.75rem;
    opacity: 0.85;
    margin: 0;
}

/* ─── Connection Status ──────────────────────────────────────────────────────── */
.connection-badge {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border-radius: 12px;
    background-color: rgba(0,0,0,0.2);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.connection-dot.connected {
    background-color: #25D366;
    box-shadow: 0 0 6px #25D366;
}

.connection-dot.disconnected {
    background-color: #ff6b6b;
    animation: pulse 1.5s ease-in-out infinite;
}

.connection-dot.connecting {
    background-color: #ffd93d;
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ─── Messages Container ─────────────────────────────────────────────────────── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 2px;
}

/* ─── Messages ───────────────────────────────────────────────────────────────── */
.message-row { display: flex; margin-bottom: 0.125rem; }
.message-row.own   { justify-content: flex-end; }
.message-row.other { justify-content: flex-start; }

.message-bubble {
    max-width: min(75%, 480px);
    border-radius: 12px;
    padding: 0.4rem 0.65rem 0.25rem;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.15);
    word-wrap: break-word;
}

.message-row.own   .message-bubble { background-color: #DCF8C6; border-bottom-right-radius: 4px; }
.message-row.other .message-bubble { background-color: #ffffff; border-bottom-left-radius: 4px; }

.message-user {
    display: block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--brand);
    margin-bottom: 0.15rem;
}

.message-row.own .message-user { display: none; }

.message-text {
    display: block;
    font-size: 0.9rem;
    line-height: 1.4;
    color: #111;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.15rem;
}

.message-time  { font-size: 0.65rem; color: #808080; }
.message-tick  { font-size: 0.65rem; color: #4FC3F7; }

/* ─── Date separator ─────────────────────────────────────────────────────────── */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.75rem 0;
}

.date-separator span {
    background-color: #FEF0EC;
    color: var(--brand-dark);
    font-size: 0.72rem;
    padding: 0.2rem 0.75rem;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 0.5rem;
    color: #888;
}

.empty-state-icon { font-size: 3rem; opacity: 0.5; }

/* ─── Username gate ──────────────────────────────────────────────────────────── */
.username-gate {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 1rem;
    padding: 2rem;
}

.username-gate-card {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.username-gate-card h2 { margin: 0; color: var(--brand); font-size: 1.25rem; }
.username-gate-card p  { margin: 0; color: #666; font-size: 0.875rem; }

/* ─── Input Bar ──────────────────────────────────────────────────────────────── */
.input-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background-color: #F0F0F0;
    flex-shrink: 0;
    border-top: 1px solid #ddd;
}

.input-field {
    flex: 1;
    border: none;
    border-radius: 24px;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    background-color: white;
    outline: none;
    transition: box-shadow 0.15s;
    min-width: 0;
}

.input-field:focus       { box-shadow: 0 0 0 2px var(--brand-subtle); }
.input-field:disabled    { background-color: #e9e9e9; color: #999; }

.btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background-color: var(--brand);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    transition: background-color 0.15s, transform 0.1s;
}

.btn-send:hover:not(:disabled)  { background-color: var(--brand-dark); transform: scale(1.05); }
.btn-send:disabled               { background-color: #ccc; cursor: not-allowed; }

.btn-join {
    width: 100%;
    padding: 0.7rem;
    border: none;
    border-radius: 8px;
    background-color: var(--brand);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s;
}

.btn-join:hover:not(:disabled)  { background-color: var(--brand-dark); }
.btn-join:disabled               { background-color: #ccc; cursor: not-allowed; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .message-bubble { max-width: 88%; }
}
