:root {
    /* Primary Colors - Dark Navy Theme */
    --primary-color: #1d2a54;
    --primary-light: #2d3e6f;
    --primary-dark: #15203d;
    --accent-color: #238dc6;
    --accent-light: #3ba3d6;

    /* Status Colors */
    --success-color: #28a745;
    --success-light: #d4edda;
    --success-dark: #155724;
    --danger-color: #e74c3c;
    --danger-light: #ffe5e5;
    --danger-dark: #c0392b;
    --warning-color: #ffc107;

    /* Neutral Colors */
    --bg-color: #f8f9fa;
    --bg-lighter: #ffffff;
    --card-bg: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --text-muted: #6b7280;
    --border-color: #e0e6ed;

    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 12px 32px rgba(0, 0, 0, 0.15);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overflow-x: hidden;
    max-width: 100vw;
}

/* Customer UI */
.screen {
    display: none;
    min-height: 100vh;
    padding: 20px;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-container {
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
}

.gate-card, .chat-card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.gate-header {
    background: var(--primary-color);
    color: white;
    padding: 48px 32px;
    text-align: center;
    position: relative;
}

.gate-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent-color);
}

.gate-header i {
    font-size: 3.5rem;
    margin-bottom: 20px;
    opacity: 0.9;
}

.gate-header h1 {
    font-size: 2rem;
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.gate-header p {
    font-size: 1rem;
    opacity: 0.85;
    font-weight: 400;
}

.status-banner {
    padding: 16px 32px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border-color);
}

.status-banner.online {
    background: var(--success-light);
    color: var(--success-dark);
}

.status-banner.offline {
    background: var(--danger-light);
    color: var(--danger-dark);
}

.status-banner i {
    font-size: 0.65rem;
}

.gate-form {
    padding: 32px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.form-group label i {
    color: var(--accent-color);
    margin-right: 8px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    font-family: inherit;
    background: var(--bg-lighter);
}

.form-input:hover {
    border-color: var(--accent-color);
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(29, 42, 84, 0.1);
}

.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.help-text {
    margin-top: 24px;
    padding: 16px;
    background: var(--bg-color);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    border-left: 3px solid var(--accent-color);
}

.help-text i {
    color: var(--accent-color);
    margin-right: 8px;
}

/* Chat UI */
.chat-card {
    height: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    background: var(--primary-color);
    color: white;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 3px solid var(--accent-color);
}

.back-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: translateX(-2px);
}

.chat-header-info {
    flex: 1;
}

.chat-header-info h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
    font-weight: 700;
}

.order-id-display {
    font-size: 0.875rem;
    opacity: 0.85;
}

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

.admin-status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.15);
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.admin-status-indicator i {
    font-size: 0.6rem;
}

.close-chat-btn {
    background: rgba(231, 76, 60, 0.15);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #ff6b6b;
    height: 40px;
    padding: 0 14px;
    gap: 6px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}

.close-chat-btn i {
    font-size: 1rem;
}

