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

:root {
    --bg0: #050505;
    --bg1: #0c0c0c;
    --card: #161616;
    --card2: #1e1e1e;
    --text: #e8e8e8;
    --muted: #a3a3a3;
    --line: rgba(255, 255, 255, 0.08);
    --accent: #7cf0b3;
    --accent-dim: rgba(124, 240, 179, 0.14);
    --danger: #ff5c77;
    --support-bg: rgba(124, 240, 179, 0.12);
    --user-bg: rgba(255, 255, 255, 0.06);
    --shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100vh;
}

body {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background:
        radial-gradient(1200px 600px at 50% 0%, #141414, var(--bg0));
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.hidden {
    display: none !important;
}

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 320px 1fr;
}

.app.panel-hidden {
    grid-template-columns: 1fr;
}

/* ===== Control Panel ===== */
.control-panel {
    background: var(--card);
    border-right: 1px solid var(--line);
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    max-height: 100vh;
    position: sticky;
    top: 0;
}

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

.panel-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.panel-header strong {
    display: block;
    font-size: 14px;
    font-weight: 800;
}

.panel-header span {
    display: block;
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

.panel-toggle {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.panel-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.field-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.datetime-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

input[type="date"],
input[type="time"] {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    padding: 8px 10px;
    font: inherit;
    font-size: 12px;
    outline: none;
    color-scheme: dark;
}

input[type="date"]:focus,
input[type="time"]:focus {
    border-color: rgba(124, 240, 179, 0.35);
}

.btn-small {
    height: 32px;
    font-size: 12px;
}

.role-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.role-btn {
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    transition: 0.15s ease;
}

.role-btn.active {
    border-color: rgba(124, 240, 179, 0.35);
    background: var(--accent-dim);
    color: var(--accent);
}

input[type="text"],
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    padding: 10px 12px;
    font: inherit;
    outline: none;
    resize: vertical;
}

input[type="text"]:focus,
textarea:focus {
    border-color: rgba(124, 240, 179, 0.35);
}

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

.btn {
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    padding: 0 14px;
}

.btn-primary {
    flex: 1;
    border-color: rgba(124, 240, 179, 0.35);
    background: linear-gradient(180deg, rgba(124, 240, 179, 0.18), rgba(124, 240, 179, 0.07));
    color: rgba(235, 255, 245, 0.98);
}

.btn-ghost {
    background: transparent;
}

.btn-danger {
    width: 100%;
    border-color: rgba(255, 92, 119, 0.35);
    background: rgba(255, 92, 119, 0.1);
    color: #ff8a9c;
}

.btn-danger:hover {
    background: rgba(255, 92, 119, 0.18);
}

.panel-fab {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(124, 240, 179, 0.35);
    background: var(--card);
    color: var(--accent);
    font-size: 18px;
    cursor: pointer;
    z-index: 20;
}

.app.panel-hidden .control-panel {
    display: none;
}

.app.panel-hidden .panel-fab {
    display: block;
}

/* ===== Chat Shell ===== */
.chat-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    min-height: 100vh;
}

.chat-widget {
    width: 420px;
    max-width: 100%;
    height: min(680px, calc(100vh - 64px));
    display: flex;
    flex-direction: column;
    border-radius: 18px;
    background: #161616;
    border: 1px solid rgba(255, 255, 255, 0.07);
    box-shadow: none;
    overflow: hidden;
    position: relative;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: rgba(30, 30, 30, 0.75);
    border-bottom: 1px solid var(--line);
}

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

.chat-brand img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

.chat-brand h1 {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.status {
    margin: 4px 0 0;
    font-size: 11px;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: rgba(20, 20, 20, 0.55);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}

.message.from-user,
.message.user {
    align-self: flex-end;
    align-items: flex-end;
}

.message.from-support,
.message.support {
    align-self: flex-start;
    align-items: flex-start;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 10px;
    color: var(--muted);
    font-weight: 600;
}

.message-meta img,
.message.from-support .message-meta img,
.message.support .message-meta img {
    width: 16px !important;
    height: 16px !important;
    max-width: 16px !important;
    max-height: 16px !important;
    object-fit: contain;
    flex-shrink: 0;
    display: inline-block;
}

.chat-messages img {
    max-width: 36px;
    max-height: 36px;
}

.message-bubble {
    padding: 10px 12px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.from-user .message-bubble,
.message.user .message-bubble {
    background: var(--user-bg);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom-right-radius: 4px;
}

.message.from-support .message-bubble,
.message.support .message-bubble {
    background: var(--support-bg);
    border: 1px solid rgba(124, 240, 179, 0.18);
    border-bottom-left-radius: 4px;
}

.message-time {
    margin-top: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.28);
    cursor: pointer;
    border-radius: 4px;
    padding: 1px 4px;
    white-space: nowrap;
    transition: color 0.15s ease, background 0.15s ease;
}

.message-time:hover {
    color: var(--accent);
    background: rgba(124, 240, 179, 0.08);
}

.message-time.editing {
    color: var(--accent);
}

.time-editor {
    position: absolute;
    z-index: 10;
    width: 240px;
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: #1a1a1a;
}

.time-editor-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.time-editor .datetime-row {
    margin-bottom: 10px;
}

.time-editor-actions {
    display: flex;
    gap: 8px;
}

.time-editor-actions .btn-primary {
    flex: 1;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 14px 8px;
}

.typing-indicator img {
    width: 18px;
    height: 18px;
    object-fit: contain;
}

.typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--support-bg);
    border: 1px solid rgba(124, 240, 179, 0.18);
}

.typing-bubble span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0.4;
    animation: bounce 1.2s infinite;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

.chat-footer {
    padding: 12px 14px 14px;
    background: rgba(30, 30, 30, 0.75);
    border-top: 1px solid var(--line);
}

.chat-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 4px 4px 14px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.2);
}

.chat-input-wrap input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    outline: none;
    min-width: 0;
}

.send-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.28);
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
    40% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 860px) {
    .app {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(320px, 88vw);
        z-index: 30;
        transform: translateX(0);
        transition: transform 0.2s ease;
    }

    .app.panel-hidden .control-panel {
        display: flex;
        transform: translateX(-110%);
    }

    .panel-fab {
        display: block;
    }

    .chat-shell {
        padding: 16px 12px;
    }

    .chat-widget {
        height: min(720px, calc(100vh - 32px));
    }
}
