/* ════════════════════════════════════════════════════════════════
   TARA — Design System (v2)
   Minimal, ChatGPT/Grok-inspired. Mono-grayscale canvas with ember
   used only as a brand accent (send button, brand mark, link hover).
   ════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    /* ─── Canvas ─── */
    --bg:           #0F1117;
    --bg-elev-1:    #15181F;
    --bg-elev-2:    #1E222C;
    --bg-elev-3:    #2A2F3B;

    /* ─── Text ─── */
    --text:         #ECEDF1;
    --text-mute:    #9CA3AF;
    --text-faint:   #6B7280;

    /* ─── Border ─── */
    --border:       rgba(255, 255, 255, 0.07);
    --border-strong:rgba(255, 255, 255, 0.13);

    /* ─── Brand accent (used sparingly) ─── */
    --ember:        #E85D3A;
    --ember-hover:  #FF7B5C;
    --ember-glow:   rgba(232, 93, 58, 0.20);

    /* ─── Status ─── */
    --danger:       #F87171;
    --danger-bg:    rgba(248, 113, 113, 0.10);

    /* ─── Radii ─── */
    --r-sm:  8px;
    --r-md:  12px;
    --r-lg:  18px;
    --r-xl:  24px;
    --r-full:9999px;

    /* ─── Motion ─── */
    --ease:     cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out: cubic-bezier(0.34, 1.56, 0.64, 1);

    /* ─── Layout ─── */
    --col-max:   780px;
    --header-h:  56px;
    --safe-bot:  env(safe-area-inset-bottom);
}

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

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

a       { color: var(--text); text-decoration: none; }
a:hover { color: var(--ember-hover); }

button {
    font-family: inherit;
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
}

/* ════════════════════════════════════════════════════════════════
   PAGE SHELL (standalone /index.php)
   ════════════════════════════════════════════════════════════════ */
.tara-app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    width: 100%;
}

/* ─── Top bar ───────────────────────────────────────────────── */
.tara-topbar {
    height: var(--header-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    z-index: 10;
}

.tara-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
}
.tara-brand-mark {
    width: 28px;
    height: 28px;
    border-radius: var(--r-full);
    overflow: hidden;
    background: var(--bg-elev-2);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}
.tara-brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.tara-brand-tag {
    color: var(--text-faint);
    font-size: 12px;
    font-weight: 500;
    margin-left: 2px;
}

.tara-topbar-spacer { flex: 1; }

.tara-iconbtn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-sm);
    display: grid;
    place-items: center;
    color: var(--text-mute);
    transition: background 0.15s, color 0.15s;
}
.tara-iconbtn:hover {
    background: var(--bg-elev-2);
    color: var(--text);
}
.tara-iconbtn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tara-pillbtn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    color: var(--text-mute);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tara-pillbtn:hover {
    background: var(--bg-elev-2);
    color: var(--text);
    border-color: var(--border-strong);
}
.tara-pillbtn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ─── Main scroll region ────────────────────────────────────── */
.tara-main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    position: relative;
}
.tara-main::-webkit-scrollbar      { width: 10px; }
.tara-main::-webkit-scrollbar-track{ background: transparent; }
.tara-main::-webkit-scrollbar-thumb{
    background: var(--bg-elev-3);
    border-radius: var(--r-full);
    border: 2px solid var(--bg);
}

.tara-col {
    max-width: var(--col-max);
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 0;
}

/* ─── Welcome / empty state ─────────────────────────────────── */
.tara-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(100dvh - var(--header-h) - 200px);
    text-align: center;
    padding: 40px 20px;
}
.tara-welcome-logo {
    width: 72px;
    height: 72px;
    margin-bottom: 24px;
    filter: drop-shadow(0 12px 32px var(--ember-glow));
    animation: tara-float 4s var(--ease) infinite alternate;
}
@keyframes tara-float {
    from { transform: translateY(0); }
    to   { transform: translateY(-6px); }
}
.tara-welcome h1 {
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}
.tara-welcome p {
    color: var(--text-mute);
    font-size: 15px;
    margin-bottom: 32px;
}
.tara-suggestions {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    width: 100%;
    max-width: 580px;
}
.tara-suggestion {
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px 16px;
    text-align: left;
    transition: background 0.15s, border-color 0.15s, transform 0.15s var(--ease);
}
.tara-suggestion:hover {
    background: var(--bg-elev-2);
    border-color: var(--border-strong);
    transform: translateY(-1px);
}
.tara-suggestion-title {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 2px;
}
.tara-suggestion-sub {
    color: var(--text-faint);
    font-size: 13px;
}
@media (max-width: 520px) {
    .tara-suggestions { grid-template-columns: 1fr; }
}