.close-chat-btn:hover {
    background: rgba(231, 76, 60, 0.25);
    border-color: rgba(231, 76, 60, 0.5);
    transform: scale(1.05);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
    background: #f5f7fa;
    min-height: 0;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-sent {
    justify-content: flex-end;
}

.message-received {
    justify-content: flex-start;
}

.message-system {
    justify-content: center;
    margin: 20px 0;
}

.message-system-content {
    background: rgba(35, 141, 198, 0.1);
    border: 1px solid rgba(35, 141, 198, 0.2);
    border-radius: 20px;
    padding: 10px 20px;
    color: var(--primary-color);
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    display: flex;
    align-items: center;
    gap: 8px;
}

.message-system-content i {
    color: var(--accent-color);
    font-size: 0.9rem;
}

.message-content {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 12px;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.message-content p {
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.message-sent .message-content {
    background: var(--primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-received .message-content {
    background: white;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.message-content p {
    margin: 0 0 6px 0;
    word-wrap: break-word;
    line-height: 1.5;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.65;
    font-weight: 500;
}

.typing-indicator {
    padding: 10px 24px;
    background: #f0f7fc;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 2px solid var(--accent-color);
    animation: fadeIn 0.2s ease;
    flex-shrink: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 6px 10px;
    background: white;
    border-radius: 16px;
    border: 1px solid rgba(35, 141, 198, 0.3);
}

.typing-dots span {
    width: 7px;
    height: 7px;
    background: var(--accent-color);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

.typing-text {
    font-size: 0.825rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.message-input-container {
    padding: 20px 24px;
    background: white;
    border-top: 1px solid var(--border-color);
}

.message-form {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-input {
    flex: 1;
    padding: 12px 20px;
    border: 2px solid var(--border-color);
    border-radius: 24px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background: var(--bg-color);
}

.message-input:hover {
    border-color: var(--accent-color);
}

.message-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: white;
    box-shadow: 0 0 0 3px rgba(29, 42, 84, 0.08);
}

.send-btn {
    width: 48px;
    height: 48px;
    background: var(--accent-color);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.send-btn:hover {
    background: var(--accent-light);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.send-btn:active {
    transform: scale(0.98);
}

/* Admin Dashboard */
.admin-body {
    background: var(--bg-color);
    margin: 0;
    padding: 0;
}

.admin-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.conversations-sidebar {
    width: 360px;
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 24px 20px;
    background: var(--primary-color);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid var(--accent-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

/* Support on/off switch: a real switch control, not a passive badge. */
.status-control {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
}

.status-switch {
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    border: none;
    color: white;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
}

.status-switch:focus-visible {
    outline: 2px solid white;
    outline-offset: 2px;
}

.status-switch-track {
    display: inline-block;
    width: 42px;
    height: 24px;
    border-radius: 12px;
    background: var(--warning-color);
    position: relative;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.status-switch[aria-checked="true"] .status-switch-track {
    background: #22c55e;
}

.status-switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease;
}

.status-switch[aria-checked="true"] .status-switch-thumb {
    transform: translateX(18px);
}

.status-caption {
    font-size: 0.72rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.75);
    padding-right: 4px;
}

/* Amber strip shown across the main area whenever support is offline, so the
   state is impossible to miss from any screen — with recovery one click away. */
.offline-banner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    background: #fff4d6;
    border-bottom: 1px solid #f0c36d;
    color: #6b4e00;
    font-size: 0.92rem;
}

.offline-banner[hidden] {
    display: none;
}

.offline-banner i {
    color: #b8860b;
}

.offline-banner span {
    flex: 1;
}

.offline-banner-btn {
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 7px 16px;
    font-family: inherit;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease;
}

.offline-banner-btn:hover {
    background: #1f8b1f;
}

.offline-banner-btn:focus-visible {
    outline: 2px solid #6b4e00;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .status-switch-track,
    .status-switch-thumb,
    .offline-banner-btn {
        transition: none;
    }
}

/* Customer presence: green dot in the list, label in the chat header. */
.presence-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
    margin-right: 7px;
    vertical-align: 1px;
}

.customer-presence {
    display: inline-block;
    font-size: 0.8rem;
    font-weight: 600;
}

.customer-presence.here {
    color: #16a34a;
}

.customer-presence.away {
    color: var(--text-muted);
}

.customer-presence.here::before,
.customer-presence.away::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: 1px;
    background: currentColor;
}

/* Right-hand column of a conversation row: unread badge over relative time. */
.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.conversation-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Inline error under the order ID field (replaces alert() popups). */
.gate-error {
    background: var(--danger-light);
    color: var(--danger-dark);
    border: 1px solid #f3c2c2;
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.gate-error[hidden] {
    display: none;
}

/* "Email me when support is back" box on the gate screen (offline only). */
.notify-box {
    margin-top: 18px;
    padding: 14px 16px;
    background: var(--bg-color);
    border: 1px dashed var(--border-color);
    border-radius: 10px;
}

.notify-box[hidden] {
    display: none;
}

.notify-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
}

.notify-title i {
    color: var(--accent-color);
    margin-right: 6px;
}

.notify-form {
    display: flex;
    gap: 8px;
}

.notify-form .form-input {
    flex: 1;
    min-width: 0;
}

.btn-secondary {
    padding: 10px 16px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 8px;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: var(--accent-light);
}

.btn-secondary:disabled {
    opacity: 0.6;
    cursor: default;
}

.notify-box .gate-error {
    margin: 10px 0 0 0;
}

.notify-done {
    color: var(--success-dark);
    font-size: 0.9rem;
    margin: 0;
}

.notify-done[hidden] {
    display: none;
}

.notify-done i {
    color: var(--success-color);
    margin-right: 4px;
}

/* Shown in the customer chat while the socket is down. */
.reconnect-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 7px 12px;
    background: #fff4d6;
    border-bottom: 1px solid #f0c36d;
    color: #6b4e00;
    font-size: 0.85rem;
    font-weight: 600;
}

.reconnect-bar[hidden] {
    display: none;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-lighter);
}

.no-conversations {
    padding: 80px 20px;
    text-align: center;
    color: var(--text-muted);
}

.no-conversations i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.3;
}

.no-conversations p {
    font-size: 1rem;
    font-weight: 500;
}

.conversation-item {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    background: white;
    position: relative;
}

.conversation-item:hover {
    background: #f8f9fb;
    padding-left: 24px;
}

.conversation-item.active {
    background: #e8f4f8;
    border-left: 4px solid var(--primary-color);
    padding-left: 20px;
}

.conversation-item.unread {
    background: #f0f8ff;
}

.conversation-item.closed {
    opacity: 0.6;
    background: #f5f5f5;
    position: relative;
}

.conversation-item.closed:hover {
    opacity: 0.8;
    background: #ececec;
}

.conversation-item.closed::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--danger-color);
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
    gap: 8px;
}

.name-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.conversation-header strong {
    font-size: 1rem;
    color: var(--text-primary);
    font-weight: 700;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.closed-badge {
    background: rgba(231, 76, 60, 0.1);
    color: var(--danger-color);
    border: 1px solid rgba(231, 76, 60, 0.2);
}

.closed-badge i {
    font-size: 0.7rem;
}

.replaced-badge {
    background: rgba(40, 167, 69, 0.1);
    color: var(--success-color);
    border: 1px solid rgba(40, 167, 69, 0.2);
}

.replaced-badge i {
    font-size: 0.7rem;
}

.unread-badge {
    background: var(--danger-color);
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 24px;
    text-align: center;
}

.conversation-order-id {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.conversation-order-id i {
    font-size: 0.75rem;
    color: var(--accent-color);
}

.conversation-last-message {
    font-size: 0.875rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f5f7fa;
}

.welcome-screen {
    display: none;
    flex: 1;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 48px;
}

.welcome-screen.active {
    display: flex;
    flex-direction: column;
}

.welcome-screen i {
    font-size: 5rem;
    color: var(--primary-color);
    margin-bottom: 24px;
    opacity: 0.2;
}

.welcome-screen h2 {
    font-size: 2.25rem;
    margin-bottom: 12px;
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: -0.5px;
}

.welcome-screen p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 48px;
    font-weight: 500;
}

.welcome-stats {
    display: flex;
    gap: 32px;
}

.stat-card {
    background: white;
    padding: 32px 48px;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.stat-card i {
    font-size: 2.5rem;
    color: var(--primary-color);
    display: block;
    margin-bottom: 16px;
    opacity: 0.8;
}

.stat-card span {
    font-size: 3rem;
    font-weight: 800;
    color: var(--primary-color);
    display: block;
}

.stat-card p {
    margin: 8px 0 0 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-area {
    display: none;
    flex: 1;
    flex-direction: column;
    background: white;
    overflow: hidden;
    max-height: 100vh;
}

.chat-header-admin {
    padding: 20px 32px;
    background: white;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.chat-header-admin h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 6px;
    font-weight: 700;
}

.order-id-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(29, 42, 84, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.copy-order-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 4px 10px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-weight: 600;
}

.copy-order-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.copy-order-btn:active {
    transform: scale(0.95);
}

.copy-order-btn.copied {
    background: var(--success-color);
    border-color: var(--success-color);
}

.copy-order-btn.copied i::before {
    content: '\f00c';
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.icon-btn:active {
    transform: scale(0.95);
}

.admin-messages {
    background: #f5f7fa;
}

/* Responsive */
@media (max-width: 768px) {
    html, body {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
        overscroll-behavior: none;
    }

    .screen {
        padding: 0;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        height: 100vh;
        height: -webkit-fill-available;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
    }

    .screen.active {
        display: flex;
        align-items: stretch;
    }

    .chat-container {
        padding: 0;
        height: 100%;
        max-width: 100%;
        width: 100%;
    }

    .gate-card, .chat-card {
        border-radius: 0;
        height: 100%;
        max-height: 100%;
        border: none;
        width: 100%;
    }

    /* Safe area support for notched devices */
    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .message-input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .gate-header {
        padding: 32px 24px;
    }

    .gate-header i {
        font-size: 2.5rem;
    }

    .gate-header h1 {
        font-size: 1.5rem;
    }

    .gate-form {
        padding: 24px 20px;
    }

    .chat-header {
        padding: 16px;
        flex-wrap: nowrap;
    }

    .chat-header-info h2 {
        font-size: 1.1rem;
    }

    .order-id-display {
        font-size: 0.75rem;
    }

    .chat-header-actions {
        gap: 8px;
    }

    .admin-status-indicator {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .close-chat-btn {
        height: 36px;
        padding: 0 10px;
        font-size: 0.75rem;
    }

    .back-btn {
        width: 36px;
        height: 36px;
    }

    .messages-container {
        padding: 16px;
    }

    .message-content {
        max-width: 85%;
        font-size: 0.9rem;
    }

    .message-time {
        font-size: 0.7rem;
    }

    .typing-indicator {
        padding: 8px 16px;
        gap: 8px;
    }

    .typing-text {
        font-size: 0.75rem;
    }

    .message-input-container {
        padding: 12px 16px;
    }

    .message-input {
        font-size: 0.95rem;
    }

    .send-btn {
        width: 42px;
        height: 42px;
    }

    /* Admin mobile */
    .admin-container {
        flex-direction: column;
        height: 100vh;
    }

    .conversations-sidebar {
        width: 100%;
        max-height: 35vh;
        min-height: 200px;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        flex-shrink: 0;
        overflow-y: auto;
    }

    .conversations-list {
        max-height: calc(35vh - 70px);
    }

    .sidebar-header {
        padding: 16px;
    }

    .sidebar-header h2 {
        font-size: 1.1rem;
    }

    .conversation-item {
        padding: 12px 16px;
    }

    .conversation-item:hover {
        padding-left: 16px;
    }

    .conversation-item.active {
        padding-left: 16px;
    }

    .chat-area {
        flex: 1;
        min-height: 0;
        max-height: calc(65vh);
    }

    .admin-messages {
        flex: 1;
        min-height: 0;
    }

    .chat-header-admin {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 8px;
    }

    .chat-header-admin h3 {
        font-size: 1.1rem;
    }

    .order-id-badge {
        padding: 6px 12px;
        font-size: 0.75rem;
        gap: 6px;
        overflow-wrap: break-word;
        word-break: break-all;
        max-width: 100%;
    }

    #orderIdText {
        word-break: break-all;
        font-size: 0.7rem;
    }

    .copy-order-btn {
        padding: 3px 8px;
        font-size: 0.7rem;
    }

    .admin-header-actions {
        gap: 8px;
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }

    .welcome-screen {
        padding: 20px;
    }

    .welcome-screen h2 {
        font-size: 1.3rem;
    }

    .welcome-stats {
        flex-direction: column;
        gap: 16px;
    }

    .stat-card span {
        font-size: 2rem;
    }

    .message-system-content {
        font-size: 0.8rem;
        padding: 8px 16px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .gate-header h1 {
        font-size: 1.3rem;
    }

    .gate-header p {
        font-size: 0.9rem;
    }

    .form-input {
        font-size: 0.95rem;
    }

    .btn-primary {
        font-size: 0.95rem;
        padding: 12px 20px;
    }

    .help-text {
        font-size: 0.8rem;
    }

    .message-content {
        max-width: 90%;
        padding: 10px 14px;
    }

    .order-id-badge {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .copy-order-btn {
        align-self: stretch;
        justify-content: center;
    }

    .status-banner {
        padding: 10px 16px;
        font-size: 0.85rem;
    }

    .conversation-order-id {
        font-size: 0.75rem;
    }

    .conversation-last-message {
        font-size: 0.8rem;
    }

    .status-badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }
}

/* Touch improvements */
@media (hover: none) and (pointer: coarse) {
    /* Touch devices - increase tap targets */
    .btn-primary,
    .send-btn,
    .back-btn,
    .close-chat-btn,
    .icon-btn,
    .copy-order-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .conversation-item {
        min-height: 60px;
    }
}

/* Scrollbar styling */
.conversations-list::-webkit-scrollbar,
.messages-container::-webkit-scrollbar {
    width: 8px;
}

.conversations-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.conversations-list::-webkit-scrollbar-thumb:hover,
.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================================
   Admin console refresh (2026-07) — labeled action bar,
   monospace order chip, cleaner cards. Admin-scoped only.
   ============================================================ */

/* Labeled, color-coded action buttons (replace the old grey icon squares).
   Each button says what it does; the tooltip states the effect. */
.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease, transform 0.08s ease, box-shadow 0.16s ease;
}
.action-btn i { font-size: 0.9rem; }
.action-btn:active { transform: scale(0.97); }
.action-btn:focus-visible { outline: 2px solid var(--accent-color); outline-offset: 2px; }

.action-btn-success {
    background: var(--success-color);
    color: #fff;
    box-shadow: 0 2px 8px rgba(40, 167, 69, 0.28);
}
.action-btn-success:hover { background: var(--success-dark); box-shadow: 0 4px 14px rgba(40, 167, 69, 0.35); }

.action-btn-danger {
    background: #fff;
    color: var(--danger-color);
    border-color: rgba(231, 76, 60, 0.4);
}
.action-btn-danger:hover { background: var(--danger-color); color: #fff; border-color: var(--danger-color); }

.action-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.action-btn-ghost:hover { background: var(--bg-color); color: var(--text-primary); border-color: var(--text-muted); }

.action-divider {
    width: 1px;
    align-self: stretch;
    min-height: 24px;
    background: var(--border-color);
    margin: 0 2px;
}

/* Order ID as data: small monospace chip that reads as an identifier you copy. */
.order-id-badge {
    font-family: 'SF Mono', 'JetBrains Mono', ui-monospace, 'Menlo', 'Consolas', monospace;
    letter-spacing: 0.2px;
    font-size: 0.72rem;
    padding: 4px 10px;
    gap: 6px;
}
.order-id-badge .copy-order-btn { padding: 2px 8px; font-size: 0.68rem; }

/* Sidebar header: sits on navy; give it a touch of hierarchy. */
.sidebar-header h2 i { color: var(--accent-light); margin-right: 6px; }

/* Conversation cards: calmer, tighter, clearer active state. */
.conversation-item { transition: background 0.16s ease, padding-left 0.16s ease, box-shadow 0.16s ease; }
.conversation-item.active {
    background: #eaf5fb;
    border-left: 4px solid var(--accent-color);
    box-shadow: inset 0 0 0 1px rgba(35, 141, 198, 0.12);
}
.conversation-item.unread strong::after {
    content: '';
    display: inline-block;
    width: 7px; height: 7px;
    margin-left: 8px;
    border-radius: 50%;
    background: var(--accent-color);
    vertical-align: middle;
}

/* Empty + welcome states as invitations, not mood. */
.no-conversations span {
    display: block;
    margin-top: 8px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    max-width: 240px;
    margin-inline: auto;
}
.welcome-screen i { opacity: 0.16; }
.stat-card { border-radius: 14px; }

/* Mobile: the action bar keeps meaning but collapses labels to icons. */
@media (max-width: 768px) {
    .chat-header-admin { padding: 14px 16px; }
    .admin-header-actions { gap: 8px; }
    .action-btn { padding: 9px 11px; }
    .action-btn span { display: none; }
    .action-divider { display: none; }
}

/* ============================================================
   Customer gate refresh (2026-07) — calmer, more trustworthy.
   ============================================================ */

/* Headset in a soft badge = a concierge you're about to talk to. */
.gate-header i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 76px;
    height: 76px;
    margin: 0 auto 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 2.1rem;
    opacity: 1;
}

/* Calmer CTA: sentence case, not a shouty all-caps banner. */
.btn-primary {
    text-transform: none;
    letter-spacing: normal;
    border-radius: 10px;
}

/* Order-ID field reads as the identifier it is. */
#orderIdInput {
    font-family: ui-monospace, 'SF Mono', 'Menlo', 'Consolas', monospace;
    letter-spacing: 0.2px;
}

/* Quality floor: honor reduced-motion for the chat animations. */
@media (prefers-reduced-motion: reduce) {
    .message,
    .typing-indicator,
    .typing-dots span {
        animation: none !important;
    }
}
