/* === Reset & Design Tokens (inspired by OpenClaw Control UI) === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #ff5c5c;
    --primary-dark: #e04545;
    --primary-light: #ff7070;
    --primary-subtle: rgba(255,92,92,0.1);
    --bg: #f8f9fa;
    --bg-accent: #f1f3f5;
    --bg-elevated: #fff;
    --bg-hover: #eceef0;
    --bg-dark: #0e1015;
    --bg-dark-accent: #13151b;
    --bg-dark-elevated: #191c24;
    --bg-dark-hover: #1f2330;
    --card: #fff;
    --card-border: #e5e5ea;
    --text: #3c3c43;
    --text-strong: #1a1a1e;
    --text-light: #8e8e93;
    --text-white: #f4f4f5;
    --border: #e5e5ea;
    --border-strong: #d1d1d6;
    --success: #22c55e;
    --success-subtle: rgba(34,197,94,0.1);
    --error: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 12px 28px rgba(0,0,0,0.08);
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    --font-mono: "Fira Code", "JetBrains Mono", "Consolas", monospace;
    --duration: 0.15s;
    --gradient: linear-gradient(135deg, #ff5c5c, #ff7070);
}
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Buttons === */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 24px; border: none; border-radius: var(--radius);
    font-size: 0.9rem; font-weight: 600; cursor: pointer;
    transition: all var(--duration); text-decoration: none; font-family: var(--font);
}
.btn:hover { text-decoration: none; }
.btn-primary, a.btn-primary {
    background: var(--primary); color: #fff;
    box-shadow: 0 2px 8px rgba(255,92,92,0.25);
}
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 4px 12px rgba(255,92,92,0.35); transform: translateY(-1px); }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-subtle); }
.btn-sm { padding: 6px 16px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* === Cards === */
.card {
    background: var(--card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 2rem;
}

/* === Hero Section === */
.hero { background: var(--gradient); color: #fff; padding: 5rem 2rem; text-align: center; }
.hero h1 { font-size: 3rem; margin-bottom: 1rem; font-weight: 800; }
.hero-title {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}
.hero-title-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.hero-title-logo img {
    display: block;
    height: 36px;
    width: auto;
}
.hero p { font-size: 1.2rem; opacity: 0.9; max-width: 600px; margin: 0 auto 2rem; }
.hero-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
}
.hero-cta {
    color: #fff;
    border-color: rgba(255,255,255,0.9);
    background: rgba(255,255,255,0.08);
}
.hero-forum-cta {
    color: #fff;
    border-color: rgba(255,255,255,0.55);
    background: rgba(0,0,0,0.12);
}
.hero-cta:hover {
    color: var(--text-strong);
    background: rgba(255,255,255,0.96);
    border-color: rgba(255,255,255,0.96);
    box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}
.hero-forum-cta:hover {
    color: var(--text-strong);
    background: rgba(255,255,255,0.88);
    border-color: rgba(255,255,255,0.88);
    box-shadow: 0 10px 24px rgba(0,0,0,0.12);
}
.hero-note {
    font-size: 0.92rem !important;
    opacity: 0.82;
    margin-top: 1rem !important;
    margin-bottom: 0 !important;
}

/* === Navbar === */
.navbar {
    background: var(--bg-elevated); border-bottom: 1px solid var(--border);
    padding: 0 2rem; height: 56px; display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 100;
}
.navbar-brand { display: flex; align-items: center; gap: 10px; font-size: 1.2rem; font-weight: 700; color: var(--primary); text-decoration: none; }
.navbar-brand:hover { text-decoration: none; }
.navbar-brand .logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 24px;
    font-size: 1.4rem;
    line-height: 1;
}
.navbar-brand .logo img {
    display: block;
    height: 24px;
    width: auto;
}
.navbar-links { display: flex; align-items: center; gap: 1rem; }
.navbar-links a { color: var(--text); font-size: 0.9rem; padding: 6px 12px; border-radius: var(--radius-sm); transition: background var(--duration), color var(--duration); }
.navbar-links .forum-link {
    color: var(--primary-dark);
    font-weight: 700;
    background: rgba(255,92,92,0.08);
    border: 1px solid rgba(255,92,92,0.18);
    box-shadow: 0 4px 12px rgba(255,92,92,0.08);
}
.navbar-links .forum-link:hover {
    background: rgba(255,92,92,0.14);
    color: var(--primary-dark);
    border-color: rgba(255,92,92,0.26);
}
.navbar-links a.btn-primary { color: #fff; }
.navbar-links a.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.navbar-links a:hover { background: var(--bg-hover); text-decoration: none; }

/* === Features Grid === */
.features { max-width: 1200px; margin: -3rem auto 4rem; padding: 0 2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.5rem; }
.feature-card { background: var(--card); border-radius: var(--radius-lg); padding: 1.5rem; border: 1px solid var(--border); transition: all var(--duration); }
.feature-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.feature-icon { font-size: 2rem; margin-bottom: 0.8rem; }
.feature-card h3 { font-size: 1rem; margin-bottom: 0.4rem; font-weight: 600; }
.feature-card p { font-size: 0.85rem; color: var(--text-light); }

/* === Auth Page === */
.auth-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg-accent); padding: 2rem; }
.auth-card { background: var(--card); border-radius: var(--radius-xl); padding: 3rem; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); }
.auth-card h2 { text-align: center; margin-bottom: 0.5rem; font-weight: 700; }
.auth-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}
.auth-title-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.auth-title-logo img {
    display: block;
    height: 28px;
    width: auto;
}
.auth-card .subtitle { text-align: center; color: var(--text-light); margin-bottom: 2rem; font-size: 0.88rem; }
.form-group { margin-bottom: 1.2rem; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.85rem; color: var(--text-strong); }
.form-group input {
    width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
    border-radius: var(--radius); font-size: 0.95rem; transition: all var(--duration);
    outline: none; background: var(--bg); font-family: var(--font);
}
.form-group input:focus { border-color: var(--primary); background: var(--bg-elevated); box-shadow: 0 0 0 3px rgba(255,92,92,0.1); }
.form-error { color: var(--error); font-size: 0.85rem; margin-top: 1rem; text-align: center; display: none; }