/* ─── Message thread ────────────────────────────────────────── */
.tara-thread {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding-bottom: 32px;
}

.tara-msg {
    display: flex;
    flex-direction: column;
    animation: tara-fade-in 0.25s var(--ease);
}
@keyframes tara-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

.tara-msg.user {
    align-items: flex-end;
}
.tara-msg.user .tara-msg-content {
    background: var(--bg-elev-2);
    border-radius: var(--r-lg);
    border-bottom-right-radius: 6px;
    padding: 11px 16px;
    max-width: 80%;
    color: var(--text);
}

.tara-msg.assistant {
    align-items: flex-start;
}
.tara-msg.assistant .tara-msg-content {
    color: var(--text);
    padding-left: 2px;
    max-width: 100%;
    width: 100%;
}

.tara-msg-content { word-wrap: break-word; overflow-wrap: break-word; }
.tara-msg-content p             { margin: 0; }
.tara-msg-content p + p         { margin-top: 12px; }
.tara-msg-content ul,
.tara-msg-content ol            { margin: 8px 0; padding-left: 22px; }
.tara-msg-content li            { margin: 2px 0; }
.tara-msg-content code          {
    background: var(--bg-elev-2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 0.88em;
    color: #FFD4B8;
}
.tara-msg-content pre           {
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: var(--r-md);
    overflow-x: auto;
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.55;
}
.tara-msg-content pre code      {
    background: transparent;
    padding: 0;
    color: var(--text);
}
.tara-msg-content a             {
    color: var(--ember-hover);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.tara-msg-content strong        { font-weight: 600; color: var(--text); }

/* Inline streaming cursor — appended at the end of the last block */
.tara-cursor-inline {
    display: inline-block;
    width: 8px;
    height: 1em;
    vertical-align: -2px;
    margin-left: 2px;
    background: currentColor;
    opacity: 0.55;
    animation: tara-blink 0.9s steps(1) infinite;
}
@keyframes tara-blink { 50% { opacity: 0; } }

/* Initial "thinking" dot (before first token arrives) */
.tara-thinking {
    display: inline-flex;
    align-items: center;
    height: 22px;
}
.tara-thinking::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-mute);
    animation: tara-pulse-dot 1.2s var(--ease) infinite;
}
@keyframes tara-pulse-dot {
    0%, 100% { transform: scale(1);   opacity: 0.4; }
    50%      { transform: scale(1.5); opacity: 1;   }
}

/* Assistant message tools (copy etc.) revealed on hover */
.tara-msg-tools {
    margin-top: 6px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
}
.tara-msg.assistant:hover .tara-msg-tools,
.tara-msg-tools.tara-revealed { opacity: 1; }
.tara-tool-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    display: grid;
    place-items: center;
    color: var(--text-faint);
    transition: background 0.15s, color 0.15s;
}
.tara-tool-btn:hover {
    background: var(--bg-elev-2);
    color: var(--text);
}
.tara-tool-btn svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Error message variant */
.tara-msg.error .tara-msg-content {
    color: var(--danger);
    background: var(--danger-bg);
    border-radius: var(--r-md);
    padding: 10px 14px;
    border: 1px solid rgba(248, 113, 113, 0.20);
}

