/* ===== Base Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ═══════════════════════════════
   Ally Tech Brand Palette
   Red #cc0000 / White #ffffff / Black #111111
   ═══════════════════════════════ */
/* ═══ Dark Mode (default) ═══ */
:root {
    --bg:          #0d0d0d;
    --surface:     #161616;
    --card:        #1f1f1f;
    --accent:      #cc0000;
    --accent-light:#e62222;
    --accent-glow: rgba(204, 0, 0, 0.30);
    --user-bubble: #cc0000;
    --bot-bubble:  #1f1f1f;
    --text:        #f0f0f0;
    --text-dim:    #888888;
    --border:      rgba(255,255,255,0.09);
    --border-red:  rgba(204,0,0,0.35);
    --radius:      16px;
    --danger:      #ff4444;
    --success:     #22c55e;
    --toggle-bg:   #2a2a2a;
    --toggle-icon: '☀️';
}

/* ═══ Light Mode ═══ */
[data-theme="light"] {
    --bg:          #f5f5f5;
    --surface:     #ffffff;
    --card:        #f0f0f0;
    --accent:      #cc0000;
    --accent-light:#e62222;
    --accent-glow: rgba(204, 0, 0, 0.20);
    --user-bubble: #cc0000;
    --bot-bubble:  #ececec;
    --text:        #111111;
    --text-dim:    #666666;
    --border:      rgba(0,0,0,0.10);
    --border-red:  rgba(204,0,0,0.30);
    --danger:      #dc2626;
    --success:     #16a34a;
    --toggle-bg:   #e2e2e2;
    --toggle-icon: '🌙';
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-image:
        radial-gradient(ellipse at 20% 10%, rgba(204,0,0,0.10) 0%, transparent 55%),
        radial-gradient(ellipse at 80% 90%, rgba(204,0,0,0.06) 0%, transparent 55%);
}

.hidden { display: none !important; }

/* ═══ Theme Toggle Button ═══ */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--toggle-bg);
    border: 1px solid var(--border-red);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.25s;
    flex-shrink: 0;
    line-height: 1;
}
.theme-toggle:hover {
    transform: rotate(20deg) scale(1.1);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

/* Position specifically for registration card */
.reg-corner-actions {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    gap: 8px;
    z-index: 10;
}

.loc-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--toggle-bg);
    border: 1px solid var(--border-red);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.25s;
    text-decoration: none;
    color: inherit;
}

.loc-btn:hover {
    transform: scale(1.1);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

/* ═══════════════════════════════
   Registration Overlay
   ═══════════════════════════════ */
#reg-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.80);
    backdrop-filter: blur(14px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeSlide 0.4s ease forwards;
}

#reg-overlay.fade-out {
    animation: fadeOut 0.4s ease forwards;
}

@keyframes fadeOut {
    to { opacity: 0; transform: scale(0.97); }
}

#reg-card {
    position: relative;
    width: 430px;
    max-width: 92vw;
    background: var(--surface);
    border: 1px solid var(--border-red);
    border-top: 3px solid var(--accent);
    border-radius: var(--radius);
    padding: 36px 32px 28px;
    box-shadow:
        0 0 60px rgba(204,0,0,0.12),
        0 24px 60px rgba(0,0,0,0.6);
}

.reg-header {
    text-align: center;
    margin-top: 10px;
    margin-bottom: 26px;
}

.reg-icon {
    font-size: 2.4rem;
    display: block;
    margin-bottom: 10px;
}

.reg-brand {
    height: 36px;
    width: auto;
    object-fit: contain;
    position: absolute;
    top: 24px;
    left: 28px;
    margin: 0;
}

.reg-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    color: #ffffff;
}

.reg-header h2 span {
    color: var(--accent);
}

.reg-header p {
    color: var(--text-dim);
    font-size: 0.84rem;
    margin-top: 6px;
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.field input,
.field select {
    width: 100%;
    padding: 11px 14px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 9px;
    color: var(--text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.field input::placeholder {
    color: var(--text-dim);
}

.field input:focus,
.field select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888888' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    cursor: pointer;
}

.field select option {
    background: var(--card);
    color: var(--text);
}

#reg-btn {
    width: 100%;
    padding: 13px;
    margin-top: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    font-family: inherit;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 20px var(--accent-glow);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    letter-spacing: 0.3px;
}

#reg-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    background: var(--accent-light);
    box-shadow: 0 6px 28px var(--accent-glow);
}