/* === Workstation Layout === */
.workstation { display: flex; height: 100vh; overflow: hidden; }

/* === Sidebar === */
.sidebar {
    width: 240px; background: var(--bg-elevated); color: var(--text);
    display: flex; flex-direction: column; flex-shrink: 0;
    border-right: 1px solid var(--border);
    transition: transform var(--duration), box-shadow var(--duration);
    z-index: 1100;
}
.sidebar-header {
    padding: 1.2rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 10px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand { min-width: 0; }
.sidebar-header h3 {
    display: flex; align-items: center; gap: 6px;
    font-size: 0.95rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text-strong);
    line-height: 1.2;
}
.sidebar-brand-logo {
    display: inline-flex; align-items: center; justify-content: center;
    line-height: 1; flex-shrink: 0;
}
.sidebar-brand-logo img {
    display: block; height: 20px; width: auto;
}
.sidebar-header p { font-size: 0.75rem; color: var(--text-light); margin-top: 2px; }
.sidebar-close {
    display: none; width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--card); color: var(--text-light); cursor: pointer; font-size: 1rem; flex-shrink: 0;
}
.sidebar-close:hover { color: var(--text-strong); border-color: var(--border-strong); background: var(--bg-hover); }
.sidebar-nav { flex: 1; padding: 0.6rem 0.5rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; color: var(--text-light);
    font-size: 0.85rem; font-weight: 600; border-radius: var(--radius);
    transition: all var(--duration); position: relative;
    border: 1px solid transparent;
}
.sidebar-nav a:hover {
    background: var(--bg-hover); color: var(--text-strong); text-decoration: none;
    border-color: rgba(0,0,0,0.04);
}
.sidebar-nav a.active {
    background: rgba(255,92,92,0.08); color: var(--primary);
    font-weight: 700; border-color: rgba(255,92,92,0.15);
}
.sidebar-nav a.active::before {
    content: ""; position: absolute; left: 0; top: 8px; bottom: 8px;
    width: 3px; border-radius: 999px;
    background: var(--primary); box-shadow: 0 0 10px rgba(255,92,92,0.4);
}
.sidebar-footer {
    padding: 0.8rem 1rem; border-top: 1px solid var(--border);
    font-size: 0.75rem; color: var(--text-light);
}
.sidebar-footer .credits { color: var(--success); font-weight: 600; }
.sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.42); backdrop-filter: blur(2px);
    opacity: 0; pointer-events: none; transition: opacity var(--duration); z-index: 1050;
}
.sidebar-backdrop.active { opacity: 1; pointer-events: auto; }
.mobile-sidebar-toggle {
    display: none; align-items: center; justify-content: center; gap: 6px;
    height: 36px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--border);
    background: var(--card); color: var(--text); font-size: 0.85rem; font-weight: 600; cursor: pointer;
}
.mobile-sidebar-toggle:hover { background: var(--bg-hover); }