/* ─── Bottom composer ───────────────────────────────────────── */
.tara-composer-wrap {
    flex-shrink: 0;
    background: linear-gradient(to top, var(--bg) 60%, rgba(15, 17, 23, 0));
    padding: 12px 16px 6px;
    position: relative;
    z-index: 10;
}
.tara-composer {
    max-width: var(--col-max);
    margin: 0 auto;
    background: var(--bg-elev-1);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: 8px 8px 8px 18px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.tara-composer:focus-within {
    border-color: var(--border-strong);
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.03);
}
.tara-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font: inherit;
    font-size: 15px;
    line-height: 1.55;
    resize: none;
    min-height: 30px;
    max-height: 200px;
    padding: 8px 0;
}
.tara-textarea::placeholder { color: var(--text-faint); }

.tara-send {
    width: 36px;
    height: 36px;
    border-radius: var(--r-full);
    background: var(--ember);
    color: #fff;
    display: grid;
    place-items: center;
    flex-shrink: 0;
    transition: background 0.15s, transform 0.15s var(--ease-out), opacity 0.15s;
}
.tara-send:hover:not(:disabled) { background: var(--ember-hover); }
.tara-send:active { transform: scale(0.94); }
.tara-send:disabled {
    background: var(--bg-elev-3);
    color: var(--text-faint);
    cursor: not-allowed;
}
.tara-send svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: currentColor;
}

/* Send button morphs into a "stop" button while streaming */
.tara-send.streaming {
    background: var(--text);
    color: var(--bg);
}
.tara-send.streaming:hover { background: var(--text-mute); }

.tara-footnote {
    max-width: var(--col-max);
    margin: 6px auto 0;
    text-align: center;
    color: var(--text-faint);
    font-size: 11px;
    line-height: 1.5;
}

/* ─── Page footer (very bottom of the page) ─────────────────── */
.tara-page-footer {
    flex-shrink: 0;
    text-align: center;
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-faint);
    background: var(--bg);
    padding: 8px 16px calc(10px + var(--safe-bot));
    border-top: 1px solid var(--border);
}
.tara-page-footer a {
    color: var(--text-mute);
    text-decoration: none;
}
.tara-page-footer a:hover {
    color: var(--ember-hover);
    text-decoration: underline;
}
.tara-widget .tara-page-footer { display: none; }

/* ════════════════════════════════════════════════════════════════
   FLOATING WIDGET (drops on any other Tratok page)
   ════════════════════════════════════════════════════════════════ */
.tara-widget {
    position: fixed;
    bottom: calc(20px + var(--safe-bot));
    right: 20px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, sans-serif;
}

.tara-widget-bubble {
    width: 56px;
    height: 56px;
    border-radius: var(--r-full);
    background: var(--ember);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 36px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.05);
    transition: transform 0.2s var(--ease-out), background 0.15s;
}
.tara-widget-bubble:hover {
    transform: scale(1.06);
    background: var(--ember-hover);
}
.tara-widget-bubble svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tara-widget-panel {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: min(400px, calc(100vw - 32px));
    height: min(620px, calc(100dvh - 110px));
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: tara-pop 0.24s var(--ease-out);
}
@keyframes tara-pop {
    from { opacity: 0; transform: scale(0.92) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
.tara-widget-panel.hidden { display: none; }

.tara-widget .tara-app {
    height: 100%;
}

/* Mobile widget = fullscreen */
@media (max-width: 520px) {
    .tara-widget-panel {
        position: fixed;
        inset: 0;
        width: 100vw;
        height: 100dvh;
        border-radius: 0;
    }
}

/* ─── Smaller welcome layout inside the widget ─────────────── */
.tara-widget .tara-welcome {
    min-height: 0;
    padding: 28px 20px 8px;
}
.tara-widget .tara-welcome-logo { width: 54px; height: 54px; margin-bottom: 16px; }
.tara-widget .tara-welcome h1   { font-size: 20px; }
.tara-widget .tara-welcome p    { font-size: 14px; margin-bottom: 18px; }
.tara-widget .tara-suggestions  { grid-template-columns: 1fr; gap: 8px; }
.tara-widget .tara-suggestion   { padding: 10px 12px; }
.tara-widget .tara-col          { padding: 16px 16px 0; }
.tara-widget .tara-composer-wrap{ padding: 10px 12px calc(10px + var(--safe-bot)); }
.tara-widget .tara-footnote     { display: none; }
