:root {
    --primary:   #1E3A8A;
    --secondary: #2563EB;
    --accent:    #60A5FA;
    --light-bg:  #EFF6FF;
    --surface:   #ffffff;
    --border:    rgba(37, 99, 235, 0.18);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(150deg, #dbeafe 0%, #eff6ff 60%, #bfdbfe 100%);
}

#background {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: -1;
    opacity: 0.12;
}

/* ── Container ── */
.container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 8px 40px rgba(30, 58, 138, 0.18);
    width: 100%;
    max-width: 600px;
    height: 100%;
    max-height: 860px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* ── Header ── */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: white;
    padding: 8px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.header h1 {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: 2px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    flex-shrink: 0;
}


/* ── Messages ── */
.content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px 14px 4px;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
}

.messages::-webkit-scrollbar        { width: 4px; }
.messages::-webkit-scrollbar-track  { background: transparent; }
.messages::-webkit-scrollbar-thumb  { background: rgba(37,99,235,0.2); border-radius: 4px; }

.message {
    margin-bottom: 10px;
    padding: 9px 13px;
    border-radius: 18px;
    max-width: 80%;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    animation: msgIn 0.18s ease;
}

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

.message.sent {
    margin-left: auto;
    border-bottom-right-radius: 4px;
    background: var(--secondary);
    color: white;
}

.message.received {
    margin-right: auto;
    border-bottom-left-radius: 4px;
    background: var(--light-bg);
    color: var(--primary);
    border: 1px solid var(--border);
}

.message-name {
    font-size: 0.75em;
    font-weight: 700;
    opacity: 0.8;
    margin-bottom: 3px;
}

.message-text {
    font-size: 14px;
    line-height: 1.45;
    white-space: pre-wrap;
}

.message-info {
    font-size: 11px;
    opacity: 0.65;
    margin-top: 4px;
    text-align: right;
}

.message.light-bg .message-info { opacity: 0.5; }

/* ── Bottom Area ── */
.bottom-area {
    display: flex;
    align-items: flex-end;
    padding: 6px 14px 12px;
    gap: 10px;
    flex-shrink: 0;
}

.left-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

/* ── Tabs Carousel ── */
.tabs-carousel-row {
    overflow: hidden;
    height: 46px;
    position: relative;
    cursor: grab;
    -webkit-mask-image: linear-gradient(to right,
        transparent 0%,
        black 18%,
        black 82%,
        transparent 100%);
    mask-image: linear-gradient(to right,
        transparent 0%,
        black 18%,
        black 82%,
        transparent 100%);
}

.tabs-carousel-row.grabbing { cursor: grabbing; }

.tabs-carousel-track {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 100%;
    will-change: transform;
}

.chat-tab {
    display: flex;
    align-items: center;
    padding: 7px 14px;
    background: rgba(219, 234, 254, 0.55);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--secondary);
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 46px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    transition: background 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.help-tab { justify-content: center; }

.chat-tab i { margin-right: 5px; opacity: 0.7; }
.help-tab i { margin-right: 0; }

.chat-tab:hover  { background: rgba(219,234,254,0.9); }
.chat-tab:active { opacity: 0.7; }

.chat-tab.active {
    background: var(--secondary);
    color: white;
    border-color: var(--secondary);
    box-shadow: 0 3px 10px rgba(37,99,235,0.3);
}

.chat-tab.active i { opacity: 1; }

/* ── Message Input ── */
#message {
    width: 100%;
    padding: 0 16px;
    height: 46px;
    background: var(--light-bg);
    border: 1.5px solid var(--border);
    border-radius: 23px;
    font-size: 14px;
    font-family: inherit;
    color: var(--primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
    min-width: 0;
    box-sizing: border-box;
}

#message::placeholder { color: #93C5FD; }

#message:focus {
    background: white;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

#message:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Right Buttons Column ── */
.right-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.add-tab-btn {
    width: 46px;
    height: 46px;
    background: rgba(219, 234, 254, 0.55);
    border: 1.5px solid var(--border);
    border-radius: 50%;
    color: var(--secondary);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: background 0.15s, transform 0.1s;
}

.add-tab-btn:hover  { background: rgba(219,234,254,0.9); }
.add-tab-btn:active { transform: scale(0.9); }

#send-button {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}

#send-button:not(:disabled):hover  { box-shadow: 0 4px 14px rgba(37,99,235,0.4); transform: scale(1.05); }
#send-button:not(:disabled):active { transform: scale(0.92); opacity: 0.85; }
#send-button:disabled              { opacity: 0.35; cursor: not-allowed; }

/* ── Settings Popup ── */
.popup {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(17, 35, 90, 0.55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 20;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.popup-content {
    background: white;
    padding: 28px 22px 22px;
    border-radius: 18px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(30,58,138,0.28);
    border: 1px solid var(--border);
}

.popup-content h2 {
    text-align: center;
    color: var(--primary);
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
}

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

.popup-content label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.popup-content input {
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    color: var(--primary);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--light-bg);
}

.popup-content input:focus {
    background: white;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.popup-buttons {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}

.popup-buttons button {
    flex: 1;
    height: 48px;
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    transition: opacity 0.15s, transform 0.1s;
}

.popup-buttons button:active { transform: scale(0.97); }

#save-session-btn { background: linear-gradient(135deg, var(--secondary), var(--primary)); }
#save-session-btn:hover { opacity: 0.9; }

.secondary-btn { background: #6B7280; }
.secondary-btn:hover { background: #4B5563; }

/* ── Context Menu ── */
.context-menu {
    position: absolute;
    background: white;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 28px rgba(30,58,138,0.18);
    padding: 5px;
    z-index: 1000;
    display: none;
    min-width: 165px;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    color: #EF4444;
    cursor: pointer;
    min-height: 44px;
    touch-action: manipulation;
    transition: background 0.12s;
}

.context-menu-item:hover  { background: #FEE2E2; }
.context-menu-item:active { background: #FECACA; }

/* ── Tutorial ── */
.tutorial {
    background: var(--light-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px 20px;
    margin: 8px auto;
    color: var(--primary);
    line-height: 1.5;
}

.tutorial h2 { font-size: 17px; margin-bottom: 12px; }

.tutorial p  { font-size: 14px; margin-bottom: 10px; }

.tutorial ol {
    font-size: 14px;
    line-height: 1.75;
    padding-left: 20px;
    margin-bottom: 14px;
}

.tutorial .warning {
    background: rgba(251,191,36,0.12);
    border-left: 4px solid #F59E0B;
    border-radius: 0 8px 8px 0;
    padding: 10px 13px;
    font-size: 13px;
    color: #92400E;
    margin-bottom: 12px;
}

.tutorial .tips { font-size: 12px; opacity: 0.75; line-height: 1.9; }

/* ── Keyboard (kbd) ── */
kbd {
    background: #F1F5F9;
    border: 1px solid #CBD5E1;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.12), 0 2px 0 rgba(255,255,255,0.7) inset;
    color: var(--primary);
    display: inline-block;
    font-family: inherit;
    font-size: 0.85em;
    font-weight: 700;
    line-height: 1;
    padding: 2px 6px;
    white-space: nowrap;
}

/* ── Mobile adjustments ── */
@media (max-width: 480px) {
    body { padding: 0; }
    .container { border-radius: 0; max-height: 100dvh; border: none; }
}
