/* ============================================================
   Ghostwheel Mini App — Styles
   Clean dark UI optimized for Telegram Web App
   ============================================================ */

:root {
    --bg: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --bg-hover: #2a2a2a;
    --text: #e8e8e8;
    --text-secondary: #888;
    --text-muted: #555;
    --accent: #7c6df0;
    --accent-dim: rgba(124, 109, 240, 0.15);
    --accent-glow: rgba(124, 109, 240, 0.3);
    --green: #4ade80;
    --yellow: #facc15;
    --red: #f87171;
    --border: #2a2a2a;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow: 0 4px 24px rgba(0,0,0,0.4);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* Splash Screen */

.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    z-index: 1000;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.splash.fade-out {
    opacity: 0;
    transform: scale(0.95);
    pointer-events: none;
}

.splash-icon {
    font-size: 64px;
    margin-bottom: 16px;
    animation: pulse 2s ease-in-out infinite;
}

.splash-text {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.splash-sub {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 14px;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.05); opacity: 0.8; }
}

/* App Layout */

.app, .dev-panel {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

/* Header */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-icon { font-size: 22px; }

.header-title {
    font-size: 17px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s;
}

.status-dot.connected { background: var(--green); }
.status-dot.connecting { background: var(--yellow); animation: blink 1s infinite; }
.status-dot.error { background: var(--red); }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-xs);
    transition: background 0.15s;
}

.btn-icon:hover { background: var(--bg-hover); }
.btn-icon:active { transform: scale(0.92); }

/* Menu */

.menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(0,0,0,0.4);
    animation: fadeIn 0.15s ease;
}

.menu-panel {
    position: absolute;
    top: 52px;
    right: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 180px;
    padding: 6px;
    box-shadow: var(--shadow);
    animation: slideDown 0.15s ease;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    color: var(--text);
    font-size: 14px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background 0.15s;
    text-align: left;
}

.menu-item:hover { background: var(--bg-hover); }
.menu-muted { color: var(--text-secondary); }
.menu-icon { font-size: 16px; }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* Chat Area */

.chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    gap: 8px;
}

.welcome-icon { font-size: 48px; margin-bottom: 8px; }

.welcome-title {
    font-size: 22px;
    font-weight: 600;
}

.welcome-sub {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
}

/* Messages */

.message {
    display: flex;
    margin-bottom: 12px;
    animation: msgIn 0.2s ease;
}

.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 15px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message.user .message-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: var(--bg-tertiary);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.message-bubble pre {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.4;
}

.message-bubble code {
    font-family: var(--font-mono);
    font-size: 13px;
    background: rgba(255,255,255,0.08);
    padding: 1px 5px;
    border-radius: 4px;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; }

.tool-call {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin: 6px 0;
    background: var(--accent-dim);
    border-left: 3px solid var(--accent);
    border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.tool-call .tool-name {
    color: var(--accent);
    font-weight: 600;
    font-family: var(--font-mono);
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typing Indicator */

.typing {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    flex-shrink: 0;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.typing-text {
    font-size: 13px;
    color: var(--text-muted);
}

/* Input Area */

.input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + var(--safe-bottom));
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s;
}

.input-row:focus-within {
    border-color: var(--accent);
}

.input-field {
    flex: 1;
    border: none;
    background: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
    padding: 8px 0;
}

.input-field::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.1s;
}

.btn-send:disabled {
    opacity: 0.3;
    cursor: default;
}

.btn-send:not(:disabled):active {
    transform: scale(0.9);
}

/* Dev Mode */

.dev-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.dev-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

.dev-input, .dev-textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.dev-input:focus, .dev-textarea:focus {
    border-color: var(--accent);
}

.dev-textarea {
    resize: vertical;
    font-family: var(--font-mono);
    line-height: 1.5;
}

.btn-primary {
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.4; cursor: default; }

.dev-log {
    margin-top: 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}

.dev-log .chunk { color: var(--text); }
.dev-log .tool { color: var(--accent); }
.dev-log .error { color: var(--red); }
.dev-log .done { color: var(--green); font-weight: 600; }

/* Scrollbar */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Telegram Theme Integration */

body.tg-theme {
    --bg: var(--tg-theme-bg-color, #0f0f0f);
    --bg-secondary: var(--tg-theme-secondary-bg-color, #1a1a1a);
    --text: var(--tg-theme-text-color, #e8e8e8);
    --text-secondary: var(--tg-theme-hint-color, #888);
    --accent: var(--tg-theme-button-color, #7c6df0);
}