#reg-btn:disabled {
    opacity: 0.7;
    cursor: wait;
}

.spinner {
    width: 18px;
    height: 18px;
    border: 2.5px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.reg-error {
    text-align: center;
    color: var(--danger);
    font-size: 0.85rem;
    margin-top: 12px;
}

/* ═══════════════════════════════
   App Shell
   ═══════════════════════════════ */
#app {
    width: 520px;
    max-width: 96vw;
    height: 92vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow:
        0 0 60px rgba(204,0,0,0.07),
        0 20px 60px rgba(0,0,0,0.55);
}

/* ===== Header ===== */
header {
    padding: 14px 22px;
    border-bottom: 1px solid var(--border-red);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(180deg, rgba(204,0,0,0.08) 0%, transparent 100%);
    position: relative;
}

header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 60px;
    height: 2px;
    background: var(--accent);
    border-radius: 2px;
}

.header-left, .header-center, .header-right {
    display: flex;
    align-items: center;
    flex: 1;
}

.header-left {
    justify-content: flex-start;
}

.header-center {
    justify-content: center;
}

.header-right {
    justify-content: flex-end;
    gap: 12px;
}

.chat-brand {
    height: 34px;
    width: auto;
    object-fit: contain;
}

.header-center h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.3px;
    margin: 0;
}

.header-center h1 span {
    color: var(--accent);
}

.status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.76rem;
    color: var(--text-dim);
    background: var(--card);
    padding: 4px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

.dot {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    animation: blink 1.6s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: .4; }
    50% { opacity: 1; }
}

/* ===== Chat Area ===== */
#chat {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    background: var(--bg);
}

#chat::-webkit-scrollbar { width: 4px; }
#chat::-webkit-scrollbar-thumb { background: rgba(204,0,0,0.3); border-radius: 10px; }

#messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* ===== Messages ===== */
.msg {
    display: flex;
    gap: 10px;
    max-width: 86%;
}

.msg.bot { align-self: flex-start; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    border: 1px solid var(--border-red);
}

.bubble {
    padding: 11px 15px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    line-height: 1.6;
    white-space: pre-wrap;
}

.bot .bubble {
    background: var(--bot-bubble);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.user .bubble {
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 4px 18px var(--accent-glow);
}

.time {
    font-size: 0.68rem;
    color: var(--text-dim);
    margin-top: 4px;
    display: block;
}

.msg.user .time { text-align: right; }

/* ===== Typing indicator ===== */
.typing {
    display: flex;
    gap: 5px;
    padding: 12px 18px !important;
}

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

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(.7); opacity: .4; }
    40% { transform: scale(1.1); opacity: 1; }
}

/* ===== Fade-in animation ===== */
.fade-in {
    animation: fadeSlide .3s ease forwards;
    opacity: 0;
}

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

/* ===== Shortcut chips ===== */
#shortcuts {
    padding: 8px 20px 6px;
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    justify-content: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.chip {
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all .2s ease;
    font-family: inherit;
}

.chip:hover {
    border-color: var(--accent);
    color: #fff;
    background: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 3px 12px var(--accent-glow);
}

/* ===== Footer / Input ===== */
footer {
    padding: 12px 20px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.input-bar {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 28px;
    padding: 6px 8px 6px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: border-color .2s, box-shadow .2s;
}

.input-bar:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

#user-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    padding: 10px 0;
    font-family: inherit;
    resize: none;
    height: auto;
    max-height: 120px;
    line-height: 1.5;
    overflow-y: auto;
}

#user-input::placeholder {
    color: var(--text-dim);
}

#send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all .2s;
    box-shadow: 0 3px 14px var(--accent-glow);
    flex-shrink: 0;
}

#send-btn:hover {
    transform: scale(1.1);
    background: var(--accent-light);
}

/* ===== Responsive ===== */
@media (max-width: 560px) {
    #app {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    #reg-card {
        margin: 16px;
        padding: 28px 22px 22px;
    }
}