.workspace-header {
    display: flex; align-items: center; gap: 12px; min-width: 0;
}
.workspace-header > div:last-child { min-width: 0; }

/* === Chat Main Area === */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg-accent); }
.chat-header {
    padding: 10px 20px; background: var(--bg-elevated);
    border-bottom: 1px solid var(--border); display: flex;
    align-items: center; justify-content: space-between; min-height: 48px;
}
.chat-header h3 { font-size: 0.95rem; font-weight: 600; color: var(--text-strong); }

/* === Messages === */
.chat-messages {
    flex: 1; overflow-y: auto; padding: 16px 16px 8px;
    display: flex; flex-direction: column; gap: 14px;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

.message {
    max-width: min(900px, calc(100% - 48px)); padding: 10px 14px;
    border-radius: var(--radius-lg); font-size: 14px;
    line-height: 1.65; word-wrap: break-word; overflow-wrap: break-word;
    animation: fadeIn 0.2s ease-out;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.message-user {
    align-self: flex-end;
    background: #fb923c1f;
    color: var(--text-strong);
    border: 1px solid #ea580c33;
}
.message-assistant {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.5);
    transition: background var(--duration);
}
.message-assistant { position: relative; }
.message-assistant:hover { background: var(--bg-hover); }
.chat-copy-btn {
    position: absolute; top: 6px; right: 6px;
    opacity: 0; pointer-events: none;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: var(--bg-accent); border: 1px solid var(--border);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: var(--text-light); transition: all var(--duration);
}
.message-assistant:hover .chat-copy-btn { opacity: 1; pointer-events: auto; }
.chat-copy-btn:hover { background: var(--bg-hover); color: var(--text-strong); border-color: var(--border-strong); }
.chat-copy-btn.copied { color: var(--success); }
.message-assistant pre {
    background: var(--bg-accent); border: 1px solid var(--border);
    border-radius: 8px; padding: 12px; overflow-x: auto; margin: 8px 0;
}
.message-assistant code { font-family: var(--font-mono); font-size: 13px; }
.message-assistant p { margin-bottom: 0.5rem; }
.message-assistant p:last-child { margin-bottom: 0; }
.message-assistant ul, .message-assistant ol { padding-left: 1.5rem; margin: 0.4rem 0; }
.message-assistant li { margin-bottom: 0.2rem; }
.message-assistant h1, .message-assistant h2, .message-assistant h3,
.message-assistant h4, .message-assistant h5, .message-assistant h6 {
    margin: 0.8rem 0 0.4rem; font-weight: 600;
}
.message-assistant blockquote {
    border-left: 3px solid var(--primary); margin: 0.5rem 0;
    padding: 0.3rem 0 0.3rem 1rem; color: var(--text-light);
}
.message-assistant a { color: var(--primary); }
.message-assistant table { border-collapse: collapse; margin: 0.5rem 0; width: 100%; font-size: 13px; }
.message-assistant th, .message-assistant td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.message-assistant th { background: var(--bg-accent); font-weight: 600; }

/* === Chat Input (OpenClaw compose style) === */
.chat-input-area {
    background: linear-gradient(to bottom, transparent, var(--bg-accent) 20%);
    padding: 12px 16px 10px; position: sticky; bottom: 0; z-index: 10;
}
.chat-input-wrapper {
    display: flex; flex-direction: column;
    max-width: 900px; margin: 0 auto;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 0;
    box-shadow: var(--shadow-md);
    transition: border-color var(--duration), box-shadow var(--duration);
}
.chat-input-wrapper:focus-within {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-lg);
}
.chat-input-wrapper textarea {
    width: 100%; padding: 14px 18px 8px; border: none;
    font-size: 14px; resize: none; outline: none;
    font-family: var(--font); min-height: 44px; max-height: 150px;
    line-height: 1.5; background: transparent; color: var(--text);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}
.chat-input-toolbar {
    display: flex; align-items: center; padding: 4px 10px 8px;
    border-top: 1px solid var(--border); margin: 0 12px;
}
.chat-input-toolbar-left { display: flex; gap: 2px; }
.chat-input-toolbar-right { display: flex; gap: 2px; margin-left: auto; }

.file-upload-label {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: var(--radius);
    background: transparent; border: none;
    cursor: pointer; font-size: 1.05rem; transition: all var(--duration);
    flex-shrink: 0; color: var(--text-light);
}
.file-upload-label:hover { background: var(--bg-hover); color: var(--text-strong); }

.send-btn {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff; border: none;
    font-size: 0.95rem; cursor: pointer; flex-shrink: 0;
    transition: all var(--duration); display: flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--primary-dark); box-shadow: 0 2px 10px rgba(255,92,92,0.3); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; box-shadow: none; }

/* === Typing Indicator === */
.typing-indicator {
    display: none; align-self: flex-start; padding: 10px 14px;
    background: var(--bg-elevated); border: 1px solid var(--border);
    border-radius: var(--radius-lg); gap: 5px;
}
.typing-indicator.active { display: flex; }
.typing-dot {
    width: 6px; height: 6px; background: var(--text-light);
    border-radius: 50%; animation: typing 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { transform: translateY(0); opacity: 0.3; } 30% { transform: translateY(-4px); opacity: 1; } }

/* === Setup Agent Page === */
.setup-container { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 2rem; }
.setup-card { text-align: center; max-width: 480px; }
.setup-card h2 { margin-bottom: 1rem; font-weight: 700; }
.setup-card p { color: var(--text-light); margin-bottom: 2rem; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.setup-status { font-size: 0.9rem; color: var(--text-light); margin-top: 1rem; }

/* === Config Page === */
.config-container { max-width: 700px; width: 100%; margin: 2rem auto; padding: 0 2rem; }
.config-section { margin-bottom: 2rem; }
.config-section h3 { margin-bottom: 1rem; padding-bottom: 0.5rem; border-bottom: 1.5px solid var(--border); font-weight: 600; }

/* === Utility === */
.container { max-width: 1200px; margin: 0 auto; padding: 0 2rem; }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-4 { margin-top: 2rem; }
.hidden { display: none; }

/* === Footer === */
.footer { text-align: center; padding: 2rem; color: var(--text-light); font-size: 0.85rem; }

@media (max-width: 768px) {
    .workstation { position: relative; }
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; width: min(280px, 82vw);
        transform: translateX(-100%); box-shadow: 0 18px 48px rgba(15, 23, 42, 0.2);
    }
    .workstation.sidebar-open .sidebar { transform: translateX(0); }
    .workstation.sidebar-open { overflow: hidden; }
    .sidebar-close, .mobile-sidebar-toggle { display: inline-flex; }
    .chat-main { width: 100%; }
    .chat-header { padding: 10px 14px; gap: 10px; }
    .workspace-header {
        flex-wrap: wrap;
        align-items: flex-start;
        gap: 10px;
    }
    .workspace-header > div:last-child {
        width: 100%;
    }
}
